I am working with arm64 assembly coding and I want to implement system calls using svc instruction . I can't find any working arm64 system call implementation online.Also, I can't find the system call list for arm64. Also explain the implementation .
Asked
Active
Viewed 1.4k times
10
-
This depends on the OS you're using. Which one are you writing code for? – jtlim Aug 21 '14 at 16:30
-
I am on amd64 linux and i am writing for aarch64 linux. – in3o Aug 21 '14 at 16:35
-
This blog explains the complete flow of system call in ARM64. May be useful to you. [http://eastrivervillage.com/Anatomy-of-Linux-system-call-in-ARM64/](http://eastrivervillage.com/Anatomy-of-Linux-system-call-in-ARM64/) – theB Jun 12 '18 at 11:08
-
This is where the syscall number table is located: https://reverseengineering.stackexchange.com/questions/16917/arm64-syscalls-table/18834#18834 – Ciro Santilli OurBigBook.com Aug 27 '18 at 21:52
1 Answers
11
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
-
-
-
can you please clarify what type of Newer generation of architectures are you talking about ? x86_64 has different syscall list. – in3o Aug 21 '14 at 17:35
-
1"arc, arm64, c6x, hexagon, metag, openrisc, score, tile, unicore32" reference: https://lkml.org/lkml/2014/2/3/248 – auselen Aug 21 '14 at 17:44