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