On 18/09/15 15:07, Gavin Wraith wrote:
> Has anyone any advice about the use of data synchronization
> barriers when calling SWIs from C code compiled with GCC?
>
> To give RiscLua a command 'sys' analogous to BASIC's SYS
> command I use this code
>
> asm volatile(
> "stmfd sp!, {r4-r8,r12}" "\n\t"
> "orr r12,%1,#0x20000 @ X-bit" "\n\t"
> "mov r8,%2 @ register buffer" "\n\t"
> "ldmia r8,{r0-r7}" "\n\t"
> "swi 0x71 @ OS_CALLASWIR12" "\n\t"
> "stmvcia r8,{r0-r7}" "\n\t"
> "movvc r0,#0 @ 0 for success" "\n\t"
> "ldmfd sp!,{r4-r8,r12}" "\n\t"
> : "=r" (p)
> : "r" (L),"r" (swinum), "r" (r)
> : "memory" );
>
> entered with the SWI number in R1 and R2 pointing to a
> buffer from which to load registers R0-R7 before entry,
> and to which to save them on exit. I never thought much
> about data synchronization, and when I compiled with
> the Norcroft C compiler and Objasm it all worked fine
> without.
> Now I am using GCC and it does not seem to work.
I think your operand numbering is a bit out:
p is %0
L is %1
swinum is %2
r is %3
In the above, your swi number is coming from %1 'L' which is
probably a stack address.
It occurs to me that you might think that %1 is R1 and %2 is R2,
but that's not the case. These refer to the operands starting
with %0 (p) after the first colon, then %1 (L), and so on.
The compiler will substitute the correct registers that match
the operands.
You can name the operands rather than numbering them to
help eliminate numbering errors. The names between [] do not have
to be the same as the variable names in () although it
does help readability:
asm volatile(
"stmfd sp!, {r4-r8,r12}" "\n\t"
"orr r12,%[swinum],#0x20000 @ X-bit" "\n\t"
"mov r8,%[r] @ register buffer" "\n\t"
"ldmia r8,{r0-r7}" "\n\t"
"swi 0x71 @ OS_CALLASWIR12" "\n\t"
"stmvcia r8,{r0-r7}" "\n\t"
"movvc r0,#0 @ 0 for success" "\n\t"
"ldmfd sp!,{r4-r8,r12}" "\n\t"
: [p] "=r" (p)
: [L] "r" (L), [swinum] "r" (swinum), [r] "r" (r)
: "memory" );
(From memory and untested :-) )
I'm assuming here that 'r' is your register buffer.
As Theo says, you don't need any special synchronization
instructions.
Lee.
_______________________________________________
GCCSDK mailing list gcc@gccsdk.riscos.info
Bugzilla: http://www.riscos.info/bugzilla/index.cgi
List Info: http://www.riscos.info/mailman/listinfo/gcc
Main Page: http://www.riscos.info/index.php/GCCSDK
No comments:
Post a Comment