]>
Commit | Line | Data |
---|---|---|
2aa62f2b | 1 | /** @file\r |
2 | Common declarations and definitions for Standard C Library headers.\r | |
3 | \r | |
4 | This header consolidates definitions and declarations for compiler specific\r | |
5 | features in one place in order to assist in making the remainder of the\r | |
6 | library as compiler independent as possible.\r | |
7 | \r | |
8 | Certain macro and type definitions are required to be provided by several\r | |
9 | different headers. In order to avoid having multiple definitions, and the\r | |
10 | attendant risk of having the definitions get out of sync, they are defined in\r | |
11 | this header.\r | |
12 | \r | |
13 | Note that MdePkg/Include/Base.h is automatically included and will bring\r | |
14 | processor architecture specific definitions along with it.\r | |
15 | \r | |
16 | Throughout the library, the following macros are used instead of keywords so\r | |
17 | that the library can be easily tuned for different compilers.\r | |
18 | __inline Defined to the appropriate keyword or not defined.\r | |
19 | __func__ Defined to __FUNC__, __FUNCTION__, or NULL as appropriate.\r | |
d7ce7006 | 20 | __restrict Defined to nothing for VC++ or to restrict for GCC and C99 compliant compilers.\r |
2aa62f2b | 21 | \r |
22 | This file and its contents are inspired by the <sys/cdefs.h> files in Berkeley\r | |
23 | Unix. They have been re-implemented to be specific to the EFI environment.\r | |
24 | \r | |
d78fab6b | 25 | Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>\r |
2aa62f2b | 26 | This program and the accompanying materials are licensed and made available under\r |
27 | the terms and conditions of the BSD License that accompanies this distribution.\r | |
28 | The full text of the license may be found at\r | |
d7ce7006 | 29 | http://opensource.org/licenses/bsd-license.\r |
2aa62f2b | 30 | \r |
31 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
32 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
33 | \r | |
34 | Portions Copyright (c) 1991, 1993\r | |
35 | The Regents of the University of California. All rights reserved.\r | |
36 | \r | |
37 | Portions of this code are derived from software contributed to Berkeley by\r | |
38 | Berkeley Software Design, Inc.\r | |
39 | Redistribution and use in source and binary forms, with or without\r | |
40 | modification, are permitted provided that the following conditions\r | |
41 | are met:\r | |
42 | 1. Redistributions of source code must retain the above copyright\r | |
43 | notice, this list of conditions and the following disclaimer.\r | |
44 | 2. Redistributions in binary form must reproduce the above copyright\r | |
45 | notice, this list of conditions and the following disclaimer in the\r | |
46 | documentation and/or other materials provided with the distribution.\r | |
47 | 3. Neither the name of the University nor the names of its contributors\r | |
48 | may be used to endorse or promote products derived from this software\r | |
49 | without specific prior written permission.\r | |
50 | \r | |
51 | THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r | |
52 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r | |
53 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r | |
54 | ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r | |
55 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r | |
56 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r | |
57 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r | |
58 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r | |
59 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r | |
60 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r | |
61 | SUCH DAMAGE.\r | |
62 | **/\r | |
63 | #ifndef _EFI_CDEFS_H\r | |
64 | #define _EFI_CDEFS_H\r | |
65 | \r | |
66 | /*\r | |
67 | * Macro to test if we're using a GNU C compiler of a specific vintage\r | |
68 | * or later, for e.g. features that appeared in a particular version\r | |
69 | * of GNU C. Usage:\r | |
70 | *\r | |
71 | * #if __GNUC_PREREQ__(major, minor)\r | |
72 | * ...cool feature...\r | |
73 | * #else\r | |
74 | * ...delete feature...\r | |
75 | * #endif\r | |
76 | */\r | |
77 | #ifdef __GNUC__\r | |
78 | #define __GNUC_PREREQ__(x, y) \\r | |
79 | ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \\r | |
80 | (__GNUC__ > (x)))\r | |
81 | \r | |
82 | #define DONT_USE_STRONG_WEAK_ALIAS 1\r | |
83 | \r | |
84 | #else\r | |
85 | #define __GNUC_PREREQ__(x, y) 0\r | |
86 | #endif\r | |
87 | \r | |
88 | #include <sys/featuretest.h>\r | |
89 | //#include <machine/_EfiCdefs.h>\r | |
90 | #ifdef __PE32__\r | |
91 | #include <sys/_EfiCdefs_PE32.h>\r | |
92 | #else\r | |
93 | #include <sys/cdefs_aout.h>\r | |
94 | #endif\r | |
95 | \r | |
96 | /* NULL is defined by the automatic inclusion of Base.h by the build tools. */\r | |
97 | \r | |
98 | #ifdef __GNUC__\r | |
99 | #define _EFI_SIZE_T_ __SIZE_TYPE__ /* sizeof() */\r | |
100 | #define _EFI_WCHAR_T __WCHAR_TYPE__\r | |
101 | #define _EFI_WINT_T __WINT_TYPE__\r | |
102 | //#define _EFI_WINT_MIN (0)\r | |
103 | //#define _EFI_WINT_MAX (0xFFFF)\r | |
104 | #define _EFI_PTRDIFF_T_ __PTRDIFF_TYPE__ /* ptr1 - ptr2 --- Must be same size as size_t */\r | |
5244f47e | 105 | \r |
2aa62f2b | 106 | #else\r |
107 | #define _EFI_SIZE_T_ UINTN /* sizeof() */\r | |
108 | #define _EFI_WCHAR_T UINT16\r | |
109 | #define _EFI_WINT_T INT32\r | |
110 | //#define _EFI_WINT_MIN (-2147483647) /* wint_t */\r | |
111 | //#define _EFI_WINT_MAX ( 2147483647) /* wint_t */\r | |
112 | #define _EFI_PTRDIFF_T_ INTN /* ptr1 - ptr2 --- Must be same size as size_t */\r | |
113 | #endif /* __GNUC__ */\r | |
114 | \r | |
115 | #define _EFI_CLOCK_T UINT64\r | |
116 | #define _EFI_TIME_T INT32\r | |
117 | \r | |
118 | #if defined(__cplusplus)\r | |
119 | #define __BEGIN_DECLS extern "C" {\r | |
120 | #define __END_DECLS }\r | |
121 | #define __static_cast(x,y) static_cast<x>(y)\r | |
122 | #else\r | |
123 | #define __BEGIN_DECLS\r | |
124 | #define __END_DECLS\r | |
125 | #define __static_cast(x,y) (x)y\r | |
126 | #endif\r | |
127 | \r | |
128 | /*\r | |
129 | * The __CONCAT macro is used to concatenate parts of symbol names, e.g.\r | |
130 | * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.\r | |
131 | * The __CONCAT macro is a bit tricky -- make sure you don't put spaces\r | |
132 | * in between its arguments. __CONCAT can also concatenate double-quoted\r | |
133 | * strings produced by the __STRING macro, but this only works with ANSI C.\r | |
134 | */\r | |
135 | \r | |
136 | #define ___STRING(x) __STRING(x)\r | |
137 | #define ___CONCAT(x,y) __CONCAT(x,y)\r | |
138 | #define __CONCAT(x,y) x ## y\r | |
139 | #define __STRING(x) #x\r | |
140 | \r | |
141 | #define __const CONST\r | |
142 | #define __signed signed\r | |
143 | #define __volatile volatile\r | |
144 | \r | |
145 | #if __STDC__ || defined(__cplusplus)\r | |
146 | #if defined(__cplusplus)\r | |
147 | #define __inline inline /* convert to C++ keyword */\r | |
148 | #else\r | |
149 | #if defined(_MSC_VER) || (!defined(__GNUC__) && !defined(__lint__))\r | |
150 | #define __inline /* delete C99 keyword */\r | |
151 | #endif /* !__GNUC__ && !__lint__ */\r | |
152 | #endif /* !__cplusplus */\r | |
153 | #endif /* !(__STDC__ || __cplusplus) */\r | |
154 | \r | |
155 | /* Used in NetBSD for internal auditing of the source tree. */\r | |
156 | #define __aconst\r | |
157 | \r | |
158 | /*\r | |
159 | * The following macro is used to remove const cast-away warnings\r | |
160 | * from gcc -Wcast-qual; it should be used with caution because it\r | |
161 | * can hide valid errors; in particular most valid uses are in\r | |
162 | * situations where the API requires it, not to cast away string\r | |
163 | * constants. We don't use *intptr_t on purpose here and we are\r | |
164 | * explicit about unsigned long so that we don't have additional\r | |
165 | * dependencies.\r | |
166 | */\r | |
167 | #define __UNCONST(a) ((void *)(a))\r | |
168 | //#define __UNCONST(a) ((void *)(PHYSICAL_ADDRESS)(const void *)(a))\r | |
169 | \r | |
170 | /*\r | |
171 | * The following macro is used to remove the volatile cast-away warnings\r | |
172 | * from gcc -Wcast-qual; as above it should be used with caution\r | |
173 | * because it can hide valid errors or warnings. Valid uses include\r | |
174 | * making it possible to pass a volatile pointer to memset().\r | |
175 | * For the same reasons as above, we use unsigned long and not intptr_t.\r | |
176 | */\r | |
177 | #define __UNVOLATILE(a) ((void *)(PHYSICAL_ADDRESS)(volatile void *)(a))\r | |
178 | \r | |
179 | /*\r | |
180 | * GCC2 provides __extension__ to suppress warnings for various GNU C\r | |
181 | * language extensions under "-ansi -pedantic".\r | |
182 | */\r | |
183 | #if !__GNUC_PREREQ__(2, 0)\r | |
184 | #define __extension__ /* delete __extension__ if non-gcc or gcc1 */\r | |
185 | #endif\r | |
186 | \r | |
187 | /*\r | |
188 | * GCC1 and some versions of GCC2 declare dead (non-returning) and\r | |
189 | * pure (no side effects) functions using "volatile" and "const";\r | |
190 | * unfortunately, these then cause warnings under "-ansi -pedantic".\r | |
191 | * GCC2 uses a new, peculiar __attribute__((attrs)) style. All of\r | |
192 | * these work for GNU C++ (modulo a slight glitch in the C++ grammar\r | |
193 | * in the distribution version of 2.5.5).\r | |
194 | */\r | |
195 | #if !__GNUC_PREREQ__(2, 5)\r | |
196 | #define __attribute__(x) /* delete __attribute__ if non-gcc or gcc1 */\r | |
197 | #if defined(__GNUC__) && !defined(__STRICT_ANSI__)\r | |
198 | #define __dead __volatile\r | |
199 | #define __pure __const\r | |
200 | #endif\r | |
201 | #endif\r | |
202 | \r | |
203 | /* Delete pseudo-keywords wherever they are not available or needed. */\r | |
204 | #ifndef __dead\r | |
205 | #define __dead\r | |
206 | #define __pure\r | |
207 | #endif\r | |
208 | \r | |
209 | #if __GNUC_PREREQ__(2, 7)\r | |
210 | #define __unused __attribute__((__unused__))\r | |
211 | #define __noreturn __attribute__((__noreturn__))\r | |
212 | #else\r | |
213 | #define __unused /* delete */\r | |
214 | #define __noreturn /* delete */\r | |
215 | #endif\r | |
216 | \r | |
217 | #if __GNUC_PREREQ__(3, 1)\r | |
218 | #define __used __attribute__((__used__))\r | |
219 | #else\r | |
220 | #define __used __unused\r | |
221 | #endif\r | |
222 | \r | |
223 | #if __GNUC_PREREQ__(2, 7)\r | |
224 | #define __packed __attribute__((__packed__))\r | |
225 | #define __aligned(x) __attribute__((__aligned__(x)))\r | |
226 | #define __section(x) __attribute__((__section__(x)))\r | |
227 | #elif defined(__lint__)\r | |
228 | #define __packed /* delete */\r | |
229 | #define __aligned(x) /* delete */\r | |
230 | #define __section(x) /* delete */\r | |
231 | #else\r | |
232 | #define __packed error: no __packed for this compiler\r | |
233 | #define __aligned(x) error: no __aligned for this compiler\r | |
234 | #define __section(x) error: no __section for this compiler\r | |
235 | #endif\r | |
236 | \r | |
237 | /*\r | |
238 | * C99 defines the restrict type qualifier keyword, which was made available\r | |
239 | * in GCC 2.92.\r | |
240 | */\r | |
241 | #if __STDC_VERSION__ >= 199901L\r | |
242 | #define __restrict restrict\r | |
243 | #else\r | |
244 | #if defined(_MSC_VER) || !__GNUC_PREREQ__(2, 92)\r | |
245 | #define __restrict /* delete __restrict when not supported */\r | |
246 | #endif\r | |
247 | #endif\r | |
248 | \r | |
249 | /*\r | |
250 | * C99 defines __func__ predefined identifier, which was made available\r | |
251 | * in GCC 2.95.\r | |
252 | */\r | |
253 | #if !(__STDC_VERSION__ >= 199901L)\r | |
254 | #if defined(_MSC_VER)\r | |
255 | #define __func__ __FUNCTION__ /* Use the MS-specific predefined macro */\r | |
256 | #elif __GNUC_PREREQ__(2, 6)\r | |
257 | #define __func__ __PRETTY_FUNCTION__\r | |
258 | #elif __GNUC_PREREQ__(2, 4)\r | |
259 | #define __func__ __FUNCTION__\r | |
260 | #else\r | |
261 | #define __func__ ""\r | |
262 | #endif\r | |
263 | #endif /* !(__STDC_VERSION__ >= 199901L) */\r | |
264 | \r | |
d7ce7006 | 265 | #define __RENAME(x)\r |
2aa62f2b | 266 | \r |
267 | /*\r | |
268 | * A barrier to stop the optimizer from moving code or assume live\r | |
269 | * register values. This is gcc specific, the version is more or less\r | |
270 | * arbitrary, might work with older compilers.\r | |
271 | */\r | |
272 | #if __GNUC_PREREQ__(2, 95)\r | |
273 | #define __insn_barrier() __asm __volatile("":::"memory")\r | |
274 | #else\r | |
275 | #define __insn_barrier() /* */\r | |
276 | #endif\r | |
277 | \r | |
278 | /*\r | |
279 | * GNU C version 2.96 adds explicit branch prediction so that\r | |
280 | * the CPU back-end can hint the processor and also so that\r | |
281 | * code blocks can be reordered such that the predicted path\r | |
282 | * sees a more linear flow, thus improving cache behavior, etc.\r | |
283 | *\r | |
284 | * The following two macros provide us with a way to use this\r | |
285 | * compiler feature. Use __predict_true() if you expect the expression\r | |
286 | * to evaluate to true, and __predict_false() if you expect the\r | |
287 | * expression to evaluate to false.\r | |
288 | *\r | |
289 | * A few notes about usage:\r | |
290 | *\r | |
291 | * * Generally, __predict_false() error condition checks (unless\r | |
292 | * you have some _strong_ reason to do otherwise, in which case\r | |
293 | * document it), and/or __predict_true() `no-error' condition\r | |
294 | * checks, assuming you want to optimize for the no-error case.\r | |
295 | *\r | |
296 | * * Other than that, if you don't know the likelihood of a test\r | |
297 | * succeeding from empirical or other `hard' evidence, don't\r | |
298 | * make predictions.\r | |
299 | *\r | |
300 | * * These are meant to be used in places that are run `a lot'.\r | |
301 | * It is wasteful to make predictions in code that is run\r | |
302 | * seldomly (e.g. at subsystem initialization time) as the\r | |
303 | * basic block reordering that this affects can often generate\r | |
304 | * larger code.\r | |
305 | */\r | |
306 | #if __GNUC_PREREQ__(2, 96)\r | |
307 | #define __predict_true(exp) __builtin_expect((exp) != 0, 1)\r | |
308 | #define __predict_false(exp) __builtin_expect((exp) != 0, 0)\r | |
309 | #else\r | |
310 | #define __predict_true(exp) (exp)\r | |
311 | #define __predict_false(exp) (exp)\r | |
312 | #endif\r | |
313 | \r | |
314 | /* find least significant bit that is set */\r | |
315 | #define __LOWEST_SET_BIT(__mask) ((((__mask) - 1) & (__mask)) ^ (__mask))\r | |
316 | \r | |
317 | #define __SHIFTOUT(__x, __mask) (((__x) & (__mask)) / __LOWEST_SET_BIT(__mask))\r | |
318 | #define __SHIFTIN(__x, __mask) ((__x) * __LOWEST_SET_BIT(__mask))\r | |
319 | #define __SHIFTOUT_MASK(__mask) __SHIFTOUT((__mask), (__mask))\r | |
320 | \r | |
321 | #if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */\r | |
322 | \r | |
323 | /* VC++, by default, defines wchar_t as an intrinsic type, equivalent to\r | |
324 | unsigned short. This conflicts which Standard C Library\r | |
325 | implementations which try to define wchar_t.\r | |
326 | Make sure that this behavior has been turned off by using\r | |
327 | /Zc:wchar_t- on the command line.\r | |
328 | */\r | |
329 | #ifdef _NATIVE_WCHAR_T_DEFINED\r | |
330 | #error You must specify /Zc:wchar_t- to the compiler to turn off intrinsic wchar_t.\r | |
331 | #endif\r | |
332 | \r | |
d78fab6b | 333 | /* Get rid of pre-defined macros that are misleading in this environment. */\r |
334 | #undef _WIN32\r | |
335 | #undef _WIN64\r | |
336 | \r | |
2aa62f2b | 337 | // Keep compiler quiet about casting from smaller to larger types\r |
338 | #pragma warning ( disable : 4306 )\r | |
b26913ef | 339 | \r |
340 | #define __STDC__ 1\r | |
341 | #define __STDC_VERSION__ 199409L\r | |
342 | #define __STDC_HOSTED__ 1\r | |
343 | \r | |
2aa62f2b | 344 | #endif /* defined(_MSC_VER) */\r |
345 | extern int _fltused; // VC++ requires this if you use floating point. KEEP for all compilers.\r | |
346 | \r | |
347 | #define _Bool BOOLEAN\r | |
348 | #define _DIAGASSERT(e)\r | |
349 | \r | |
350 | // Types used to replace long so that it will have constant length regardless of compiler.\r | |
5244f47e | 351 | typedef INT32 LONG32;\r |
2aa62f2b | 352 | typedef UINT32 ULONG32;\r |
353 | typedef INT64 LONG64;\r | |
354 | typedef UINT64 ULONG64;\r | |
355 | \r | |
d78fab6b | 356 | typedef INTN EFI_LONG_T;\r |
357 | typedef UINTN EFI_ULONG_T;\r | |
5244f47e | 358 | \r |
359 | /* These types reflect the compiler's size for long */\r | |
360 | #if defined(__GNUC__)\r | |
361 | #if __GNUC_PREREQ__(4,4)\r | |
362 | /* GCC 4.4 or later */\r | |
363 | typedef INT64 LONGN;\r | |
364 | typedef UINT64 ULONGN;\r | |
365 | #else\r | |
366 | /* minGW gcc variant */\r | |
367 | typedef INT32 LONGN;\r | |
368 | typedef UINT32 ULONGN;\r | |
369 | #endif /* __GNUC_PREREQ__(4,4) */\r | |
370 | #else /* NOT GCC */\r | |
371 | /* Microsoft or Intel compilers */\r | |
372 | typedef INT32 LONGN;\r | |
373 | typedef UINT32 ULONGN;\r | |
374 | #endif /* defined(__GNUC__) */\r | |
375 | \r | |
2aa62f2b | 376 | #endif /* _EFI_CDEFS_H */\r |