You can pass six arguments in x0
to x5
, return value is saved in x0
.
To give an assembler snippet, this is write
syscall from Android Bionic's libc implementation. write
's three arguments would already be in x0-x2
. Syscall number is passed in x8
.
/* Generated by gensyscalls.py. Do not edit. */
#include <private/bionic_asm.h>
.hidden __set_errno
ENTRY(write)
mov x8, __NR_write
svc #0
cmn x0, #(MAX_ERRNO + 1)
cneg x0, x0, hi
b.hi __set_errno
ret
END(write)
Give AArch64 ABI a look.
Newer generation of architectures all use numbers from include/uapi/asm-generic/unistd.h.
You can also check arch/arm64/include/asm/syscall.h for argument and return value handling.
Another example:
If you have as
and ld
in hand, you can create a simple executable just quitting with an exit value.
Here 42
is our return value and 93
is exit
system call.
$cat answer.s
.global _start
_start:
mov x0, #42
mov x8, #93
svc #0
$as answer.s -o answer.o
$ld answer.o -o answer
$./answer
$echo $?
42
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…