]> git.saurik.com Git - apple/xnu.git/blob - osfmk/mach/i386/syscall_sw.h
xnu-1228.7.58.tar.gz
[apple/xnu.git] / osfmk / mach / i386 / syscall_sw.h
1 /*
2 * Copyright (c) 2000-2006 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 #ifdef PRIVATE
57
58 #ifndef _MACH_I386_SYSCALL_SW_H_
59 #define _MACH_I386_SYSCALL_SW_H_
60
61 #include <architecture/i386/asm_help.h>
62
63 #if defined(__i386__)
64 /*
65 * Software interrupt codes for 32-bit system call entry:
66 */
67 #define UNIX_INT 0x80
68 #define MACH_INT 0x81
69 #define MACHDEP_INT 0x82
70 #define DIAG_INT 0x83
71
72 #ifndef KERNEL
73 /*
74 * Syscall entry macros for use in libc:
75 */
76 #define UNIX_SYSCALL_TRAP \
77 int $(UNIX_INT)
78 #define MACHDEP_SYSCALL_TRAP \
79 int $(MACHDEP_INT)
80
81 /*
82 * Macro to generate Mach call stubs in libc:
83 */
84
85 #define kernel_trap(trap_name,trap_number,number_args) \
86 LEAF(_##trap_name,0) ;\
87 movl $##trap_number, %eax ;\
88 call __sysenter_trap ;\
89 END(_##trap_name)
90
91 #endif
92 #endif /* defined(__i386__) */
93
94 #if defined(__x86_64__)
95
96 #ifndef KERNEL
97
98 #define UNIX_SYSCALL_TRAP \
99 syscall
100 #define MACHDEP_SYSCALL_TRAP \
101 syscall
102
103 /*
104 * Macro to generate Mach call stubs in Libc.
105 * Existing calls use negative numbers for Mach traps, so
106 * until we change those and change the 32-bit kernel_trap
107 * macro above, we negate those numbers here for the 64-bit
108 * code path.
109 */
110 #define kernel_trap(trap_name,trap_number,number_args) \
111 LEAF(_##trap_name,0) ;\
112 movq %rcx, %r10 ;\
113 movl $ SYSCALL_CONSTRUCT_MACH(-##trap_number), %eax ;\
114 syscall ;\
115 END(_##trap_name)
116
117 #endif
118 #endif /* defined(__x86_64__) */
119
120 /*
121 * Syscall classes for 64-bit system call entry.
122 * For 64-bit users, the 32-bit syscall number is partitioned
123 * with the high-order bits representing the class and low-order
124 * bits being the syscall number within that class.
125 * The high-order 32-bits of the 64-bit syscall number are unused.
126 * All system classes enter the kernel via the syscall instruction.
127 *
128 * These are not #ifdef'd for x86-64 because they might be used for
129 * 32-bit someday and so the 64-bit comm page in a 32-bit kernel
130 * can use them.
131 */
132 #define SYSCALL_CLASS_SHIFT 24
133 #define SYSCALL_CLASS_MASK (0xFF << SYSCALL_CLASS_SHIFT)
134 #define SYSCALL_NUMBER_MASK (~SYSCALL_CLASS_MASK)
135
136 #define I386_SYSCALL_CLASS_MASK SYSCALL_CLASS_MASK
137 #define I386_SYSCALL_ARG_BYTES_SHIFT (16)
138 #define I386_SYSCALL_ARG_DWORDS_SHIFT (I386_SYSCALL_ARG_BYTES_SHIFT + 2)
139 #define I386_SYSCALL_ARG_BYTES_NUM (64) /* Must be <= sizeof(uu_arg) */
140 #define I386_SYSCALL_ARG_DWORDS_MASK ((I386_SYSCALL_ARG_BYTES_NUM >> 2) -1)
141 #define I386_SYSCALL_ARG_BYTES_MASK (((I386_SYSCALL_ARG_BYTES_NUM -1)&~0x3) << I386_SYSCALL_ARG_BYTES_SHIFT)
142 #define I386_SYSCALL_NUMBER_MASK (0xFFFF)
143
144 #define SYSCALL_CLASS_NONE 0 /* Invalid */
145 #define SYSCALL_CLASS_MACH 1 /* Mach */
146 #define SYSCALL_CLASS_UNIX 2 /* Unix/BSD */
147 #define SYSCALL_CLASS_MDEP 3 /* Machine-dependent */
148 #define SYSCALL_CLASS_DIAG 4 /* Diagnostics */
149
150 /* Macros to simpllfy constructing syscall numbers. */
151 #define SYSCALL_CONSTRUCT_MACH(syscall_number) \
152 ((SYSCALL_CLASS_MACH << SYSCALL_CLASS_SHIFT) | \
153 (SYSCALL_NUMBER_MASK & (syscall_number)))
154 #define SYSCALL_CONSTRUCT_UNIX(syscall_number) \
155 ((SYSCALL_CLASS_UNIX << SYSCALL_CLASS_SHIFT) | \
156 (SYSCALL_NUMBER_MASK & (syscall_number)))
157 #define SYSCALL_CONSTRUCT_MDEP(syscall_number) \
158 ((SYSCALL_CLASS_MDEP << SYSCALL_CLASS_SHIFT) | \
159 (SYSCALL_NUMBER_MASK & (syscall_number)))
160 #define SYSCALL_CONSTRUCT_DIAG(syscall_number) \
161 ((SYSCALL_CLASS_DIAG << SYSCALL_CLASS_SHIFT) | \
162 (SYSCALL_NUMBER_MASK & (syscall_number)))
163
164 #endif /* _MACH_I386_SYSCALL_SW_H_ */
165
166 #endif /* PRIVATE */