1

我目前正在使用 Cortex-M3,但无法理解 xPSR 的使用。我不确定为什么 ISR 编号存储在最低 8 位中。

在线资源和数据表没有说明为什么必须将数字存储在 xPSR 中。在 ARM7-TDMI 上,当前模式(FIQ、IRQ、SVC、USR、ABT、UND)存储在 CPSR 的最低 8 位中。我假设它存储在那里,因此当引发异常并切换模式时,处理器知道将 CPSR 的状态保存到哪个寄存器组。然而,Cortex-M3 没有分组寄存器,当需要服务 ISR 时,xPSR 被保存到堆栈中。

任何人都可以启发我吗?

4

2 回答 2

2

Is this what you are talking about?

The IPSR
The processor writes to the IPSR on exception entry and exit. Software can use an MRS instruction, to read
the IPSR, but the processor ignores writes to the IPSR by an MSR instruction. The IPSR Exception Number
field is defined as follows:
•    in Thread mode, the value is 0
•    in Handler mode, holds the exception number of the currently-executing exception.
An exception number indicates the currently executing exception and its entry vector, see Exception number
definition on page B1-633 and The vector table on page B1-634.
On reset, the processor is in Thread mode and the Exception Number field of the IPSR is cleared to 0. As a
result, the value 1, the exception number for reset, is a transitory value, that software cannot see as a valid
IPSR Exception Number.

I would see that as similar to the cpsr in the ARMv4/ARM7TDMI as it gives you the state in which you are executing. if you are executing in an exception and if so which one. It likely has meaning to the chip designers for similar reasons and that is where that information or a copy of that information is held. Perhaps to not re-enter an exception handler if already in that exception mode for example. Or if a second exception of some type, say a prefetch abort while executing the prefetch abort perhaps the processor hangs on purpose or chooses a different exception.

于 2013-06-12T14:01:05.343 回答
0

好吧,我不完全确定我理解了这个问题-您是在问“为什么不同”或“有什么意义”?

在第一种情况下 - 答案与“为什么它不支持 ARM 指令集”、“为什么只有 2 种执行模式”、“为什么向量表很大并且包含地址而不是指令”和“为什么只有 2 个可能的堆栈指针”:“因为”。因为 M-profile 有一个完全不同的异常模型。(而且由于异常模型不同,CPSR 中的模式位可以自由用于其他用途。)

在第二种情况下......好吧,这取决于开发人员,不是吗?恰好有一个寄存器保存当前活动的中断 ID。如果这对您有好处,请务必使用它。您可以(例如)使用它将单个中断处理程序地址存储到向量表中的多个位置,然后使用中断 ID 来识别哪个特定设备触发了中断。

从可重入异常处理的角度来看,这听起来也很方便。

http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0552a/CHDBIBGJ.html

于 2013-06-12T07:29:05.320 回答