2

如何在 32 位保护模式(显然是 x86)下查看 PIT IRQ 处理程序的返回值?我想我可以这样做,我不完全确定。

pop eax ; pop last thing from stack
mov dword return_address,eax
push eax
iret 
4

2 回答 2

5

这将从堆栈中读取正确的项目,但如果你这样做,你会损坏eax.

一个适当的 ISR 在其执行结束时必须将所有使用的寄存器恢复到它们在 ISR 启动时所处的状态。

另一件需要注意的事情......return_address将通过段寄存器(这里,ds)被(隐式地)引用。如果ds在 ISR 和 ISR 中断的代码中始终相同,则可以。然而,如果被中断的代码发生变化ds,ISR 必须ds在其开始处保存,将其设置为正确的选择器值,使用它然后恢复它。如果您不这样做,该mov指令可能会损坏内存或导致异常。

于 2012-09-16T09:02:45.257 回答
0

更像的东西

push eax
push ds
mov eax,cs:saved_ds
mov ds,eax
mov eax,[esp+8]
mov return_address,eax
pop ds
pop eax
iret

将保留 eax 并可以处理任意段值。它要求您在saved_ds上述 ISR 运行之前保存“ds”段寄存器。它使用cs寄存器来访问它 - 大多数(所有?)平台的基数 c 等于 ds 的基数,并且 cs 可读。

Usually, an ISR has to acknowledge the IRQ (is your code a software interrupt hook?). Your code isn't showing it so I figured your code fragment in the question was just a stripped down version of the real code.

于 2013-01-21T23:20:16.773 回答