免费注册 查看新帖 |

Chinaunix

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

[学习] asm 32/64区别 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-01-06 14:12 |只看该作者 |倒序浏览
1、系统调用及C函数调用,参数传递方式不同
  • 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.
  • A system-call is done via the syscall instruction. The kernel destroys registers %rcx and %r11.
  • The number of the syscall has to be passed in register %rax.
  • System-calls are limited to six arguments, no argument is passed directly on the stack.
  • 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.
  • Only values of class INTEGER or class MEMORY are passed to the kernel.

2、调用指令不同
  • For a 32bit kernel, SYSENTER/SYSEXIT are the only compatible pair [between AMD and Intel CPUs]
  • For a 64bit kernel in Long mode only… SYSCALL/SYSRET are the only compatible pair [between AMD and Intel CPUs]

论坛徽章:
6
数据库技术版块每日发帖之星
日期:2015-11-27 06:20:00程序设计版块每日发帖之星
日期:2015-12-01 06:20:00每日论坛发贴之星
日期:2015-12-01 06:20:0015-16赛季CBA联赛之佛山
日期:2017-03-26 23:38:0315-16赛季CBA联赛之江苏
日期:2017-07-17 10:08:4415-16赛季CBA联赛之北京
日期:2018-03-04 17:01:50
2 [报告]
发表于 2016-01-19 17:26 |只看该作者
做个备忘吧。
相信使用不会很难。

论坛徽章:
0
3 [报告]
发表于 2016-02-02 10:42 |只看该作者
回复 1# vtudiv


    对于第二点,SYSCALL/SYSRET这一对指令,AMD和Intel公司的实现是有差异的,更重要的是intel的实现方式存在严重stack漏洞,intel官方虽然没有直接承认这个bug,但是在很多cpu型号里面都没有实现这对指令(应该算是intel公司默认这个bug了),可以通过cpuid指令的返回信息确认是否支持这对指令,但是intel的SYSENTER/SYSEXIT是有64bit实现的(AMD的SYSENTER/SYSEXIT是否有64位实现我不清楚)。因此,主流OS不大可能使用这一对AMD和intel共有指令,对于OS而言,可用的选项是:
1)对于AMD处理器,可以使用SYSCALL/SYSRET(32bit,64bit?),或者使用SYSENTER/SYSEXIT(64bit)
2)对于intel处理器,只能使用SYSENTER/SYSEXIT(32bit,64bit)
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP