Peter Verbrugge
Peter Verbrugge

Reputation: 75

Initializing stack pointer

I'm currently trying to use the GCC toolchain for RISC-V but i'm running into a few problems.

It looks like the stack pointer doesn't get initialized properly. I know i should initialize it myself, but i can't figure out where. I'm using the default linker script altered with the correct memory addresses and in this script a constant _gp gets set. This constant is used in the default startup code to initialize the gp register.

Unfortunately this doesn't set the sp register. How can i set up the stack pointer without using my own start up code?

Upvotes: 2

Views: 2188

Answers (1)

user2548418
user2548418

Reputation: 1571

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)

Upvotes: 2

Related Questions