From f6cdc3005df1942024e5c9ba5418d124788dfa76 Mon Sep 17 00:00:00 2001 From: Julien CLEMENT Date: Mon, 26 Jul 2021 14:15:21 +0200 Subject: [PATCH] feat(pit): add pit initialization and handler Signed-off-by: Julien CLEMENT --- k/events/idt.c | 4 +--- k/events/pic/pic.c | 1 + k/events/pic/pit.c | 14 ++++++++++++++ k/events/pic/pit.h | 10 +++++++++- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/k/events/idt.c b/k/events/idt.c index 69f2176..179018a 100644 --- a/k/events/idt.c +++ b/k/events/idt.c @@ -46,8 +46,6 @@ static struct idt_entry_descriptor idt_entries_descriptors[IDT_NB_ENTRIES] = { void interrupt_handler(struct isr_param *isr_param) { - printf("Oh no %d!\r\n", isr_param->int_vector); - switch (isr_param->int_vector) { case PIT_INT_VECTOR: @@ -58,7 +56,7 @@ void interrupt_handler(struct isr_param *isr_param) break; } - if (isr_param->int_vector > IDT_RESERVED_ENTRIES + if (isr_param->int_vector >= IDT_RESERVED_ENTRIES && isr_param->int_vector < IDT_RESERVED_ENTRIES + 16) acknowledge(isr_param->int_vector); } diff --git a/k/events/pic/pic.c b/k/events/pic/pic.c index 47ec9cb..1ade6de 100644 --- a/k/events/pic/pic.c +++ b/k/events/pic/pic.c @@ -44,6 +44,7 @@ void init_pic(void) send_icw4(); mask_irqs(); init_keyboard(); + init_pit(); asm volatile("sti"); } diff --git a/k/events/pic/pit.c b/k/events/pic/pit.c index d0510d1..bc48849 100644 --- a/k/events/pic/pit.c +++ b/k/events/pic/pit.c @@ -1,9 +1,23 @@ #include "pit.h" +#include "io.h" +#include "stdio.h" + +static unsigned long ticks = 0; void pit_handler(void) { + ++ticks; } unsigned long gettick(void) { + return ticks; +} + +void init_pit(void) +{ + outb(PIT_CONTROL_REG, PIT_MODE_2 | PIT_RW_LSB | PIT_RW_MSB); + + outb(PIT_COUNTER_0, PIT_DIVIDER & 0xff); + outb(PIT_COUNTER_0, PIT_DIVIDER >> 8); } diff --git a/k/events/pic/pit.h b/k/events/pic/pit.h index 348d885..200cec1 100644 --- a/k/events/pic/pit.h +++ b/k/events/pic/pit.h @@ -4,9 +4,17 @@ #define PIT_COUNTER_0 0x40 #define PIT_COUNTER_1 0x41 #define PIT_COUNTER_2 0x42 -#define PIT_CONTROL_REGISTER 0x43 +#define PIT_CONTROL_REG 0x43 + +#define PIT_MODE_2 (0x2 << 1) + +#define PIT_RW_LSB (0x1 << 4) +#define PIT_RW_MSB (0x1 << 5) + +#define PIT_DIVIDER 11931 void pit_handler(void); unsigned long gettick(void); +void init_pit(void); #endif /* !PIT_H */