]>
Commit | Line | Data |
---|---|---|
2d21ac55 | 1 | /* |
316670eb | 2 | * Copyright (c) 1999-2011 Apple Inc. All rights reserved. |
2d21ac55 A |
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 | ||
6d2010ae | 51 | #if defined(__i386__) |
2d21ac55 A |
52 | |
53 | #include <architecture/i386/asm_help.h> | |
54 | #include <mach/i386/syscall_sw.h> | |
55 | ||
56 | /* | |
57 | * We have two entry points. int's is used for syscalls which need to preserve | |
58 | * %ecx across the call, or return a 64-bit value in %eax:%edx. sysenter is used | |
59 | * for the majority of syscalls which just return a value in %eax. | |
60 | */ | |
61 | ||
62 | #define UNIX_SYSCALL_SYSENTER call __sysenter_trap | |
63 | #define UNIX_SYSCALL(name, nargs) \ | |
39236c6e | 64 | .globl tramp_cerror ;\ |
2d21ac55 A |
65 | LEAF(_##name, 0) ;\ |
66 | movl $ SYS_##name, %eax ;\ | |
67 | UNIX_SYSCALL_SYSENTER ;\ | |
68 | jnb 2f ;\ | |
39236c6e | 69 | BRANCH_EXTERN(tramp_cerror) ;\ |
2d21ac55 A |
70 | 2: |
71 | ||
72 | #define UNIX_SYSCALL_INT(name, nargs) \ | |
39236c6e | 73 | .globl tramp_cerror ;\ |
2d21ac55 A |
74 | LEAF(_##name, 0) ;\ |
75 | movl $ SYS_##name, %eax ;\ | |
76 | UNIX_SYSCALL_TRAP ;\ | |
77 | jnb 2f ;\ | |
39236c6e | 78 | BRANCH_EXTERN(tramp_cerror) ;\ |
2d21ac55 A |
79 | 2: |
80 | ||
4a3eedf9 | 81 | #if defined(__SYSCALL_32BIT_ARG_BYTES) && ((__SYSCALL_32BIT_ARG_BYTES >= 4) && (__SYSCALL_32BIT_ARG_BYTES <= 20)) |
316670eb | 82 | #define UNIX_SYSCALL_NONAME(name, nargs, cerror) \ |
4a3eedf9 | 83 | movl $(SYS_##name | (__SYSCALL_32BIT_ARG_BYTES << I386_SYSCALL_ARG_BYTES_SHIFT)), %eax ;\ |
2d21ac55 A |
84 | UNIX_SYSCALL_SYSENTER ;\ |
85 | jnb 2f ;\ | |
39236c6e | 86 | BRANCH_EXTERN(tramp_##cerror) ;\ |
2d21ac55 | 87 | 2: |
4a3eedf9 | 88 | #else /* __SYSCALL_32BIT_ARG_BYTES < 4 || > 20 */ |
39236c6e | 89 | #define UNIX_SYSCALL_NONAME(name, nargs, cerror) \ |
2d21ac55 A |
90 | movl $ SYS_##name, %eax ;\ |
91 | UNIX_SYSCALL_SYSENTER ;\ | |
92 | jnb 2f ;\ | |
39236c6e | 93 | BRANCH_EXTERN(tramp_##cerror) ;\ |
2d21ac55 A |
94 | 2: |
95 | #endif | |
96 | ||
97 | #define UNIX_SYSCALL_INT_NONAME(name, nargs) \ | |
39236c6e | 98 | .globl tramp_cerror_nocancel ;\ |
2d21ac55 A |
99 | movl $ SYS_##name, %eax ;\ |
100 | UNIX_SYSCALL_TRAP ;\ | |
101 | jnb 2f ;\ | |
39236c6e | 102 | BRANCH_EXTERN(tramp_cerror_nocancel) ;\ |
2d21ac55 A |
103 | 2: |
104 | ||
39236c6e | 105 | #define PSEUDO(pseudo, name, nargs, cerror) \ |
6d2010ae | 106 | LEAF(pseudo, 0) ;\ |
316670eb | 107 | UNIX_SYSCALL_NONAME(name, nargs, cerror) |
2d21ac55 | 108 | |
39236c6e | 109 | #define PSEUDO_INT(pseudo, name, nargs) \ |
6d2010ae | 110 | LEAF(pseudo, 0) ;\ |
2d21ac55 A |
111 | UNIX_SYSCALL_INT_NONAME(name, nargs) |
112 | ||
316670eb A |
113 | #define __SYSCALL2(pseudo, name, nargs, cerror) \ |
114 | PSEUDO(pseudo, name, nargs, cerror) ;\ | |
115 | ret | |
116 | ||
2d21ac55 | 117 | #define __SYSCALL(pseudo, name, nargs) \ |
39236c6e | 118 | PSEUDO(pseudo, name, nargs, cerror) ;\ |
2d21ac55 A |
119 | ret |
120 | ||
121 | #define __SYSCALL_INT(pseudo, name, nargs) \ | |
122 | PSEUDO_INT(pseudo, name, nargs) ;\ | |
123 | ret | |
124 | ||
125 | #elif defined(__x86_64__) | |
126 | ||
127 | #include <architecture/i386/asm_help.h> | |
128 | #include <mach/i386/syscall_sw.h> | |
129 | ||
130 | #define UNIX_SYSCALL_SYSCALL \ | |
131 | movq %rcx, %r10 ;\ | |
132 | syscall | |
133 | ||
39236c6e A |
134 | #define UNIX_SYSCALL(name, nargs) \ |
135 | .globl cerror ;\ | |
136 | LEAF(_##name, 0) ;\ | |
137 | movl $ SYSCALL_CONSTRUCT_UNIX(SYS_##name), %eax ;\ | |
138 | UNIX_SYSCALL_SYSCALL ;\ | |
139 | jnb 2f ;\ | |
140 | movq %rax, %rdi ;\ | |
141 | BRANCH_EXTERN(_cerror) ;\ | |
2d21ac55 A |
142 | 2: |
143 | ||
39236c6e A |
144 | #define UNIX_SYSCALL_NONAME(name, nargs, cerror) \ |
145 | .globl cerror ;\ | |
146 | movl $ SYSCALL_CONSTRUCT_UNIX(SYS_##name), %eax ;\ | |
147 | UNIX_SYSCALL_SYSCALL ;\ | |
148 | jnb 2f ;\ | |
149 | movq %rax, %rdi ;\ | |
150 | BRANCH_EXTERN(_##cerror) ;\ | |
2d21ac55 A |
151 | 2: |
152 | ||
316670eb | 153 | #define PSEUDO(pseudo, name, nargs, cerror) \ |
6d2010ae | 154 | LEAF(pseudo, 0) ;\ |
316670eb A |
155 | UNIX_SYSCALL_NONAME(name, nargs, cerror) |
156 | ||
157 | #define __SYSCALL2(pseudo, name, nargs, cerror) \ | |
158 | PSEUDO(pseudo, name, nargs, cerror) ;\ | |
159 | ret | |
2d21ac55 A |
160 | |
161 | #define __SYSCALL(pseudo, name, nargs) \ | |
316670eb | 162 | PSEUDO(pseudo, name, nargs, cerror) ;\ |
2d21ac55 A |
163 | ret |
164 | ||
2d21ac55 A |
165 | #else |
166 | #error Unsupported architecture | |
167 | #endif | |
316670eb | 168 |