简体   繁体   English

ARM pc寄存器并不总是当前指令的地址加4(拇指状态)

[英]ARM pc register is not always the address of the current instruction plus 4 (Thumb state)

According to the ARM IC. 根据ARM IC。

In Thumb state: 在Thumb状态下:

  • For B, BL, CBNZ, and CBZ instructions, the value of the PC is the address of the current instruction plus 4 bytes. 对于B,BL,CBNZ和CBZ指令,PC的值是当前指令的地址加上4个字节。
  • For all other instructions that use labels, the value of the PC is the address of the current instruction plus 4 bytes. 对于所有使用标签的其他指令,PC的值是当前指令的地址加上4个字节。

When debugging a program, I found pc is not always is the address of the current instruction plus 4 bytes,eg, the following instruction(2). 当调试程序时,我发现pc并不总是当前指令的地址加上4个字节,例如以下指令(2)。
Could someone give some explanations? 有人可以解释一下吗? thanks. 谢谢。

0x2a003118  ldr r3, [pc, #120]  ; (0x2a003194 <main()+684>)   <---(1)
0x2a00311a  ldr r3, [r4, r3] 
0x2a00311c  mov r0, r3 
0x2a00311e  ldr r3, [pc, #136]  ; (0x2a0031a8 <main()+704>)   <---(2)
0x2a003120  add r3, pc                                        <---(3)
0x2a003122  mov r1, r3 
0x2a003124  bl 0x2a00338c
0x2a003128  mov r3, r0 
0x2a00312a  mov r0, r3 
0x2a00312c  ldr r3, [pc, #108]  ; (0x2a00319c <main()+692>)   <---(4)

============================================================ ================================================== ==========

(1).ldr r3, [pc, #120] ; (0x2a003194 <main()+684>)
    p/x $pc+4+120 
    $1 = 0x2a003194
   ; $pc+4 ,Correct

(2).ldr r3, [pc, #136] ; (0x2a0031a8 <main()+704>) 
    p/x $pc+4+136 
    $2 = 0x2a0031aa
   ; Wrong! it should be 0x2a0031a8($pc+2) instead of 0x2a0031aa($pc+4).

(3).add r3, pc
    p/x $r3+$pc+4  
    $3 = 0x2a025c04
   ; $pc+4 ,Correct

(4).ldr r3, [pc, #108]  ; (0x2a00319c <main()+692>)
    p/x $pc+4+108 
    $4 = 0x2a00319c
   ; $pc+4 ,Correct

In ARM DDI 0487B.a 在ARM DDI 0487B.a中

T32 restrictions on the use of the PC, and use of 0b1111 as a register specifier The use of 0b1111 as a register specifier is not normally permitted in T32 instructions. T32对PC使用的限制以及将0b1111用作寄存器说明符在T32指令中通常不允许将0b1111用作寄存器说明符。 When a value of 0b1111 is permitted, a variety of meanings is possible. 当允许值为0b1111时,可能有多种含义。 For register reads, these meanings include: 对于寄存器读取,这些含义包括:

  • Read the PC value, that is, the address of the current instruction + 4. The base register of the table branch instructions TBB and TBH can be the PC. 读取PC值,即当前指令的地址+4。表分支指令TBB和TBH的基址寄存器可以是PC。 This means branch tables can be placed in memory immediately after the instruction. 这意味着可以在指令之后立即将分支表放置在内存中。

Note - ARM deprecates use of the PC as the base register in the STC instruction. 注– ARM拒绝将PC用作STC指令中的基址寄存器。

  • Read the word-aligned PC value, that is, the address of the current instruction + 4, with bits[1:0] forced to zero. 读取字对齐的PC值,即当前指令的地址+ 4, 将位[1:0]强制为零。 The base register of LDC, LDR, LDRB, LDRD (pre-indexed, no writeback), LDRH, LDRSB, and LDRSH instructions can be the word-aligned PC. LDC,LDR,LDRB,LDRD(预索引,无写回),LDRH,LDRSB和LDRSH指令的基址寄存器可以是字对齐的PC。 This provides PC-relative data addressing. 这提供了PC相关的数据寻址。 In addition, some encodings of the ADD and SUB instructions permit their source registers to be 0b1111 for the same purpose. 另外,出于相同的目的,ADD和SUB指令的某些编码允许其源寄存器为0b1111。

You should look for something similar in your reference. 您应该在参考资料中寻找类似的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM