简体   繁体   English

ARM-Cortex M4F 的 R3 寄存器在 ldr 指令后突然改变值

[英]R3 register of ARM-Cortex M4F suddenly changes value right after ldr instruction

I have this really strange bug where an ldr instruction first loads in a valid value into the R3 register, then when I use the debugger to step over one instruction, it all of a sudden contains the value 0x0.我有一个非常奇怪的错误,其中 ldr 指令首先将有效值加载到 R3 寄存器中,然后当我使用调试器单步执行一条指令时,它突然包含值 0x0。
This assembly is generated from C++ by GCC9 for C++17.此程序集由 GCC9 为 C++17 从 C++ 生成。

The instructions are:指令是:

ldr r3, [r7, #12]    ; after this instruction r3 will have value 0x20009da0
ldr r3, [r3, #8]     ; after this instruction r3 will have value 0x20003e28
ldr r3, [r3]         ; after this instruction r3 will have value 0x00020a2c, the value at this addr is 0000a1a9
ldr r3, [r3]         ; after this instruction r3 will suddenly have value 0x00000000
ldr r2, [r7, #12]        
ldr r2, [r2, #8]         
mov r0, r2       
blx r3               ; at this point r3 still has value 0x00000000 causing the reset handler to be called

Shouldn't r3 have the value 0x0000a1a9 after the last ldr instruction? r3 不应该在最后一条ldr指令之后具有值0x0000a1a9吗?

To give some more information, I am developing for Microchip's ATSAMD51J20A using Microchip Studio with GCC9 installed.为了提供更多信息,我正在使用安装了 GCC9 的 Microchip Studio 为 Microchip 的 ATSAMD51J20A 进行开发。 The code in question where this occurs is:发生这种情况的有问题的代码是:

auto& socket = m_device.get_socket();

where get_socket() has as its return value a reference to an interface class and the actual implementation of get_socket() returns a reference to a class which extends this interface.其中get_socket()的返回值是对接口类的引用,而get_socket()的实际实现返回对扩展此接口的类的引用。

I remember Microchip compilers having strange (timing?) issues where lines of repeated instructions behave in unexpected ways.我记得 Microchip 编译器有奇怪的(时序?)问题,重复指令行以意想不到的方式表现。 I still don't know about the details but sometimes padding NOPs between these lines resolves the problem.我仍然不知道细节,但有时在这些行之间填充 NOP 可以解决问题。

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

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