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