]> git.saurik.com Git - apple/xnu.git/blob - osfmk/mach/i386/syscall_sw.h
ac8999730fc84ae2768fe56f5f3e732f9508e37a
[apple/xnu.git] / osfmk / mach / i386 / syscall_sw.h
1 /*
2 * Copyright (c) 2000-2004 Apple Computer, 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 /*
29 * @OSF_COPYRIGHT@
30 */
31 /*
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University
34 * All Rights Reserved.
35 *
36 * Permission to use, copy, modify and distribute this software and its
37 * documentation is hereby granted, provided that both the copyright
38 * notice and this permission notice appear in all copies of the
39 * software, derivative works or modified versions, and any portions
40 * thereof, and that both notices appear in supporting documentation.
41 *
42 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
45 *
46 * Carnegie Mellon requests users of this software to return to
47 *
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
52 *
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
55 */
56 /*
57 */
58
59 #ifdef PRIVATE
60
61 #ifndef _MACH_I386_SYSCALL_SW_H_
62 #define _MACH_I386_SYSCALL_SW_H_
63
64 #include <architecture/i386/asm_help.h>
65
66 #if defined(__i386__)
67 /*
68 * Software interrupt codes for 32-bit system call entry:
69 */
70 #define UNIX_INT 0x80
71 #define MACH_INT 0x81
72 #define MACHDEP_INT 0x82
73 #define DIAG_INT 0x83
74
75 #ifndef KERNEL
76 /*
77 * Syscall entry macros for use in libc:
78 * [Note that the nop padding is temporary during 4/4 transition.]
79 */
80 #define SYSENTER_PAD nop;nop;
81 #define SYSCALL_PAD nop;nop;nop;nop;nop;
82 #define UNIX_SYSCALL_TRAP \
83 SYSCALL_PAD \
84 int $(UNIX_INT)
85 #define MACHDEP_SYSCALL_TRAP \
86 SYSCALL_PAD \
87 int $(MACHDEP_INT)
88
89 /*
90 * Macro to generate Mach call stubs in libc:
91 */
92 #define kernel_trap(trap_name,trap_number,number_args) \
93 LEAF(_##trap_name,0) ;\
94 movl $##trap_number,%eax ;\
95 int $(MACH_INT) ;\
96 END(_##trap_name)
97
98 #endif
99 #endif /* defined(__i386__) */
100
101 #if defined(__x86_64__)
102
103 #ifndef KERNEL
104
105 #define UNIX_SYSCALL_TRAP \
106 syscall
107 #define MACHDEP_SYSCALL_TRAP \
108 syscall
109
110 /*
111 * Macro to generate Mach call stubs in Libc.
112 * Existing calls use negative numbers for Mach traps, so
113 * until we change those and change the 32-bit kernel_trap
114 * macro above, we negate those numbers here for the 64-bit
115 * code path.
116 */
117 #define kernel_trap(trap_name,trap_number,number_args) \
118 LEAF(_##trap_name,0) ;\
119 movq %rcx, %r10 ;\
120 movl $ SYSCALL_CONSTRUCT_MACH(-##trap_number), %eax ;\
121 syscall ;\
122 END(_##trap_name)
123
124 #endif
125 #endif /* defined(__x86_64__) */
126
127 /*
128 * Syscall classes for 64-bit system call entry.
129 * For 64-bit users, the 32-bit syscall number is partitioned
130 * with the high-order bits representing the class and low-order
131 * bits being the syscall number within that class.
132 * The high-order 32-bits of the 64-bit syscall number are unused.
133 * All system classes enter the kernel via the syscall instruction.
134 *
135 * These are not #ifdef'd for x86-64 because they might be used for
136 * 32-bit someday and so the 64-bit comm page in a 32-bit kernel
137 * can use them.
138 */
139 #define SYSCALL_CLASS_SHIFT 24
140 #define SYSCALL_CLASS_MASK (0xFF << SYSCALL_CLASS_SHIFT)
141 #define SYSCALL_NUMBER_MASK (~SYSCALL_CLASS_MASK)
142
143 #define SYSCALL_CLASS_NONE 0 /* Invalid */
144 #define SYSCALL_CLASS_MACH 1 /* Mach */
145 #define SYSCALL_CLASS_UNIX 2 /* Unix/BSD */
146 #define SYSCALL_CLASS_MDEP 3 /* Machine-dependent */
147 #define SYSCALL_CLASS_DIAG 4 /* Diagnostics */
148
149 /* Macros to simpllfy constructing syscall numbers. */
150 #define SYSCALL_CONSTRUCT_MACH(syscall_number) \
151 ((SYSCALL_CLASS_MACH << SYSCALL_CLASS_SHIFT) | \
152 (SYSCALL_NUMBER_MASK & (syscall_number)))
153 #define SYSCALL_CONSTRUCT_UNIX(syscall_number) \
154 ((SYSCALL_CLASS_UNIX << SYSCALL_CLASS_SHIFT) | \
155 (SYSCALL_NUMBER_MASK & (syscall_number)))
156 #define SYSCALL_CONSTRUCT_MDEP(syscall_number) \
157 ((SYSCALL_CLASS_MDEP << SYSCALL_CLASS_SHIFT) | \
158 (SYSCALL_NUMBER_MASK & (syscall_number)))
159 #define SYSCALL_CONSTRUCT_DIAG(syscall_number) \
160 ((SYSCALL_CLASS_DIAG << SYSCALL_CLASS_SHIFT) | \
161 (SYSCALL_NUMBER_MASK & (syscall_number)))
162
163 #endif /* _MACH_I386_SYSCALL_SW_H_ */
164
165 #endif /* PRIVATE */