FreeBSD System Calls in Assembly

Polytropon freebsd at
Tue Aug 1 21:11:58 UTC 2017

On Tue, 1 Aug 2017 03:00:42 +0200, cpghost wrote:
> On 07/31/17 21:59, Makketron wrote:
> > Hello,
> > It seems that the  documentation here doesn't apply for 64-bits.
> > 
> >
> > 
> > I asked a question on stackoverflow. I thought I should ask it here too
> >
> > 
> > I am running FreeBSD 11.0.
> > 
> > The following from the FreeBSD manual does NOT print the "Hello, World!"
> > message:
> [snip]
> Basically, in i386, you pass function values on the stack,
> and on amd64 via registers.
> The amd64 ABI calling convention, shared by common Unices:
> Just remember that the list of syscalls and therefore the
> syscall ID differs across the various Unix variants...


The 64 bit ABI specifies that the registers to be used for
parameters are rdi, rsi, rdx, r10, r8, r9.

Compare with this table, but as it has been mentioned, the
syscall numbers of FreeBSD are different than the ones of

You can find the correct numbers in /usr/src/sys/kern/syscalls.c
(and in different places on the system, as they are generated
from a master table into different formats for the various
purposes). However, FreeBSD manual pages are a good place for
reference for the parameters, and you just have to use the
registers in the same order as the parameters.

For example, from "man 2 write":

	ssize_t write(int d, const void *buf, size_t nbytes);
	                  ^              ^           ^
	                 rdi            rsi         rdx

The syscalls usually don't have hundreds of parameters. :-)

Further documentation:

Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...

More information about the freebsd-questions mailing list