C FreeBSD's syscall ABI for (mostly) all supported architectures

I have started an own libc for the purpose of education. Started the development on a Linux system. Now I want to port my library to FreeBSD.
Where can I find a full list of all syscall's depending on the supported architecture? Uses FreeBSD the same syscall numbers on all architectures?
Is there an example for how to execute an syscall on ARM64 or RISCV as example?

Thanks in advance!
 
See /usr/include/sys/syscall.h (hope you have src installed).

Since I have only one architecture handy/installed, I can't easily verify if numbering is consistent across all FreeBSD architectures, but I'd guess it probably is.

I suggest doing a man 2 syscall or see syscall(2) for more info on how to actually invoke a system call.
 
Hi marq !

Thanks for the answer.

I suggest doing a man 2 syscall or see syscall(2) for more info on how to actually invoke a system call.
These use the FreeBSD's userland libc. I need the complete ABI (Application Binary Interface), not the FreeBSD's libc API (Application Programming Interface). Or how to execute the syscalls with Assembler.

As example a syscall for Linux on AMD64 (sys_exit):


C:
#define _ASM_ASSEMBLY_

#include <asm.h>

#include <bits/linux-syscall.h>

.text

FUNCTION_S(_sys_exit)
    pushq %rbp
    movq %rsp, %rbp
    movq $__LINUX_SYS_EXIT, %rax
    syscall
    popq %rbp       /* Normally not needed, because sys_exit doesn't return */
    ret
FUNCTION_E(_sys_exit)

.end

I my own libc I call the self written _sys_* functions in C.

Okay, the C tag was is a little bit misleading. I have should use Assembler if exist in the thread title.

What I need to know for each architecture is:
  • - CPU register where I must place the syscall number
  • - CPU register for the arguments (if any)
  • - Which assembly command must I execute to invoke the Kernel
EDIT:

I have found the ABI meanwhile in src/lib/libsys for all supported architectures.
 
What I need to know for each architecture is:
  • - CPU register where I must place the syscall number
  • - CPU register for the arguments (if any)
  • - Which assembly command must I execute to invoke the Kernel
EDIT:

I have found the ABI meanwhile in src/lib/libsys for all supported architectures.

I just peeked in /usr/src/lib/libc/i386/sys/syscall.S and saw that the syscall number goes to %eax before doing KERNCALL. It looks like for most architectures, there is a corresponding syscall.S file, think you'll find what you need by looking in each specific architecture subdirectory below /usr/src/lib/libc/.

I didn't see a syscall.S file in the amd64/ subdirectory, but looks like /usr/src/lib/libc/amd64/SYS.h also uses %eax in the RSYSCALL() macro.

Disclaimer: While I'm experienced with C and FreeBSD, I've never looked at the specific code to setup and do syscalls before today, so YMMV. :) Hope this helps..
 
Disclaimer: While I'm experienced with C and FreeBSD, I've never looked at the specific code to setup and do syscalls before today, so YMMV. :) Hope this helps..
Yes, it really helps.

Okay I have seen now in FreeBSD 14.3 release there exists no /usr/src/lib/libsys currently. But in the FreeBSD GitHub repo. The FreeBSD developers also use the RSYSCALL() macro. And there is also a syscall list for each architecture. :)
 
Could this be of help?
On FreeBSD, starting from upcoming 15.0, core syscall parts of libc is splitted out from libc as libsys.

Note that currently supported 14.2, 14.3 and 13.5 incuding corresponding stable/14 and stable/13 does not have the changes, as of POLA violation.
 
Back
Top