]> git.saurik.com Git - apple/xnu.git/blob - libsyscall/custom/SYS.h
xnu-1699.32.7.tar.gz
[apple/xnu.git] / libsyscall / custom / SYS.h
1 /*
2 * Copyright (c) 1999-2007 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved.
29 *
30 * File: SYS.h
31 *
32 * Definition of the user side of the UNIX system call interface
33 * for M98K.
34 *
35 * Errors are flagged by the location of the trap return (ie., which
36 * instruction is executed upon rfi):
37 *
38 * SC PC + 4: Error (typically branch to cerror())
39 * SC PC + 8: Success
40 *
41 * HISTORY
42 * 18-Nov-92 Ben Fathi (benf@next.com)
43 * Ported to m98k.
44 *
45 * 9-Jan-92 Peter King (king@next.com)
46 * Created.
47 */
48
49 #include <sys/syscall.h>
50
51 #ifndef SYS_setquota
52 #define SYS_setquota 148
53 #endif
54 #ifndef SYS_quota
55 #define SYS_quota 149
56 #endif
57
58 #if defined(__i386__)
59
60 #include <architecture/i386/asm_help.h>
61 #include <mach/i386/syscall_sw.h>
62
63 /*
64 * We have two entry points. int's is used for syscalls which need to preserve
65 * %ecx across the call, or return a 64-bit value in %eax:%edx. sysenter is used
66 * for the majority of syscalls which just return a value in %eax.
67 */
68
69 #define UNIX_SYSCALL_SYSENTER call __sysenter_trap
70 #define UNIX_SYSCALL(name, nargs) \
71 .globl cerror ;\
72 LEAF(_##name, 0) ;\
73 movl $ SYS_##name, %eax ;\
74 UNIX_SYSCALL_SYSENTER ;\
75 jnb 2f ;\
76 BRANCH_EXTERN(cerror) ;\
77 2:
78
79 #define UNIX_SYSCALL_INT(name, nargs) \
80 .globl cerror ;\
81 LEAF(_##name, 0) ;\
82 movl $ SYS_##name, %eax ;\
83 UNIX_SYSCALL_TRAP ;\
84 jnb 2f ;\
85 BRANCH_EXTERN(cerror) ;\
86 2:
87
88 #if defined(__SYSCALL_32BIT_ARG_BYTES) && ((__SYSCALL_32BIT_ARG_BYTES >= 4) && (__SYSCALL_32BIT_ARG_BYTES <= 20))
89 #define UNIX_SYSCALL_NONAME(name, nargs) \
90 movl $(SYS_##name | (__SYSCALL_32BIT_ARG_BYTES << I386_SYSCALL_ARG_BYTES_SHIFT)), %eax ;\
91 UNIX_SYSCALL_SYSENTER ;\
92 jnb 2f ;\
93 BRANCH_EXTERN(cerror) ;\
94 2:
95 #else /* __SYSCALL_32BIT_ARG_BYTES < 4 || > 20 */
96 #define UNIX_SYSCALL_NONAME(name, nargs) \
97 .globl cerror ;\
98 movl $ SYS_##name, %eax ;\
99 UNIX_SYSCALL_SYSENTER ;\
100 jnb 2f ;\
101 BRANCH_EXTERN(cerror) ;\
102 2:
103 #endif
104
105 #define UNIX_SYSCALL_INT_NONAME(name, nargs) \
106 .globl cerror ;\
107 movl $ SYS_##name, %eax ;\
108 UNIX_SYSCALL_TRAP ;\
109 jnb 2f ;\
110 BRANCH_EXTERN(cerror) ;\
111 2:
112
113 #define PSEUDO(pseudo, name, nargs) \
114 LEAF(pseudo, 0) ;\
115 UNIX_SYSCALL_NONAME(name, nargs)
116
117 #define PSEUDO_INT(pseudo, name, nargs) \
118 LEAF(pseudo, 0) ;\
119 UNIX_SYSCALL_INT_NONAME(name, nargs)
120
121 #define __SYSCALL(pseudo, name, nargs) \
122 PSEUDO(pseudo, name, nargs) ;\
123 ret
124
125 #define __SYSCALL_INT(pseudo, name, nargs) \
126 PSEUDO_INT(pseudo, name, nargs) ;\
127 ret
128
129 #elif defined(__x86_64__)
130
131 #include <architecture/i386/asm_help.h>
132 #include <mach/i386/syscall_sw.h>
133
134 #define UNIX_SYSCALL_SYSCALL \
135 movq %rcx, %r10 ;\
136 syscall
137
138 #define UNIX_SYSCALL(name, nargs) \
139 .globl cerror ;\
140 LEAF(_##name, 0) ;\
141 movl $ SYSCALL_CONSTRUCT_UNIX(SYS_##name), %eax ;\
142 UNIX_SYSCALL_SYSCALL ;\
143 jnb 2f ;\
144 BRANCH_EXTERN(cerror) ;\
145 2:
146
147 #define UNIX_SYSCALL_NONAME(name, nargs) \
148 .globl cerror ;\
149 movl $ SYSCALL_CONSTRUCT_UNIX(SYS_##name), %eax ;\
150 UNIX_SYSCALL_SYSCALL ;\
151 jnb 2f ;\
152 BRANCH_EXTERN(cerror) ;\
153 2:
154
155 #define PSEUDO(pseudo, name, nargs) \
156 LEAF(pseudo, 0) ;\
157 UNIX_SYSCALL_NONAME(name, nargs)
158
159 #define __SYSCALL(pseudo, name, nargs) \
160 PSEUDO(pseudo, name, nargs) ;\
161 ret
162
163 #else
164 #error Unsupported architecture
165 #endif