summaryrefslogtreecommitdiff
path: root/arch/i386/kernel
diff options
context:
space:
mode:
authorDanny Holman <dholman@gymli.org>2024-02-16 12:43:03 -0600
committerDanny Holman <dholman@gymli.org>2024-02-16 12:43:03 -0600
commitd0eef864dad134c482f853df5ef70caf522d3e9e (patch)
treed74c56d15463c56ec9670ca7f604805f92487f58 /arch/i386/kernel
parent5c8265d9634836217f1a814ee2b56942e06259a4 (diff)
arch: i386: add operations to control PIT timer
Add a set of functions that control the programmable interrupt timer. This will be used as the primary means of preemption on this architecture. Signed-off-by: Danny Holman <dholman@gymli.org>
Diffstat (limited to 'arch/i386/kernel')
-rw-r--r--arch/i386/kernel/timer.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/arch/i386/kernel/timer.c b/arch/i386/kernel/timer.c
new file mode 100644
index 0000000..9e53fbd
--- /dev/null
+++ b/arch/i386/kernel/timer.c
@@ -0,0 +1,29 @@
+#include <kernel/timer.h>
+#include <kernel/asm.h>
+#include <kernel/pic.h>
+#include <kernel/sched.h>
+
+static uint32_t num_ticks = 0;
+
+void timer_handler(struct isr_frame *frame) {
+ num_ticks++;
+ if (num_ticks == 3) {
+ num_ticks = 0;
+ //schedule_next();
+ }
+}
+
+void timer_init(void) {
+ asm __volatile__("cli");
+ int divisor = 1193182 / 100;
+ outb(0x43, 0x34);
+ outb(0x40, divisor && 0xFF);
+ outb(0x40, divisor && 0xFF00 >> 8);
+ asm __volatile__("sti");
+
+ //uint8_t read = 0;
+ //outb(0x43, 0xE2);
+ //read = inb(0x40);
+
+ register_irq_handler(0, timer_handler);
+}