[英]C Environment Init Bare Metal ARM GCC
I'm trying to get a C++ project to work on a cortex-m0
processor (the nRF51822
to be specific). 我正在尝试让一个C ++项目在
cortex-m0
处理器(具体来说是nRF51822
)上工作。 I'm using codesourcery lite g++ 2013.05.23. 我正在使用codesourcery lite g ++ 2013.05.23。 I'm using the clib that comes with codesourcery (newlib) and the CS3 c init routine __cs3_start_c.
我正在使用代码源(newlib)和CS3 c初始化例程__cs3_start_c随附的clib。 I've rewritten the __cs3_restart, and __cs3_start_asm functions.
我已经重写了__cs3_restart和__cs3_start_asm函数。
I can get as far as the clib _init
function, which is called from something like __libc_init_array
. 我可以深入到clib
_init
函数,该函数从__libc_init_array
东西__libc_init_array
。 When I execute the instruction at address 00012388
, the processor faults. 当我在地址
00012388
执行指令时,处理器出现故障。
Since this instruction is a pop
, I immediately suspected the stack pointer was invalid; 由于该指令是
pop
,因此我立即怀疑堆栈指针无效; however, the register values captured before the fault indicate otherwise. 但是,在故障发生之前捕获的寄存器值表明情况并非如此。 Any ideas why the processor is faulting?
任何有关处理器故障的想法吗? What can I do to init the C++ environment so that I can start running code?
我该怎么做才能初始化C ++环境,以便可以开始运行代码?
_init:
00012384: _init+0 push {r3, r4, r5, r6, r7, lr}
00012386: _init+2 nop ; (mov r8, r8)
00012388: _init+4 pop {r3, r4, r5, r6, r7}
0001238a: _init+6 pop {r3}
0001238c: _init+8 mov lr, r3
0001238e: _init+10 bx lr
Register Values: 注册值:
Register Val: Hex Val: Dec
r0 0x20008d8 33556696
r1 0x123c0 74688
r2 0xa68 2664
r3 0x2001340 33559360
r4 0x0 0
r5 0x12390 74640
r6 0x0 0
r7 0x12c90 76944
r8 0xffffffff 4294967295
r9 0xffffffff 4294967295
r10 0xffffffff 4294967295
r11 0xffffffff 4294967295
r12 0xffffffff 4294967295
sp 0x2003fb8 0x2003fb8
lr 0xff89 65417
pc 0x12388 0x12388 <_init+4>
xpsr 0x41000003 1090519043
MSP 0x2003fb8 33570744
PSP 0xfffffffc 4294967292
PRIMASK 0x0 0
BASEPRI 0x0 0
FAULTMASK 0x0 0
CONTROL 0x0 0
The code I'm trying compile is the following I don't have any statically allocated classes so I don't quite understand why this code is even running. 我尝试编译的代码如下,但我没有任何静态分配的类,因此我不太理解为什么该代码甚至在运行。
Main.cpp
volatile int i = 4;
volatile int j = 0;
volatile int k;
int main(void)
{
for(;j< i; j++)
{
k = k +2;
}
TestClass * tc = new TestClass(3);
while(1){};
}
Testclass.h
class TestClass {
public:
int i;
TestClass(int num);
virtual ~TestClass();
};
TestClass.cpp
TestClass::TestClass(int num) {
this->i = num;
}
TestClass::~TestClass() {
}
Thanks! 谢谢!
Sorry to trouble everyone, figured out the issue. 很抱歉麻烦大家,解决了这个问题。 The stack pointer was bad.
堆栈指针错误。 The top of the stack should have been set to 0x20040000, it was actually set to 0x02040000.
堆栈的顶部应已设置为0x20040000,实际上已设置为0x02040000。 I'm just surprised the code made it as far as it did without a fault.
我很惊讶代码达到了它没有错误的程度。
Thanks again. 再次感谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.