From 30d6e8f850d2fe26fffdeef0c38fc627ef8bab9a Mon Sep 17 00:00:00 2001 From: "Anna (navi) Figueiredo Gomes" Date: Wed, 13 Dec 2023 13:24:48 +0100 Subject: initial commit currently with: booted via multiboot 1 protected mode to long mode boostrap code vga used for outputting gdt and idt set up identity paging for the whole memory reported by multiboot pic and ps/2 set up acpi code exists but is broken --- src/pic.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 src/pic.c (limited to 'src/pic.c') diff --git a/src/pic.c b/src/pic.c new file mode 100644 index 0000000..ad2c15d --- /dev/null +++ b/src/pic.c @@ -0,0 +1,107 @@ +#include +#include +#include +#include + +extern void toggle_interrupts(bool enable); + +#define pic1 0x20 +#define pic2 0xA0 +#define pic1_d (pic1 + 1) +#define pic2_d (pic2 + 2) + +void pic_remap(uint32_t offset1, uint32_t offset2) { + uint8_t a1, a2; + + a1 = inb(pic1_d); + a2 = inb(pic2_d); + + outb(pic1, 0x10 | 0x01); + io_wait(); + outb(pic2, 0x10 | 0x01); + io_wait(); + outb(pic1_d, offset1); + io_wait(); + outb(pic2_d, offset2); + io_wait(); + outb(pic1_d, 4); + io_wait(); + outb(pic2_d, 2); + io_wait(); + + outb(pic1_d, 0x01); + io_wait(); + outb(pic2_d, 0x01); + io_wait(); + + outb(pic1_d, a1); + outb(pic2_d, a2); +} + +void pic_set_mask(uint8_t irq_line) { + uint32_t port; + uint8_t value; + + if (irq_line < 8) + port = pic1_d; + else { + port = pic2_d; + irq_line -= 8; + } + value = inb(port) | (1 << irq_line); + outb(port, value); +} + +void pic_clear_mask(uint8_t irq_line) { + uint32_t port; + uint8_t value; + + if (irq_line < 8) + port = pic1_d; + else { + port = pic2_d; + irq_line -= 8; + } + value = inb(port) & ~(1 << irq_line); + outb(port, value); +} + +void pic_set_all_masks(void) { + outb(pic1_d, 0xFF); + outb(pic2_d, 0xFF); +} + +void pic_clear_all_masks(void) { + outb(pic1_d, 0x00); + outb(pic2_d, 0x00); +} + +void pic_eoi(uint8_t irq) { + if (irq >= 8) + outb(pic2, 0x20); + outb(pic1, 0x20); +} + +void keyboard_handler(uint64_t num, uint64_t _unused) { + (void)num; + (void)_unused; + uint8_t key = inb(0x60); + vga_puts("key pressed: "); + vga_putx(key); + vga_putc('\n'); + pic_eoi(0x1); +} + +void pic_init(void) { + pic_set_all_masks(); + pic_clear_mask(1); + //pic_clear_mask(12); + pic_remap(32, 40); + + for (size_t i = 32; i < 48; i++) + idt_set_isr(i, isr_table[i], 0x08, 0x8E); + + idt_register_isr(33, keyboard_handler); + + toggle_interrupts(true); +} -- cgit v1.2.3