Re: Stack pointer is 0 in a bare metal AArch64 program
Orlando Arias via Newlib <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <[email protected]> |
Greetings,
On 5/10/20 10:31 PM, Simon Marchi via Newlib wrote:
> $ ./sim/aarch64/run --trace=on --trace-disasm=on ./sim/aarch64/a.out
> memory: ERROR: executable is too big: ffffffffffffffff
> insn: pc = 400168 instr = 58000281
> disasm: ldr x1, 0x00000000004001b8
> memory: read of 0 (8 bytes) from 4001b8
> insn: pc = 40016c instr = 927cec20
> disasm: and x0, x1, #0xfffffffffffffff0
> insn: pc = 400170 instr = 9100001f
> disasm: mov sp, x0
> insn: pc = 400174 instr = d280001d
> disasm: mov x29, #0x0 // #0
> insn: pc = 400178 instr = a9bf77fd
> disasm: stp x29, x29, [sp, #-16]!
Within libgloss for Aarch64, the stack is initialized using a weak
symbol with the value of 0:
.macro GEN_DWORD name
#if defined(__ILP32__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
.word \name
.word 0
#elif defined(__ILP32__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
.word 0
.word \name
#else
.dword \name
#endif
.endm
.Lstack:
GEN_DWORD __stack
.weak __stack
If the linker script you are utilizing does not define __stack, then the
weak symbol is used.
As an aside, this behavior in libgloss has always annoyed me. When
working with Cortex-M cores [both ARMv7-M and ARMv8-M], msp is
initialized using the value stored in address 0 of the memory map by the
hardware. Yes, the application is free to change it afterwards, but it
just seems redundant to me.
Cheers,
Orlando.
signature.asc
(application/pgp-signature, 195 B)
-----BEGIN PGP SIGNATURE----- iF0EAREKAB0WIQQNWDJzd34+k5noE3NTFb9QFn4uoQUCXrjO5QAKCRBTFb9QFn4u oZclAKCY4MueEZaqLVS13hLVXMoRgFs50gCfSDu7QhbLwLuys+u0KkrTqDkynPM= =Yocb -----END PGP SIGNATURE-----