免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2593 | 回复: 3
打印 上一主题 下一主题

[内核入门] 请教一个X64 LINUX内核寄存器调用约定的问题 [复制链接]

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-05-02 14:03 |只看该作者 |倒序浏览
X64 LINUX应用程序的调用约定我找到了,网上可以下载到AMD64 SYS-V ABI
如果是在LINUX内核里呢?我记得LDD3说不要在内核模块中使用浮点寄存器,因为内核线程切换时不维护浮点堆栈
完整的LINUX X64内核ABI应该去哪里找呢?能够在内核源码目录中找到吗?

论坛徽章:
2
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:53:17
2 [报告]
发表于 2013-05-02 14:31 |只看该作者
kernel和userspace是一样的

只有一点需要注意, 使用syscall指令时,有个gpr用来做特殊用途了, 具体请自行search google

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
3 [报告]
发表于 2013-05-02 15:47 |只看该作者
回复 2# 帅绝人寰


THX

google了LINUX + kernel + ABI

看到的内容相当崩溃,LINUX内核果然是猪突猛进(没有历史负担其实也很好),既不保证API的延续性也不保证ABI的延续性
只能是开发哪个版本的内核模块就得看对应源代码的Documentation/ABI/下面的内容
最近需要写点汇编小程序在模块里,看来是绕不开内核ABI这块内容了。

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
4 [报告]
发表于 2013-05-02 16:20 |只看该作者
回复 2# 帅绝人寰


找到详细资料了,就在
System V Application Binary Interface AMD64 Architecture Processor Supplement

附录A.2关于寄存器的使用约定:

A.2 AMD64 Linux Kernel Conventions

1. User-level applications use as integer registers for passing the sequence
%rdi, %rsi, %rdx, %rcx, %r8 and %r9. The kernel interface uses %rdi,
%rsi, %rdx, %r10, %r8 and %r9.

2. A system-call is done via the syscall instruction. The kernel destroys
registers %rcx and %r11.

3. The number of the syscall has to be passed in register %rax.
4. System-calls are limited to six arguments, no argument is passed directly on
the stack.

5. Returning from the syscall, register %rax contains the result of the
system-call. A value in the range between -4095 and -1 indicates an error,
it is -errno.

6. Only values of class INTEGER or class MEMORY are passed to the kernel.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP