Files
ClassicOS/kernel/irq.c
vmttmv 8743fa9e24 Multiple changes:
- Makefile: fix linker script path
- irq.c: `irqN()` stubs
- irq.h: fix missing header
- isr.h/isr.c extern `interrupt_handlers`
- utils.c: remove duplicate `memcmp`
2025-11-19 03:32:06 +02:00

77 lines
1.9 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "idt.h"
#include "irq.h"
#include "io.h"
#include "isr.h"
#define PIC1_CMD 0x20
#define PIC1_DATA 0x21
#define PIC2_CMD 0xA0
#define PIC2_DATA 0xA1
// FIXME: stubs
void irq0() {}
void irq1() {}
void irq2() {}
void irq3() {}
void irq4() {}
void irq5() {}
void irq6() {}
void irq7() {}
void irq8() {}
void irq9() {}
void irq10() {}
void irq11() {}
void irq12() {}
void irq13() {}
void irq14() {}
void irq15() {}
// --- stubs end
void irq_remap(void)
{
outb(PIC1_CMD, 0x11); // ICW1 edge triggered, cascade, need ICW4
outb(PIC2_CMD, 0x11);
outb(PIC1_DATA, 0x20); // ICW2 master base vector
outb(PIC2_DATA, 0x28); // ICW2 slave base vector
outb(PIC1_DATA, 0x04); // ICW3 slave on IRQ2
outb(PIC2_DATA, 0x02); // ICW3 cascade identity
outb(PIC1_DATA, 0x01); // ICW4 8086 mode
outb(PIC2_DATA, 0x01);
// Mask everything except IRQ0 (timer) and IRQ1 (keyboard) for now
outb(PIC1_DATA, 0b11111001);
outb(PIC2_DATA, 0xFF);
}
void irq_install(void)
{
irq_remap();
/* Fill IRQ entries in the IDT (0x20 … 0x2F) */
//extern void irq0(), irq1(), irq2(), irq3(), irq4(), irq5(), irq6(), irq7();
//extern void irq8(), irq9(), irq10(), irq11(), irq12(), irq13(), irq14(), irq15();
idt_set_gate(0x20, (uint32_t)irq0);
idt_set_gate(0x21, (uint32_t)irq1);
/* … repeat for the rest or loop … */
for (int i = 2; i < 16; ++i)
idt_set_gate(0x20 + i, (uint32_t)irq0 + i * 8); // crude but works
}
/* Called from the assembly stubs (see irq.asm below) */
void irq_handler(uint32_t int_num)
{
/* int_num is the *remapped* vector, e.g. 0x21 for keyboard */
if (interrupt_handlers[int_num]) {
interrupt_handlers[int_num]();
}
/* ---- EOI ---- */
if (int_num >= 0x28) // slave PIC
outb(PIC2_CMD, 0x20);
outb(PIC1_CMD, 0x20); // always master
}