Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
647 views
in Technique[技术] by (71.8m points)

arm - How to implement system call in ARM64?

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 .

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...