[英]How to calculate the LR value when ARMv7-A architecture implementation takes an IRQ exception
I'm researching the the Arm Architecture Reference Manual ARMv7-A ARMv7-R edition document these days.这些天我正在研究Arm 架构参考手册 ARMv7-A ARMv7-R 版文档。 When I read about the exception handling part of this manual, it comes across a confusions to me.
当我阅读本手册的异常处理部分时,我感到困惑。 The problem is about how to decide the LR value when ARMv7-A architecture implementation takes an IRQ exception .
问题是当 ARMv7-A 架构实现出现 IRQ 异常时如何决定 LR 值。
EXAMPLE: Suppose that the processor is executing an instruction at the address of 0x_0000_1000 and an IRQ is taken.First, we have to calculate some parameters to be used to calculate the LR.示例:假设处理器正在执行地址为 0x_0000_1000 的指令,并采取了 IRQ。首先,我们必须计算一些用于计算 LR 的参数。
Then, here are 2 methods mentioned in the document to decide the LR value when taking this IRQ exception.然后,这里有文档中提到的两种方法,用于在采取此 IRQ 异常时确定 LR 值。
Problem :the LR results calculated by the 2 methods are different both in thumb set state and arm set state(with first method we get LR = 0x_0000_1006 or LR = 0x_0000_1008 ,but second method we get LR = 0x_0000_1004 or LR = 0x_0000_1004 ).问题:两种方法计算的 LR 结果在拇指设置状态和手臂设置状态下都不同(第一种方法我们得到LR = 0x_0000_1006 或 LR = 0x_0000_1008 ,但第二种方法我们得到LR = 0x_0000_1004 或 LR = 0x_0040 )。 which one is correct or is there any wrong with my understanding?
哪一个是正确的,或者我的理解有什么问题?
TL;DR - the IRQ LR
will point to the next instruction to complete work as would normally be run without an interrupt. TL;DR - IRQ
LR
将指向下一条指令以完成正常运行而没有中断的工作。 Otherwise, code would not execute the same in the presence of interrupts.否则,在存在中断的情况下,代码将不会执行相同的操作。
It is confusing as the ARM documents may refer to PC
in many different contexts and they are not the same.这是令人困惑的,因为 ARM 文档可能在许多不同的上下文中提到
PC
,而且它们并不相同。
EXAMPLE:Suppose that the processor is executing an instruction at the address of 0x_0000_1000 and an IRQ is taken.
示例:假设处理器正在执行地址为 0x_0000_1000 的指令,并采取了 IRQ。 First, we have to calculate some parameters to be used to calculate the LR.
首先,我们必须计算一些用于计算LR的参数。
preferred return address,which is the Address of next instruction to execute in this case.
首选返回地址,即在这种情况下要执行的下一条指令的地址。 So preferred return address = 0x_0000_1002 in thumb instruction set or preferred return address = 0x_0000_1004 for arm instruction set.preferred return address for the exception
因此,thumb 指令集中的首选返回地址 = 0x_0000_1002 或 arm 指令集的首选返回地址 = 0x_0000_1004。异常的首选返回地址
This is not correct.这是不正确的。 The ARM cpu has a pipeline and the last instruction that it has deemed to have completed is the next instruction .
ARM cpu 有一条流水线,它认为已完成的最后一条指令是下一条指令。 Take for example this sequence,
以这个序列为例,
0: cmp r1, #42
1: bne 4f ; interrupt happens as this completes.
2: add r2, r2, #4
3: b 5f
4: sub r2, r2, #2
5: ; more code.
If the interrupt happens as label '1:' happens, the next instruction will be either '2:' or '4:'.如果中断在标签“1:”发生时发生,则下一条指令将是“2:”或“4:”。 If you followed your rule this would either increase interrupt latency by never allowing an interrupt in such cases, or interrupts would cause incorrect code.
如果您遵循您的规则,这将增加中断延迟,因为在这种情况下不允许中断,或者中断会导致不正确的代码。 Specifically, your link says next instruction to execute .
具体来说,您的链接表示要执行的下一条指令。
PC,which is the program counter and holds the current program address.In this case, PC = 0x_0000_1004 in thumb instruction state or PC = 0x_0000_1008 in arm instruction state.how to calculate PC
PC,它是程序计数器,保存当前程序地址。在这种情况下,拇指指令状态下PC = 0x_0000_1004或arm指令状态下PC = 0x_0000_1008。如何计算PC
Here you are mixing concepts.在这里,您正在混合概念。 One is when you use a value like
ldr r0, [pc, #42]
.一种是当您使用
ldr r0, [pc, #42]
。 When you calculate the offset, you must add two to the current ldr
instruction.计算偏移量时,必须将两个添加到当前
ldr
指令。 The actual PC
is not necessarily this value.实际
PC
不一定是这个值。 At some point (original version), the ARM was a two stage pipeline.在某些时候(原始版本),ARM 是一个两阶段流水线。 In order to keep behaviour the same, subsequent ARM cpus follow the rule of being two ahead when calculating
ldr r0, [pc, #42]
type addresses.为了保持行为不变,后续的ARM cpus在计算
ldr r0, [pc, #42]
类型地址时遵循前两位的规则。 However, the actual PC may be much different inside the CPU.但是,实际 PC 的 CPU 内部可能大不相同。 The concept above describes the programmer visible
PC
for use with addressing.上述概念描述了用于寻址的程序员可见
PC
。
The CPU will make a decision, sometimes base on configuration, on what work to complete. CPU 有时会根据配置做出决定,决定要完成哪些工作。 For instance,
ldm sp!, {r0-r12}
may take some time to complete.例如,
ldm sp!, {r0-r12}
可能需要一些时间才能完成。 The CPU may decide to abort this instruction to keep interrupt latency low. CPU 可能会决定中止该指令以保持较低的中断延迟。 Alternatively, it may perform 12 memory reads which could have wait states.
或者,它可以执行 12 次可能具有等待状态的内存读取。 The
LR_irq
will be set to the ldm
instruction or the next instruction depending whether it is aborted or not. LR_irq
将被设置为ldm
指令或下一条指令,具体取决于它是否中止。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.