初始化堆栈指针

时间:2015-05-04 07:22:11

标签: riscv

我目前正在尝试将GCC工具链用于RISC-V,但我遇到了一些问题。

看起来堆栈指针没有正确初始化。我知道我应该自己初始化它,但我无法弄清楚在哪里。我使用更改了正确内存地址的默认链接描述文件,并在此脚本中设置常量_gp。此常量用于默认启动代码以初始化gp寄存器。

不幸的是,这并没有设置sp寄存器。如何在不使用自己的启动代码的情况下设置堆栈指针?

1 个答案:

答案 0 :(得分:2)

This was answered on github:

The execution environment (e.g., OS kernel) is expected to have initialized sp before jumping to the program's entry point. If you're in an embedded domain with different constraints, you need to use a different crt0 that sets up that kind of thing. gp is the ABI global pointer to the small data section. The OS doesn't initialize it because it's a property of the binary, not the execution environment (unlike the stack)