diff --git a/k/Makefile b/k/Makefile index 99c5520..6dcdf99 100644 --- a/k/Makefile +++ b/k/Makefile @@ -33,7 +33,8 @@ OBJS = \ serial.o \ gdt.o \ idt.o \ - isr.o + isr.o \ + pic.o DEPS = $(OBJS:.o=.d) diff --git a/k/idt.c b/k/idt.c index 99cac59..90d4503 100644 --- a/k/idt.c +++ b/k/idt.c @@ -35,7 +35,9 @@ static struct idt_entry_descriptor idt_entries_descriptors[IDT_NB_ENTRIES] = { {0, {0, 0, 0}, 0}, // 28 {0, {0, 0, 0}, 0}, // 29 {0, {0, 0, 0}, 0}, // 30 - {0, {0, 0, 0}, 0} // 31 + {0, {0, 0, 0}, 0}, // 31 + {0, {0, 0, 0}, 0}, // 32 + {(uint32_t)&isr_keyboard, KERNEL_CS_SEGMENT_SELECTOR, INTERRUPT_TYPE}, // 33 }; void interrupt_handler(struct isr_param *isr_param) diff --git a/k/idt.h b/k/idt.h index 2d6c276..88a306a 100644 --- a/k/idt.h +++ b/k/idt.h @@ -5,7 +5,8 @@ #include "gdt.h" #include "isr.h" -#define IDT_NB_ENTRIES 32 +#define IDT_RESERVED_ENTRIES 32 +#define IDT_NB_ENTRIES 34 #define IDT_SIZE (IDT_NB_ENTRIES * sizeof(struct idt_entry)) #define INTERRUPT_TYPE 0x6 diff --git a/k/isr.S b/k/isr.S index 8a32164..66e02c5 100644 --- a/k/isr.S +++ b/k/isr.S @@ -44,3 +44,4 @@ 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_keyboard, 33) diff --git a/k/isr.h b/k/isr.h index 1d5c8a6..a831474 100644 --- a/k/isr.h +++ b/k/isr.h @@ -28,5 +28,6 @@ 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_keyboard(void); #endif /* !ISR_H */ diff --git a/k/k.c b/k/k.c index 5e7c1f4..87091cf 100644 --- a/k/k.c +++ b/k/k.c @@ -26,6 +26,7 @@ #include "gdt.h" #include "idt.h" #include "multiboot.h" +#include "pic.h" #include "serial.h" #include "stdio.h" @@ -34,6 +35,7 @@ static void k_init(void) init_serial(); init_gdt(); init_idt(); + init_pic(); } void k_main(unsigned long magic, multiboot_info_t *info) diff --git a/k/pic.c b/k/pic.c new file mode 100644 index 0000000..982e6c1 --- /dev/null +++ b/k/pic.c @@ -0,0 +1,44 @@ +#include "idt.h" +#include "io.h" +#include "pic.h" + +static void send_icw1(void) +{ + outb(MASTER_PIC_A, ICW1); + outb(SLAVE_PIC_A, ICW1); +} + +static void send_icw2(void) +{ + outb(MASTER_PIC_B, IDT_RESERVED_ENTRIES); + outb(SLAVE_PIC_B, IDT_RESERVED_ENTRIES + 8); +} + +static void send_icw3(void) +{ + outb(MASTER_PIC_B, 0x4); + outb(SLAVE_PIC_B, 0x2); +} + + +static void send_icw4(void) +{ + outb(MASTER_PIC_B, 0x1); + outb(SLAVE_PIC_B, 0x1); +} + +static void mask_irqs(void) +{ + outb(MASTER_PIC_B, 0xff); + outb(SLAVE_PIC_B, 0xff); +} + +void init_pic(void) +{ + send_icw1(); + send_icw2(); + send_icw3(); + send_icw4(); + mask_irqs(); + asm volatile("sti"); +} diff --git a/k/pic.h b/k/pic.h new file mode 100644 index 0000000..c5cb2d8 --- /dev/null +++ b/k/pic.h @@ -0,0 +1,13 @@ +#ifndef PIC_H +#define PIC_H + +#define MASTER_PIC_A 0x20 +#define MASTER_PIC_B 0x21 +#define SLAVE_PIC_A 0xa0 +#define SLAVE_PIC_B 0xa1 + +#define ICW1 0x11 + +void init_pic(void); + +#endif /* !PIC_H */