]> git.saurik.com Git - apple/xnu.git/blob - osfmk/sys/varargs.h
52611e38f02efdc0223aad0cb4164f04309a778c
[apple/xnu.git] / osfmk / sys / varargs.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * @OSF_COPYRIGHT@
32 */
33 /*
34 * HISTORY
35 *
36 * Revision 1.1.1.1 1998/09/22 21:05:49 wsanchez
37 * Import of Mac OS X kernel (~semeria)
38 *
39 * Revision 1.1.1.1 1998/03/07 02:25:59 wsanchez
40 * Import of OSF Mach kernel (~mburg)
41 *
42 * Revision 1.2.28.1 1996/11/29 16:59:53 stephen
43 * nmklinux_1.0b3_shared into pmk1.1
44 * Added powerpc special case
45 * [1996/11/29 16:34:18 stephen]
46 *
47 * Revision 1.2.15.2 1996/01/09 19:23:16 devrcs
48 * Added alpha varargs.h
49 * [1995/12/01 20:39:10 jfraser]
50 *
51 * Merged '64-bit safe' changes from DEC alpha port.
52 * [1995/11/21 18:10:39 jfraser]
53 *
54 * Revision 1.2.15.1 1994/09/23 03:13:46 ezf
55 * change marker to not FREE
56 * [1994/09/22 21:59:07 ezf]
57 *
58 * Revision 1.2.4.3 1993/08/03 18:30:40 gm
59 * CR9596: Change KERNEL to MACH_KERNEL.
60 * [1993/08/02 19:03:10 gm]
61 *
62 * Revision 1.2.4.2 1993/06/09 02:55:42 gm
63 * Added to OSF/1 R1.3 from NMK15.0.
64 * [1993/06/02 21:31:11 jeffc]
65 *
66 * Revision 1.2 1993/04/19 17:17:26 devrcs
67 * correct endif tags for ansi
68 * [1993/02/25 17:56:02 david]
69 *
70 * Revision 1.1 1992/09/30 02:37:05 robert
71 * Initial revision
72 *
73 * $EndLog$
74 */
75 /* CMU_HIST */
76 /*
77 * Revision 2.10 91/12/10 16:32:53 jsb
78 * Fixes from Intel
79 * [91/12/10 15:52:01 jsb]
80 *
81 * Revision 2.9 91/09/12 16:54:22 debo
82 * Added mac2.
83 * [91/09/11 17:22:52 debo]
84 *
85 * Revision 2.8 91/07/09 23:23:50 danner
86 * Added luna88k support.
87 * [91/06/24 danner]
88 *
89 * Revision 2.7 91/06/18 20:53:02 jsb
90 * Moved i860 varargs code here from i860/i860_varargs.h, thanks to
91 * new copyright from Intel.
92 * [91/06/18 19:15:02 jsb]
93 *
94 * Revision 2.6 91/05/14 17:40:46 mrt
95 * Correcting copyright
96 *
97 * Revision 2.5 91/02/05 17:57:12 mrt
98 * Changed to new Mach copyright
99 * [91/02/01 17:49:51 mrt]
100 *
101 * Revision 2.4 90/11/25 17:48:50 jsb
102 * Added i860 support.
103 * [90/11/25 16:54:09 jsb]
104 *
105 * Revision 2.3 90/05/03 15:51:29 dbg
106 * Added i386.
107 * [90/02/08 dbg]
108 *
109 * Revision 2.2 89/11/29 14:16:44 af
110 * RCS-ed, added mips case. Mips also needs it in Mach standalone
111 * programs.
112 * [89/10/28 10:39:14 af]
113 *
114 */
115 /* CMU_ENDHIST */
116 /*
117 * Mach Operating System
118 * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University
119 * All Rights Reserved.
120 *
121 * Permission to use, copy, modify and distribute this software and its
122 * documentation is hereby granted, provided that both the copyright
123 * notice and this permission notice appear in all copies of the
124 * software, derivative works or modified versions, and any portions
125 * thereof, and that both notices appear in supporting documentation.
126 *
127 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
128 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
129 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
130 *
131 * Carnegie Mellon requests users of this software to return to
132 *
133 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
134 * School of Computer Science
135 * Carnegie Mellon University
136 * Pittsburgh PA 15213-3890
137 *
138 * any improvements or extensions that they make and grant Carnegie Mellon rights
139 * to redistribute these changes.
140 */
141 /*
142 */
143
144 #ifndef _SYS_VARARGS_H_
145 #define _SYS_VARARGS_H_
146
147 #if defined(vax) || defined(sun3) || defined(mips) || defined(i386) || defined(mac2)
148 #define va_dcl int va_alist;
149 typedef char * va_list;
150
151 #define va_start(pvar) (pvar) = (va_list)&va_alist
152 #define va_end(pvar)
153 #ifdef mips
154 # define va_arg(pvar, type) ((type *)(pvar = \
155 (va_list) (sizeof(type) > 4 ? ((int)pvar + 2*8 - 1) & -8 \
156 : ((int)pvar + 2*4 - 1) & -4)))[-1]
157 #else /* mips */
158 #define va_arg(pvar,type) ( \
159 (pvar) += ((sizeof(type)+3) & ~0x3), \
160 *((type *)((pvar) - ((sizeof(type)+3) & ~0x3))) )
161 #endif /* mips */
162 #endif /* vax */
163
164 /*
165 * Try to make varargs work for the Multimax so that _doprnt can be
166 * declared as
167 * _doprnt(file, fmt, list)
168 * FILE *file;
169 * char *fmt;
170 * va_list *list;
171 * and use
172 *
173 * n = va_arg(*list, type)
174 *
175 * without needing to drag in extra declarations
176 *
177 * and printf becomes
178 *
179 * printf(fmt, va_alist)
180 * char *fmt;
181 * va_dcl
182 * {
183 * va_list listp;
184 * va_start(listp);
185 * _doprnt((FILE *)0, fmt, &listp);
186 * va_end(listp);
187 * }
188 */
189
190 #if defined(multimax) && defined(MACH_KERNEL)
191
192 /*
193 * the vararglist pointer is an elaborate structure (ecch)
194 */
195 typedef struct va_list {
196 char *va_item; /* current item */
197 int *va_ptr1, /* arglist pointers for 1, 2, n */
198 *va_ptr2,
199 *va_ptrn;
200 int va_ct; /* current argument number */
201 } va_list;
202
203 #define va_alist va_arg1, va_arg2, va_argn
204 #define va_dcl int va_arg1, va_arg2, va_argn;
205
206 #define va_start(pvar) ( \
207 (pvar).va_ptr1 = &va_arg1, \
208 (pvar).va_ptr2 = &va_arg2, \
209 (pvar).va_ptrn = &va_argn, \
210 (pvar).va_ct = 0 )
211
212 #define va_end(pvar)
213
214 #define va_arg(pvar, type) ( \
215 (pvar).va_ct++, \
216 (pvar).va_item = (char *) \
217 ( ((pvar).va_ct == 1) \
218 ? (pvar).va_ptr1 \
219 : ((pvar).va_ct == 2) \
220 ? (pvar).va_ptr2 \
221 : (pvar).va_ptrn++ ) , \
222 *((type *)((pvar).va_item)) )
223
224 /* what a mess! */
225 #endif /* defined(multimax) && defined(MACH_KERNEL) */
226
227 #if i860
228 #include <i860/varargs.h> /* PGI vs. Greenhills */
229 #endif
230
231 #ifdef luna88k
232 #include <luna88k/varargs.h> /* How nice */
233 #endif
234
235 #if defined (__PPC__) && defined (_CALL_SYSV)
236 #include <ppc/va-ppc.h> /* care of gcc compiler - TEMPORARY 2.7.1 TODO NMGS*/
237 #endif
238
239 #if defined(__alpha)
240 # include <varargs.h>
241 #endif /* defined(__alpha) */
242
243 #endif /* _SYS_VARARGS_H_ */