From 18d7dbb9279850e8deb8636107dbcea73a4d2846 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sun, 13 Mar 2016 04:44:22 -0400 Subject: [PATCH] Implement hardware interrupt enable/disable --- src/PIC.cc | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/PIC.hh | 5 +++++ 2 files changed, 51 insertions(+) diff --git a/src/PIC.cc b/src/PIC.cc index e958b16..76d84ea 100644 --- a/src/PIC.cc +++ b/src/PIC.cc @@ -164,4 +164,50 @@ PIC::endOfInterrupt(uint8_t irq) kernel::io::outb(PIC1.command, OCW2::NOPEOI); } + +void +PIC::enableInterrupt(uint8_t irq, + bool enabled) +{ + if (enabled) { + enableIRQ(irq); + } else { + disableIRQ(irq); + } +} + +/* + * Private + */ + +inline uint16_t +PIC::portForIRQ(uint8_t irq) +{ + return irq < 8 ? PIC1.data : PIC2.data; +} + + +void +PIC::enableIRQ(uint8_t irq) +{ + uint16_t port = portForIRQ(irq); + if (irq >= 8) { + irq -= 8; + } + uint8_t value = kernel::io::inb(port) & ~(1 << irq); + kernel::io::outb(port, value); +} + + +void +PIC::disableIRQ(uint8_t irq) +{ + uint16_t port = portForIRQ(irq); + if (irq >= 8) { + irq -= 8; + } + uint8_t value = kernel::io::inb(port) | (1 << irq); + kernel::io::outb(port, value); +} + } /* namespace x86 */ diff --git a/src/PIC.hh b/src/PIC.hh index aebad34..26cd581 100644 --- a/src/PIC.hh +++ b/src/PIC.hh @@ -48,6 +48,11 @@ struct PIC * the PIC's IMR register. If the bit is set, the IRQ is ignored. */ void enableInterrupt(uint8_t irq, bool enabled); + +private: + uint16_t portForIRQ(uint8_t irq); + void enableIRQ(uint8_t irq); + void disableIRQ(uint8_t irq); }; } /* namespace x86 */