I'm currently following JamesM's tutorials, and I'd like to "clean up" the IRQ/ISR code a bit by reducing the amount of repetition it has. Right now, it does some NASM macro trickery to generate the different stubs for the various ISRs, which is already great for reducing the amount of assembly code required, but does little to reduce the C side of things, which looks like this for me:
Code:
idt_entries [0] = IdtEntry::makeEntry(isr0, 0x08, PrivilegeLevel::Ring0);
idt_entries [1] = IdtEntry::makeEntry(isr1, 0x08, PrivilegeLevel::Ring0);
idt_entries [2] = IdtEntry::makeEntry(isr2, 0x08, PrivilegeLevel::Ring0);
// ...
idt_entries[31] = IdtEntry::makeEntry(isr31, 0x08, PrivilegeLevel::Ring0);
idt_entries[32] = IdtEntry::makeEntry(irq0, 0x08, PrivilegeLevel::Ring0);
idt_entries[33] = IdtEntry::makeEntry(irq1, 0x08, PrivilegeLevel::Ring0);
// ...
idt_entries[47] = IdtEntry::makeEntry(irq15, 0x08, PrivilegeLevel::Ring0);
Ideally, I'd like to turn that into something like this:
Code:
for(int i = 0; i < num_isrs; i++) {
idt_entries[i] = IdtEntry::makeEntry(irqs[i], 0x08, PrivilegeLevel::Ring0);
}
To do that, I though of reserving some space in the assembly code like this:
Code:
isr_handlers: resd 32
irq_handlers: resd 16
So that I can put the pointers to all the different isrs into those two vectors... But I have no idea how to do it, or even if it's possible! Does NASM support this? Can I populate a reserved section with pointers?