Stack pointer is 0 in a bare metal AArch64 program
Orlando Arias
orlandoarias@gmail.com
Mon May 11 04:04:45 GMT 2020
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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: OpenPGP digital signature
URL: <https://sourceware.org/pipermail/newlib/attachments/20200511/df1b8652/attachment.sig>
More information about the Newlib
mailing list