flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Unix > Syscall convention for FreeBSD (AMD64)

Author
Thread Post new topic Reply to topic
Chewy509



Joined: 19 Jun 2003
Posts: 297
Location: Bris-vegas, Australia

Syscall convention for FreeBSD (AMD64)

Hi Guys,

I'm about to start porting an app from Linux to FreeBSD, and haven't been able to confirm the kernel calling convention for FreeBSD apps?

Reading the output from gcc, it looks like the normal x86-64 ABI (with rax = function number and 'syscall' to invoke), but gcc seems to be taking some short-cuts with it's generated code?

So does FreeBSD use the standard x86-64 ABI with 'syscall' to invoke the kernel and rax = the function number? (with function numbers from syscalls.master).

eg.

Code:
mov rax4 ; write
mov rdi1; stdout file handle
mov rsihello_world; pointer to string
mov rdx11 ; 11 chars
syscall

Post 07 Nov 2006, 04:15
View user's profile Send private message Visit poster's website Reply with quote
Chewy509



Joined: 19 Jun 2003
Posts: 297
Location: Bris-vegas, Australia

After a lot of testing, FreeBSD uses the x86-64 SYSV ABI, with rax being the function call, and 'syscall' to invoke the call...
Post 07 Nov 2006, 23:24
View user's profile Send private message Visit poster's website Reply with quote
codsna



Joined: 08 Aug 2007
Posts: 10

Many thanks, Chewy509

I have written a modified elf64 your code. Works fine.
(FreeBSD 6.2 AMD64, fasm 32 bit elf_i386_fbsd libc)

format ELF64
public main

main:
mov rax, 4 ; write
mov rdi, 1; stdout file handle
mov rsi, hello_world; pointer to string
mov rdx, len ; string len
syscall

xor rax, rax ; sys_exit
syscall

hello_world db "Hello World Smile", 10
len = $-hello_world
Post 09 Aug 2007, 22:07
View user's profile Send private message Reply with quote
codsna



Joined: 08 Aug 2007
Posts: 10

with simple

fasm hello64.asm

gcc hello64.o -o hello64

or..
gcc -m64 hello64.o -o hello64

easier than build (ld link) 32 bit in FreeBSD AMD64
Post 09 Aug 2007, 22:11
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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2017, Tomasz Grysztar.