简体   繁体   English

ARMv7-A架构实现出现IRQ异常时如何计算LR值

[英]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 的参数。

  1. 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.在拇指指令集或用于臂指令集优选返回地址= 0x_0000_1004所以优选返回地址= 0x_0000_1002。 preferred return address for the exception异常的首选返回地址
  2. 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. PC ,它是程序计数器并保存当前程序地址。在这种情况下,在拇指指令状态下PC = 0x_0000_1004或在 arm 指令状态下PC = 0x_0000_1008 how to calculate PC如何计算PC

Then, here are 2 methods mentioned in the document to decide the LR value when taking this IRQ exception.然后,这里有文档中提到的两种方法,用于在采取此 IRQ 异常时确定 LR 值。

  1. by using preferred return address .通过使用首选返回地址 LR = preferred return address + offset that depends on the instruction set state when the exception was taken.In this case LR = 0x_0000_1002 + 4 in thumb instruction state or LR = 0x_0000_1004 + 4 in arm instruction state. LR =首选返回地址+偏移量,取决于发生异常时的指令集状态。在这种情况下,拇指指令状态下的LR = 0x_0000_1002 + 4或 arm 指令状态下的LR = 0x_0000_1004 + 4 Offsets applied to Link value for exceptions taken to PL1 modes应用于 PL1 模式异常的链路值的偏移量
  2. by using PC .通过使用PC LR = PC-0 if in thumb instruction set or LR = PC-4 when in arm instruction set.In this case LR = 0x_0000_1004 - 0 in thumb instruction set or LR = 0x_0000_1008 - 4 in arm instruction state.如果在thumb 指令集中LR = PC-0或在arm 指令集中LR = PC-4 。在这种情况下LR = 0x_0000_1004 - 0在thumb 指令集中或LR = 0x_0000_1008 - 4在arm 指令状态。 Pseudocode description of taking the IRQ exception采取 IRQ 异常的伪代码描述

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.

相关问题 如何确定执行是在线程模式下发生还是异常处于活动状态? (ARMv7-A 架构) - How can I determin if execution takes place in thread mode or if an exception is active? (ARMv7-A architecture) 为什么 ARMv7-A 在从缓存中刷新堆栈指针时会崩溃 - Why ARMv7-A crashes when flushing the stack pointer from the cache 如何以及何时初始化此irq的值 - How and when value for this irq is initialised 如何在ARMv8中将ERET转换为相同的异常级别? - How to ERET to the same exception level in ARMv8? 如何将armv6 / armv7架构更改为armv6会影响我的iPad应用程序?是否会出现性能/稳定性损失? - How does changing armv6/armv7 architecture to armv6 affect my iPad app? Will there be performance/stability losses? 如何在ARMV4i架构上模拟Windows CE 5.0 - How to emulate Windows CE 5.0 on ARMV4i architecture 怎么 ”!” Armv6-M 架构编码中“LDM R1!{R2}”指令的一部分? - How is "!" part of "LDM R1! {R2}" instruction in Armv6-M Architecture Encoded? ARMv8异常向量和处理 - ARMv8 exception vectors and handling ARMv8 程序集,如何将 integer 值转换为浮点值,以及如何打印? - ARMv8 Assembly, How to cast integer value to float value, and how to print it? Armv7:从异常返回到Thumb代码 - Armv7: return frome exception to Thumb Code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM