Error code for exception is not pushed ??

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
neurocom
Posts: 8
Joined: Wed Nov 27, 2013 8:33 pm

Error code for exception is not pushed ??

Post by neurocom »

Hi All,
I have a very simple code to test if an exception error code is pushed right after 'int 0x08', for example
When I run it, I do NOT get any error code for int 0x8.

Here is the snapshot of the code

Code: Select all

disable_interrupts(); // same as 'cli'

// Initialize 8259 PIC and remapping
outb(0x20, 0x11);
outb(0xA0, 0x11);
outb(0x21, 0x20);
outb(0xA1, 0x28);
outb(0x21, 0x04);
outb(0xA1, 0x02);
outb(0x21, 0x01);
outb(0xA1, 0x01);
outb(0x21, 0x0);
outb(0xA1, 0x0);

// trigger Double Fault 
asm ("int $0x08");
When I run Bochs with it and debug it, I've got the following result in the stack

>> Right before the execution of 'init 0x08'
| STACK 0x00001b10 [0x000000a1]
| STACK 0x00001b14 [0x00000000]
| STACK 0x00001b18 [0x00000000]
| STACK 0x00001b1c [0x00000000]
| STACK 0x00001b20 [0x000e0000]
| STACK 0x00001b24 [0x0000ffac]
| STACK 0x00001b28 [0x00000000]
| STACK 0x00001b2c [0x00000616]
| STACK 0x00001b30 [0x00000000]
| STACK 0x00001b34 [0x00000000]
| STACK 0x00001b38 [0x00000000]
| STACK 0x00001b3c [0x00000000]
| STACK 0x00001b40 [0x00000000]
| STACK 0x00001b44 [0x00000000]
| STACK 0x00001b48 [0x00000000]
| STACK 0x00001b4c [0x00000000]

>>Right after in 0x08 (first line of the exception hanlder)
| STACK 0x00001b04 [0x000008c8]
| STACK 0x00001b08 [0x00000008]
| STACK 0x00001b0c [0x00000002]

| STACK 0x00001b10 [0x000000a1]
| STACK 0x00001b14 [0x00000000]
| STACK 0x00001b18 [0x00000000]
| STACK 0x00001b1c [0x00000000]
| STACK 0x00001b20 [0x000e0000]
| STACK 0x00001b24 [0x0000ffac]
| STACK 0x00001b28 [0x00000000]
| STACK 0x00001b2c [0x00000616]
| STACK 0x00001b30 [0x00000000]
| STACK 0x00001b34 [0x00000000]
| STACK 0x00001b38 [0x00000000]
| STACK 0x00001b3c [0x00000000]
| STACK 0x00001b40 [0x00000000]

I'm sure that only EFLAGS, CS and EIP are pushed, not ERR CODE for the exception
| STACK 0x00001b04 [0x000008c8] ==> EIP
| STACK 0x00001b08 [0x00000008] ==> CS
| STACK 0x00001b0c [0x00000002] ==> EFLAGS

I think there are two possible problems
1. There is not 8259PIC in my Bochs
2. My initialization of 8259PIC is wrong

Can someone kindly explain/advise me to fix the problem.
Appreicated!

Jason
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Error code for exception is not pushed ??

Post by iansjack »

You are not triggering an exception; you are calling the interrupt routine that would run if the exception were triggered. Calling an interrupt does not push an error code.
neurocom
Posts: 8
Joined: Wed Nov 27, 2013 8:33 pm

Re: Error code for exception is not pushed ??

Post by neurocom »

iansjack wrote:You are not triggering an exception; you are calling the interrupt routine that would run if the exception were triggered. Calling an interrupt does not push an error code.
=D> Thank you for your answer.
One more question.
If 'INT 0x08' is not for triggering the exception, what is the way to trigger exceptions (e.g Double fault) to identify the error code for the testing purpose?

Thank you,
Jason
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Error code for exception is not pushed ??

Post by iansjack »

You need to create the conditions that trigger the exception. That's easy enough for most exceptions but a little trickier for the double-fault exception. (Double-faults tend to progress to triple faults.) Do something that will create a page fault in your GPF handler, then in your main program do something to create a GPF. That should do the trick I think.

But you don't really need to test that an error code (of zero) is pushed to the stack; that's guaranteed.
neurocom
Posts: 8
Joined: Wed Nov 27, 2013 8:33 pm

Re: Error code for exception is not pushed ??

Post by neurocom »

iansjack wrote:You need to create the conditions that trigger the exception. That's easy enough for most exceptions but a little trickier for the double-fault exception. (Double-faults tend to progress to triple faults.) Do something that will create a page fault in your GPF handler, then in your main program do something to create a GPF. That should do the trick I think.

But you don't really need to test that an error code (of zero) is pushed to the stack; that's guaranteed.
Thanks, iansjack
Great help!

Jason
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Error code for exception is not pushed ??

Post by bluemoon »

iansjack wrote:You need to create the conditions that trigger the exception. That's easy enough for most exceptions but a little trickier for the double-fault exception. (Double-faults tend to progress to triple faults.) Do something that will create a page fault in your GPF handler, then in your main program do something to create a GPF. That should do the trick I think.
But you don't really need to test that an error code (of zero) is pushed to the stack; that's guaranteed.
It might seem weird, but generate a #PF inside the #GP handler is still a single fault.
To create #DF scenario you need a fault when the CPU attempt to call the fault handler. Easiest way is perhaps a NULL handler(CS=0) for divided by zero exception.
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Error code for exception is not pushed ??

Post by iansjack »

You are quite right (and it makes sense). I should have said it the other way round - a GPF inside the PF handler. As I understand it that would cause a double-fault?
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: Error code for exception is not pushed ??

Post by Combuster »

iansjack wrote:a GPF inside the PF handler
Double faults are only triggered if the interrupt invocation itself generates additional exceptions. If for instance the CS:IP in the IDT points to unmapped space, then you get back-to-back pagefaults because each individual cause can be logged. That "works" until the stack runs out milliseconds later and pushing the old CS:IP as part of the interrupt fails in which case the handler has to report two specific issues (cs:*ip and ss:*sp) at the same time and ends up in a double fault.
"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 ]
Post Reply