On 09/18/2015 08:18 PM, Lee Noar wrote:
> [...]
>
> 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" );
This corrupts r0-r3, possibly r14 when this gets executed in SVC. You
need to tell gcc this. Inline assembler does not follow the APCS-32 ABI
calling conventions (which I think you seem to assume here).
Aside, it is very easy to get things subtly wrong with inline
assembler. Even when it seems to be working and you got it wrong in the
first place, one day it will bite you when changing optimization level,
ask for global optimisation or doing simply a minor version upgrade.
A much safer approach for SWI calling and with additional C type safety
is to use OSLib (http://ro-oslib.sf.net/).
John.
_______________________________________________
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