初始化堆栈指针
Initializing stack pointer
我目前正在尝试将 GCC 工具链用于 RISC-V,但我 运行 遇到了一些问题。
看起来堆栈指针没有正确初始化。我知道我应该自己初始化它,但我不知道在哪里。我正在使用用正确的内存地址修改过的默认链接描述文件,并且在这个脚本中设置了一个常量 _gp。该常量在默认启动代码中用于初始化 gp 寄存器。
不幸的是,这并没有设置 sp 寄存器。如何在不使用我自己的启动代码的情况下设置堆栈指针?
已在 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)
我目前正在尝试将 GCC 工具链用于 RISC-V,但我 运行 遇到了一些问题。
看起来堆栈指针没有正确初始化。我知道我应该自己初始化它,但我不知道在哪里。我正在使用用正确的内存地址修改过的默认链接描述文件,并且在这个脚本中设置了一个常量 _gp。该常量在默认启动代码中用于初始化 gp 寄存器。
不幸的是,这并没有设置 sp 寄存器。如何在不使用我自己的启动代码的情况下设置堆栈指针?
已在 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)