diff --git a/paw/stos/arch/amd64/platform/board.c b/paw/stos/arch/amd64/platform/board.c index 64dd5f5..977b14a 100644 --- a/paw/stos/arch/amd64/platform/board.c +++ b/paw/stos/arch/amd64/platform/board.c @@ -8,9 +8,14 @@ #include #include +#include VOID HalBoardInit(VOID) { + /* Initialize HPET */ MdHpetInit(); + + /* Initialize IRQ chips */ + MdIrqChipInit(); } diff --git a/paw/stos/arch/amd64/platform/irqchip.c b/paw/stos/arch/amd64/platform/irqchip.c new file mode 100644 index 0000000..034a80b --- /dev/null +++ b/paw/stos/arch/amd64/platform/irqchip.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: IRQ chip management + * Author: Chloe M. + */ + +#include +#include +#include +#include +#include +#include + +/* PIC data ports */ +#define PIC_MASTER_DATA 0x21 +#define PIC_SLAVE_DATA 0xA1 + +#define DTRACE(Fmt, ...) \ + TRACE("[ IRQCHIP ]: " Fmt, ##__VA_ARGS__) + +/* Set if dual i8259 is present */ +#define MADT_PCAT_COMPAT BIT(0) + +VOID +MdIrqChipInit(VOID) +{ + ACPI_MADT *Madt; + + Madt = AcpiQuery("APIC"); + if (Madt == NULL) { + KeKnot( + KNOT_UNBOUND_RSRC, + "could not locate ACPI MADT\n" + ); + } + + /* + * If we have a dual-i8259 configuration present on the + * machine, we'll want to disable it so it doesn't mess + * up Local APIC operation and such. + */ + if (ISSET(Madt->Flags, MADT_PCAT_COMPAT)) { + DTRACE("detected dual i8259; disabling...\n"); + MdOutb(PIC_MASTER_DATA, 0xFF); + MdOutb(PIC_SLAVE_DATA, 0xFF); + } +} diff --git a/paw/stos/head/arch/amd64/irqchip.h b/paw/stos/head/arch/amd64/irqchip.h new file mode 100644 index 0000000..594b29f --- /dev/null +++ b/paw/stos/head/arch/amd64/irqchip.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: IRQ chip management + * Author: Chloe M. + */ + +#ifndef _MACHINE_IRQCHIP_H_ +#define _MACHINE_IRQCHIP_H_ 1 + +#include + +/* + * Enumerate and save all platform IRQ chips + */ +VOID MdIrqChipInit(VOID); + +#endif /* !_MACHINE_IRQCHIP_H_ */