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