public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: newlib@sourceware.org
Subject: Stack pointer is 0 in a bare metal AArch64 program
Date: Sun, 10 May 2020 22:31:54 -0400	[thread overview]
Message-ID: <1eabaa19-fb43-e45d-1b16-12edcdf4aa3e@polymtl.ca> (raw)

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

             reply	other threads:[~2020-05-11  2:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-11  2:31 Simon Marchi [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1eabaa19-fb43-e45d-1b16-12edcdf4aa3e@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=newlib@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).