diff options
Diffstat (limited to 'arch')
-rw-r--r-- | arch/i386/include/kernel/timer.h | 9 | ||||
-rw-r--r-- | arch/i386/kernel/timer.c | 29 |
2 files changed, 38 insertions, 0 deletions
diff --git a/arch/i386/include/kernel/timer.h b/arch/i386/include/kernel/timer.h new file mode 100644 index 0000000..0d90369 --- /dev/null +++ b/arch/i386/include/kernel/timer.h @@ -0,0 +1,9 @@ +#ifndef I386_TIMER_H +#define I386_TIMER_H + +#include <kernel/isr.h> + +void timer_handler(struct isr_frame *frame); +void timer_init(void); + +#endif 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); +} |