Page 1 of 1

Interrupt Vector 0x08 Not Pushing Error Code

Posted: Thu Jul 04, 2013 5:12 pm
by Geometrian
Hi,

I am trying to get software interrupts working. After loading the GDT, IDT, and then reloading the segment registers, shortly after I enable interrupts, a double fault (0x08) is set. I have done nothing with hardware interrupts yet.

While trying to track down the cause, it seems that the vector is not passing an error code. The Intel Docs say that it should.

I used a Bochs magic breakpoint to stop immediately after the interrupt fires. Using the idea here, all interrupt handlers push a dummy error code 0 if the CPU didn't, push the interrupt vector number, and then call a common subroutine.

In the following image, you can see the IDT entry 0x08 pointing to 0x0008:0x001035F1 (note that the code segment accounts for the 0x0008 in the address). 0x0008:0x001035F1 is shown on the left, where the magic breakpoint stopped us. Notice the surrounding interrupt vectors 0x07 and 0x09, neither of which are supposed to pass error codes. Consequently, they push 0 onto the stack first. However, since interrupt vector 0x08 is supposed to push an error code, it only pushes the interrupt number.
Image

In the following image from an identical rerun, you can see the stack. According to the manual (pg. 247-248), it should push eflags, cs, eip, and the error code (if any). Address 0x0018490C is eflags, address 0x00184908 is cs, and address 0x00184904 was the eip. Notice the lack of error code.
Image

When the next instruction happens, it pushes an 8 onto the stack, and the program continues. Unfortunately, since the interrupt handler was expecting an error code, the stack gets munged.

So: what causes the double fault, and why is it that the vector only pushed three values onto the stack?

Thanks,

P.S. if you need the source, the SVN in my signature has been updated with the whole thing.

Re: Interrupt Vector 0x08 Not Pushing Error Code

Posted: Thu Jul 04, 2013 5:22 pm
by bluemoon
Geometrian wrote:I am trying to get software interrupts working. After loading the GDT, IDT, and then reloading the segment registers, shortly after I enable interrupts, a double fault (0x08) is set. I have done nothing with hardware interrupts yet.
Without reading the whole post, I guess you haven't properly setup PIC and timer IRQ (INT08 upon boot) messed things up.

Re: Interrupt Vector 0x08 Not Pushing Error Code

Posted: Thu Jul 04, 2013 5:32 pm
by Geometrian
bluemoon wrote:
Geometrian wrote:I am trying to get software interrupts working. After loading the GDT, IDT, and then reloading the segment registers, shortly after I enable interrupts, a double fault (0x08) is set. I have done nothing with hardware interrupts yet.
Without reading the whole post, I guess you haven't properly setup PIC and timer IRQ (INT08 upon boot) messed things up.
I haven't done anything with hardware interrupts yet, including remap the PIC to different interrupt vectors. I had thought of this, especially since exactly where the interrupt happens varies, but based on skimming the PIC pages in the wiki, I had thought that hardware interrupts would not be available to the CPU until the PIC was configured. Is that incorrect?

Re: Interrupt Vector 0x08 Not Pushing Error Code

Posted: Thu Jul 04, 2013 5:49 pm
by Nessphoro
No, the PIC is preconfigured And enabled by BIOS at boot. It will tick at a its lowest frequency however. By enabling interrupts you enable the CPU to receive external interrupts. If you only want software ones, don't do an STI

Re: Interrupt Vector 0x08 Not Pushing Error Code

Posted: Thu Jul 04, 2013 5:50 pm
by Geometrian
Thanks,

Re: Interrupt Vector 0x08 Not Pushing Error Code

Posted: Thu Jul 04, 2013 6:12 pm
by Geometrian
I suppose this raises a different question though: does any PIC IRQ ever push an error code?

Re: Interrupt Vector 0x08 Not Pushing Error Code

Posted: Thu Jul 04, 2013 6:41 pm
by Nessphoro
No.
As IRQs are not errors.

Re: Interrupt Vector 0x08 Not Pushing Error Code

Posted: Fri Jul 05, 2013 1:32 am
by Combuster
Interestingly, this whole sequence has been discussed in the FAQ... Maybe you should go read it before you end up with more surprises :wink:

Re: Interrupt Vector 0x08 Not Pushing Error Code

Posted: Fri Jul 05, 2013 1:38 am
by Geometrian
Combuster wrote:Interestingly, this whole sequence has been discussed in the FAQ... Maybe you should go read it before you end up with more surprises :wink:
It's a good suggestion. I have read all the basic pages completely at least once, and recently the ones on interrupts, the GDT, the IDT, and the PIC I've read and reread very thoroughly. Sometimes I don't understand all of them (in this case, I misunderstood them), but the fact I've made any progress at all shows that your wiki works :wink:. Thanks,

Re: Interrupt Vector 0x08 Not Pushing Error Code

Posted: Fri Jul 05, 2013 1:55 am
by dozniak
Geometrian wrote:but the fact I've made any progress at all shows that your wiki works :wink:. Thanks,
It's your wiki now too.

Re: Interrupt Vector 0x08 Not Pushing Error Code

Posted: Fri Jul 05, 2013 1:57 am
by Geometrian
dozniak wrote:It's your wiki now too.
Ostensibly so, although my edits so far have been mostly to fix typos (with which the wiki unfortunately abounds).

Re: Interrupt Vector 0x08 Not Pushing Error Code

Posted: Sat Jul 13, 2013 8:15 am
by JohnXiba
Hi Geometrian,

Show us the code that invokes the interrupt or that causes the #DF. Are you invoking it through an "INT 8" instruction?

Re: Interrupt Vector 0x08 Not Pushing Error Code

Posted: Sat Jul 13, 2013 3:24 pm
by Geometrian
JohnXiba wrote:Show us the code that invokes the interrupt or that causes the #DF. Are you invoking it through an "INT 8" instruction?
As established above, the problem was due to an IRQ from the PIC, which hadn't been remapped.
Cheers,

Re: Interrupt Vector 0x08 Not Pushing Error Code

Posted: Sat Jul 13, 2013 4:36 pm
by JohnXiba
Sorry, my mistake :)