~kernel/entry.asm
.asm
Assembly
(text/assembly)
bits 32

extern kearly
extern kmain

extern irq_dispatcher_c
extern pic_send_eoi

; void outb(uint16, uint8)
global outb
outb:
  out dx, al
  ret

; void set_cursor_pos(int32, int32)
global set_cursor_pos
set_cursor_pos:
  push    ebp
  mov     ebp, esp

  mov     eax, dword [ebp + 8]    ; eax = row
  mov     ebx, 80
  imul    eax, ebx                ; eax = row * 80
  add     eax, dword [ebp + 12]   ; eax += col
  mov     bx, ax                  ; bx = position (16-bit)

  ; outb(0x3D4, 0x0E);
  mov     dx, 0x3D4
  mov     al, 0x0E
  out     dx, al

  ; outb(0x3D5, (position >> 8) & 0xFF);
  mov     dx, 0x3D5
  mov     al, bh
  out     dx, al

  ; outb(0x3D4, 0x0F);
  mov     dx, 0x3D4
  mov     al, 0x0F
  out     dx, al

  ; outb(0x3D5, position & 0xFF);
  mov     dx, 0x3D5
  mov     al, bl
  out     dx, al

  mov     esp, ebp
  pop     ebp
  ret

; void hide_cursor(void)
global hide_cursor
hide_cursor:
  ; Read: write index 0x0A, then write data with bit 5 set
  ; For simplicity we don't read current value; we set start = 0x20 (disabled)
  mov     dx, 0x3D4
  mov     al, 0x0A
  out     dx, al

  mov     dx, 0x3D5
  mov     al, 0x20   ; set bit 5 to disable cursor
  out     dx, al

  ret

; void show_cursor(void)
global show_cursor
show_cursor:
  ; Restore a typical cursor shape: start = 0 (scanline start)
  mov     dx, 0x3D4
  mov     al, 0x0A
  out     dx, al

  mov     dx, 0x3D5
  mov     al, 0x00    ; cursor start = 0
  out     dx, al

  ; set cursor end (e.g., 15)
  mov     dx, 0x3D4
  mov     al, 0x0B
  out     dx, al

  mov     dx, 0x3D5
  mov     al, 0x0F  ; cursor end = 15 (typical)
  out     dx, al

  ret

section .text

global irq_common_entry
irq_common_entry:
    pushad
    push eax
    call irq_dispatcher_c
    add  esp, 4
    popad
    ret

global irq1_stub
irq1_stub:
    cli
    push byte 1
    call irq_common_entry
    push byte 1
    call pic_send_eoi
    add  esp, 4
    iret

section .entry

; void start()
global _start
_start:
	mov esp, kernelStackStart
	
	push eax  ; video mode
	push ebx  ; memory map
	push ecx  ; number of lines printed
	
	call kearly
	call kmain

	.hang:
		cli
		hlt
		jmp .hang

align 16
kernelStackEnd:
	times 16384 db 0
kernelStackStart:

section .magic

global crystalOSMagic
crystalOSMagic: db "123113371338"

global crystalOSVersion
crystalOSVersion: db "0.1.0"