System call number and return value
Arch/ABI Instruction System Ret Ret Error Notes
call # val val2
───────────────────────────────────────────────────────────────────
x86-64 syscall rax rax rdx - 5
x32 syscall rax rax rdx - 5
Arguments
Arch/ABI arg1 arg2 arg3 arg4 arg5 arg6 arg7 Notes
──────────────────────────────────────────────────────────────
x86-64 rdi rsi rdx r10 r8 r9 -
x32 rdi rsi rdx r10 r8 r9 -
.text
.global _start
_start:
movq $1, %rax # write() system call number
movq $1, %rdi # first parameter -- standard output file descriptor
movq $message, %rsi # second parameter -- buffer
movq $12, %rdx # third parameter -- buffer length
syscall # invoke system call
movq $60, %rax # exit() system call number
xor %rdi, %rdi # first parameter -- exit status
syscall # invoke system call; this will never return
message:
.ascii "hello world\n"
$ gcc -c hello.s -o hello.o
$ ld hello.o
- https://man7.org/linux/man-pages/man2/syscall.2.html
- https://man7.org/linux/man-pages/man7/vdso.7.html
- https://unix.stackexchange.com/questions/461107/are-system-calls-stored-in-registers
- https://cs.lmu.edu/~ray/notes/gasexamples/
- https://www.linuxjournal.com/article/6100
- https://bbs.pediy.com/thread-265812.htm