1 /* 2 * This file is subject to the terms and conditions of the GNU General Public 3 * License. See the file "COPYING" in the main directory of this archive 4 * for more details. 5 * 6 * Copyright (C) 2018 Kalray Inc. 7 */ 8 9 #ifndef _BITS_SYSCALLS_H 10 #define _BITS_SYSCALLS_H 11 #ifndef _SYSCALL_H 12 # error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead." 13 #endif 14 15 #ifndef __ASSEMBLER__ 16 17 #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \ 18 ({ \ 19 register long _ret __asm__("r0"); \ 20 register unsigned long _scno __asm__("r6") = name; \ 21 LOAD_ARGS_##nr (args) \ 22 __asm__ __volatile__("scall %[r_scno]" \ 23 : "=r" (_ret) \ 24 : [r_scno] "r" (_scno) ASM_ARGS_##nr \ 25 : ASM_CLOBBER_##nr); \ 26 _ret; \ 27 }) 28 29 /* Mark all argument registers as per ABI in the range r1-r5 as 30 clobbered when they are not used for the invocation of the scall */ 31 #define ASM_CLOBBER_6 "cc", "memory", \ 32 "r7", "r8", "r9", "r10", "r11", /* unused argument registers */ \ 33 "r15", /* struct pointer */ \ 34 "r16", "r17", /* veneer registers */ \ 35 "r32", "r33", "r34", "r35", "r36", "r37", "r38", "r39", /* 32->63 are caller-saved */ \ 36 "r40", "r41", "r42", "r43", "r44", "r45", "r46", "r47", \ 37 "r48", "r49", "r50", "r51", "r52", "r53", "r54", "r55", \ 38 "r56", "r57", "r58", "r59", "r60", "r61", "r62", "r63" 39 #define ASM_CLOBBER_5 "r5", ASM_CLOBBER_6 40 #define ASM_CLOBBER_4 "r4", ASM_CLOBBER_5 41 #define ASM_CLOBBER_3 "r3", ASM_CLOBBER_4 42 #define ASM_CLOBBER_2 "r2", ASM_CLOBBER_3 43 #define ASM_CLOBBER_1 "r1", ASM_CLOBBER_2 44 #define ASM_CLOBBER_0 ASM_CLOBBER_1 45 46 #define LOAD_ARGS_0() 47 #define ASM_ARGS_0 48 49 #define LOAD_ARGS_1(a1) \ 50 LOAD_ARGS_0(); \ 51 _ret = (long) a1; 52 #define ASM_ARGS_1 ASM_ARGS_0, "r"(_ret) 53 54 #define LOAD_ARGS_2(a1, a2) \ 55 LOAD_ARGS_1(a1); \ 56 register long _a2 __asm__("r1") = (long) a2; 57 #define ASM_ARGS_2 ASM_ARGS_1, "r"(_a2) 58 59 #define LOAD_ARGS_3(a1, a2, a3) \ 60 LOAD_ARGS_2(a1, a2); \ 61 register long _a3 __asm__("r2") = (long) a3; 62 #define ASM_ARGS_3 ASM_ARGS_2, "r"(_a3) 63 64 #define LOAD_ARGS_4(a1, a2, a3, a4) \ 65 LOAD_ARGS_3(a1, a2, a3); \ 66 register long _a4 __asm__("r3") = (long) a4; 67 #define ASM_ARGS_4 ASM_ARGS_3, "r"(_a4) 68 69 #define LOAD_ARGS_5(a1, a2, a3, a4, a5) \ 70 LOAD_ARGS_4(a1, a2, a3, a4); \ 71 register long _a5 __asm__("r4") = (long) a5; 72 #define ASM_ARGS_5 ASM_ARGS_4, "r"(_a5) 73 74 #define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \ 75 LOAD_ARGS_5(a1, a2, a3, a4, a5); \ 76 register long _a6 __asm__("r5") = (long) a6; 77 #define ASM_ARGS_6 ASM_ARGS_5, "r"(_a6) 78 79 #endif /* __ASSEMBLER__ */ 80 #endif /* _BITS_SYSCALLS_H */ 81