如何在 x64 中编写一个空的中断服务处理程序?

How would an empty interrupt service handler be written in x64?

我已阅读有关中断例程的 AMD64 开发人员手册。根据手册,

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.

因此,空的 ISR 处理程序是否符合此 ASM 代码?

add rsp, 4       ;pop err code off stack
iretq

我假设错误代码的大小是 4 个字节,正如其他网站告诉我的那样。我很确定这是完全错误的,但一些指导会有所帮助。

长模式 (x64) 中的错误代码大小为 8 个字节。因此,您需要添加 8 个字节,而不是向堆栈指针添加 4 个字节。

此外,并非所有异常都会将错误代码压入堆栈。 table 可以在这里找到包含哪些异常可以和不可以的异常:https://wiki.osdev.org/Exceptions

如果处理程序不推送错误代码,则空处理程序只是处理程序对 return 的 iretq 指令。如果确实推送错误代码,我们只需将 8 个字节添加到堆栈指针,然后从处理程序中添加 return。

add rsp, 8
iretq

谢谢@MichaelPetch