Implement hardware interrupt enable/disable

This commit is contained in:
Eryn Wells 2016-03-13 04:44:22 -04:00
parent 9bb7e91b66
commit 18d7dbb927
2 changed files with 51 additions and 0 deletions

View file

@ -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 */

View file

@ -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 */