public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* Stack pointer is 0 in a bare metal AArch64 program
@ 2020-05-11  2:31 Simon Marchi
  2020-05-11  4:04 ` Orlando Arias
  0 siblings, 1 reply; 5+ messages in thread
From: Simon Marchi @ 2020-05-11  2:31 UTC (permalink / raw)
  To: newlib

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-05-11 16:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-11  2:31 Stack pointer is 0 in a bare metal AArch64 program Simon Marchi
2020-05-11  4:04 ` Orlando Arias
2020-05-11 12:40   ` Joel Sherrill
2020-05-11 12:49     ` Christophe Lyon
2020-05-11 16:00     ` Orlando Arias

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).