flat assembler
Message board for the users of flat assembler.

Index > 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
Chewy509 07 Nov 2006, 04:15
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 rax, 4 ; write
mov rdi, 1; stdout file handle
mov rsi, hello_world; pointer to string
mov rdx, 11 ; 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
Chewy509 07 Nov 2006, 23:24
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
codsna 09 Aug 2007, 22:07
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
codsna 09 Aug 2007, 22:11
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


Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.