Posts: 17
Joined: Wed Jul 03, 2019 5:18 pm

Application freezes on atomic write to memory

Tue Oct 08, 2019 9:34 pm

AArch64 code runs on RPi4.
My binary disassembles to

Code: Select all

// halt cores 1..3, setup stack and go to main
 0:   d53800a9    mrs x9, mpidr_el1
 4:   92400529    and x9, x9, #0x3
 8:   b4000069    cbz x9, 0x14
 c:   d503205f    wfe
10:   17ffffff    b   0xc
14:   10ffff69    adr x9, 0x0
18:   9100013f    mov sp, x9

// atomic write
1c:   90000008    adrp    x8, 0x0
20:   91016108    add x8, x8, #0x58
24:   c85ffd09    ldaxr   x9, [x8]
28:   b2720129    orr x9, x9, #0x4000
2c:   c80afd09    stlxr   w10, x9, [x8]
30:   35ffffaa    cbnz    w10, 0x24

// Turn on LED <-- this code is never executed
34:   d2bfc404    mov x4, #0xfe200000
38:   b9401080    ldr w0, [x4, #16]
3c:   12177000    and w0, w0, #0xfffffe3f
40:   321a0000    orr w0, w0, #0x40
44:   b9001080    str w0, [x4, #16]
48:   52808000    mov w0, #0x400
4c:   f9001080    str x0, [x4, #32]
50:   14000000    b   0x50
The problem is it enters infinite loop on ldaxr/stlxr instructions. All works OK as soon as I replace ldaxr/stlxr with ldr/str.
What could be the reason for not being able to write atomically? Could it be something with memory access settings? I have no idea how to debug this code and where to look at. Any help or advice is highly appreciated. Thanks in advance!

Posts: 1593
Joined: Wed Dec 07, 2016 2:29 pm

Re: Application freezes on atomic write to memory

Tue Oct 08, 2019 11:28 pm

ldaxr/stlxr requires the MMU to be on and the memory to be properly shared, read the manual on the instruction on the processor.

Return to “Bare metal, Assembly language”