I assumed it was just like if the vector is 0x20 then that would map to the 32nd entry in the 64bit wide IDT.
This doesn't seem to be the case on VirtualBox anyway. When I map the PIC master vector to 8 the corresponding entry
in IDT is 11, with vector 16 the IDT entry is 19 and with the recommended 32, the IDT entry is not within 256 entries!?
The interrupt service routine is working for vectors 8, 16 though, but at a weird IDT offset.
Code: Select all
void init_interrupts(uint64_t *interrupt_descriptor_table)
{
uint8_t *ptr = (uint8_t *) &asm_ISR_keyboard + image_base;
uint32_t *ISR_keyboard = (uint32_t *) ptr;
// remap VECTORs
PIC_remap(0x20, 0x28);
// lazy: set all interrupts to the same routine, check which IDT entry is the correct one for the VECTOR
for (uint16_t i=0;i<256;i++)
{
interrupt_descriptor_table[i] = 0 | ((uint64_t) GD_PRESENT_BIT << 47)
| ((uint64_t) GD_DPL_KERNEL << 45)
| ((uint64_t) 0 << 44)
| ((uint64_t) GD32_INTERRUPT_GATE << 40)
| ((uint64_t) 0x8 << 16)
| (((uint64_t) ((uint32_t) ISR_keyboard & 0xffff0000)) << 32)
| ((uint64_t) ((uint32_t) ISR_keyboard & 0x0000ffff));
}
// disable all interrupts except keyboard
for (uint8_t j =0 ; j<16; j++)
{
IRQ_set_mask(j);
wait();
}
IRQ_clear_mask(IRQ_KEYBOARD);
asm("sti");
return;
}