Schnoogle
Posts: 90
Joined: Sun Feb 11, 2018 4:47 pm

[SLOVED] Aarch64 - "stp q0, q0, [x8, #224]" hangs my Pi3

Fri Oct 18, 2019 12:59 pm

Hi there,

while playing around with aarch64 mode I've seen my Raspberry Pi hangs at a specific instruction.
The compiler is generating:

Code: Select all

stp	q0, q0, [x8, #224]
and I've proven with handwritten code at a specific known location that this code hangs my Pi.

Does anyone could point me into a direction what might be a reason for this?
I've checked that the actual core is running in EL1 and that I've enabled to use FP/NEON instructions with cpacr_el1 register.

I've also cross-checked behaviour in lates QEMU version and there the code gets executed fine (no exception thrown or the like)

Thanks in advance for your support.
BR
Schnoogle
Last edited by Schnoogle on Fri Oct 25, 2019 11:14 am, edited 1 time in total.

DoubleCheck
Posts: 4
Joined: Fri Sep 27, 2019 9:36 pm

Re: Aarch64 - "stp q0, q0, [x8, #224]" hangs my Pi3

Fri Oct 18, 2019 3:12 pm

I suppose you haven't enabled the MMU?

It's an alignment problem.

LdB
Posts: 1317
Joined: Wed Dec 07, 2016 2:29 pm

Re: Aarch64 - "stp q0, q0, [x8, #224]" hangs my Pi3

Fri Oct 18, 2019 3:55 pm

What value is in x8? It should to be 16 byte aligned.

Schnoogle
Posts: 90
Joined: Sun Feb 11, 2018 4:47 pm

Re: Aarch64 - "stp q0, q0, [x8, #224]" hangs my Pi3

Fri Oct 18, 2019 5:08 pm

DoubleCheck wrote: I suppose you haven't enabled the MMU?

It's an alignment problem.
Hi, I checked with and without MMU beeing enabled. Some behaviour.
LdB wrote:What value is in x8? It should to be 16 byte aligned.
Well actually this is the stackpointer. The compiler generates code like this:

Code: Select all

sub sp, sp, #0x130
    add x8, sp, #0x8
to set X8 to a specific part of the current stack frame.

However, you pointed me into the right direction (thanks for that ;) )and I disabled the alignment checks with this:

Code: Select all

mrs		x1, sctlr_el1
    mov     x2, #(1 << 1 | 1 << 3 | 1 << 4) 
	bic     x1, x1, x2  // clear SA0, SA and A bits
	msr     sctlr_el1, x1
	isb
And the code does work now, BUT only when MMU is enabled. So I guess only the enabled MMU can handle the unaligned access ???

LdB
Posts: 1317
Joined: Wed Dec 07, 2016 2:29 pm

Re: Aarch64 - "stp q0, q0, [x8, #224]" hangs my Pi3

Sun Oct 20, 2019 5:58 pm

Yes but more specifically you have broken the AAPCS64 calling convention somehow

AARCH64 makes an absolute requirement that when calling external functions the stack must be 16byte aligned
GCC will default -mpreferred-stack-boundary=4 meaning all its stack stuff is 16byte aligned

So what are you doing to the stack that it is getting so upset about?
Specifically I am querying are you inlining 64bit code assembler on a 32 bit version of linux which will have 8 byte stack alignment :-)

Schnoogle
Posts: 90
Joined: Sun Feb 11, 2018 4:47 pm

Re: Aarch64 - "stp q0, q0, [x8, #224]" hangs my Pi3

Mon Oct 21, 2019 8:37 am

LdB wrote:
Sun Oct 20, 2019 5:58 pm
So what are you doing to the stack that it is getting so upset about?
Specifically I am querying are you inlining 64bit code assembler on a 32 bit version of linux which will have 8 byte stack alignment :-)
Hey,

well, interestingly I'm dooing complete bare-metal stuff in Aarch64. So there is no Linux running nor is it a mixture of 32bit and 64bit. I'm using ARM's Aarch64-elf cross compiler toolchain to build the RasPi bare metal kernel on my Windows machine.

The only "speciality" might be, that I'm not compiling from C but rather using Rust and I'm not sure whether I could pass the "preferred-stack-boundary" flag to the rust compiler. I'll check in the Rust forum as well :)

Schnoogle
Posts: 90
Joined: Sun Feb 11, 2018 4:47 pm

Re: Aarch64 - "stp q0, q0, [x8, #224]" hangs my Pi3

Mon Oct 21, 2019 6:54 pm

Hi there,

it turned out to really be an issue with the rust compiler. Adding a strict alignment flag solved the issue by generating code that complies to the required alignment rules...

https://users.rust-lang.org/t/rust-comp ... talestudio

Return to “Bare metal, Assembly language”