Interrupt Vector 0x08 Not Pushing Error Code

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Geometrian
Member
Member
Posts: 77
Joined: Tue Nov 20, 2012 4:45 pm
Contact:

Interrupt Vector 0x08 Not Pushing Error Code

Post 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.
Last edited by Geometrian on Wed Jan 31, 2024 5:40 pm, edited 1 time in total.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Interrupt Vector 0x08 Not Pushing Error Code

Post 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.
Geometrian
Member
Member
Posts: 77
Joined: Tue Nov 20, 2012 4:45 pm
Contact:

Re: Interrupt Vector 0x08 Not Pushing Error Code

Post 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?
User avatar
Nessphoro
Member
Member
Posts: 308
Joined: Sat Apr 30, 2011 12:50 am

Re: Interrupt Vector 0x08 Not Pushing Error Code

Post 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
Geometrian
Member
Member
Posts: 77
Joined: Tue Nov 20, 2012 4:45 pm
Contact:

Re: Interrupt Vector 0x08 Not Pushing Error Code

Post by Geometrian »

Thanks,
Geometrian
Member
Member
Posts: 77
Joined: Tue Nov 20, 2012 4:45 pm
Contact:

Re: Interrupt Vector 0x08 Not Pushing Error Code

Post by Geometrian »

I suppose this raises a different question though: does any PIC IRQ ever push an error code?
User avatar
Nessphoro
Member
Member
Posts: 308
Joined: Sat Apr 30, 2011 12:50 am

Re: Interrupt Vector 0x08 Not Pushing Error Code

Post by Nessphoro »

No.
As IRQs are not errors.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Interrupt Vector 0x08 Not Pushing Error Code

Post 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:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Geometrian
Member
Member
Posts: 77
Joined: Tue Nov 20, 2012 4:45 pm
Contact:

Re: Interrupt Vector 0x08 Not Pushing Error Code

Post 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,
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: Interrupt Vector 0x08 Not Pushing Error Code

Post 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.
Learn to read.
Geometrian
Member
Member
Posts: 77
Joined: Tue Nov 20, 2012 4:45 pm
Contact:

Re: Interrupt Vector 0x08 Not Pushing Error Code

Post 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).
JohnXiba
Posts: 5
Joined: Sat Jul 13, 2013 7:26 am

Re: Interrupt Vector 0x08 Not Pushing Error Code

Post 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?
Geometrian
Member
Member
Posts: 77
Joined: Tue Nov 20, 2012 4:45 pm
Contact:

Re: Interrupt Vector 0x08 Not Pushing Error Code

Post 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,
JohnXiba
Posts: 5
Joined: Sat Jul 13, 2013 7:26 am

Re: Interrupt Vector 0x08 Not Pushing Error Code

Post by JohnXiba »

Sorry, my mistake :)
Post Reply