2

我已经阅读(并研究过)有关中断处理的信息。
我一直无法理解的是,我们如何知道从中断处理程序返回到(PC / IP)的位置。
据我了解:

  1. 中断是由设备引起的(比如键盘)
  2. 相关的处理程序被调用 - 在正在运行的进程下。也就是说,不执行到 OS 的上下文切换。
  3. 中断处理程序完成,并将控制权交还给正在运行的应用程序。

上面描述的过程,这是我对中断处理的理解,发生在当前运行进程的上下文中。所以它类似于方法调用,而不是上下文切换。
然而,由于我们实际上并没有调用中断处理程序,所以我们没有机会将当前 IP 推入堆栈。
那么我们如何知道从中断中跳回的位置。我很困惑。

将不胜感激任何解释,包括简单地指向一个好的 pdf/ppt 专门解决这个问题的单行词。
[我通常指的是Linux和C代码下的上述过程-但欢迎所有好的答案]

4

3 回答 3

2

It's pretty architecture dependent.

On Intel processors, the interrupt return address is pushed on the stack when an interrupt occurs. You would use an iret instruction to return from the interrupt context.

On ARM, an interrupt causes a processor mode change (to the INT, FIQ, or SVC mode, for example), saving the current CPSR (current program status register) into the SPSR (saved program status register), putting the current execution address into the new mode's LR (link register), and then jumping to the appropriate interrupt vector. Therefore, returning from an interrupt is done by moving the SPSR into the CPSR and then jumping to an address saved in LR - usually done in one step with a subs or movs instruction:

movs pc, lr
于 2012-02-27T22:55:47.863 回答
1

When an interrupt is triggered, the CPU pushes several registers onto the stack, including the instruction pointer (EIP) of the code that was executing before the interrupt. You can put iret and the end of your ISR to pop these values, and restore EIP (as well as CS, EFLAGS, SS and ESP).

By the way, interrupts aren't necessarily triggered by devices. In Linux and DOS, user space programs use interrupts (via int) to make system calls. Some kernel code uses interrupts, for example intentionally triple faulting in order to force a shutdown.

于 2012-02-27T22:55:34.237 回答
0

CPU 中的中断触发机制将返回地址压入堆栈(除其他外)。

于 2012-02-27T22:52:27.613 回答