diff --git a/irq_handler.c b/irq_handler.c index 7a30083..a6316dd 100644 --- a/irq_handler.c +++ b/irq_handler.c @@ -1,11 +1,13 @@ #include "interrupt.h" #include "vga.h" #include "io.h" +#include "pic.h" +#include "irq.h" // Need GCC > 6 __attribute__((interrupt)) void keyboard_handler(struct interrupt_frame *frame) { - printString("Keyboard!", RED, BLACK, 0, 7); + EOIIrq(IRQ_KEYBOARD); char c = 0; if (inb(0x60) != c) { c = inb(0x60); @@ -17,6 +19,8 @@ __attribute__((interrupt)) void keyboard_handler(struct interrupt_frame *frame) __attribute__((interrupt)) void timer_handler(struct interrupt_frame *frame) { - printString("Timer!", RED, BLACK, 0, 9); + static int timeCnt = 0; + EOIIrq(IRQ_TIMER); + printInt(timeCnt++, RED, BLACK, 0, 9); (void)frame; } diff --git a/pic.c b/pic.c index ff53d5d..bdae842 100644 --- a/pic.c +++ b/pic.c @@ -42,6 +42,14 @@ void initPic(void) outb(PIC_SLAVE_DATA, 0xFF); } +void EOIIrq(int irq) +{ + if (irq >= 8) + outb(PIC_SLAVE_CMD, PIC_EOI); + + outb(PIC_MASTER_CMD, PIC_EOI); +} + void disableIrq(int irq) { if (irq < 8) { diff --git a/pic.h b/pic.h index 05113ba..da6f99d 100644 --- a/pic.h +++ b/pic.h @@ -1,5 +1,5 @@ #pragma once -//2 PIC 8259 are available on x86 +// 2 PIC 8259 are available on x86 // // Master - command: 0x20, data: 0x21 // Slave - command: 0xA0, data: 0xA1 @@ -9,10 +9,13 @@ // http://wiki.osdev.org/PIC #define PIC_MASTER_CMD 0x20 -#define PIC_SLAVE_CMD 0xa0 +#define PIC_SLAVE_CMD 0xa0 #define PIC_MASTER_DATA 0x21 -#define PIC_SLAVE_DATA 0xa1 +#define PIC_SLAVE_DATA 0xa1 +#define PIC_EOI 0x20 /* End-of-interrupt command code */ + +void EOIIrq(int irq); void initPic(void); void enableIrq(int irq); void disableIrq(int irq);