flat assembler
Message board for the users of flat assembler.

Index > Linux > system call in 64-bits

Author
Thread Post new topic Reply to topic
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Hi, someone knows when I must use 64-bit registers in a system call? Only in the case of memory pointers?

When I must use stack to pass parameters, is there a difference with the 32-bit way?

Is there a way to make system calls using SYSCALL? It's supposed to be faster than INT but I don't see any example using it.

I'm very newbie on linux, I'd just assembled the "hello 64-bit world" example some minutes ago (and tested SYSCALL without success) Razz

Regards,
HernĂ¡n
Post 16 Feb 2006, 23:57
View user's profile Send private message Reply with quote
Feryno



Joined: 23 Mar 2005
Posts: 447
Location: Czech republic, Slovak republic
Feryno
http://www.x86-64.org/documentation/abi-0.96.pdf
A.2.1 Calling Conventions
3.2.3 Parameter Passing
Just dl the pdf and read it, especialy Figure 3.4: Register Usage (hard to convert the table into this reply, there are 3 collumns:
Register, Usage, Preserved across function calls).

The pdf haven't helped me too much, here are my practical experiences (and they are in contradiction with infos from pdf):

It looks like there aren't parameters passed on the stack, and limit is max 6 params, but I'm not sure and I have never used more than 4 args to syscall.
I pass args in this way:
1st in rax = syscall_number, mov EAX,syscall_number is enough to set RAX
2nd in rbx
3rd in rcx
4th in rdx
(I have never passed more args)
For memory pointers use lea reg64,[...] as you have written
For values use 32-bit reg which is zero extended to 64 bit by CPU itself
(e.g. rax=FFFFFFFFFFFFFFFF
mov eax,1
rax=0000000000000001 now)
this can reduce opcode size (e.g. xor eax,eax is enough for zeroing RAX reg and produce only 2 byte opcode instead of 3 byte xor rax,rax (1 byte rex prefix + 2 bytes opcode)

If your ELF is under offset 100000000h, you can use lea reg32,[...] for addressing (saving 1 byte of REX prefix in opcode), but I don't suggest it to you because you cannot load your ELF at RIP=100000000h or higher.


Description: small sample with max 4 args passed to int 80h
Download
Filename: a02.asm
Filesize: 3.64 KB
Downloaded: 183 Time(s)

Post 17 Feb 2006, 08:23
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Thanks Feryno!!!
Post 17 Feb 2006, 13:50
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.