System call ABI

System calls are services offered by zuzu for userspace programs to request from the kernel that they are not allowed direct access to, such as virtual memory management, IPC, devices or handle management. zuzu defines an Application Binary Interface (ABI) that dictates how registers etc. must be configured for the system call to be reliably serviced.

Calling convention

FieldLocationNotes
Syscall numberSVC #n immediate (lower 8 bits)ARM mode only
Arg 0 / return valuer0Modified by kernel on return
Arg 1r1Preserved if unused
Arg 2r2Preserved if unused
Arg 3r3Preserved if unused
Clobberedr0 onlyr1-r12, sp, lr preserved

Negative r0 on return indicates an error (check error codes table). Zero or positive is success.

The kernel extracts the syscall number at LR_svc - 4 (the instruction word before the return address) by masking the lower 8 bits. Arguments are already in r0-r3 per AAPCS so call site wrappers need zero register shuffling.

AArch64 actually doesn't need an extra memory access, instead the kernel can read the ESR and grab the SVC number.


Alignment requirements

Any pointer passed as a syscall argument must be 4-byte aligned. Also, sp must be 8-byte aligned before syscall entry (but this is not enforced by the kernel).

Notes