小编Ult*_*alt的帖子

gcc arm 在系统调用之前优化掉参数

我正在尝试使用 gcc arm 在 arm7tdmi-s 上实现一些“OSEK-Services”。不幸的是,提高优化级别会导致“错误”的代码生成。我不明白的主要事情是编译器似乎忽略了过程调用标准,例如通过将参数移动到寄存器 r0-r3 将参数传递给函数。我知道函数调用可以内联,但参数仍然需要在寄存器中才能执行系统调用。

考虑以下代码来演示我的问题:

unsigned SysCall(unsigned param)
{
    volatile unsigned ret_val;
    __asm __volatile
    (
        "swi 0          \n\t"    /* perform SystemCall */
        "mov %[v], r0   \n\t"    /* move the result into ret_val */
        : [v]"=r"(ret_val) 
        :: "r0" 
    );

    return ret_val;              /* return the result */
}

int main()
{
    unsigned retCode;
    retCode = SysCall(5); // expect retCode to be 6 when returning back to usermode
}
Run Code Online (Sandbox Code Playgroud)

我在汇编中编写了顶级软件中断处理程序,如下所示:

.type   SWIHandler, %function
.global SWIHandler
SWIHandler:

    stmfd   sp! , …
Run Code Online (Sandbox Code Playgroud)

c assembly arm system-calls inline-assembly

1
推荐指数
1
解决办法
105
查看次数

标签 统计

arm ×1

assembly ×1

c ×1

inline-assembly ×1

system-calls ×1