Stack pointer is 0 in a bare metal AArch64 program
Simon Marchi via Newlib <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <[email protected]> |
Hi, Following this thread: https://sourceware.org/pipermail/gdb/2020-May/048516.html I've been trying to build a bare metal AArch64 program and run it in the binutils-gdb simulator. The program is just an empty main function, and it is compiled with: $ aarch64-none-elf-gcc test.c -specs=nosys.specs -g3 -O0 When I try to run it, I get: $ ./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]! memory: write of 0 (8 bytes) to fffffffffffffff0 core: 8 byte write to unmapped address 0xfffffff0 at 0x0 program stopped with signal 11 (Segmentation fault). I understand that these instructions try to set up the stack pointer, reading its initial value from 0x4001b8. This value happens to be 0, not a good value for a stack pointer. I'm guessing that these instructions come from crt0.S, from newlib/libgloss: https://sourceware.org/git/?p=newlib-cygwin.git;a=blob;f=libgloss/aarch64/crt0.S;h=f831be12e6a17e67908dba3e6ffbe5de4e3b58a0;hb=HEAD#l141 With the steps I've done, is it expected that the stack pointer is 0? Is there something I'm missing to make it have some value that makes more sense? Simon