public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Orlando Arias <orlandoarias@gmail.com>
To: newlib@sourceware.org
Subject: Re: Stack pointer is 0 in a bare metal AArch64 program
Date: Mon, 11 May 2020 00:04:45 -0400	[thread overview]
Message-ID: <439c535b-67be-4d8c-5d9f-9722310cdbdc@gmail.com> (raw)
In-Reply-To: <1eabaa19-fb43-e45d-1b16-12edcdf4aa3e@polymtl.ca>


[-- Attachment #1.1: Type: text/plain, Size: 1519 bytes --]

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.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

  reply	other threads:[~2020-05-11  4:04 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 [this message]
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=439c535b-67be-4d8c-5d9f-9722310cdbdc@gmail.com \
    --to=orlandoarias@gmail.com \
    --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).