Why isn't my interrupt handler firing?
assembly, bochs, interrupt, interrupt-handling, x86
Solution
Here:
IDT[0x03]=32-Bit Interrupt Gate target=0x0001:0xc000416c, DPL=0
0x0001 is a selector value. Its 2 least significant bits are `RPL` bits. The rest of the bits are used as an index into a segment descriptor table (GDT or LDT). And these bits are 0. For all intents and purposes that's a NULL selector.
Most likely you want 8 there, not 1.
See the CPU documentation for how exactly selectors are used.
Problem
I'm trying to install an interrupt handler in Bochs, but for some reason my interrupt handler isn't firing. First I set a breakpoint: ``` 00036440222i[CPU0 ] [36440222] Stopped on MAGIC BREAKPOINT (0) [0x0000000000703044] 0008:00000000c0003044 (unk. ctxt): int3 ``` Then I try to execute `int 3`. When I do, though, the error says `int_trap_gate(): selector null`, which seems to be telling me a selector in some table is null. However, the GDT is shown below: ``` <bochs:2> info gdt Global Descriptor Table (base=0x0000000000007c08, limit=23): GDT[0x00]=??? descriptor hi=0x00000000, lo=0x00000000 GDT[0x01]=Code segment, base=0x00000000, limit=0xffffffff, Execute/Read, Accessed, 32-bit GDT[0x02]=Data segment, base=0x00000000, limit=0xffffffff, Read/Write, Accessed ``` and so is the IDT: ``` <bochs:3> info idt Interrupt Descriptor Table (base=0x00000000c0101020, limit=2047): IDT[0x00]=32-Bit Interrupt Gate target=0x0001:0xc0004148, DPL=0 IDT[0x01]=32-Bit Interrupt Gate target=0x0001:0xc0004154, DPL=0 IDT[0x02]=32-Bit Interrupt Gate target=0x0001:0xc0004160, DPL=0 IDT[0x03]=32-Bit Interrupt Gate target=0x0001:0xc000416c, DPL=0 IDT[0x04]=32-Bit Interrupt Gate target=0x0001:0xc0004178, DPL=0 IDT[0x05]=32-Bit Interrupt Gate target=0x0001:0xc0004184, DPL=0 IDT[0x06]=32-Bit Interrupt Gate target=0x0001:0xc0004190, DPL=0 IDT[0x07]=32-Bit Interrupt Gate target=0x0001:0xc000419c, DPL=0 IDT[0x08]=32-Bit Interrupt Gate target=0x0001:0xc00041a8, DPL=0 IDT[0x09]=32-Bit Interrupt Gate target=0x0001:0xc00041b0, DPL=0 IDT[0x0a]=32-Bit Interrupt Gate target=0x0001:0xc00041bc, DPL=0 IDT[0x0b]=32-Bit Interrupt Gate target=0x0001:0xc00041c4, DPL=0 IDT[0x0c]=32-Bit Interrupt Gate target=0x0001:0xc00041cc, DPL=0 IDT[0x0d]=32-Bit Interrupt Gate target=0x0001:0xc00041d4, DPL=0 IDT[0x0e]=32-Bit Interrupt Gate target=0x0001:0xc00041dc, DPL=0 IDT[0x0f]=32-Bit Interrupt Gate target=0x0001:0xc00041e4, DPL=0 IDT[0x10]=32-Bit Interrupt Gate target=0x0001:0xc00041f0, DPL=0 IDT[0x11]=32-Bit Interrupt Gate target=0x0001:0xc00041fc, DPL=0 IDT[0x12]=32-Bit Interrupt Gate target=0x0001:0xc0004208, DPL=0 IDT[0x13]=32-Bit Interrupt Gate target=0x0001:0xc0004214, DPL=0 IDT[0x14]=32-Bit Interrupt Gate target=0x0001:0xc0004220, DPL=0 IDT[0x15]=32-Bit Interrupt Gate target=0x0001:0xc000422c, DPL=0 IDT[0x16]=32-Bit Interrupt Gate target=0x0001:0xc0004238, DPL=0 IDT[0x17]=32-Bit Interrupt Gate target=0x0001:0xc0004244, DPL=0 IDT[0x18]=32-Bit Interrupt Gate target=0x0001:0xc0004250, DPL=0 IDT[0x19]=32-Bit Interrupt Gate target=0x0001:0xc000425c, DPL=0 IDT[0x1a]=32-Bit Interrupt Gate target=0x0001:0xc0004268, DPL=0 IDT[0x1b]=32-Bit Interrupt Gate target=0x0001:0xc0004274, DPL=0 IDT[0x1c]=32-Bit Interrupt Gate target=0x0001:0xc0004280, DPL=0 IDT[0x1d]=32-Bit Interrupt Gate target=0x0001:0xc000428c, DPL=0 IDT[0x1e]=32-Bit Interrupt Gate target=0x0001:0xc0004298, DPL=0 IDT[0x1f]=??? descriptor hi=0x00000000, lo=0x00000000 <...> IDT[0xff]=??? descriptor hi=0x00000000, lo=0x00000000 ``` It seems to me that the IDT entries have valid GDT selectors, so I don't understand what causes the problem when I execute an interrupt: ``` <bochs:5> s ; step (0).[36440222] [0x0000000000703044] 0008:00000000c0003044 (unk. ctxt): int3 CPU 0: Interrupt 0x03 occured (error_code=0x0000) 00036440222e[CPU0 ] int_trap_gate(): selector null CPU 0: Exception 0x0d - (#GP) general protection fault occured (error_code=0x0000) CPU 0: Interrupt 0x0d occured (error_code=0x0000) 00036440222e[CPU0 ] int_trap_gate(): selector null CPU 0: Exception 0x0d - (#GP) general protection fault occured (error_code=0x0000) CPU 0: Exception 0x08 - (#DF) double fault occured (error_code=0x0000) CPU 0: Interrupt 0x08 occured (error_code=0x0000) 00036440222e[CPU0 ] int_trap_gate(): selector null CPU 0: Exception 0x0d - (#GP) general protection fault occured (error_code=0x0000) ``` What is the problem?