其中Interrupt保存当前activity的地址,以便执行完中断处理程序后恢复
where Interrupt saves the address of the current activity to resume it after executing the interrupt handler
"When an interrupt is occurred, The processor responds by suspending its current activities, saving its state, and executing a function called an interrupt handler"
The question is where the processor save the address of the current
activities to resume it after executing the interrupt handler?
这取决于您所属的体系结构。但通常是处理器自己在中断的瞬间将当前程序计数器压入当前栈。然后中断的 return 将获取那些堆栈的 PC 信息和 returns 到正常的程序流程。例如。将 PC 推入堆栈的架构:Atmel AVR、ARM Cortex-M、PowerPC。
爱特梅尔 AVR:http://www.atmel.com/webdoc/avrassembler/avrassembler.wb_RETI.html
ARM Cortex-M:http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0552a/Babefdjc.html
很大程度上取决于体系结构。
我想到了几种方法(我相信还有更多):
- 将必要的寄存器压入当前堆栈(例如:指令指针),然后跳转到异常处理程序。然后异常处理程序负责保存它需要使用的任何其他寄存器。我相信这是 x86 CPUs 所做的方法。我只是不确定它是默认推送所有寄存器,还是推送基本寄存器。
- CPU根据CPU模式有不同的寄存器集。 (例如::用户模式、中断模式)。本质上,当中断发生时,它开始使用不同的寄存器组。例如,ARM cpus 就是这样做的,尽管它们不使用每个 CPU 模式的完整寄存器集。参见 https://en.wikipedia.org/wiki/ARM_architecture#Registers
- 一些古老的cpu本身就在RAM中设置了寄存器,所以切换上下文只是改变寄存器组在内存中的位置。参见 https://en.wikipedia.org/wiki/Texas_Instruments_TMS9900#Architecture. This approach is not feasible if the RAM is way slower than the CPU itself. But it's still feasible for simulated computers. For example, my hobby project (A fully simulated computer) uses this approach. The kernel setups up a different register set per application.https://bitbucket.org/ruifig/g4devkit。虽然我可能会在某些时候更改为不同的解决方案。
"When an interrupt is occurred, The processor responds by suspending its current activities, saving its state, and executing a function called an interrupt handler"
The question is where the processor save the address of the current activities to resume it after executing the interrupt handler?
这取决于您所属的体系结构。但通常是处理器自己在中断的瞬间将当前程序计数器压入当前栈。然后中断的 return 将获取那些堆栈的 PC 信息和 returns 到正常的程序流程。例如。将 PC 推入堆栈的架构:Atmel AVR、ARM Cortex-M、PowerPC。
爱特梅尔 AVR:http://www.atmel.com/webdoc/avrassembler/avrassembler.wb_RETI.html
ARM Cortex-M:http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0552a/Babefdjc.html
很大程度上取决于体系结构。 我想到了几种方法(我相信还有更多):
- 将必要的寄存器压入当前堆栈(例如:指令指针),然后跳转到异常处理程序。然后异常处理程序负责保存它需要使用的任何其他寄存器。我相信这是 x86 CPUs 所做的方法。我只是不确定它是默认推送所有寄存器,还是推送基本寄存器。
- CPU根据CPU模式有不同的寄存器集。 (例如::用户模式、中断模式)。本质上,当中断发生时,它开始使用不同的寄存器组。例如,ARM cpus 就是这样做的,尽管它们不使用每个 CPU 模式的完整寄存器集。参见 https://en.wikipedia.org/wiki/ARM_architecture#Registers
- 一些古老的cpu本身就在RAM中设置了寄存器,所以切换上下文只是改变寄存器组在内存中的位置。参见 https://en.wikipedia.org/wiki/Texas_Instruments_TMS9900#Architecture. This approach is not feasible if the RAM is way slower than the CPU itself. But it's still feasible for simulated computers. For example, my hobby project (A fully simulated computer) uses this approach. The kernel setups up a different register set per application.https://bitbucket.org/ruifig/g4devkit。虽然我可能会在某些时候更改为不同的解决方案。