开发者

ARM v4 Returning the value stored in r0 from a C function making a SWI call

开发者 https://www.devze.com 2023-04-08 05:50 出处:网络
I\'ve got a function as follows: int foo() { asm(\"swi 1\"); } The underlying handler for swi 1, plac开发者_高级运维es the return value correctly into r0, I want foo() to correctly return this valu

I've got a function as follows:

int foo()
{
    asm("swi 1");
}

The underlying handler for swi 1, plac开发者_高级运维es the return value correctly into r0, I want foo() to correctly return this value. ARM-ELF-GCC warns about control reaching the end of a non-void function for the above.

ARM-ELF-GCC still warns with the following:

int foo()
{
    asm("swi 1");
    return;
}

I've instead resorted to the following:

int foo()
{
    int ret_val;
    asm("swi 1");
    asm("mov %[v], r0" : [v]"=r"(ret_val) :: "r0", "r3" )
    return ret_val;
}

Is there a more elegant way of getting GCC to return the value in r0 without resorting to the above?

Thanks.


Try this (works on gcc):

int foo()
{
    register int ret_val __asm__("r0");
    __asm__ __volatile__ ("swi 1" : "=r"(ret_val));
    return ret_val;
}


if you are going to use assembler...then...use assembler.

.globl foo
foo:
   swi i
   mov pc,lr
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号