Assembly – do you have to pop an error code pushed onto the stack by some exceptions before returning from the interrupt handler?
I have loaded an IDT table with 256 entries, all of which point to similar handlers:
>Push exception numbers for exceptions 8 and 10-14 (these exceptions will automatically push error codes) > push "virtual" error codes and exception numbers for others; > Then jump to a public handler
Therefore, when the common handler enters, the stack is properly aligned and contains exception / interrupt numbers, error codes (possibly just virtual code), EFLAGS, CS, and EIP
My question is about returning from the interrupt handler I take the exception number and error code from the stack and use IRET to return, but this has no effect on exception NR 8; If I leave the error code on the stack, it returns to normal!
Question:
>Do I have to leave the error code on the stack to find the exception where the error code is placed? If so, how does IRET determine if an error code must pop up? > Once I enable interrupts, I always get exception 8 (double fault), but everything works normally (I'm developing a hobby operating system) Is this normal behavior or something wrong?
Solution
If the CPU automatically pushes the error code, the handler must eject it before IRET If it is a fault, trap or external interrupt, the IRET command does not know where you come from It is always the same and assumes that there are no error codes on the stack
From SDM (software developer's manual), Volume 3, Chapter 5, section 5.13, entitled error code:
You can find IA-32 software developer's manual here: http://www.intel.com/products/processor/manuals/
Chapter 5, Part 1, Volume 3, describes exception and interrupt handling Volume 2, Part 1, contains specifications for the IRET directive