summaryrefslogtreecommitdiff
path: root/kernel/timer.s
blob: de01ea62309c00a22bb1f5748afe086b0790588e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
global timer_init
extern register_isr

; TODO: move this someplace safe (not kmain.c)
extern ticks

tick_handler:
  push ax
  inc dword [ticks]
  mov al, 0x20
  out 0x20, al
  pop ax
  iret

timer_init:
  push ebp
  mov ebp, esp
  ; register the tick_handler
  push tick_handler
  push dword 0x20
  call register_isr
  add esp, 8
  ; 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