x86_64的大会的Linux系统调用混乱 [英] x86_64 Assembly Linux System Call Confusion

查看:188
本文介绍了x86_64的大会的Linux系统调用混乱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在学习Linux上的汇编语言。我一直在使用这本书的编程从地上爬起来和所有的例子都是32位的。我的操作系统是64位的,我一直试图做所有的例子在64位。我有麻烦但是:

I am currently learning Assembly language on Linux. I have been using the book 'Programming From the Ground Up' and all the examples are 32-bit. My OS is 64-bit and I have been trying to do all the examples in 64-bit. I am having trouble however:

.section .data

.section .text
.global _start
_start:
movq $60, %rax
movq $2, %rbx
int $0x80

这仅仅只是调用Linux的退出系统调用,或者它应该。相反,它会导致赛格故障,当我不是这样做

This merely just calls the Linux exit System call or it should. Instead it causes a SEG FAULT and when I instead do this

.section .data

.section .text
.global _start
_start:
movq $1, %rax
movq $2, %rbx
int $0x80

它的工作原理。显然,问题是我移动到%RAX值。该值$ 1中我的第二个例子用的是什么编程从地上爬起来之称但使用互联网上的多个消息来源称,在64位系统调用号为$ 60个的参考 我究竟做错了什么?另外,我应该注意什么等问题出来了,什么我应该使用的参考?以防万一你要知道,我是在第5章的程序从地上爬起来。

it works. Clearly the problem is the value I move to %rax. The value $1 that I use in the second example is what 'Programming From the Ground Up' said to use however multiple sources on the Internet have said that the 64-bit System Call Number is $60. Reference What am I doing wrong? Also what other issues should I watch out for and what should I use for a reference? Just in case you need to know, I am on Chapter 5 in Programming From The Ground Up.

推荐答案

您正在运行到i386和x86_64的之间的一个令人吃惊的区别:他们不使用相同的系统调用机制。正确的code是:

You're running into one surprising difference between i386 and x86_64: they don't use the same system call mechanism. The correct code is:

movq $60, %rax
movq $2,  %rdi   ; not %rbx!
sysenter

中断 0x80的总是调用32位的系统调用。它是用来让32位应用程序在64位系统上运行。

Interrupt 0x80 always invokes 32-bit system calls. It's used to allow 32-bit applications to run on 64-bit systems.

有关学习的目的,你应该尽量按照教程完全相同,而不是翻译的飞行到64位 - 有一些你可能会遇到一些其他显著行为上的差异。一旦你熟悉的i386,然后的,你可以单独拿起x86_64的。

For the purposes of learning, you should probably try to follow the tutorial exactly, rather than translating on the fly to 64-bit -- there are a few other significant behavioral differences that you're likely to run into. Once you're familiar with i386, then you can pick up x86_64 separately.

这篇关于x86_64的大会的Linux系统调用混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆