]> git.saurik.com Git - apple/xnu.git/blob - libsyscall/custom/SYS.h
xnu-1504.9.26.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(__ppc__) || defined(__ppc64__)
59
60 #include <architecture/ppc/mode_independent_asm.h>
61
62 /*
63 * Macros.
64 */
65
66 #define SYSCALL(name, nargs) \
67 .globl cerror @\
68 MI_ENTRY_POINT(_##name) @\
69 li r0,SYS_##name @\
70 sc @\
71 b 1f @\
72 blr @\
73 1: MI_BRANCH_EXTERNAL(cerror)
74
75
76 #define SYSCALL_NONAME(name, nargs) \
77 .globl cerror @\
78 li r0,SYS_##name @\
79 sc @\
80 b 1f @\
81 b 2f @\
82 1: MI_BRANCH_EXTERNAL(cerror) @\
83 2:
84
85
86 #define PSEUDO(pseudo, name, nargs) \
87 .private_extern _##pseudo @\
88 .text @\
89 .align 2 @\
90 _##pseudo: @\
91 SYSCALL_NONAME(name, nargs)
92
93 #define __SYSCALL(pseudo, name, nargs) \
94 PSEUDO(pseudo, name, nargs) @\
95 blr
96
97 #elif defined(__i386__)
98
99 #include <architecture/i386/asm_help.h>
100 #include <mach/i386/syscall_sw.h>
101
102 /*
103 * We have two entry points. int's is used for syscalls which need to preserve
104 * %ecx across the call, or return a 64-bit value in %eax:%edx. sysenter is used
105 * for the majority of syscalls which just return a value in %eax.
106 */
107
108 #define UNIX_SYSCALL_SYSENTER call __sysenter_trap
109 #define UNIX_SYSCALL(name, nargs) \
110 .globl cerror ;\
111 LEAF(_##name, 0) ;\
112 movl $ SYS_##name, %eax ;\
113 UNIX_SYSCALL_SYSENTER ;\
114 jnb 2f ;\
115 BRANCH_EXTERN(cerror) ;\
116 2:
117
118 #define UNIX_SYSCALL_INT(name, nargs) \
119 .globl cerror ;\
120 LEAF(_##name, 0) ;\
121 movl $ SYS_##name, %eax ;\
122 UNIX_SYSCALL_TRAP ;\
123 jnb 2f ;\
124 BRANCH_EXTERN(cerror) ;\
125 2:
126
127 #if defined(__SYSCALL_32BIT_ARG_BYTES) && ((__SYSCALL_32BIT_ARG_BYTES >= 4) && (__SYSCALL_32BIT_ARG_BYTES <= 20))
128 #define UNIX_SYSCALL_NONAME(name, nargs) \
129 movl $(SYS_##name | (__SYSCALL_32BIT_ARG_BYTES << I386_SYSCALL_ARG_BYTES_SHIFT)), %eax ;\
130 UNIX_SYSCALL_SYSENTER ;\
131 jnb 2f ;\
132 BRANCH_EXTERN(cerror) ;\
133 2:
134 #else /* __SYSCALL_32BIT_ARG_BYTES < 4 || > 20 */
135 #define UNIX_SYSCALL_NONAME(name, nargs) \
136 .globl cerror ;\
137 movl $ SYS_##name, %eax ;\
138 UNIX_SYSCALL_SYSENTER ;\
139 jnb 2f ;\
140 BRANCH_EXTERN(cerror) ;\
141 2:
142 #endif
143
144 #define UNIX_SYSCALL_INT_NONAME(name, nargs) \
145 .globl cerror ;\
146 movl $ SYS_##name, %eax ;\
147 UNIX_SYSCALL_TRAP ;\
148 jnb 2f ;\
149 BRANCH_EXTERN(cerror) ;\
150 2:
151
152 #define PSEUDO(pseudo, name, nargs) \
153 LEAF(_##pseudo, 0) ;\
154 UNIX_SYSCALL_NONAME(name, nargs)
155
156 #define PSEUDO_INT(pseudo, name, nargs) \
157 LEAF(_##pseudo, 0) ;\
158 UNIX_SYSCALL_INT_NONAME(name, nargs)
159
160 #define __SYSCALL(pseudo, name, nargs) \
161 PSEUDO(pseudo, name, nargs) ;\
162 ret
163
164 #define __SYSCALL_INT(pseudo, name, nargs) \
165 PSEUDO_INT(pseudo, name, nargs) ;\
166 ret
167
168 #elif defined(__x86_64__)
169
170 #include <architecture/i386/asm_help.h>
171 #include <mach/i386/syscall_sw.h>
172
173 #define UNIX_SYSCALL_SYSCALL \
174 movq %rcx, %r10 ;\
175 syscall
176
177 #define UNIX_SYSCALL(name, nargs) \
178 .globl cerror ;\
179 LEAF(_##name, 0) ;\
180 movl $ SYSCALL_CONSTRUCT_UNIX(SYS_##name), %eax ;\
181 UNIX_SYSCALL_SYSCALL ;\
182 jnb 2f ;\
183 BRANCH_EXTERN(cerror) ;\
184 2:
185
186 #define UNIX_SYSCALL_NONAME(name, nargs) \
187 .globl cerror ;\
188 movl $ SYSCALL_CONSTRUCT_UNIX(SYS_##name), %eax ;\
189 UNIX_SYSCALL_SYSCALL ;\
190 jnb 2f ;\
191 BRANCH_EXTERN(cerror) ;\
192 2:
193
194 #define PSEUDO(pseudo, name, nargs) \
195 LEAF(_##pseudo, 0) ;\
196 UNIX_SYSCALL_NONAME(name, nargs)
197
198 #define __SYSCALL(pseudo, name, nargs) \
199 PSEUDO(pseudo, name, nargs) ;\
200 ret
201
202 #else
203 #error Unsupported architecture
204 #endif