This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Issue with stxr in ARMv8

Hi,

I am writing a simple spinlock taking Juno arm trusted firmware spinlock code.

But for me stxr instruction is always failing giving w1 value as "1" always.

When I read ARMv8 spec it says (under section B2.10.5) "Unpredictable behavior when load-ex/store-ex access a different number of registers" - subsection stxr instruction always fails returning "1".

I am not sure how for Juno below code is working as the ldaxr and stxr instruction access different number of registers and also if I take same code it doesn't work and stxr instruction always fails.

I suspect may be I am setting memory attributes wrongly (for X0) ? Can some one explain the difference between ldxr vs ldaxr and stxr vs stlxr instruction as well ?

        mov     w2, #1

        sevl

l1:     wfe

l2:     ldaxr   w1, [x0]

        cbnz    w1, l1

        stxr    w1, w2, [x0]

        cbnz    w1, l2

        ret

Thanks,

Parents
  • I'm no great expert but to go through your points:

    The code's purpose is to get a lock on some data. The data is unlocked when the semaphore is 0 and locked when it is 1. The load does an acquire so any data written before the release of the data when the lock is freed is up to date.

    You are loading and storing the same number and type of values - a single word register. The Rs is just a status response.

    If you are using normal memory it should work. You are saying you always get 1 in w1 after the stxr, that shouldn't happen so the question is why is it happening.


    Racking my brain the only feeble thought that comes to mind is that perhaps somehow you are single stepping through the code. A debugger should execute code from the ldaxr to the stxr without single stepping otherwise the local monitor will almost certainly be cleared. Hopefully someone else has a better idea.

Reply
  • I'm no great expert but to go through your points:

    The code's purpose is to get a lock on some data. The data is unlocked when the semaphore is 0 and locked when it is 1. The load does an acquire so any data written before the release of the data when the lock is freed is up to date.

    You are loading and storing the same number and type of values - a single word register. The Rs is just a status response.

    If you are using normal memory it should work. You are saying you always get 1 in w1 after the stxr, that shouldn't happen so the question is why is it happening.


    Racking my brain the only feeble thought that comes to mind is that perhaps somehow you are single stepping through the code. A debugger should execute code from the ldaxr to the stxr without single stepping otherwise the local monitor will almost certainly be cleared. Hopefully someone else has a better idea.

Children