EmbDev.net

Forum: ARM programming with GCC/GNU tools arm gcc swi call


von Vova7890 V. (vova7890)


Rate this post
useful
not useful
Hello! I recently started using gcc-arm and I have a problem with swi. 
How to call a function with arguments? For example, my swi function:
"int sprintf (char * buf, const char * str, ...)" = swi 22

 Previously, I used IAR it was possible to do so:
# Pragma swi_number = 22
__swi __arm int sprintf (char * buf, const char * str, ...);

How it organized on gcc?

von Martin T. (mthomas) (Moderator)


Rate this post
useful
not useful
You may look into these codes:

http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/index_at91.html#at91_gamma

http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/lpc2k_bundle_port/index.html

They are rather old and I did not check them with the latest versions of 
the GNU tools but they should at least give an idea.

Also browse through the newlib sources, there are implemantations of 
SWIs to implement semihosting.

von Vova7890 V. (vova7890)


Rate this post
useful
not useful
Thanks, I already thought of myself today :)

von Vova7890 V. (vova7890)


Rate this post
useful
not useful
but this method is why it failed to function on 8 arguments, such as the 
transfer goes through the stack, but normally does not work. Maybe 
someone knows a working method? There must be some interface for a swi 
in gcc ...

von Vova7890 V. (vova7890)


Rate this post
useful
not useful
why the params are not transferred in this case?

_inline_ void  sp(char*dest, char *cst, ...)

{

   asm volatile("swi 22");

}

and it works

void  sp(char*dest, char *cst, ...)

{

   asm volatile("swi 22");

}

In this case, the parameres are transmitted through the stack, but I do 
not need. When used inline it fits into the function.

How do I type this, an unspecified number of parameters?

_inline_ void sm(int i, int l)

{
   register int p0 asm("r0") = i;
   register int p1 asm("r1") = l;

   asm ("swi 0x148"::"r"(p0),"r"(p1));

}


_inline_ void sm(int i,...)

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.