How to implement system call in ARM64?

我怕爱的太早我们不能终老 提交于 2019-11-29 04:21:20

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!