1 /* SPDX-License-Identifier: LGPL-2.1 OR MIT */
3 * AARCH64 specific definitions for NOLIBC
4 * Copyright (C) 2017-2022 Willy Tarreau <w@1wt.eu>
7 #ifndef _NOLIBC_ARCH_AARCH64_H
8 #define _NOLIBC_ARCH_AARCH64_H
13 /* Syscalls for AARCH64 :
14 * - registers are 64-bit
15 * - stack is 16-byte aligned
16 * - syscall number is passed in x8
17 * - arguments are in x0, x1, x2, x3, x4, x5
18 * - the system call is performed by calling svc 0
19 * - syscall return comes in x0.
20 * - the arguments are cast to long and assigned into the target registers
21 * which are then simply passed as registers to the asm code, so that we
22 * don't have to experience issues with register constraints.
25 #define my_syscall0(num) \
27 register long _num __asm__ ("x8") = (num); \
28 register long _arg1 __asm__ ("x0"); \
39 #define my_syscall1(num, arg1) \
41 register long _num __asm__ ("x8") = (num); \
42 register long _arg1 __asm__ ("x0") = (long)(arg1); \
54 #define my_syscall2(num, arg1, arg2) \
56 register long _num __asm__ ("x8") = (num); \
57 register long _arg1 __asm__ ("x0") = (long)(arg1); \
58 register long _arg2 __asm__ ("x1") = (long)(arg2); \
63 : "r"(_arg1), "r"(_arg2), \
70 #define my_syscall3(num, arg1, arg2, arg3) \
72 register long _num __asm__ ("x8") = (num); \
73 register long _arg1 __asm__ ("x0") = (long)(arg1); \
74 register long _arg2 __asm__ ("x1") = (long)(arg2); \
75 register long _arg3 __asm__ ("x2") = (long)(arg3); \
80 : "r"(_arg1), "r"(_arg2), "r"(_arg3), \
87 #define my_syscall4(num, arg1, arg2, arg3, arg4) \
89 register long _num __asm__ ("x8") = (num); \
90 register long _arg1 __asm__ ("x0") = (long)(arg1); \
91 register long _arg2 __asm__ ("x1") = (long)(arg2); \
92 register long _arg3 __asm__ ("x2") = (long)(arg3); \
93 register long _arg4 __asm__ ("x3") = (long)(arg4); \
98 : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), \
105 #define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) \
107 register long _num __asm__ ("x8") = (num); \
108 register long _arg1 __asm__ ("x0") = (long)(arg1); \
109 register long _arg2 __asm__ ("x1") = (long)(arg2); \
110 register long _arg3 __asm__ ("x2") = (long)(arg3); \
111 register long _arg4 __asm__ ("x3") = (long)(arg4); \
112 register long _arg5 __asm__ ("x4") = (long)(arg5); \
117 : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), \
124 #define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \
126 register long _num __asm__ ("x8") = (num); \
127 register long _arg1 __asm__ ("x0") = (long)(arg1); \
128 register long _arg2 __asm__ ("x1") = (long)(arg2); \
129 register long _arg3 __asm__ ("x2") = (long)(arg3); \
130 register long _arg4 __asm__ ("x3") = (long)(arg4); \
131 register long _arg5 __asm__ ("x4") = (long)(arg5); \
132 register long _arg6 __asm__ ("x5") = (long)(arg6); \
137 : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), \
138 "r"(_arg6), "r"(_num) \
145 void __attribute__((weak
, noreturn
)) __nolibc_entrypoint __no_stack_protector
_start(void)
148 "mov x0, sp\n" /* save stack pointer to x0, as arg1 of _start_c */
149 "and sp, x0, -16\n" /* sp must be 16-byte aligned in the callee */
150 "bl _start_c\n" /* transfer to c runtime */
152 __nolibc_entrypoint_epilogue();
154 #endif /* _NOLIBC_ARCH_AARCH64_H */