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