From 5064efa10135a2060f71ce45fbcab7525d740bc8 Mon Sep 17 00:00:00 2001 From: Julien CLEMENT Date: Mon, 26 Jul 2021 11:17:52 +0200 Subject: [PATCH] feat(pit): add pit isr, empty handler and unmasked pit irq Signed-off-by: Julien CLEMENT --- k/Makefile | 1 + k/events/idt.c | 8 ++++++-- k/events/idt.h | 1 + k/events/isr.S | 1 + k/events/isr.h | 1 + k/events/pic/pic.c | 3 ++- k/events/pic/pic.h | 9 +++++++++ k/events/pic/pit.c | 9 +++++++++ k/events/pic/pit.h | 12 ++++++++++++ k/k.c | 2 -- 10 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 k/events/pic/pit.c create mode 100644 k/events/pic/pit.h diff --git a/k/Makefile b/k/Makefile index 4020c65..c3965ea 100644 --- a/k/Makefile +++ b/k/Makefile @@ -36,6 +36,7 @@ OBJS = \ events/isr.o \ events/pic/pic.o \ events/pic/keyboard.o \ + events/pic/pit.o \ utils/ring_buffer.o diff --git a/k/events/idt.c b/k/events/idt.c index 735cc24..69f2176 100644 --- a/k/events/idt.c +++ b/k/events/idt.c @@ -2,6 +2,7 @@ #include "stdio.h" #include "pic/pic.h" #include "pic/keyboard.h" +#include "pic/pit.h" #include "io.h" static struct idt idt = { 0 }; @@ -39,8 +40,8 @@ static struct idt_entry_descriptor idt_entries_descriptors[IDT_NB_ENTRIES] = { {0, {0, 0, 0}, 0}, // 29 {0, {0, 0, 0}, 0}, // 30 {0, {0, 0, 0}, 0}, // 31 - {0, {0, 0, 0}, 0}, // 32 - {(uint32_t)&isr_keyboard, KERNEL_CS_SEGMENT_SELECTOR, INTERRUPT_TYPE}, // 33 + {(uint32_t)&isr_pit, KERNEL_CS_SEGMENT_SELECTOR, INTERRUPT_TYPE}, // 32 + {(uint32_t)&isr_keyboard, KERNEL_CS_SEGMENT_SELECTOR, INTERRUPT_TYPE} // 33 }; void interrupt_handler(struct isr_param *isr_param) @@ -49,6 +50,9 @@ void interrupt_handler(struct isr_param *isr_param) switch (isr_param->int_vector) { + case PIT_INT_VECTOR: + pit_handler(); + break; case KEYBOARD_INT_VECTOR: keyboard_handler(); break; diff --git a/k/events/idt.h b/k/events/idt.h index b50948f..3ce1c25 100644 --- a/k/events/idt.h +++ b/k/events/idt.h @@ -12,6 +12,7 @@ #define INTERRUPT_TYPE 0x6 #define TRAP_TYPE 0x7 +#define PIT_INT_VECTOR 32 #define KEYBOARD_INT_VECTOR 33 struct idt_entry diff --git a/k/events/isr.S b/k/events/isr.S index 66e02c5..36f31af 100644 --- a/k/events/isr.S +++ b/k/events/isr.S @@ -44,4 +44,5 @@ isr_callback_no_error(isr_machine_check, 18) isr_callback_no_error(isr_simd_floating_point_exception, 19) isr_callback_no_error(isr_virtualization_exception, 20) isr_callback_error(isr_control_protection_exception, 21) +isr_callback_no_error(isr_pit, 32) isr_callback_no_error(isr_keyboard, 33) diff --git a/k/events/isr.h b/k/events/isr.h index a831474..34943cb 100644 --- a/k/events/isr.h +++ b/k/events/isr.h @@ -28,6 +28,7 @@ void isr_machine_check(void); void isr_simd_floating_point_exception(void); void isr_virtualization_exception(void); void isr_control_protection_exception(void); +void isr_pit(void); void isr_keyboard(void); #endif /* !ISR_H */ diff --git a/k/events/pic/pic.c b/k/events/pic/pic.c index 55ce695..47ec9cb 100644 --- a/k/events/pic/pic.c +++ b/k/events/pic/pic.c @@ -31,7 +31,8 @@ static void send_icw4(void) static void mask_irqs(void) { - outb(MASTER_PIC_B, 0xff ^ 0x2); + outb(MASTER_PIC_B, IRQ2_PIN | IRQ3_PIN | IRQ4_PIN | IRQ5_PIN | IRQ6_PIN + | IRQ7_PIN); outb(SLAVE_PIC_B, 0xff); } diff --git a/k/events/pic/pic.h b/k/events/pic/pic.h index 40b44cc..c0f5afc 100644 --- a/k/events/pic/pic.h +++ b/k/events/pic/pic.h @@ -8,6 +8,15 @@ #define ICW1 0x11 +#define IRQ0_PIN 0x1 +#define IRQ1_PIN 0x2 +#define IRQ2_PIN 0x4 +#define IRQ3_PIN 0x8 +#define IRQ4_PIN 0x10 +#define IRQ5_PIN 0x20 +#define IRQ6_PIN 0x40 +#define IRQ7_PIN 0x80 + void init_pic(void); void acknowledge(uint32_t int_vector); diff --git a/k/events/pic/pit.c b/k/events/pic/pit.c new file mode 100644 index 0000000..d0510d1 --- /dev/null +++ b/k/events/pic/pit.c @@ -0,0 +1,9 @@ +#include "pit.h" + +void pit_handler(void) +{ +} + +unsigned long gettick(void) +{ +} diff --git a/k/events/pic/pit.h b/k/events/pic/pit.h new file mode 100644 index 0000000..348d885 --- /dev/null +++ b/k/events/pic/pit.h @@ -0,0 +1,12 @@ +#ifndef PIT_H +#define PIT_H + +#define PIT_COUNTER_0 0x40 +#define PIT_COUNTER_1 0x41 +#define PIT_COUNTER_2 0x42 +#define PIT_CONTROL_REGISTER 0x43 + +void pit_handler(void); +unsigned long gettick(void); + +#endif /* !PIT_H */ diff --git a/k/k.c b/k/k.c index b26d602..0982b72 100644 --- a/k/k.c +++ b/k/k.c @@ -53,8 +53,6 @@ void k_main(unsigned long magic, multiboot_info_t *info) :); printf("bonjour\r\n"); - - for (unsigned i = 0; ; ) { *fb = star[i++ % 4]; }