irq: make IRQs dynamically mappable
This commit is contained in:
parent
4b813d7c86
commit
b8b67aadc9
7 changed files with 108 additions and 21 deletions
57
init/irq.c
57
init/irq.c
|
|
@ -10,7 +10,11 @@
|
|||
#define exception(_i) _exception_##_i
|
||||
#define exception_decl(_j) void exception(_j)()
|
||||
|
||||
#define irq_decl(_i) void _irq_##_i()
|
||||
#define __irq(_i) _irq_##_i
|
||||
|
||||
static bool irq_mapped[16] = { false };
|
||||
static void *irq_handlers[16] = { NULL };
|
||||
|
||||
exception_decl(0x00);
|
||||
exception_decl(0x01);
|
||||
|
|
@ -45,8 +49,25 @@ exception_decl(0x1D);
|
|||
exception_decl(0x1E);
|
||||
exception_decl(0x1F);
|
||||
|
||||
irq_decl(0x00);
|
||||
irq_decl(0x01);
|
||||
irq_decl(0x02);
|
||||
irq_decl(0x03);
|
||||
irq_decl(0x04);
|
||||
irq_decl(0x05);
|
||||
irq_decl(0x06);
|
||||
irq_decl(0x07);
|
||||
irq_decl(0x08);
|
||||
irq_decl(0x09);
|
||||
irq_decl(0x0A);
|
||||
irq_decl(0x0B);
|
||||
irq_decl(0x0C);
|
||||
irq_decl(0x0D);
|
||||
irq_decl(0x0E);
|
||||
irq_decl(0x0F);
|
||||
|
||||
void idt_load(); /* descriptor.S */
|
||||
void isr_sched(); /* isr.S */
|
||||
void __irq_handler_base(); /* isr.S */
|
||||
|
||||
void sched_test()
|
||||
{
|
||||
|
|
@ -66,13 +87,13 @@ void idt_insert(uint16_t gate, uint8_t type, uint8_t ist, uint16_t segment, void
|
|||
irqdesc->attrs = type;
|
||||
}
|
||||
|
||||
int irq_map(uint8_t irq, uint8_t ist, void *func)
|
||||
int irq_map(uint8_t irq, void *func)
|
||||
{
|
||||
if (irq_mapped[irq])
|
||||
return 1;
|
||||
|
||||
irq_mapped[irq] = true;
|
||||
idt_insert(irq + 0x20, GATE_INTR, ist, GDT_SEGMENT_CODE_RING0, func);
|
||||
irq_handlers[irq] = func;
|
||||
pic_mask(irq, 0);
|
||||
|
||||
return 0;
|
||||
|
|
@ -81,6 +102,7 @@ int irq_map(uint8_t irq, uint8_t ist, void *func)
|
|||
void irq_unmap(uint8_t irq)
|
||||
{
|
||||
irq_mapped[irq] = false;
|
||||
irq_handlers[irq] = NULL;
|
||||
idt_insert(irq + 0x20, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, NULL);
|
||||
pic_mask(irq, 1);
|
||||
}
|
||||
|
|
@ -95,6 +117,16 @@ int irq_highest_free()
|
|||
return -1;
|
||||
}
|
||||
|
||||
void irq(int irq)
|
||||
{
|
||||
if (irq_handlers[irq] != NULL) {
|
||||
void (*handler)() = irq_handlers[irq];
|
||||
handler();
|
||||
}
|
||||
|
||||
pic_eoi(irq);
|
||||
}
|
||||
|
||||
void idt_init()
|
||||
{
|
||||
idt_insert(0x00, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x00));
|
||||
|
|
@ -130,7 +162,24 @@ void idt_init()
|
|||
idt_insert(0x1E, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x1E));
|
||||
idt_insert(0x1F, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x1F));
|
||||
|
||||
irq_map(4, 0, isr_serial_input);
|
||||
idt_insert(0x20, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x00));
|
||||
idt_insert(0x21, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x01));
|
||||
idt_insert(0x22, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x02));
|
||||
idt_insert(0x23, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x03));
|
||||
idt_insert(0x24, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x04));
|
||||
idt_insert(0x25, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x05));
|
||||
idt_insert(0x26, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x06));
|
||||
idt_insert(0x27, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x07));
|
||||
idt_insert(0x28, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x08));
|
||||
idt_insert(0x29, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x09));
|
||||
idt_insert(0x2A, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x0A));
|
||||
idt_insert(0x2B, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x0B));
|
||||
idt_insert(0x2C, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x0C));
|
||||
idt_insert(0x2D, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x0D));
|
||||
idt_insert(0x2E, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x0E));
|
||||
idt_insert(0x2F, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x0F));
|
||||
|
||||
irq_map(4, serial_trap);
|
||||
|
||||
__idtr.size = (IDT_SIZE - 1);
|
||||
__idtr.offset = (uint64_t)__idt;
|
||||
|
|
|
|||
Loading…
Reference in a new issue