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
| Field | Location | Notes |
|---|---|---|
| Syscall number | SVC #n immediate (lower 8 bits) | ARM mode only |
| Arg 0 / return value | r0 | Modified by kernel on return |
| Arg 1 | r1 | Preserved if unused |
| Arg 2 | r2 | Preserved if unused |
| Arg 3 | r3 | Preserved if unused |
| Clobbered | r0 only | r1-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
- The syscall number is limited to 8 bits. In ARM mode, the full 24-bit SVC immediate is available but only the lower 8 bits are used. In Thumb mode, the SVC immediate is natively 8 bits. Both modes are handled by checking the T bit in SPSR and reading a 2-byte or 4-byte instruction accordingly.
- Syscall number extraction reads the instruction word at
LR_svc - 4through the D-cache. CLREXis issued at the top of each exception vector entry inentry.Sto clear any outstanding exclusive monitor reservation from preempted LDREX/STREX sequences.