0
votes

I have an issue with my ARM asm, on Cortex A53 (64bits). I have to write 128 instruction like this one :

#define MACRO1()                                         \
__asm__ volatile ("str  %0,[%1], #4\n\t"                 \
                      "str  %0,[%1], #4\n\t"             \
                 :      "=r"(here)                       \
                 :      "r"(here)                        \
                 :      );

Therefore, I created a Macro called MACRO1 and I duplicate it 128 times. The variable here is declared in previous part of code like this :

P4_uint32_t * buffer;
... code
P4_uint32_t *here = buffer;

My issue is that the compiler do something like that :

 8014b40:   f8008400    str x0, [x0],#4
 8014b44:   f8008400    str x0, [x0],#4
 8014b48:   f8008413    str x19, [x0],#4
 8014b4c:   f8008413    str x19, [x0],#4
 8014b50:   f8008673    str x19, [x19],#4
 8014b54:   f8008673    str x19, [x19],#4

I have an issue with these registers because the variable here is declared in the x19 register and so why is it using the x0 register. The issue is :

access to unmapped memory during write at address 0x802e000

And this address point on this part of the code...

Thank you for your help :)

1
Was that asm supposed to refer to the variable named output? While it's legal to use the same c variable for both an input and an output, be advised that the compiler may use different registers for %0 and %1. And since you don't seem to be assigning a value to %0, the contents of here would be undefined after executing this statement. - David Wohlferd
I really don't understand why you need to use inline assembly for that. Wouldn't using a volatile array (or pointer to volatile int) suffice? - fuz
Thank you for your help, it is a bit tricky to explain why I have to do it in asm but to explain it fast : I need to have entire control on this part of the code because it is used to perform a charge on cache. Therefore asm is the easier way to control the generated code. - Gaëtan

1 Answers

0
votes

The fix is to add a clobber list at the end of my assembly code, like this:

__asm__ volatile ("str  %0,[%1], #4\n\t"             \
                  "str  %0,[%1], #4\n\t"             \
                 :  "=r"(here)                       \
                 :  "r"(here)                        \
                 :  "%0", "%1");

That helps the compiler to understand that each register changed, which solved my issue.