cnlohr / mini-rv32ima

A tiny C header-only risc-v emulator.
MIT License
1.69k stars 137 forks source link

baremetal: initial stack pointer #21

Closed ronanj closed 1 year ago

ronanj commented 1 year ago

The initial stack pointer is currently set up using lui sp, 0x80100 in baremetal.S.

Since the stack is also defined in the linker file, it is instead possible to use la sp, _sstack to get the exact stack address computed by the linker.

Note that since la is a pseudo instruction, it is converted by the compiler to the following code:

80000000 <__TEXT_BEGIN__>:
80000000:   00002117            auipc   sp,0x2
80000004:   1c010113            addi    sp,sp,448 # 800021c0 <_sstack>
cnlohr commented 1 year ago

Thank you for finding this.