diff --git a/prototypes/base/include/pic.hpp b/prototypes/base/include/pic.hpp new file mode 100644 index 0000000..eba8304 --- /dev/null +++ b/prototypes/base/include/pic.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include + +class PIC +{ +private: + uint16_t port; +public: + PIC(uint16_t port); + + void initialize(uint16_t irqBase, uint16_t icw3, uint16_t icw4); + + void maskInterrupts(uint8_t mask); +}; + +extern PIC masterPIC, slavePIC; \ No newline at end of file diff --git a/prototypes/base/src/idt.cpp b/prototypes/base/src/idt.cpp index 4c14e65..221c203 100644 --- a/prototypes/base/src/idt.cpp +++ b/prototypes/base/src/idt.cpp @@ -1,6 +1,7 @@ #include "idt.hpp" #include "io.hpp" #include "console.hpp" +#include "pic.hpp" #define ISR(num) extern "C" void isr_##num(); #define ISR_ERR(num) ISR(num) @@ -44,20 +45,11 @@ void IDT::initialize() void IDT::setupPIC() { - outb(0x20, 0x11); - outb(0x21, 0x20); - outb(0x21, 0x04); - outb(0x21, 0x01); + masterPIC.initialize(0x20, 0x04, 0x01); + slavePIC.initialize(0x28, 0x02, 0x01); - // Slave-PIC - outb(0xa0, 0x11); - outb(0xa1, 0x28); - outb(0xa1, 0x02); - outb(0xa1, 0x01); - - // Demask all interrupts - outb(0x20, 0x0); - outb(0xa0, 0x0); + masterPIC.maskInterrupts(0x00); + slavePIC.maskInterrupts(0x00); } void IDT::dispatch(CpuState *cpu) diff --git a/prototypes/base/src/pic.cpp b/prototypes/base/src/pic.cpp new file mode 100644 index 0000000..63a1027 --- /dev/null +++ b/prototypes/base/src/pic.cpp @@ -0,0 +1,24 @@ +#include "pic.hpp" +#include "io.hpp" + +PIC masterPIC(0x20); +PIC slavePIC(0xA0); + +PIC::PIC(uint16_t port) : + port(port) +{ + +} + +void PIC::initialize(uint16_t irqBase, uint16_t icw3, uint16_t icw4) +{ + outb(this->port + 0x00, 0x11); + outb(this->port + 0x01, irqBase); + outb(this->port + 0x02, icw3); + outb(this->port + 0x03, icw4); +} + +void PIC::maskInterrupts(uint8_t mask) +{ + outb(this->port + 0x01, mask); +} \ No newline at end of file