summaryrefslogtreecommitdiff
path: root/kernel/timer.s
diff options
context:
space:
mode:
authorJake Mannens <jake72360@gmail.com>2018-06-19 05:22:54 +1000
committerJake Mannens <jake72360@gmail.com>2018-06-19 05:22:54 +1000
commitf6858b7333139441215e83e070e098bf09056762 (patch)
tree65b7ad0680174bc5331a5db8505be4213e6cc736 /kernel/timer.s
parent627d2d0c0ee5147f53fdba8fc1f9108f8edeb8f3 (diff)
Added foundation code to initialize the PIT and create a 10ms jiffies
counter.
Diffstat (limited to 'kernel/timer.s')
-rw-r--r--kernel/timer.s34
1 files changed, 34 insertions, 0 deletions
diff --git a/kernel/timer.s b/kernel/timer.s
new file mode 100644
index 0000000..de01ea6
--- /dev/null
+++ b/kernel/timer.s
@@ -0,0 +1,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