~kernel/kernel.cr
.cr
Crystal
(text/x-crystal)
lib LibBootstrap
  @[Packed]
  struct StartInfo
    multiboot_ptr : UInt32
    end_of_kernel : UInt32
  end
end

fun kearly(info_ptr: LibBootstrap::StartInfo*)

  # Get the startup info
  info = info_ptr.value

  # Initialize stuff
  # GDT.init
  # Heap.init info.end_of_kernel
  # PIC.remap
  # PIC.enable
  # IDT.init
end

def clear_screen
  video_memory = Pointer(UInt8).new(0xB8000)
  screen_size = 80 * 25

  i = 0
  while i < screen_size
    video_memory[2 * i] = ' '.ord.to_u8
    video_memory[2 * i + 1] = 0x07_u8
    i += 1
  end
end

fun kmain
  # IDT.enable_interrupts
  # kprint "Hello from Fluorite."

  address = Pointer(UInt8).new(0xb8000)

  string = "[CrystalOS Kernel] Hello from Crystal"
  # string_size = 33 # string.size

  # clear_screen

  # Loop over each character in the string
  # i = 0
  # while i < string.size
  #   # Write the character
  #   address.value = string[i].to_u8
  #   address += 1
  #   # Write the attribute byte
  #   address.value = 0xA0.to_u8
  #   address += 1
  #   i += 1
  # end

  # prevent bootloader to take back
  # while true
  #   asm("cli")
  #   asm("hlt")
  # end
end