Chinaunix
标题:
linux 驱动程序 call convention 如何设置
[打印本页]
作者:
SZ_DIV8
时间:
2012-07-06 11:13
标题:
linux 驱动程序 call convention 如何设置
Hi,各位好:
遇到问题像大家请教:
1.在linux驱动中需要调用 一个VC编译的Bin 文件中的函数,该Bin中的函数是用 _cdecl 的方式(堆栈)传参数
2.而我发现 我们在liunx 内核态的函数都用 fastcall(寄存器传参数),导致调用失败
3.请问下, 如何才能 在 make linux 驱动的时候 指定 call convention???
谢谢,盼指点
作者:
sanbiangongzi
时间:
2012-07-07 15:13
对自己的bin中的函数做封装比较好,比如有如下函数
long fun(long a, long b, long c);
可以这样实现,后续你的driver调用
fun_wrap就可以了
long fun_wrap(long a, long b, long c)
{
long addr_of_fun = ....;
long rc;
asm ( "pushq %[c]\n\t"
"pushq %[b]\n\t"
"pushq %[a]\n\t"
"callq *%%rax\n\t"
"addq $24, %%rsp\n\t"
: "=a"(rc)
: "0"(addr_of_fun), [c]"m"(c), [b]"m"(b), [a]"m"(a)
: "memory", "cc"
);
return rc;
}
复制代码
作者:
SZ_DIV8
时间:
2012-07-12 11:54
回复
2#
sanbiangongzi
Hi,您好,我的问题已经解决啦,, 在 我的Linux driver 中的函数加上 声明 __attribute__((regparm(0))) 即可实现强制传参数的方式改变为 堆栈
谢谢您的回复!!
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2