Reputation: 1420
I have read the AMD64 Developer manual on interrupt routines. According to the manual,
The interrupt handler must pop the error code off the stack if one was pushed by the interrupt or exception. IRET restores the interrupted program's rIP, CS and rFLAGS by popping their saved values off of the stack and into their respective registers.
Therefore, would an empty ISR handler look something along this ASM code?
add rsp, 4 ;pop err code off stack
iretq
I am assuming the size of the error code is 4 bytes, as other websites have told me. I'm pretty sure this is totally wrong, but some guidance will help.
Upvotes: 1
Views: 778
Reputation: 1420
The error code size in long-mode (x64) is 8 bytes long. So instead of adding 4 bytes to the stack pointer, you will need to add 8 bytes.
In addition, not all exceptions push an error code onto the stack. A table that contains which exceptions do and do not can be found here: https://wiki.osdev.org/Exceptions
If a hander does not push an error code, the empty handler is just the iretq
instruction to return from the handler. If it DOES push an error code, we simply add 8 bytes to the stack pointer and then return from the handler.
add rsp, 8
iretq
Thanks @MichaelPetch
Upvotes: 4