From: Joel Sherrill <joel@rtems.org>
To: Orlando Arias <orlandoarias@gmail.com>
Cc: Newlib <newlib@sourceware.org>
Subject: Re: Stack pointer is 0 in a bare metal AArch64 program
Date: Mon, 11 May 2020 07:40:12 -0500 [thread overview]
Message-ID: <CAF9ehCW+oMAGyLOfjXc34mReACcdpzcd-Tn42oLNLUdmC=N1oA@mail.gmail.com> (raw)
In-Reply-To: <439c535b-67be-4d8c-5d9f-9722310cdbdc@gmail.com>
On Sun, May 10, 2020 at 11:04 PM Orlando Arias via Newlib <
newlib@sourceware.org> wrote:
> 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.
>
Then why isn't a linker script provided which provides this? This behavior
is in sharp contrast with other CPU-elf targets with libgloss support. They
can produce executables out of the box with no requirements like this.
--joel
RTEMS
>
> Cheers,
> Orlando.
>
>
next prev parent reply other threads:[~2020-05-11 12:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-11 2:31 Simon Marchi
2020-05-11 4:04 ` Orlando Arias
2020-05-11 12:40 ` Joel Sherrill [this message]
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='CAF9ehCW+oMAGyLOfjXc34mReACcdpzcd-Tn42oLNLUdmC=N1oA@mail.gmail.com' \
--to=joel@rtems.org \
--cc=newlib@sourceware.org \
--cc=orlandoarias@gmail.com \
/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).