]> git.saurik.com Git - apple/xnu.git/blobdiff - libsyscall/custom/SYS.h
xnu-6153.141.1.tar.gz
[apple/xnu.git] / libsyscall / custom / SYS.h
index 3f95dbbaf4f7f8b321bec240f2b1a9ec16511659..ffc6a8f2e725d039dbd0ca96372aa6a4c2b59c7b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999-2007 Apple Inc. All rights reserved.
+ * Copyright (c) 1999-2011 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
 
 #include <sys/syscall.h>
 
-#ifndef SYS_setquota
-#define SYS_setquota   148
-#endif
-#ifndef SYS_quota
-#define SYS_quota      149
-#endif
-
-#if defined(__ppc__) || defined(__ppc64__)
-
-#include <architecture/ppc/mode_independent_asm.h>
-
-/* From rhapsody kernel mach/ppc/syscall_sw.h */
-#define        kernel_trap_args_0
-#define        kernel_trap_args_1
-#define        kernel_trap_args_2
-#define        kernel_trap_args_3
-#define        kernel_trap_args_4
-#define        kernel_trap_args_5
-#define        kernel_trap_args_6
-#define        kernel_trap_args_7
-#define        kernel_trap_args_8
-/* End of rhapsody kernel mach/ppc/syscall_sw.h */
-
-/*
- * Macros.
- */
-
-#define        SYSCALL(name, nargs)                    \
-       .globl  cerror                          @\
-    MI_ENTRY_POINT(_##name)     @\
-       kernel_trap_args_##nargs    @\
-       li      r0,SYS_##name                   @\
-       sc                          @\
-       b       1f                      @\
-       blr                         @\
-1:     MI_BRANCH_EXTERNAL(cerror)
-
-
-#define        SYSCALL_NONAME(name, nargs)             \
-       .globl  cerror                          @\
-       kernel_trap_args_##nargs    @\
-       li      r0,SYS_##name                   @\
-       sc                          @\
-       b       1f                      @\
-       b       2f                      @\
-1:     MI_BRANCH_EXTERNAL(cerror)  @\
-2:
-
-
-#define        PSEUDO(pseudo, name, nargs)             \
-    .private_extern  _##pseudo           @\
-    .text                       @\
-    .align  2                   @\
-_##pseudo:                      @\
-       SYSCALL_NONAME(name, nargs)
-
-#define __SYSCALL(pseudo, name, nargs) \
-    PSEUDO(pseudo, name, nargs)        @\
-    blr
-
-#elif defined(__i386__)
+#if defined(__i386__)
 
 #include <architecture/i386/asm_help.h>
 #include <mach/i386/syscall_sw.h>
@@ -121,58 +61,61 @@ _##pseudo:                      @\
 
 #define UNIX_SYSCALL_SYSENTER          call __sysenter_trap
 #define UNIX_SYSCALL(name, nargs)                      \
-       .globl  cerror                                  ;\
+       .globl  tramp_cerror                            ;\
 LEAF(_##name, 0)                                       ;\
        movl    $ SYS_##name, %eax                      ;\
        UNIX_SYSCALL_SYSENTER                           ;\
        jnb     2f                                      ;\
-       BRANCH_EXTERN(cerror)                           ;\
+       BRANCH_EXTERN(tramp_cerror)                     ;\
 2:
 
 #define UNIX_SYSCALL_INT(name, nargs)                  \
-       .globl  cerror                                  ;\
+       .globl  tramp_cerror                            ;\
 LEAF(_##name, 0)                                       ;\
        movl    $ SYS_##name, %eax                      ;\
        UNIX_SYSCALL_TRAP                               ;\
        jnb     2f                                      ;\
-       BRANCH_EXTERN(cerror)                           ;\
+       BRANCH_EXTERN(tramp_cerror)                     ;\
 2:
 
-#if defined(__SYSCALL_I386_ARG_BYTES) && ((__SYSCALL_I386_ARG_BYTES >= 4) && (__SYSCALL_I386_ARG_BYTES <= 20))
-#define UNIX_SYSCALL_NONAME(name, nargs)                       \
-       movl    $(SYS_##name | (__SYSCALL_I386_ARG_BYTES << I386_SYSCALL_ARG_BYTES_SHIFT)), %eax                ;\
+#if defined(__SYSCALL_32BIT_ARG_BYTES) && ((__SYSCALL_32BIT_ARG_BYTES >= 4) && (__SYSCALL_32BIT_ARG_BYTES <= 20))
+#define UNIX_SYSCALL_NONAME(name, nargs, cerror)                       \
+       movl    $(SYS_##name | (__SYSCALL_32BIT_ARG_BYTES << I386_SYSCALL_ARG_BYTES_SHIFT)), %eax               ;\
        UNIX_SYSCALL_SYSENTER                                   ;\
        jnb     2f                                              ;\
-       BRANCH_EXTERN(cerror)                                   ;\
+       BRANCH_EXTERN(tramp_##cerror)                           ;\
 2:
-#else /* __SYSCALL_I386_ARG_BYTES < 4 || > 20 */
-#define UNIX_SYSCALL_NONAME(name, nargs)               \
-       .globl  cerror                                  ;\
+#else /* __SYSCALL_32BIT_ARG_BYTES < 4 || > 20 */
+#define UNIX_SYSCALL_NONAME(name, nargs, cerror)       \
        movl    $ SYS_##name, %eax                      ;\
        UNIX_SYSCALL_SYSENTER                           ;\
        jnb     2f                                      ;\
-       BRANCH_EXTERN(cerror)                           ;\
+       BRANCH_EXTERN(tramp_##cerror)                   ;\
 2:
 #endif
 
 #define UNIX_SYSCALL_INT_NONAME(name, nargs)           \
-       .globl  cerror                                  ;\
+       .globl  tramp_cerror_nocancel                   ;\
        movl    $ SYS_##name, %eax                      ;\
        UNIX_SYSCALL_TRAP                               ;\
        jnb     2f                                      ;\
-       BRANCH_EXTERN(cerror)                           ;\
+       BRANCH_EXTERN(tramp_cerror_nocancel)            ;\
 2:
 
-#define PSEUDO(pseudo, name, nargs)                    \
-LEAF(_##pseudo, 0)                                     ;\
-       UNIX_SYSCALL_NONAME(name, nargs)
+#define PSEUDO(pseudo, name, nargs, cerror)    \
+LEAF(pseudo, 0)                                        ;\
+       UNIX_SYSCALL_NONAME(name, nargs, cerror)
 
-#define PSEUDO_INT(pseudo, name, nargs)                        \
-LEAF(_##pseudo, 0)                                     ;\
+#define PSEUDO_INT(pseudo, name, nargs)                \
+LEAF(pseudo, 0)                                        ;\
        UNIX_SYSCALL_INT_NONAME(name, nargs)
 
+#define __SYSCALL2(pseudo, name, nargs, cerror)                        \
+       PSEUDO(pseudo, name, nargs, cerror)                     ;\
+       ret
+
 #define __SYSCALL(pseudo, name, nargs)                 \
-       PSEUDO(pseudo, name, nargs)                     ;\
+       PSEUDO(pseudo, name, nargs, cerror)             ;\
        ret
 
 #define __SYSCALL_INT(pseudo, name, nargs)             \
@@ -188,34 +131,41 @@ LEAF(_##pseudo, 0)                                        ;\
        movq    %rcx, %r10              ;\
        syscall
 
-#define UNIX_SYSCALL(name, nargs)                      \
-       .globl  cerror                                  ;\
-LEAF(_##name, 0)                                       ;\
-       movl    $ SYSCALL_CONSTRUCT_UNIX(SYS_##name), %eax      ;\
-       UNIX_SYSCALL_SYSCALL                            ;\
-       jnb     2f                                      ;\
-       BRANCH_EXTERN(cerror)                           ;\
+#define UNIX_SYSCALL(name, nargs)                                               \
+       .globl  cerror                                                          ;\
+LEAF(_##name, 0)                                                               ;\
+       movl    $ SYSCALL_CONSTRUCT_UNIX(SYS_##name), %eax                      ;\
+       UNIX_SYSCALL_SYSCALL                                                    ;\
+       jnb             2f                                                      ;\
+       movq    %rax, %rdi                                                      ;\
+       BRANCH_EXTERN(_cerror)                                                  ;\
 2:
 
-#define UNIX_SYSCALL_NONAME(name, nargs)               \
-       .globl  cerror                                  ;\
-       movl    $ SYSCALL_CONSTRUCT_UNIX(SYS_##name), %eax      ;\
-       UNIX_SYSCALL_SYSCALL                            ;\
-       jnb     2f                                      ;\
-       BRANCH_EXTERN(cerror)                           ;\
+#define UNIX_SYSCALL_NONAME(name, nargs, cerror)                \
+       .globl  cerror                                                          ;\
+       movl    $ SYSCALL_CONSTRUCT_UNIX(SYS_##name), %eax                      ;\
+       UNIX_SYSCALL_SYSCALL                                                    ;\
+       jnb             2f                                                      ;\
+       movq    %rax, %rdi                                                      ;\
+       BRANCH_EXTERN(_##cerror)                                                ;\
 2:
 
-#define PSEUDO(pseudo, name, nargs)                    \
-LEAF(_##pseudo, 0)                                     ;\
-       UNIX_SYSCALL_NONAME(name, nargs)
+#define PSEUDO(pseudo, name, nargs, cerror)                    \
+LEAF(pseudo, 0)                                        ;\
+       UNIX_SYSCALL_NONAME(name, nargs, cerror)
+
+#define __SYSCALL2(pseudo, name, nargs, cerror) \
+       PSEUDO(pseudo, name, nargs, cerror)                     ;\
+       ret
 
 #define __SYSCALL(pseudo, name, nargs)                 \
-       PSEUDO(pseudo, name, nargs)                     ;\
+       PSEUDO(pseudo, name, nargs, cerror)                     ;\
        ret
 
 #elif defined(__arm__)
 
-#define SWI_SYSCALL 0x80       // from <mach/vm_param.h>
+#include <architecture/arm/asm_help.h>
+#include <mach/arm/syscall_sw.h>
 
 /*
  * ARM system call interface:
@@ -270,8 +220,7 @@ LEAF(_##pseudo, 0)                                  ;\
 #define MI_CALL_EXTERNAL(var)    \
        .globl  var                             ;\
        MI_GET_ADDRESS(ip,var)  ;\
-       mov     lr, pc          ;\
-       bx      ip
+       blx     ip
 #else
 #define MI_CALL_EXTERNAL(var)                          \
        .globl  var                                                             ;\
@@ -279,9 +228,9 @@ LEAF(_##pseudo, 0)                                  ;\
 #endif
 
 #define MI_ENTRY_POINT(name)                           \
+       .text                                                                   ;\
        .align 2        ;\
        .globl  name                                                    ;\
-       .text                                                                   ;\
 name:
 
 /* load the syscall number into r12 and trap */
@@ -297,14 +246,14 @@ name:
        swi             #SWI_SYSCALL
 
 /* simple syscalls (0 to 4 args) */
-#define        SYSCALL_0to4(name)                                      \
+#define        SYSCALL_0to4(name, cerror)                      \
        MI_ENTRY_POINT(_##name)                                 ;\
        DO_SYSCALL(SYS_##name)                                  ;\
        bxcc    lr                                                              /* return if carry is clear (no error) */ ; \
-1:     MI_BRANCH_EXTERNAL(cerror)
+1:     MI_BRANCH_EXTERNAL(_##cerror)
 
 /* syscalls with 5 args is different, because of the single arg register load */
-#define        SYSCALL_5(name)                                         \
+#define        SYSCALL_5(name, cerror)                         \
        MI_ENTRY_POINT(_##name)                                 ;\
        mov             ip, sp                                                  /* save a pointer to the args */ ; \
        stmfd   sp!, { r4-r5 }                                  /* save r4-r5 */ ;\
@@ -312,10 +261,10 @@ name:
        DO_SYSCALL(SYS_##name)                                  ;\
        ldmfd   sp!, { r4-r5 }                                  /* restore r4-r5 */ ; \
        bxcc    lr                                                              /* return if carry is clear (no error) */ ; \
-1:     MI_BRANCH_EXTERNAL(cerror)
+1:     MI_BRANCH_EXTERNAL(_##cerror)
 
-/* syscalls with 6 to 8 args */
-#define SYSCALL_6to8(name, save_regs, arg_regs) \
+/* syscalls with 6 to 12 args. kernel may have to read from stack */
+#define SYSCALL_6to12(name, save_regs, arg_regs, cerror) \
        MI_ENTRY_POINT(_##name)                                 ;\
        mov             ip, sp                                                  /* save a pointer to the args */ ; \
        stmfd   sp!, { save_regs }                              /* callee saved regs */ ;\
@@ -323,73 +272,221 @@ name:
        DO_SYSCALL(SYS_##name)                                  ;\
        ldmfd   sp!, { save_regs }                              /* restore callee saved regs */ ; \
        bxcc    lr                                                              /* return if carry is clear (no error) */ ; \
-1:     MI_BRANCH_EXTERNAL(cerror)
+1:     MI_BRANCH_EXTERNAL(_##cerror)
 
 #define COMMA ,
 
+#if __BIGGEST_ALIGNMENT__ > 4
+
+/* For the armv7k ABI, the alignment requirements may add padding. So we
+ * let the kernel figure it out and push extra on the stack to avoid un-needed
+ * copy-ins */
+
+ /* We'll also use r8 for moving arguments */
+
+#define SYSCALL_0(name)                                                SYSCALL_0to4(name)
+#define SYSCALL_1(name)                                                SYSCALL_0to4(name)
+#define SYSCALL_2(name)                                                SYSCALL_0to4(name)
+#define SYSCALL_3(name)                                                SYSCALL_0to4(name)
+#define SYSCALL_4(name)                                                SYSCALL_6to12(name, r4-r5, r4-r5)
+#undef SYSCALL_5
+#define SYSCALL_5(name)                                                SYSCALL_6to12(name, r4-r5, r4-r5)
+#define SYSCALL_6(name)                                                SYSCALL_6to12(name, r4-r6 COMMA r8, r4-r6 COMMA r8)
+#define SYSCALL_7(name)                                                SYSCALL_6to12(name, r4-r6 COMMA r8, r4-r6 COMMA r8)
+#define SYSCALL_8(name)                                                SYSCALL_6to12(name, r4-r6 COMMA r8, r4-r6 COMMA r8)
+#define SYSCALL_12(name)                                       SYSCALL_6to12(name, r4-r6 COMMA r8, r4-r6 COMMA r8)
+
+#else // !(__BIGGEST_ALIGNMENT__ > 4) (the normal arm32 ABI case)
+
 #define SYSCALL_0(name)                                                SYSCALL_0to4(name)
 #define SYSCALL_1(name)                                                SYSCALL_0to4(name)
 #define SYSCALL_2(name)                                                SYSCALL_0to4(name)
 #define SYSCALL_3(name)                                                SYSCALL_0to4(name)
 #define SYSCALL_4(name)                                                SYSCALL_0to4(name)
 /* SYSCALL_5 declared above */
-#define SYSCALL_6(name)                                                SYSCALL_6to8(name, r4-r5, r4-r5)
-#define SYSCALL_7(name)                                                SYSCALL_6to8(name, r4-r6 COMMA r8, r4-r6)
-#define SYSCALL_8(name)                                                SYSCALL_6to8(name, r4-r6 COMMA r8, r4-r6 COMMA r8)
+#define SYSCALL_6(name)                                                SYSCALL_6to12(name, r4-r5, r4-r5)
+#define SYSCALL_7(name)                                                SYSCALL_6to12(name, r4-r6 COMMA r8, r4-r6)
+#define SYSCALL_8(name)                                                SYSCALL_6to12(name, r4-r6 COMMA r8, r4-r6) /* 8th on stack */
+#define SYSCALL_12(name)                                       SYSCALL_6to12(name, r4-r6 COMMA r8, r4-r6) /* 8th-12th on stack */
+
+#endif // __BIGGEST_ALIGNMENT__ > 4
 
 /* select the appropriate syscall code, based on the number of arguments */
-#define SYSCALL(name, nargs)   SYSCALL_##nargs(name)
+#ifndef __SYSCALL_32BIT_ARG_BYTES
+#define SYSCALL(name, nargs, cerror)           SYSCALL_##nargs(name, cerror)
+#define SYSCALL_NONAME(name, nargs, cerror)    SYSCALL_NONAME_##nargs(name, cerror)
+#else
+#if __SYSCALL_32BIT_ARG_BYTES < 20
+#define SYSCALL(name, nargs, cerror)           SYSCALL_0to4(name, cerror)
+#define SYSCALL_NONAME(name, nargs, cerror)    SYSCALL_NONAME_0to4(name, cerror)
+#elif __SYSCALL_32BIT_ARG_BYTES == 20
+#define SYSCALL(name, nargs, cerror)           SYSCALL_5(name, cerror)
+#define SYSCALL_NONAME(name, nargs, cerror)    SYSCALL_NONAME_5(name, cerror)
+#elif __SYSCALL_32BIT_ARG_BYTES == 24
+#define SYSCALL(name, nargs, cerror)           SYSCALL_6(name, cerror)
+#define SYSCALL_NONAME(name, nargs, cerror)    SYSCALL_NONAME_6(name, cerror)
+#elif __SYSCALL_32BIT_ARG_BYTES == 28 
+#define SYSCALL(name, nargs, cerror)           SYSCALL_7(name, cerror)
+#define SYSCALL_NONAME(name, nargs, cerror)    SYSCALL_NONAME_7(name, cerror)
+#elif __SYSCALL_32BIT_ARG_BYTES == 32 
+#define SYSCALL(name, nargs, cerror)           SYSCALL_8(name, cerror)
+#define SYSCALL_NONAME(name, nargs, cerror)    SYSCALL_NONAME_8(name, cerror)
+#elif __SYSCALL_32BIT_ARG_BYTES == 36 
+#define SYSCALL(name, nargs, cerror)           SYSCALL_8(name, cerror)
+#define SYSCALL_NONAME(name, nargs, cerror)    SYSCALL_NONAME_8(name, cerror)
+#elif __SYSCALL_32BIT_ARG_BYTES == 44 
+#define SYSCALL(name, nargs, cerror)           SYSCALL_8(name, cerror)
+#define SYSCALL_NONAME(name, nargs, cerror)    SYSCALL_NONAME_8(name, cerror)
+#elif __SYSCALL_32BIT_ARG_BYTES == 48 
+#define SYSCALL(name, nargs, cerror)           SYSCALL_12(name, cerror)
+#define SYSCALL_NONAME(name, nargs, cerror)    SYSCALL_NONAME_12(name, cerror)
+#endif
+#endif
 
-#define        SYSCALL_NONAME_0to4(name)                       \
+#define        SYSCALL_NONAME_0to4(name, cerror)       \
        DO_SYSCALL(SYS_##name)                                  ;\
        bcc             1f                                                              /* branch if carry bit is clear (no error) */ ; \
-       MI_BRANCH_EXTERNAL(cerror)                              /* call cerror */ ; \
+       MI_BRANCH_EXTERNAL(_##cerror)                   /* call cerror */ ; \
 1:
 
-#define        SYSCALL_NONAME_5(name)                          \
+#define        SYSCALL_NONAME_5(name, cerror)          \
        mov             ip, sp                                                  /* save a pointer to the args */ ; \
        stmfd   sp!, { r4-r5 }                                  /* save r4-r5 */ ;\
        ldr             r4, [ip]                                                /* load 5th arg */ ; \
        DO_SYSCALL(SYS_##name)                                  ;\
        ldmfd   sp!, { r4-r5 }                                  /* restore r4-r7 */ ; \
        bcc             1f                                                              /* branch if carry bit is clear (no error) */ ; \
-       MI_BRANCH_EXTERNAL(cerror)                              /* call cerror */ ; \
+       MI_BRANCH_EXTERNAL(_##cerror)                   /* call cerror */ ; \
 1:
 
-#define        SYSCALL_NONAME_6to8(name, save_regs, arg_regs)  \
+#define        SYSCALL_NONAME_6to12(name, save_regs, arg_regs, cerror) \
        mov             ip, sp                                                  /* save a pointer to the args */ ; \
        stmfd   sp!, { save_regs }                              /* callee save regs */ ;\
        ldmia   ip, { arg_regs }                                /* load arguments */ ; \
        DO_SYSCALL(SYS_##name)                                  ;\
        ldmfd   sp!, { save_regs }                              /* restore callee saved regs */ ; \
        bcc             1f                                                              /* branch if carry bit is clear (no error) */ ; \
-       MI_BRANCH_EXTERNAL(cerror)                              /* call cerror */ ; \
+       MI_BRANCH_EXTERNAL(_##cerror)                   /* call cerror */ ; \
 1:
 
-#define SYSCALL_NONAME_0(name)                         SYSCALL_NONAME_0to4(name)
-#define SYSCALL_NONAME_1(name)                         SYSCALL_NONAME_0to4(name)
-#define SYSCALL_NONAME_2(name)                         SYSCALL_NONAME_0to4(name)
-#define SYSCALL_NONAME_3(name)                         SYSCALL_NONAME_0to4(name)
-#define SYSCALL_NONAME_4(name)                         SYSCALL_NONAME_0to4(name)
+
+#if __BIGGEST_ALIGNMENT__ > 4
+
+/* For the armv7k ABI, the alignment requirements may add padding. So we
+ * let the kernel figure it out and push extra on the stack to avoid un-needed
+ * copy-ins. We are relying on arguments that aren't in registers starting
+ * 32 bytes from sp. We also use r8 like in the mach case. */
+
+#define SYSCALL_NONAME_0(name, cerror)                         SYSCALL_NONAME_0to4(name, cerror)
+#define SYSCALL_NONAME_1(name, cerror)                         SYSCALL_NONAME_0to4(name, cerror)
+#define SYSCALL_NONAME_2(name, cerror)                         SYSCALL_NONAME_0to4(name, cerror)
+#define SYSCALL_NONAME_3(name, cerror)                         SYSCALL_NONAME_0to4(name, cerror)
+#define SYSCALL_NONAME_4(name, cerror)                         SYSCALL_NONAME_6to12(name, r4-r5, r4-r5, cerror)
+#undef SYSCALL_NONAME_5
+#define SYSCALL_NONAME_5(name, cerror)                         SYSCALL_NONAME_6to12(name, r4-r5, r4-r5, cerror)
+#define SYSCALL_NONAME_6(name, cerror)                         SYSCALL_NONAME_6to12(name, r4-r6 COMMA r8, r4-r6 COMMA r8, cerror)
+#define SYSCALL_NONAME_7(name, cerror)                         SYSCALL_NONAME_6to12(name, r4-r6 COMMA r8, r4-r6 COMMA r8, cerror)
+#define SYSCALL_NONAME_8(name, cerror)                         SYSCALL_NONAME_6to12(name, r4-r6 COMMA r8, r4-r6 COMMA r8, cerror)
+#define SYSCALL_NONAME_12(name, cerror)                                SYSCALL_NONAME_6to12(name, r4-r6 COMMA r8, r4-r6 COMMA r8, cerror)
+
+#else // !(__BIGGEST_ALIGNMENT__ > 4) (the normal arm32 ABI case)
+
+#define SYSCALL_NONAME_0(name, cerror)                         SYSCALL_NONAME_0to4(name, cerror)
+#define SYSCALL_NONAME_1(name, cerror)                         SYSCALL_NONAME_0to4(name, cerror)
+#define SYSCALL_NONAME_2(name, cerror)                         SYSCALL_NONAME_0to4(name, cerror)
+#define SYSCALL_NONAME_3(name, cerror)                         SYSCALL_NONAME_0to4(name, cerror)
+#define SYSCALL_NONAME_4(name, cerror)                         SYSCALL_NONAME_0to4(name, cerror)
 /* SYSCALL_NONAME_5 declared above */
-#define SYSCALL_NONAME_6(name)                         SYSCALL_NONAME_6to8(name, r4-r5, r4-r5)
-#define SYSCALL_NONAME_7(name)                         SYSCALL_NONAME_6to8(name, r4-r6 COMMA r8, r4-r6)
-#define SYSCALL_NONAME_8(name)                         SYSCALL_NONAME_6to8(name, r4-r6 COMMA r8, r4-r6 COMMA r8)
+#define SYSCALL_NONAME_6(name, cerror)                         SYSCALL_NONAME_6to12(name, r4-r5, r4-r5, cerror)
+#define SYSCALL_NONAME_7(name, cerror)                         SYSCALL_NONAME_6to12(name, r4-r6 COMMA r8, r4-r6, cerror)
+#define SYSCALL_NONAME_8(name, cerror)                         SYSCALL_NONAME_6to12(name, r4-r6 COMMA r8, r4-r6, cerror)
+#define SYSCALL_NONAME_12(name, cerror)                                SYSCALL_NONAME_6to12(name, r4-r6 COMMA r8, r4-r6, cerror)
 
-/* select the appropriate syscall code, based on the number of arguments */
-#define SYSCALL_NONAME(name, nargs)    SYSCALL_NONAME_##nargs(name)
+#endif // __BIGGEST_ALIGNMENT__ > 4
 
-#define        PSEUDO(pseudo, name, nargs)                     \
-       .globl  _##pseudo                                               ;\
+#define        PSEUDO(pseudo, name, nargs, cerror)                     \
+       .globl pseudo                                           ;\
        .text                                                                   ;\
        .align  2                                                               ;\
-_##pseudo:                                                                     ;\
-       SYSCALL_NONAME(name, nargs)
+pseudo:                                                                        ;\
+       SYSCALL_NONAME(name, nargs, cerror)
 
-#define __SYSCALL(pseudo, name, nargs)         \
-       PSEUDO(pseudo, name, nargs)                             ;\
+#define __SYSCALL2(pseudo, name, nargs, cerror)                \
+       PSEUDO(pseudo, name, nargs, cerror)                             ;\
+       bx lr
+
+#define __SYSCALL(pseudo, name, nargs)                         \
+       PSEUDO(pseudo, name, nargs, cerror)                             ;\
        bx lr
 
+#elif defined(__arm64__)
+
+#include <mach/arm/syscall_sw.h>
+#include <mach/arm/vm_param.h>
+#include <mach/arm64/asm.h>
+
+#if defined(__arm64__) && !defined(__LP64__)
+#define ZERO_EXTEND(argnum) uxtw  x ## argnum, w ## argnum
+#else
+#define ZERO_EXTEND(argnum)
+#endif
+
+#if defined(__arm64__) && !defined(__LP64__)
+#define SIGN_EXTEND(argnum) sxtw  x ## argnum, w ## argnum
+#else
+#define SIGN_EXTEND(argnum)
+#endif
+
+/*
+ * ARM64 system call interface:
+ *
+ * TBD
+ */
+
+#define DO_SYSCALL(num, cerror)        \
+   mov   x16, #(num)    %%\
+   svc   #SWI_SYSCALL  %%\
+   b.cc  2f             %%\
+   PUSH_FRAME                  %%\
+   bl    _##cerror             %%\
+   POP_FRAME                   %%\
+   ret                                 %%\
+2:                     
+
+#define MI_GET_ADDRESS(reg,var)  \
+   adrp        reg, var@page      %%\
+   add  reg, reg, var@pageoff   %%
+
+#define MI_CALL_EXTERNAL(sym)  \
+   .globl sym                %% \
+   bl sym                      
+
+#define        SYSCALL_NONAME(name, nargs, cerror)                                             \
+  DO_SYSCALL(SYS_##name, cerror)                                       %%      \
+1:
+
+#define MI_ENTRY_POINT(name)                           \
+  .text                                        %% \
+  .align 2                 %% \
+  .globl  name                 %%      \
+name:
+
+#define        PSEUDO(pseudo, name, nargs, cerror)                     \
+  .text                                                                        %% \
+  .align  2                                                            %% \
+  .globl pseudo                                                %%              \
+  pseudo:                                                                      %% \
+       SYSCALL_NONAME(name, nargs, cerror)
+
+#define __SYSCALL(pseudo, name, nargs)         \
+  PSEUDO(pseudo, name, nargs, cerror)          %%      \
+  ret
+
+#define __SYSCALL2(pseudo, name, nargs, cerror)                \
+  PSEUDO(pseudo, name, nargs, cerror)          %% \
+  ret
+
 #else
 #error Unsupported architecture
 #endif
+