diff --git a/arch/hwint.c b/arch/hwint.c index 9ea3546..4dbb5f3 100644 --- a/arch/hwint.c +++ b/arch/hwint.c @@ -52,4 +52,6 @@ void hwint_register_handler(unsigned int int_no, hwint_handler_t handler) } handlers[int_no] = handler; + + pic_enable(int_no); } diff --git a/arch/pic.c b/arch/pic.c index 5056f23..1ad7504 100644 --- a/arch/pic.c +++ b/arch/pic.c @@ -10,6 +10,7 @@ #define SLAVE_DATA 0xA1 #define IRQS_COUNT 8 +#define IRQS_TOTAL 16 static unsigned char master_irq_start = 0; static unsigned char slave_irq_start = 8; @@ -30,6 +31,45 @@ void pic_disable_all() outportb(SLAVE_DATA, 0xFF); } +void pic_enable(const unsigned char line) +{ + if (line >= IRQS_TOTAL) { + logger_warn_from("pic", "Invalid line %u.", line); + return; + } + + logger_info_from("pic", "Enable line %u.", line); + + if (line < IRQS_COUNT) { + const unsigned char mask = inportb(MASTER_DATA); + outportb(MASTER_DATA, mask & ~(1 << line)); + } + else { + const unsigned char mask = inportb(SLAVE_DATA); + outportb(SLAVE_DATA, mask & ~(1 << (line - IRQS_COUNT))); + } +} + +void pic_disable(const unsigned char line) +{ + if (line >= IRQS_TOTAL) { + logger_warn_from("pic", "Invalid line %u.", line); + return; + } + + logger_info_from("pic", "Disable line %u.", line); + + if (line < IRQS_COUNT) { + const unsigned char mask = inportb(MASTER_DATA); + outportb(MASTER_DATA, mask | (1 << line)); + } + else { + const unsigned char mask = inportb(SLAVE_DATA); + outportb(SLAVE_DATA, mask | (1 << (line - IRQS_COUNT))); + } +} + + void pic_remap(const unsigned char new_master_irq_start, const unsigned char new_slave_irq_start) { logger_info_from("pic", "Remap the IRQ table."); diff --git a/arch/pic.h b/arch/pic.h index a2fdcb7..a420bd1 100644 --- a/arch/pic.h +++ b/arch/pic.h @@ -6,6 +6,9 @@ void pic_remap(unsigned char master_irq_start, unsigned char slave_irq_start); void pic_enable_all(); void pic_disable_all(); +void pic_enable(unsigned char line); +void pic_disable(unsigned char line); + unsigned char pic_end_of_interrupt(unsigned char irq); #endif diff --git a/arch/protected.c b/arch/protected.c index f0bb717..41d404b 100644 --- a/arch/protected.c +++ b/arch/protected.c @@ -54,7 +54,7 @@ void idt_flush(const struct IdtPointer *pointer); void protected_initialize(const struct KernelMQ_Info *const kinfo) { pic_remap(32, 40); - pic_enable_all(); + pic_disable_all(); logger_info_from("protected", "Setup GDT.");