global ticks global timer_init extern register_isr extern sched_tick ticks: dd 0 tick_handler: pusha ; save the data segment selectors mov ax, ds push ax ; switch to kernel data segments mov ax, 0x10 mov ds, ax mov es, ax mov fs, ax mov gs, ax ; handle the timer tick inc dword [ticks] mov al, 0x20 out 0x20, al ; call the scheduler call sched_tick ; restore the data segment selectors pop ax mov ds, ax mov es, ax mov fs, ax mov gs, ax popa iret timer_init: push ebp mov ebp, esp ; register the tick_handler push tick_handler push dword 0 push dword 0x20 call register_isr add esp, 12 ; initialize the pit mov ax, 0x36 out 0x43, al mov ax, 0x2E9C ; 10ms tick interval out 0x40, al mov al, ah out 0x40, al in al, 0x21 and al, 0xFE out 0x21, al pop ebp ret