From c4845de1e4ba49ba066e5729814fdb5bcd7e46f8 Mon Sep 17 00:00:00 2001 From: Danny Holman Date: Tue, 28 Sep 2021 12:25:46 -0500 Subject: arch: i386: add PIC register support Add functions that let the OS read the internal state registers of the 8259 PIC. Signed-off-by: Danny Holman --- arch/i386/boot/pic.c | 14 ++++++++++++++ arch/i386/include/kernel/pic.h | 5 +++++ 2 files changed, 19 insertions(+) (limited to 'arch') diff --git a/arch/i386/boot/pic.c b/arch/i386/boot/pic.c index f103b92..607023c 100644 --- a/arch/i386/boot/pic.c +++ b/arch/i386/boot/pic.c @@ -22,6 +22,20 @@ void pic_remap(void) { outb(PIC2_DATA, a2); } +static uint16_t __pic_get_irq_reg(int ocw3) { + outb(PIC1_COMMAND, ocw3); + outb(PIC2_COMMAND, ocw3); + return (inb(PIC2_COMMAND) << 8) | inb(PIC1_COMMAND); +} + +uint16_t pic_get_irr(void) { + return __pic_get_irq_reg(PIC_READ_IRR); +} + +uint16_t pic_get_isr(void) { + return __pic_get_irq_reg(PIC_READ_ISR); +} + void irq_set_mask(uint8_t irq) { uint16_t port; uint8_t data; diff --git a/arch/i386/include/kernel/pic.h b/arch/i386/include/kernel/pic.h index c3ede4f..a9387db 100644 --- a/arch/i386/include/kernel/pic.h +++ b/arch/i386/include/kernel/pic.h @@ -22,6 +22,9 @@ #define ICW4_BUF_MASTER 0x0C #define ICW4_SFNM 0x10 +#define PIC_READ_IRR 0x0A +#define PIC_READ_ISR 0x0B + static inline void outb(uint16_t port, uint8_t value) { asm volatile("outb %0, %1" : : "a"(value), "Nd"(port)); } @@ -38,6 +41,8 @@ static inline void io_wait(void) { void pic_eoi(unsigned char irq); void pic_remap(void); +uint16_t pic_get_irr(void); +uint16_t pic_get_isr(void); void irq_set_mask(uint8_t irq); void irq_clear_mask(uint8_t irq); -- cgit v1.2.3