1*043036a2SApple OSS Distributions /* 2*043036a2SApple OSS Distributions * Copyright (c) 1999-2011 Apple Inc. All rights reserved. 3*043036a2SApple OSS Distributions * 4*043036a2SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5*043036a2SApple OSS Distributions * 6*043036a2SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code 7*043036a2SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License 8*043036a2SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in 9*043036a2SApple OSS Distributions * compliance with the License. The rights granted to you under the License 10*043036a2SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of, 11*043036a2SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to 12*043036a2SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any 13*043036a2SApple OSS Distributions * terms of an Apple operating system software license agreement. 14*043036a2SApple OSS Distributions * 15*043036a2SApple OSS Distributions * Please obtain a copy of the License at 16*043036a2SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file. 17*043036a2SApple OSS Distributions * 18*043036a2SApple OSS Distributions * The Original Code and all software distributed under the License are 19*043036a2SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20*043036a2SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21*043036a2SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22*043036a2SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23*043036a2SApple OSS Distributions * Please see the License for the specific language governing rights and 24*043036a2SApple OSS Distributions * limitations under the License. 25*043036a2SApple OSS Distributions * 26*043036a2SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27*043036a2SApple OSS Distributions */ 28*043036a2SApple OSS Distributions /* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. 29*043036a2SApple OSS Distributions * 30*043036a2SApple OSS Distributions * File: SYS.h 31*043036a2SApple OSS Distributions * 32*043036a2SApple OSS Distributions * Definition of the user side of the UNIX system call interface 33*043036a2SApple OSS Distributions * for M98K. 34*043036a2SApple OSS Distributions * 35*043036a2SApple OSS Distributions * Errors are flagged by the location of the trap return (ie., which 36*043036a2SApple OSS Distributions * instruction is executed upon rfi): 37*043036a2SApple OSS Distributions * 38*043036a2SApple OSS Distributions * SC PC + 4: Error (typically branch to cerror()) 39*043036a2SApple OSS Distributions * SC PC + 8: Success 40*043036a2SApple OSS Distributions * 41*043036a2SApple OSS Distributions * HISTORY 42*043036a2SApple OSS Distributions * 18-Nov-92 Ben Fathi ([email protected]) 43*043036a2SApple OSS Distributions * Ported to m98k. 44*043036a2SApple OSS Distributions * 45*043036a2SApple OSS Distributions * 9-Jan-92 Peter King ([email protected]) 46*043036a2SApple OSS Distributions * Created. 47*043036a2SApple OSS Distributions */ 48*043036a2SApple OSS Distributions 49*043036a2SApple OSS Distributions #include <sys/syscall.h> 50*043036a2SApple OSS Distributions 51*043036a2SApple OSS Distributions #if defined(__i386__) 52*043036a2SApple OSS Distributions 53*043036a2SApple OSS Distributions #include <architecture/i386/asm_help.h> 54*043036a2SApple OSS Distributions #include <mach/i386/syscall_sw.h> 55*043036a2SApple OSS Distributions 56*043036a2SApple OSS Distributions /* 57*043036a2SApple OSS Distributions * We have two entry points. int's is used for syscalls which need to preserve 58*043036a2SApple OSS Distributions * %ecx across the call, or return a 64-bit value in %eax:%edx. sysenter is used 59*043036a2SApple OSS Distributions * for the majority of syscalls which just return a value in %eax. 60*043036a2SApple OSS Distributions */ 61*043036a2SApple OSS Distributions 62*043036a2SApple OSS Distributions #define UNIX_SYSCALL_SYSENTER call __sysenter_trap 63*043036a2SApple OSS Distributions #define UNIX_SYSCALL(name, nargs) \ 64*043036a2SApple OSS Distributions .globl tramp_cerror ;\ 65*043036a2SApple OSS Distributions LEAF(_##name, 0) ;\ 66*043036a2SApple OSS Distributions movl $ SYS_##name, %eax ;\ 67*043036a2SApple OSS Distributions UNIX_SYSCALL_SYSENTER ;\ 68*043036a2SApple OSS Distributions jnb 2f ;\ 69*043036a2SApple OSS Distributions BRANCH_EXTERN(tramp_cerror) ;\ 70*043036a2SApple OSS Distributions 2: 71*043036a2SApple OSS Distributions 72*043036a2SApple OSS Distributions #define UNIX_SYSCALL_INT(name, nargs) \ 73*043036a2SApple OSS Distributions .globl tramp_cerror ;\ 74*043036a2SApple OSS Distributions LEAF(_##name, 0) ;\ 75*043036a2SApple OSS Distributions movl $ SYS_##name, %eax ;\ 76*043036a2SApple OSS Distributions UNIX_SYSCALL_TRAP ;\ 77*043036a2SApple OSS Distributions jnb 2f ;\ 78*043036a2SApple OSS Distributions BRANCH_EXTERN(tramp_cerror) ;\ 79*043036a2SApple OSS Distributions 2: 80*043036a2SApple OSS Distributions 81*043036a2SApple OSS Distributions #if defined(__SYSCALL_32BIT_ARG_BYTES) && ((__SYSCALL_32BIT_ARG_BYTES >= 4) && (__SYSCALL_32BIT_ARG_BYTES <= 20)) 82*043036a2SApple OSS Distributions #define UNIX_SYSCALL_NONAME(name, nargs, cerror) \ 83*043036a2SApple OSS Distributions movl $(SYS_##name | (__SYSCALL_32BIT_ARG_BYTES << I386_SYSCALL_ARG_BYTES_SHIFT)), %eax ;\ 84*043036a2SApple OSS Distributions UNIX_SYSCALL_SYSENTER ;\ 85*043036a2SApple OSS Distributions jnb 2f ;\ 86*043036a2SApple OSS Distributions BRANCH_EXTERN(tramp_##cerror) ;\ 87*043036a2SApple OSS Distributions 2: 88*043036a2SApple OSS Distributions #else /* __SYSCALL_32BIT_ARG_BYTES < 4 || > 20 */ 89*043036a2SApple OSS Distributions #define UNIX_SYSCALL_NONAME(name, nargs, cerror) \ 90*043036a2SApple OSS Distributions movl $ SYS_##name, %eax ;\ 91*043036a2SApple OSS Distributions UNIX_SYSCALL_SYSENTER ;\ 92*043036a2SApple OSS Distributions jnb 2f ;\ 93*043036a2SApple OSS Distributions BRANCH_EXTERN(tramp_##cerror) ;\ 94*043036a2SApple OSS Distributions 2: 95*043036a2SApple OSS Distributions #endif 96*043036a2SApple OSS Distributions 97*043036a2SApple OSS Distributions #define UNIX_SYSCALL_INT_NONAME(name, nargs) \ 98*043036a2SApple OSS Distributions .globl tramp_cerror_nocancel ;\ 99*043036a2SApple OSS Distributions movl $ SYS_##name, %eax ;\ 100*043036a2SApple OSS Distributions UNIX_SYSCALL_TRAP ;\ 101*043036a2SApple OSS Distributions jnb 2f ;\ 102*043036a2SApple OSS Distributions BRANCH_EXTERN(tramp_cerror_nocancel) ;\ 103*043036a2SApple OSS Distributions 2: 104*043036a2SApple OSS Distributions 105*043036a2SApple OSS Distributions #define PSEUDO(pseudo, name, nargs, cerror) \ 106*043036a2SApple OSS Distributions LEAF(pseudo, 0) ;\ 107*043036a2SApple OSS Distributions UNIX_SYSCALL_NONAME(name, nargs, cerror) 108*043036a2SApple OSS Distributions 109*043036a2SApple OSS Distributions #define PSEUDO_INT(pseudo, name, nargs) \ 110*043036a2SApple OSS Distributions LEAF(pseudo, 0) ;\ 111*043036a2SApple OSS Distributions UNIX_SYSCALL_INT_NONAME(name, nargs) 112*043036a2SApple OSS Distributions 113*043036a2SApple OSS Distributions #define __SYSCALL2(pseudo, name, nargs, cerror) \ 114*043036a2SApple OSS Distributions PSEUDO(pseudo, name, nargs, cerror) ;\ 115*043036a2SApple OSS Distributions ret 116*043036a2SApple OSS Distributions 117*043036a2SApple OSS Distributions #define __SYSCALL(pseudo, name, nargs) \ 118*043036a2SApple OSS Distributions PSEUDO(pseudo, name, nargs, cerror) ;\ 119*043036a2SApple OSS Distributions ret 120*043036a2SApple OSS Distributions 121*043036a2SApple OSS Distributions #define __SYSCALL_INT(pseudo, name, nargs) \ 122*043036a2SApple OSS Distributions PSEUDO_INT(pseudo, name, nargs) ;\ 123*043036a2SApple OSS Distributions ret 124*043036a2SApple OSS Distributions 125*043036a2SApple OSS Distributions #elif defined(__x86_64__) 126*043036a2SApple OSS Distributions 127*043036a2SApple OSS Distributions #include <architecture/i386/asm_help.h> 128*043036a2SApple OSS Distributions #include <mach/i386/syscall_sw.h> 129*043036a2SApple OSS Distributions 130*043036a2SApple OSS Distributions #define UNIX_SYSCALL_SYSCALL \ 131*043036a2SApple OSS Distributions movq %rcx, %r10 ;\ 132*043036a2SApple OSS Distributions syscall 133*043036a2SApple OSS Distributions 134*043036a2SApple OSS Distributions #define UNIX_SYSCALL(name, nargs) \ 135*043036a2SApple OSS Distributions .globl cerror ;\ 136*043036a2SApple OSS Distributions LEAF(_##name, 0) ;\ 137*043036a2SApple OSS Distributions movl $ SYSCALL_CONSTRUCT_UNIX(SYS_##name), %eax ;\ 138*043036a2SApple OSS Distributions UNIX_SYSCALL_SYSCALL ;\ 139*043036a2SApple OSS Distributions jnb 2f ;\ 140*043036a2SApple OSS Distributions movq %rax, %rdi ;\ 141*043036a2SApple OSS Distributions BRANCH_EXTERN(_cerror) ;\ 142*043036a2SApple OSS Distributions 2: 143*043036a2SApple OSS Distributions 144*043036a2SApple OSS Distributions #define UNIX_SYSCALL_NONAME(name, nargs, cerror) \ 145*043036a2SApple OSS Distributions .globl cerror ;\ 146*043036a2SApple OSS Distributions movl $ SYSCALL_CONSTRUCT_UNIX(SYS_##name), %eax ;\ 147*043036a2SApple OSS Distributions UNIX_SYSCALL_SYSCALL ;\ 148*043036a2SApple OSS Distributions jnb 2f ;\ 149*043036a2SApple OSS Distributions movq %rax, %rdi ;\ 150*043036a2SApple OSS Distributions BRANCH_EXTERN(_##cerror) ;\ 151*043036a2SApple OSS Distributions 2: 152*043036a2SApple OSS Distributions 153*043036a2SApple OSS Distributions #define PSEUDO(pseudo, name, nargs, cerror) \ 154*043036a2SApple OSS Distributions LEAF(pseudo, 0) ;\ 155*043036a2SApple OSS Distributions UNIX_SYSCALL_NONAME(name, nargs, cerror) 156*043036a2SApple OSS Distributions 157*043036a2SApple OSS Distributions #define __SYSCALL2(pseudo, name, nargs, cerror) \ 158*043036a2SApple OSS Distributions PSEUDO(pseudo, name, nargs, cerror) ;\ 159*043036a2SApple OSS Distributions ret ;\ 160*043036a2SApple OSS Distributions UNWIND_EPILOGUE 161*043036a2SApple OSS Distributions 162*043036a2SApple OSS Distributions #define __SYSCALL(pseudo, name, nargs) \ 163*043036a2SApple OSS Distributions PSEUDO(pseudo, name, nargs, cerror) ;\ 164*043036a2SApple OSS Distributions ret ;\ 165*043036a2SApple OSS Distributions UNWIND_EPILOGUE 166*043036a2SApple OSS Distributions 167*043036a2SApple OSS Distributions #elif defined(__arm__) 168*043036a2SApple OSS Distributions 169*043036a2SApple OSS Distributions #include <architecture/arm/asm_help.h> 170*043036a2SApple OSS Distributions #include <mach/arm/syscall_sw.h> 171*043036a2SApple OSS Distributions 172*043036a2SApple OSS Distributions /* 173*043036a2SApple OSS Distributions * ARM system call interface: 174*043036a2SApple OSS Distributions * 175*043036a2SApple OSS Distributions * swi 0x80 176*043036a2SApple OSS Distributions * args: r0-r6 177*043036a2SApple OSS Distributions * return code: r0 178*043036a2SApple OSS Distributions * on error, carry bit is set in the psr, otherwise carry bit is cleared. 179*043036a2SApple OSS Distributions */ 180*043036a2SApple OSS Distributions 181*043036a2SApple OSS Distributions /* 182*043036a2SApple OSS Distributions * Macros. 183*043036a2SApple OSS Distributions */ 184*043036a2SApple OSS Distributions 185*043036a2SApple OSS Distributions /* 186*043036a2SApple OSS Distributions * until we update the architecture project, these live here 187*043036a2SApple OSS Distributions */ 188*043036a2SApple OSS Distributions 189*043036a2SApple OSS Distributions #if defined(__DYNAMIC__) 190*043036a2SApple OSS Distributions #define MI_GET_ADDRESS(reg,var) \ 191*043036a2SApple OSS Distributions ldr reg, 4f ;\ 192*043036a2SApple OSS Distributions 3: ldr reg, [pc, reg] ;\ 193*043036a2SApple OSS Distributions b 5f ;\ 194*043036a2SApple OSS Distributions 4: .long 6f - (3b + 8) ;\ 195*043036a2SApple OSS Distributions 5: ;\ 196*043036a2SApple OSS Distributions .non_lazy_symbol_pointer ;\ 197*043036a2SApple OSS Distributions 6: ;\ 198*043036a2SApple OSS Distributions .indirect_symbol var ;\ 199*043036a2SApple OSS Distributions .long 0 ;\ 200*043036a2SApple OSS Distributions .text ;\ 201*043036a2SApple OSS Distributions .align 2 202*043036a2SApple OSS Distributions #else 203*043036a2SApple OSS Distributions #define MI_GET_ADDRESS(reg,var) \ 204*043036a2SApple OSS Distributions ldr reg, 3f ;\ 205*043036a2SApple OSS Distributions b 4f ;\ 206*043036a2SApple OSS Distributions 3: .long var ;\ 207*043036a2SApple OSS Distributions 4: 208*043036a2SApple OSS Distributions #endif 209*043036a2SApple OSS Distributions 210*043036a2SApple OSS Distributions #if defined(__DYNAMIC__) 211*043036a2SApple OSS Distributions #define MI_BRANCH_EXTERNAL(var) \ 212*043036a2SApple OSS Distributions .globl var ;\ 213*043036a2SApple OSS Distributions MI_GET_ADDRESS(ip, var) ;\ 214*043036a2SApple OSS Distributions bx ip 215*043036a2SApple OSS Distributions #else 216*043036a2SApple OSS Distributions #define MI_BRANCH_EXTERNAL(var) ;\ 217*043036a2SApple OSS Distributions .globl var ;\ 218*043036a2SApple OSS Distributions b var 219*043036a2SApple OSS Distributions #endif 220*043036a2SApple OSS Distributions 221*043036a2SApple OSS Distributions #if defined(__DYNAMIC__) 222*043036a2SApple OSS Distributions #define MI_CALL_EXTERNAL(var) \ 223*043036a2SApple OSS Distributions .globl var ;\ 224*043036a2SApple OSS Distributions MI_GET_ADDRESS(ip,var) ;\ 225*043036a2SApple OSS Distributions blx ip 226*043036a2SApple OSS Distributions #else 227*043036a2SApple OSS Distributions #define MI_CALL_EXTERNAL(var) \ 228*043036a2SApple OSS Distributions .globl var ;\ 229*043036a2SApple OSS Distributions bl var 230*043036a2SApple OSS Distributions #endif 231*043036a2SApple OSS Distributions 232*043036a2SApple OSS Distributions #define MI_ENTRY_POINT(name) \ 233*043036a2SApple OSS Distributions .text ;\ 234*043036a2SApple OSS Distributions .align 2 ;\ 235*043036a2SApple OSS Distributions .globl name ;\ 236*043036a2SApple OSS Distributions name: 237*043036a2SApple OSS Distributions 238*043036a2SApple OSS Distributions /* load the syscall number into r12 and trap */ 239*043036a2SApple OSS Distributions #define DO_SYSCALL(num) \ 240*043036a2SApple OSS Distributions .if (((num) & 0xff) == (num)) ;\ 241*043036a2SApple OSS Distributions mov r12, #(num) ;\ 242*043036a2SApple OSS Distributions .elseif (((num) & 0x3fc) == (num)) ;\ 243*043036a2SApple OSS Distributions mov r12, #(num) ;\ 244*043036a2SApple OSS Distributions .else ;\ 245*043036a2SApple OSS Distributions mov r12, #((num) & 0xffffff00) /* top half of the syscall number */ ;\ 246*043036a2SApple OSS Distributions orr r12, r12, #((num) & 0xff) /* bottom half */ ;\ 247*043036a2SApple OSS Distributions .endif ;\ 248*043036a2SApple OSS Distributions swi #SWI_SYSCALL 249*043036a2SApple OSS Distributions 250*043036a2SApple OSS Distributions /* simple syscalls (0 to 4 args) */ 251*043036a2SApple OSS Distributions #define SYSCALL_0to4(name, cerror) \ 252*043036a2SApple OSS Distributions MI_ENTRY_POINT(_##name) ;\ 253*043036a2SApple OSS Distributions DO_SYSCALL(SYS_##name) ;\ 254*043036a2SApple OSS Distributions bxcc lr /* return if carry is clear (no error) */ ; \ 255*043036a2SApple OSS Distributions 1: MI_BRANCH_EXTERNAL(_##cerror) 256*043036a2SApple OSS Distributions 257*043036a2SApple OSS Distributions /* syscalls with 5 args is different, because of the single arg register load */ 258*043036a2SApple OSS Distributions #define SYSCALL_5(name, cerror) \ 259*043036a2SApple OSS Distributions MI_ENTRY_POINT(_##name) ;\ 260*043036a2SApple OSS Distributions mov ip, sp /* save a pointer to the args */ ; \ 261*043036a2SApple OSS Distributions stmfd sp!, { r4-r5 } /* save r4-r5 */ ;\ 262*043036a2SApple OSS Distributions ldr r4, [ip] /* load 5th arg */ ; \ 263*043036a2SApple OSS Distributions DO_SYSCALL(SYS_##name) ;\ 264*043036a2SApple OSS Distributions ldmfd sp!, { r4-r5 } /* restore r4-r5 */ ; \ 265*043036a2SApple OSS Distributions bxcc lr /* return if carry is clear (no error) */ ; \ 266*043036a2SApple OSS Distributions 1: MI_BRANCH_EXTERNAL(_##cerror) 267*043036a2SApple OSS Distributions 268*043036a2SApple OSS Distributions /* syscalls with 6 to 12 args. kernel may have to read from stack */ 269*043036a2SApple OSS Distributions #define SYSCALL_6to12(name, save_regs, arg_regs, cerror) \ 270*043036a2SApple OSS Distributions MI_ENTRY_POINT(_##name) ;\ 271*043036a2SApple OSS Distributions mov ip, sp /* save a pointer to the args */ ; \ 272*043036a2SApple OSS Distributions stmfd sp!, { save_regs } /* callee saved regs */ ;\ 273*043036a2SApple OSS Distributions ldmia ip, { arg_regs } /* load arg regs */ ; \ 274*043036a2SApple OSS Distributions DO_SYSCALL(SYS_##name) ;\ 275*043036a2SApple OSS Distributions ldmfd sp!, { save_regs } /* restore callee saved regs */ ; \ 276*043036a2SApple OSS Distributions bxcc lr /* return if carry is clear (no error) */ ; \ 277*043036a2SApple OSS Distributions 1: MI_BRANCH_EXTERNAL(_##cerror) 278*043036a2SApple OSS Distributions 279*043036a2SApple OSS Distributions #define COMMA , 280*043036a2SApple OSS Distributions 281*043036a2SApple OSS Distributions #if __BIGGEST_ALIGNMENT__ > 4 282*043036a2SApple OSS Distributions 283*043036a2SApple OSS Distributions /* For the armv7k ABI, the alignment requirements may add padding. So we 284*043036a2SApple OSS Distributions * let the kernel figure it out and push extra on the stack to avoid un-needed 285*043036a2SApple OSS Distributions * copy-ins */ 286*043036a2SApple OSS Distributions 287*043036a2SApple OSS Distributions /* We'll also use r8 for moving arguments */ 288*043036a2SApple OSS Distributions 289*043036a2SApple OSS Distributions #define SYSCALL_0(name) SYSCALL_0to4(name) 290*043036a2SApple OSS Distributions #define SYSCALL_1(name) SYSCALL_0to4(name) 291*043036a2SApple OSS Distributions #define SYSCALL_2(name) SYSCALL_0to4(name) 292*043036a2SApple OSS Distributions #define SYSCALL_3(name) SYSCALL_0to4(name) 293*043036a2SApple OSS Distributions #define SYSCALL_4(name) SYSCALL_6to12(name, r4-r5, r4-r5) 294*043036a2SApple OSS Distributions #undef SYSCALL_5 295*043036a2SApple OSS Distributions #define SYSCALL_5(name) SYSCALL_6to12(name, r4-r5, r4-r5) 296*043036a2SApple OSS Distributions #define SYSCALL_6(name) SYSCALL_6to12(name, r4-r6 COMMA r8, r4-r6 COMMA r8) 297*043036a2SApple OSS Distributions #define SYSCALL_7(name) SYSCALL_6to12(name, r4-r6 COMMA r8, r4-r6 COMMA r8) 298*043036a2SApple OSS Distributions #define SYSCALL_8(name) SYSCALL_6to12(name, r4-r6 COMMA r8, r4-r6 COMMA r8) 299*043036a2SApple OSS Distributions #define SYSCALL_12(name) SYSCALL_6to12(name, r4-r6 COMMA r8, r4-r6 COMMA r8) 300*043036a2SApple OSS Distributions 301*043036a2SApple OSS Distributions #else // !(__BIGGEST_ALIGNMENT__ > 4) (the normal arm32 ABI case) 302*043036a2SApple OSS Distributions 303*043036a2SApple OSS Distributions #define SYSCALL_0(name) SYSCALL_0to4(name) 304*043036a2SApple OSS Distributions #define SYSCALL_1(name) SYSCALL_0to4(name) 305*043036a2SApple OSS Distributions #define SYSCALL_2(name) SYSCALL_0to4(name) 306*043036a2SApple OSS Distributions #define SYSCALL_3(name) SYSCALL_0to4(name) 307*043036a2SApple OSS Distributions #define SYSCALL_4(name) SYSCALL_0to4(name) 308*043036a2SApple OSS Distributions /* SYSCALL_5 declared above */ 309*043036a2SApple OSS Distributions #define SYSCALL_6(name) SYSCALL_6to12(name, r4-r5, r4-r5) 310*043036a2SApple OSS Distributions #define SYSCALL_7(name) SYSCALL_6to12(name, r4-r6 COMMA r8, r4-r6) 311*043036a2SApple OSS Distributions #define SYSCALL_8(name) SYSCALL_6to12(name, r4-r6 COMMA r8, r4-r6) /* 8th on stack */ 312*043036a2SApple OSS Distributions #define SYSCALL_12(name) SYSCALL_6to12(name, r4-r6 COMMA r8, r4-r6) /* 8th-12th on stack */ 313*043036a2SApple OSS Distributions 314*043036a2SApple OSS Distributions #endif // __BIGGEST_ALIGNMENT__ > 4 315*043036a2SApple OSS Distributions 316*043036a2SApple OSS Distributions /* select the appropriate syscall code, based on the number of arguments */ 317*043036a2SApple OSS Distributions #ifndef __SYSCALL_32BIT_ARG_BYTES 318*043036a2SApple OSS Distributions #define SYSCALL(name, nargs, cerror) SYSCALL_##nargs(name, cerror) 319*043036a2SApple OSS Distributions #define SYSCALL_NONAME(name, nargs, cerror) SYSCALL_NONAME_##nargs(name, cerror) 320*043036a2SApple OSS Distributions #else 321*043036a2SApple OSS Distributions #if __SYSCALL_32BIT_ARG_BYTES < 20 322*043036a2SApple OSS Distributions #define SYSCALL(name, nargs, cerror) SYSCALL_0to4(name, cerror) 323*043036a2SApple OSS Distributions #define SYSCALL_NONAME(name, nargs, cerror) SYSCALL_NONAME_0to4(name, cerror) 324*043036a2SApple OSS Distributions #elif __SYSCALL_32BIT_ARG_BYTES == 20 325*043036a2SApple OSS Distributions #define SYSCALL(name, nargs, cerror) SYSCALL_5(name, cerror) 326*043036a2SApple OSS Distributions #define SYSCALL_NONAME(name, nargs, cerror) SYSCALL_NONAME_5(name, cerror) 327*043036a2SApple OSS Distributions #elif __SYSCALL_32BIT_ARG_BYTES == 24 328*043036a2SApple OSS Distributions #define SYSCALL(name, nargs, cerror) SYSCALL_6(name, cerror) 329*043036a2SApple OSS Distributions #define SYSCALL_NONAME(name, nargs, cerror) SYSCALL_NONAME_6(name, cerror) 330*043036a2SApple OSS Distributions #elif __SYSCALL_32BIT_ARG_BYTES == 28 331*043036a2SApple OSS Distributions #define SYSCALL(name, nargs, cerror) SYSCALL_7(name, cerror) 332*043036a2SApple OSS Distributions #define SYSCALL_NONAME(name, nargs, cerror) SYSCALL_NONAME_7(name, cerror) 333*043036a2SApple OSS Distributions #elif __SYSCALL_32BIT_ARG_BYTES == 32 334*043036a2SApple OSS Distributions #define SYSCALL(name, nargs, cerror) SYSCALL_8(name, cerror) 335*043036a2SApple OSS Distributions #define SYSCALL_NONAME(name, nargs, cerror) SYSCALL_NONAME_8(name, cerror) 336*043036a2SApple OSS Distributions #elif __SYSCALL_32BIT_ARG_BYTES == 36 337*043036a2SApple OSS Distributions #define SYSCALL(name, nargs, cerror) SYSCALL_8(name, cerror) 338*043036a2SApple OSS Distributions #define SYSCALL_NONAME(name, nargs, cerror) SYSCALL_NONAME_8(name, cerror) 339*043036a2SApple OSS Distributions #elif __SYSCALL_32BIT_ARG_BYTES == 40 340*043036a2SApple OSS Distributions #define SYSCALL(name, nargs, cerror) SYSCALL_8(name, cerror) 341*043036a2SApple OSS Distributions #define SYSCALL_NONAME(name, nargs, cerror) SYSCALL_NONAME_8(name, cerror) 342*043036a2SApple OSS Distributions #elif __SYSCALL_32BIT_ARG_BYTES == 44 343*043036a2SApple OSS Distributions #define SYSCALL(name, nargs, cerror) SYSCALL_8(name, cerror) 344*043036a2SApple OSS Distributions #define SYSCALL_NONAME(name, nargs, cerror) SYSCALL_NONAME_8(name, cerror) 345*043036a2SApple OSS Distributions #elif __SYSCALL_32BIT_ARG_BYTES == 48 346*043036a2SApple OSS Distributions #define SYSCALL(name, nargs, cerror) SYSCALL_12(name, cerror) 347*043036a2SApple OSS Distributions #define SYSCALL_NONAME(name, nargs, cerror) SYSCALL_NONAME_12(name, cerror) 348*043036a2SApple OSS Distributions #endif 349*043036a2SApple OSS Distributions #endif 350*043036a2SApple OSS Distributions 351*043036a2SApple OSS Distributions #define SYSCALL_NONAME_0to4(name, cerror) \ 352*043036a2SApple OSS Distributions DO_SYSCALL(SYS_##name) ;\ 353*043036a2SApple OSS Distributions bcc 1f /* branch if carry bit is clear (no error) */ ; \ 354*043036a2SApple OSS Distributions MI_BRANCH_EXTERNAL(_##cerror) /* call cerror */ ; \ 355*043036a2SApple OSS Distributions 1: 356*043036a2SApple OSS Distributions 357*043036a2SApple OSS Distributions #define SYSCALL_NONAME_5(name, cerror) \ 358*043036a2SApple OSS Distributions mov ip, sp /* save a pointer to the args */ ; \ 359*043036a2SApple OSS Distributions stmfd sp!, { r4-r5 } /* save r4-r5 */ ;\ 360*043036a2SApple OSS Distributions ldr r4, [ip] /* load 5th arg */ ; \ 361*043036a2SApple OSS Distributions DO_SYSCALL(SYS_##name) ;\ 362*043036a2SApple OSS Distributions ldmfd sp!, { r4-r5 } /* restore r4-r7 */ ; \ 363*043036a2SApple OSS Distributions bcc 1f /* branch if carry bit is clear (no error) */ ; \ 364*043036a2SApple OSS Distributions MI_BRANCH_EXTERNAL(_##cerror) /* call cerror */ ; \ 365*043036a2SApple OSS Distributions 1: 366*043036a2SApple OSS Distributions 367*043036a2SApple OSS Distributions #define SYSCALL_NONAME_6to12(name, save_regs, arg_regs, cerror) \ 368*043036a2SApple OSS Distributions mov ip, sp /* save a pointer to the args */ ; \ 369*043036a2SApple OSS Distributions stmfd sp!, { save_regs } /* callee save regs */ ;\ 370*043036a2SApple OSS Distributions ldmia ip, { arg_regs } /* load arguments */ ; \ 371*043036a2SApple OSS Distributions DO_SYSCALL(SYS_##name) ;\ 372*043036a2SApple OSS Distributions ldmfd sp!, { save_regs } /* restore callee saved regs */ ; \ 373*043036a2SApple OSS Distributions bcc 1f /* branch if carry bit is clear (no error) */ ; \ 374*043036a2SApple OSS Distributions MI_BRANCH_EXTERNAL(_##cerror) /* call cerror */ ; \ 375*043036a2SApple OSS Distributions 1: 376*043036a2SApple OSS Distributions 377*043036a2SApple OSS Distributions 378*043036a2SApple OSS Distributions #if __BIGGEST_ALIGNMENT__ > 4 379*043036a2SApple OSS Distributions 380*043036a2SApple OSS Distributions /* For the armv7k ABI, the alignment requirements may add padding. So we 381*043036a2SApple OSS Distributions * let the kernel figure it out and push extra on the stack to avoid un-needed 382*043036a2SApple OSS Distributions * copy-ins. We are relying on arguments that aren't in registers starting 383*043036a2SApple OSS Distributions * 32 bytes from sp. We also use r8 like in the mach case. */ 384*043036a2SApple OSS Distributions 385*043036a2SApple OSS Distributions #define SYSCALL_NONAME_0(name, cerror) SYSCALL_NONAME_0to4(name, cerror) 386*043036a2SApple OSS Distributions #define SYSCALL_NONAME_1(name, cerror) SYSCALL_NONAME_0to4(name, cerror) 387*043036a2SApple OSS Distributions #define SYSCALL_NONAME_2(name, cerror) SYSCALL_NONAME_0to4(name, cerror) 388*043036a2SApple OSS Distributions #define SYSCALL_NONAME_3(name, cerror) SYSCALL_NONAME_0to4(name, cerror) 389*043036a2SApple OSS Distributions #define SYSCALL_NONAME_4(name, cerror) SYSCALL_NONAME_6to12(name, r4-r5, r4-r5, cerror) 390*043036a2SApple OSS Distributions #undef SYSCALL_NONAME_5 391*043036a2SApple OSS Distributions #define SYSCALL_NONAME_5(name, cerror) SYSCALL_NONAME_6to12(name, r4-r5, r4-r5, cerror) 392*043036a2SApple OSS Distributions #define SYSCALL_NONAME_6(name, cerror) SYSCALL_NONAME_6to12(name, r4-r6 COMMA r8, r4-r6 COMMA r8, cerror) 393*043036a2SApple OSS Distributions #define SYSCALL_NONAME_7(name, cerror) SYSCALL_NONAME_6to12(name, r4-r6 COMMA r8, r4-r6 COMMA r8, cerror) 394*043036a2SApple OSS Distributions #define SYSCALL_NONAME_8(name, cerror) SYSCALL_NONAME_6to12(name, r4-r6 COMMA r8, r4-r6 COMMA r8, cerror) 395*043036a2SApple OSS Distributions #define SYSCALL_NONAME_12(name, cerror) SYSCALL_NONAME_6to12(name, r4-r6 COMMA r8, r4-r6 COMMA r8, cerror) 396*043036a2SApple OSS Distributions 397*043036a2SApple OSS Distributions #else // !(__BIGGEST_ALIGNMENT__ > 4) (the normal arm32 ABI case) 398*043036a2SApple OSS Distributions 399*043036a2SApple OSS Distributions #define SYSCALL_NONAME_0(name, cerror) SYSCALL_NONAME_0to4(name, cerror) 400*043036a2SApple OSS Distributions #define SYSCALL_NONAME_1(name, cerror) SYSCALL_NONAME_0to4(name, cerror) 401*043036a2SApple OSS Distributions #define SYSCALL_NONAME_2(name, cerror) SYSCALL_NONAME_0to4(name, cerror) 402*043036a2SApple OSS Distributions #define SYSCALL_NONAME_3(name, cerror) SYSCALL_NONAME_0to4(name, cerror) 403*043036a2SApple OSS Distributions #define SYSCALL_NONAME_4(name, cerror) SYSCALL_NONAME_0to4(name, cerror) 404*043036a2SApple OSS Distributions /* SYSCALL_NONAME_5 declared above */ 405*043036a2SApple OSS Distributions #define SYSCALL_NONAME_6(name, cerror) SYSCALL_NONAME_6to12(name, r4-r5, r4-r5, cerror) 406*043036a2SApple OSS Distributions #define SYSCALL_NONAME_7(name, cerror) SYSCALL_NONAME_6to12(name, r4-r6 COMMA r8, r4-r6, cerror) 407*043036a2SApple OSS Distributions #define SYSCALL_NONAME_8(name, cerror) SYSCALL_NONAME_6to12(name, r4-r6 COMMA r8, r4-r6, cerror) 408*043036a2SApple OSS Distributions #define SYSCALL_NONAME_12(name, cerror) SYSCALL_NONAME_6to12(name, r4-r6 COMMA r8, r4-r6, cerror) 409*043036a2SApple OSS Distributions 410*043036a2SApple OSS Distributions #endif // __BIGGEST_ALIGNMENT__ > 4 411*043036a2SApple OSS Distributions 412*043036a2SApple OSS Distributions #define PSEUDO(pseudo, name, nargs, cerror) \ 413*043036a2SApple OSS Distributions .globl pseudo ;\ 414*043036a2SApple OSS Distributions .text ;\ 415*043036a2SApple OSS Distributions .align 2 ;\ 416*043036a2SApple OSS Distributions pseudo: ;\ 417*043036a2SApple OSS Distributions SYSCALL_NONAME(name, nargs, cerror) 418*043036a2SApple OSS Distributions 419*043036a2SApple OSS Distributions #define __SYSCALL2(pseudo, name, nargs, cerror) \ 420*043036a2SApple OSS Distributions PSEUDO(pseudo, name, nargs, cerror) ;\ 421*043036a2SApple OSS Distributions bx lr 422*043036a2SApple OSS Distributions 423*043036a2SApple OSS Distributions #define __SYSCALL(pseudo, name, nargs) \ 424*043036a2SApple OSS Distributions PSEUDO(pseudo, name, nargs, cerror) ;\ 425*043036a2SApple OSS Distributions bx lr 426*043036a2SApple OSS Distributions 427*043036a2SApple OSS Distributions #elif defined(__arm64__) 428*043036a2SApple OSS Distributions 429*043036a2SApple OSS Distributions #include <mach/arm/syscall_sw.h> 430*043036a2SApple OSS Distributions #include <mach/arm/vm_param.h> 431*043036a2SApple OSS Distributions #include <mach/arm64/asm.h> 432*043036a2SApple OSS Distributions 433*043036a2SApple OSS Distributions #if defined(__arm64__) && !defined(__LP64__) 434*043036a2SApple OSS Distributions #define ZERO_EXTEND(argnum) uxtw x ## argnum, w ## argnum 435*043036a2SApple OSS Distributions #else 436*043036a2SApple OSS Distributions #define ZERO_EXTEND(argnum) 437*043036a2SApple OSS Distributions #endif 438*043036a2SApple OSS Distributions 439*043036a2SApple OSS Distributions #if defined(__arm64__) && !defined(__LP64__) 440*043036a2SApple OSS Distributions #define SIGN_EXTEND(argnum) sxtw x ## argnum, w ## argnum 441*043036a2SApple OSS Distributions #else 442*043036a2SApple OSS Distributions #define SIGN_EXTEND(argnum) 443*043036a2SApple OSS Distributions #endif 444*043036a2SApple OSS Distributions 445*043036a2SApple OSS Distributions /* 446*043036a2SApple OSS Distributions * ARM64 system call interface: 447*043036a2SApple OSS Distributions * 448*043036a2SApple OSS Distributions * TBD 449*043036a2SApple OSS Distributions */ 450*043036a2SApple OSS Distributions 451*043036a2SApple OSS Distributions #define DO_SYSCALL(num, cerror) \ 452*043036a2SApple OSS Distributions mov x16, #(num) %%\ 453*043036a2SApple OSS Distributions svc #SWI_SYSCALL %%\ 454*043036a2SApple OSS Distributions b.cc 2f %%\ 455*043036a2SApple OSS Distributions ARM64_STACK_PROLOG %%\ 456*043036a2SApple OSS Distributions PUSH_FRAME %%\ 457*043036a2SApple OSS Distributions bl _##cerror %%\ 458*043036a2SApple OSS Distributions POP_FRAME %%\ 459*043036a2SApple OSS Distributions ARM64_STACK_EPILOG %%\ 460*043036a2SApple OSS Distributions 2: 461*043036a2SApple OSS Distributions 462*043036a2SApple OSS Distributions #define MI_GET_ADDRESS(reg,var) \ 463*043036a2SApple OSS Distributions adrp reg, var@page %%\ 464*043036a2SApple OSS Distributions add reg, reg, var@pageoff %% 465*043036a2SApple OSS Distributions 466*043036a2SApple OSS Distributions #define MI_CALL_EXTERNAL(sym) \ 467*043036a2SApple OSS Distributions .globl sym %% \ 468*043036a2SApple OSS Distributions bl sym 469*043036a2SApple OSS Distributions 470*043036a2SApple OSS Distributions #define SYSCALL_NONAME(name, nargs, cerror) \ 471*043036a2SApple OSS Distributions DO_SYSCALL(SYS_##name, cerror) %% \ 472*043036a2SApple OSS Distributions 1: 473*043036a2SApple OSS Distributions 474*043036a2SApple OSS Distributions #define MI_ENTRY_POINT(name) \ 475*043036a2SApple OSS Distributions .text %% \ 476*043036a2SApple OSS Distributions .align 2 %% \ 477*043036a2SApple OSS Distributions .globl name %% \ 478*043036a2SApple OSS Distributions name: 479*043036a2SApple OSS Distributions 480*043036a2SApple OSS Distributions #define PSEUDO(pseudo, name, nargs, cerror) \ 481*043036a2SApple OSS Distributions .text %% \ 482*043036a2SApple OSS Distributions .align 2 %% \ 483*043036a2SApple OSS Distributions .globl pseudo %% \ 484*043036a2SApple OSS Distributions pseudo: %% \ 485*043036a2SApple OSS Distributions SYSCALL_NONAME(name, nargs, cerror) 486*043036a2SApple OSS Distributions 487*043036a2SApple OSS Distributions #define __SYSCALL(pseudo, name, nargs) \ 488*043036a2SApple OSS Distributions PSEUDO(pseudo, name, nargs, cerror) %% \ 489*043036a2SApple OSS Distributions ret 490*043036a2SApple OSS Distributions 491*043036a2SApple OSS Distributions #define __SYSCALL2(pseudo, name, nargs, cerror) \ 492*043036a2SApple OSS Distributions PSEUDO(pseudo, name, nargs, cerror) %% \ 493*043036a2SApple OSS Distributions ret 494*043036a2SApple OSS Distributions 495*043036a2SApple OSS Distributions #else 496*043036a2SApple OSS Distributions #error Unsupported architecture 497*043036a2SApple OSS Distributions #endif 498*043036a2SApple OSS Distributions 499