xref: /freebsd/sys/contrib/edk2/Include/Base.h (revision 3245fa215aca18d135839a15c80ae1c905666a37)
10d1ba665SWarner Losh /** @file
20d1ba665SWarner Losh   Root include file for Mde Package Base type modules
30d1ba665SWarner Losh 
40d1ba665SWarner Losh   This is the include file for any module of type base. Base modules only use
50d1ba665SWarner Losh   types defined via this include file and can be ported easily to any
60d1ba665SWarner Losh   environment. There are a set of base libraries in the Mde Package that can
70d1ba665SWarner Losh   be used to implement base modules.
80d1ba665SWarner Losh 
9*3245fa21SMitchell Horne Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
100d1ba665SWarner Losh Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
11*3245fa21SMitchell Horne SPDX-License-Identifier: BSD-2-Clause-Patent
120d1ba665SWarner Losh 
130d1ba665SWarner Losh **/
140d1ba665SWarner Losh 
150d1ba665SWarner Losh 
160d1ba665SWarner Losh #ifndef __BASE_H__
170d1ba665SWarner Losh #define __BASE_H__
180d1ba665SWarner Losh 
190d1ba665SWarner Losh //
200d1ba665SWarner Losh // Include processor specific binding
210d1ba665SWarner Losh //
220d1ba665SWarner Losh #include <ProcessorBind.h>
230d1ba665SWarner Losh 
240d1ba665SWarner Losh #if defined(_MSC_EXTENSIONS)
250d1ba665SWarner Losh //
260d1ba665SWarner Losh // Disable warning when last field of data structure is a zero sized array.
270d1ba665SWarner Losh //
280d1ba665SWarner Losh #pragma warning ( disable : 4200 )
290d1ba665SWarner Losh #endif
300d1ba665SWarner Losh 
310d1ba665SWarner Losh //
320d1ba665SWarner Losh // The Microsoft* C compiler can removed references to unreferenced data items
330d1ba665SWarner Losh //  if the /OPT:REF linker option is used. We defined a macro as this is a
340d1ba665SWarner Losh //  a non standard extension
350d1ba665SWarner Losh //
36*3245fa21SMitchell Horne #if defined(_MSC_VER) && _MSC_VER < 1800 && !defined (MDE_CPU_EBC)
370d1ba665SWarner Losh   ///
380d1ba665SWarner Losh   /// Remove global variable from the linked image if there are no references to
390d1ba665SWarner Losh   /// it after all compiler and linker optimizations have been performed.
400d1ba665SWarner Losh   ///
410d1ba665SWarner Losh   ///
420d1ba665SWarner Losh   #define GLOBAL_REMOVE_IF_UNREFERENCED __declspec(selectany)
430d1ba665SWarner Losh #else
440d1ba665SWarner Losh   ///
450d1ba665SWarner Losh   /// Remove the global variable from the linked image if there are no references
460d1ba665SWarner Losh   ///  to it after all compiler and linker optimizations have been performed.
470d1ba665SWarner Losh   ///
480d1ba665SWarner Losh   ///
490d1ba665SWarner Losh   #define GLOBAL_REMOVE_IF_UNREFERENCED
500d1ba665SWarner Losh #endif
510d1ba665SWarner Losh 
520d1ba665SWarner Losh //
530d1ba665SWarner Losh // Should be used in combination with NORETURN to avoid 'noreturn' returns
540d1ba665SWarner Losh // warnings.
550d1ba665SWarner Losh //
560d1ba665SWarner Losh #ifndef UNREACHABLE
57*3245fa21SMitchell Horne   #ifdef __GNUC__
580d1ba665SWarner Losh     ///
590d1ba665SWarner Losh     /// Signal compilers and analyzers that this call is not reachable.  It is
600d1ba665SWarner Losh     /// up to the compiler to remove any code past that point.
610d1ba665SWarner Losh     ///
620d1ba665SWarner Losh     #define UNREACHABLE()  __builtin_unreachable ()
630d1ba665SWarner Losh   #elif defined (__has_feature)
640d1ba665SWarner Losh     #if __has_builtin (__builtin_unreachable)
650d1ba665SWarner Losh       ///
660d1ba665SWarner Losh       /// Signal compilers and analyzers that this call is not reachable.  It is
670d1ba665SWarner Losh       /// up to the compiler to remove any code past that point.
680d1ba665SWarner Losh       ///
690d1ba665SWarner Losh       #define UNREACHABLE()  __builtin_unreachable ()
700d1ba665SWarner Losh     #endif
710d1ba665SWarner Losh   #endif
720d1ba665SWarner Losh 
730d1ba665SWarner Losh   #ifndef UNREACHABLE
740d1ba665SWarner Losh     ///
750d1ba665SWarner Losh     /// Signal compilers and analyzers that this call is not reachable.  It is
760d1ba665SWarner Losh     /// up to the compiler to remove any code past that point.
770d1ba665SWarner Losh     ///
780d1ba665SWarner Losh     #define UNREACHABLE()
790d1ba665SWarner Losh   #endif
800d1ba665SWarner Losh #endif
810d1ba665SWarner Losh 
820d1ba665SWarner Losh //
830d1ba665SWarner Losh // Signaling compilers and analyzers that a certain function cannot return may
840d1ba665SWarner Losh // remove all following code and thus lead to better optimization and less
850d1ba665SWarner Losh // false positives.
860d1ba665SWarner Losh //
870d1ba665SWarner Losh #ifndef NORETURN
880d1ba665SWarner Losh   #if defined (__GNUC__) || defined (__clang__)
890d1ba665SWarner Losh     ///
900d1ba665SWarner Losh     /// Signal compilers and analyzers that the function cannot return.
910d1ba665SWarner Losh     /// It is up to the compiler to remove any code past a call to functions
920d1ba665SWarner Losh     /// flagged with this attribute.
930d1ba665SWarner Losh     ///
940d1ba665SWarner Losh     #define NORETURN  __attribute__((noreturn))
950d1ba665SWarner Losh   #elif defined(_MSC_EXTENSIONS) && !defined(MDE_CPU_EBC)
960d1ba665SWarner Losh     ///
970d1ba665SWarner Losh     /// Signal compilers and analyzers that the function cannot return.
980d1ba665SWarner Losh     /// It is up to the compiler to remove any code past a call to functions
990d1ba665SWarner Losh     /// flagged with this attribute.
1000d1ba665SWarner Losh     ///
1010d1ba665SWarner Losh     #define NORETURN  __declspec(noreturn)
1020d1ba665SWarner Losh   #else
1030d1ba665SWarner Losh     ///
1040d1ba665SWarner Losh     /// Signal compilers and analyzers that the function cannot return.
1050d1ba665SWarner Losh     /// It is up to the compiler to remove any code past a call to functions
1060d1ba665SWarner Losh     /// flagged with this attribute.
1070d1ba665SWarner Losh     ///
1080d1ba665SWarner Losh     #define NORETURN
1090d1ba665SWarner Losh   #endif
1100d1ba665SWarner Losh #endif
1110d1ba665SWarner Losh 
1120d1ba665SWarner Losh //
1130d1ba665SWarner Losh // Should be used in combination with ANALYZER_NORETURN to avoid 'noreturn'
1140d1ba665SWarner Losh // returns warnings.
1150d1ba665SWarner Losh //
1160d1ba665SWarner Losh #ifndef ANALYZER_UNREACHABLE
1170d1ba665SWarner Losh   #ifdef __clang_analyzer__
1180d1ba665SWarner Losh     #if __has_builtin (__builtin_unreachable)
1190d1ba665SWarner Losh       ///
1200d1ba665SWarner Losh       /// Signal the analyzer that this call is not reachable.
1210d1ba665SWarner Losh       /// This excludes compilers.
1220d1ba665SWarner Losh       ///
1230d1ba665SWarner Losh       #define ANALYZER_UNREACHABLE()  __builtin_unreachable ()
1240d1ba665SWarner Losh     #endif
1250d1ba665SWarner Losh   #endif
1260d1ba665SWarner Losh 
1270d1ba665SWarner Losh   #ifndef ANALYZER_UNREACHABLE
1280d1ba665SWarner Losh     ///
1290d1ba665SWarner Losh     /// Signal the analyzer that this call is not reachable.
1300d1ba665SWarner Losh     /// This excludes compilers.
1310d1ba665SWarner Losh     ///
1320d1ba665SWarner Losh     #define ANALYZER_UNREACHABLE()
1330d1ba665SWarner Losh   #endif
1340d1ba665SWarner Losh #endif
1350d1ba665SWarner Losh 
1360d1ba665SWarner Losh //
1370d1ba665SWarner Losh // Static Analyzers may issue errors about potential NULL-dereferences when
1380d1ba665SWarner Losh // dereferencing a pointer, that has been checked before, outside of a
1390d1ba665SWarner Losh // NULL-check.  This may lead to false positives, such as when using ASSERT()
1400d1ba665SWarner Losh // for verification.
1410d1ba665SWarner Losh //
1420d1ba665SWarner Losh #ifndef ANALYZER_NORETURN
1430d1ba665SWarner Losh   #ifdef __has_feature
1440d1ba665SWarner Losh     #if __has_feature (attribute_analyzer_noreturn)
1450d1ba665SWarner Losh       ///
1460d1ba665SWarner Losh       /// Signal analyzers that the function cannot return.
1470d1ba665SWarner Losh       /// This excludes compilers.
1480d1ba665SWarner Losh       ///
1490d1ba665SWarner Losh       #define ANALYZER_NORETURN  __attribute__((analyzer_noreturn))
1500d1ba665SWarner Losh     #endif
1510d1ba665SWarner Losh   #endif
1520d1ba665SWarner Losh 
1530d1ba665SWarner Losh   #ifndef ANALYZER_NORETURN
1540d1ba665SWarner Losh     ///
1550d1ba665SWarner Losh     /// Signal the analyzer that the function cannot return.
1560d1ba665SWarner Losh     /// This excludes compilers.
1570d1ba665SWarner Losh     ///
1580d1ba665SWarner Losh     #define ANALYZER_NORETURN
1590d1ba665SWarner Losh   #endif
1600d1ba665SWarner Losh #endif
1610d1ba665SWarner Losh 
162*3245fa21SMitchell Horne ///
163*3245fa21SMitchell Horne /// Tell the code optimizer that the function will return twice.
164*3245fa21SMitchell Horne /// This prevents wrong optimizations which can cause bugs.
165*3245fa21SMitchell Horne ///
166*3245fa21SMitchell Horne #ifndef RETURNS_TWICE
167*3245fa21SMitchell Horne   #if defined (__GNUC__) || defined (__clang__)
168*3245fa21SMitchell Horne     ///
169*3245fa21SMitchell Horne     /// Tell the code optimizer that the function will return twice.
170*3245fa21SMitchell Horne     /// This prevents wrong optimizations which can cause bugs.
171*3245fa21SMitchell Horne     ///
172*3245fa21SMitchell Horne     #define RETURNS_TWICE  __attribute__((returns_twice))
173*3245fa21SMitchell Horne   #else
174*3245fa21SMitchell Horne     ///
175*3245fa21SMitchell Horne     /// Tell the code optimizer that the function will return twice.
176*3245fa21SMitchell Horne     /// This prevents wrong optimizations which can cause bugs.
177*3245fa21SMitchell Horne     ///
178*3245fa21SMitchell Horne     #define RETURNS_TWICE
179*3245fa21SMitchell Horne   #endif
180*3245fa21SMitchell Horne #endif
181*3245fa21SMitchell Horne 
1820d1ba665SWarner Losh //
1830d1ba665SWarner Losh // For symbol name in assembly code, an extra "_" is sometimes necessary
1840d1ba665SWarner Losh //
1850d1ba665SWarner Losh 
1860d1ba665SWarner Losh ///
1870d1ba665SWarner Losh /// Private worker functions for ASM_PFX()
1880d1ba665SWarner Losh ///
1890d1ba665SWarner Losh #define _CONCATENATE(a, b)  __CONCATENATE(a, b)
1900d1ba665SWarner Losh #define __CONCATENATE(a, b) a ## b
1910d1ba665SWarner Losh 
1920d1ba665SWarner Losh ///
1930d1ba665SWarner Losh /// The __USER_LABEL_PREFIX__ macro predefined by GNUC represents the prefix
1940d1ba665SWarner Losh /// on symbols in assembly language.
1950d1ba665SWarner Losh ///
1960d1ba665SWarner Losh #define ASM_PFX(name) _CONCATENATE (__USER_LABEL_PREFIX__, name)
1970d1ba665SWarner Losh 
198*3245fa21SMitchell Horne #ifdef __APPLE__
1990d1ba665SWarner Losh   //
2000d1ba665SWarner Losh   // Apple extension that is used by the linker to optimize code size
2010d1ba665SWarner Losh   // with assembly functions. Put at the end of your .S files
2020d1ba665SWarner Losh   //
2030d1ba665SWarner Losh   #define ASM_FUNCTION_REMOVE_IF_UNREFERENCED  .subsections_via_symbols
2040d1ba665SWarner Losh #else
2050d1ba665SWarner Losh   #define ASM_FUNCTION_REMOVE_IF_UNREFERENCED
2060d1ba665SWarner Losh #endif
2070d1ba665SWarner Losh 
2080d1ba665SWarner Losh #ifdef __CC_ARM
2090d1ba665SWarner Losh   //
2100d1ba665SWarner Losh   // Older RVCT ARM compilers don't fully support #pragma pack and require __packed
2110d1ba665SWarner Losh   // as a prefix for the structure.
2120d1ba665SWarner Losh   //
2130d1ba665SWarner Losh   #define PACKED  __packed
2140d1ba665SWarner Losh #else
2150d1ba665SWarner Losh   #define PACKED
2160d1ba665SWarner Losh #endif
2170d1ba665SWarner Losh 
2180d1ba665SWarner Losh ///
2190d1ba665SWarner Losh /// 128 bit buffer containing a unique identifier value.
2200d1ba665SWarner Losh /// Unless otherwise specified, aligned on a 64 bit boundary.
2210d1ba665SWarner Losh ///
2220d1ba665SWarner Losh typedef struct {
2230d1ba665SWarner Losh   UINT32  Data1;
2240d1ba665SWarner Losh   UINT16  Data2;
2250d1ba665SWarner Losh   UINT16  Data3;
2260d1ba665SWarner Losh   UINT8   Data4[8];
2270d1ba665SWarner Losh } GUID;
2280d1ba665SWarner Losh 
2290d1ba665SWarner Losh ///
2300d1ba665SWarner Losh /// 4-byte buffer. An IPv4 internet protocol address.
2310d1ba665SWarner Losh ///
2320d1ba665SWarner Losh typedef struct {
2330d1ba665SWarner Losh   UINT8 Addr[4];
2340d1ba665SWarner Losh } IPv4_ADDRESS;
2350d1ba665SWarner Losh 
2360d1ba665SWarner Losh ///
2370d1ba665SWarner Losh /// 16-byte buffer. An IPv6 internet protocol address.
2380d1ba665SWarner Losh ///
2390d1ba665SWarner Losh typedef struct {
2400d1ba665SWarner Losh   UINT8 Addr[16];
2410d1ba665SWarner Losh } IPv6_ADDRESS;
2420d1ba665SWarner Losh 
2430d1ba665SWarner Losh //
2440d1ba665SWarner Losh // 8-bytes unsigned value that represents a physical system address.
2450d1ba665SWarner Losh //
2460d1ba665SWarner Losh typedef UINT64 PHYSICAL_ADDRESS;
2470d1ba665SWarner Losh 
2480d1ba665SWarner Losh ///
2490d1ba665SWarner Losh /// LIST_ENTRY structure definition.
2500d1ba665SWarner Losh ///
2510d1ba665SWarner Losh typedef struct _LIST_ENTRY LIST_ENTRY;
2520d1ba665SWarner Losh 
2530d1ba665SWarner Losh ///
2540d1ba665SWarner Losh /// _LIST_ENTRY structure definition.
2550d1ba665SWarner Losh ///
2560d1ba665SWarner Losh struct _LIST_ENTRY {
2570d1ba665SWarner Losh   LIST_ENTRY  *ForwardLink;
2580d1ba665SWarner Losh   LIST_ENTRY  *BackLink;
2590d1ba665SWarner Losh };
2600d1ba665SWarner Losh 
2610d1ba665SWarner Losh //
2620d1ba665SWarner Losh // Modifiers to abstract standard types to aid in debug of problems
2630d1ba665SWarner Losh //
2640d1ba665SWarner Losh 
2650d1ba665SWarner Losh ///
2660d1ba665SWarner Losh /// Datum is read-only.
2670d1ba665SWarner Losh ///
2680d1ba665SWarner Losh #define CONST     const
2690d1ba665SWarner Losh 
2700d1ba665SWarner Losh ///
2710d1ba665SWarner Losh /// Datum is scoped to the current file or function.
2720d1ba665SWarner Losh ///
2730d1ba665SWarner Losh #define STATIC    static
2740d1ba665SWarner Losh 
2750d1ba665SWarner Losh ///
2760d1ba665SWarner Losh /// Undeclared type.
2770d1ba665SWarner Losh ///
2780d1ba665SWarner Losh #define VOID      void
2790d1ba665SWarner Losh 
2800d1ba665SWarner Losh //
2810d1ba665SWarner Losh // Modifiers for Data Types used to self document code.
2820d1ba665SWarner Losh // This concept is borrowed for UEFI specification.
2830d1ba665SWarner Losh //
2840d1ba665SWarner Losh 
2850d1ba665SWarner Losh ///
2860d1ba665SWarner Losh /// Datum is passed to the function.
2870d1ba665SWarner Losh ///
2880d1ba665SWarner Losh #define IN
2890d1ba665SWarner Losh 
2900d1ba665SWarner Losh ///
2910d1ba665SWarner Losh /// Datum is returned from the function.
2920d1ba665SWarner Losh ///
2930d1ba665SWarner Losh #define OUT
2940d1ba665SWarner Losh 
2950d1ba665SWarner Losh ///
2960d1ba665SWarner Losh /// Passing the datum to the function is optional, and a NULL
2970d1ba665SWarner Losh /// is passed if the value is not supplied.
2980d1ba665SWarner Losh ///
2990d1ba665SWarner Losh #define OPTIONAL
3000d1ba665SWarner Losh 
3010d1ba665SWarner Losh //
3020d1ba665SWarner Losh //  UEFI specification claims 1 and 0. We are concerned about the
3030d1ba665SWarner Losh //  compiler portability so we did it this way.
3040d1ba665SWarner Losh //
3050d1ba665SWarner Losh 
3060d1ba665SWarner Losh ///
3070d1ba665SWarner Losh /// Boolean true value.  UEFI Specification defines this value to be 1,
3080d1ba665SWarner Losh /// but this form is more portable.
3090d1ba665SWarner Losh ///
3100d1ba665SWarner Losh #define TRUE  ((BOOLEAN)(1==1))
3110d1ba665SWarner Losh 
3120d1ba665SWarner Losh ///
3130d1ba665SWarner Losh /// Boolean false value.  UEFI Specification defines this value to be 0,
3140d1ba665SWarner Losh /// but this form is more portable.
3150d1ba665SWarner Losh ///
3160d1ba665SWarner Losh #define FALSE ((BOOLEAN)(0==1))
3170d1ba665SWarner Losh 
3180d1ba665SWarner Losh ///
3190d1ba665SWarner Losh /// NULL pointer (VOID *)
3200d1ba665SWarner Losh ///
3210d1ba665SWarner Losh #define NULL  ((VOID *) 0)
3220d1ba665SWarner Losh 
3230d1ba665SWarner Losh //
3240d1ba665SWarner Losh // Null character
3250d1ba665SWarner Losh //
3260d1ba665SWarner Losh #define CHAR_NULL             0x0000
3270d1ba665SWarner Losh 
3280d1ba665SWarner Losh ///
3290d1ba665SWarner Losh /// Maximum values for common UEFI Data Types
3300d1ba665SWarner Losh ///
3310d1ba665SWarner Losh #define MAX_INT8    ((INT8)0x7F)
3320d1ba665SWarner Losh #define MAX_UINT8   ((UINT8)0xFF)
3330d1ba665SWarner Losh #define MAX_INT16   ((INT16)0x7FFF)
3340d1ba665SWarner Losh #define MAX_UINT16  ((UINT16)0xFFFF)
3350d1ba665SWarner Losh #define MAX_INT32   ((INT32)0x7FFFFFFF)
3360d1ba665SWarner Losh #define MAX_UINT32  ((UINT32)0xFFFFFFFF)
3370d1ba665SWarner Losh #define MAX_INT64   ((INT64)0x7FFFFFFFFFFFFFFFULL)
3380d1ba665SWarner Losh #define MAX_UINT64  ((UINT64)0xFFFFFFFFFFFFFFFFULL)
3390d1ba665SWarner Losh 
340*3245fa21SMitchell Horne ///
341*3245fa21SMitchell Horne /// Minimum values for the signed UEFI Data Types
342*3245fa21SMitchell Horne ///
343*3245fa21SMitchell Horne #define MIN_INT8   (((INT8)  -127) - 1)
344*3245fa21SMitchell Horne #define MIN_INT16  (((INT16) -32767) - 1)
345*3245fa21SMitchell Horne #define MIN_INT32  (((INT32) -2147483647) - 1)
346*3245fa21SMitchell Horne #define MIN_INT64  (((INT64) -9223372036854775807LL) - 1)
347*3245fa21SMitchell Horne 
3480d1ba665SWarner Losh #define  BIT0     0x00000001
3490d1ba665SWarner Losh #define  BIT1     0x00000002
3500d1ba665SWarner Losh #define  BIT2     0x00000004
3510d1ba665SWarner Losh #define  BIT3     0x00000008
3520d1ba665SWarner Losh #define  BIT4     0x00000010
3530d1ba665SWarner Losh #define  BIT5     0x00000020
3540d1ba665SWarner Losh #define  BIT6     0x00000040
3550d1ba665SWarner Losh #define  BIT7     0x00000080
3560d1ba665SWarner Losh #define  BIT8     0x00000100
3570d1ba665SWarner Losh #define  BIT9     0x00000200
3580d1ba665SWarner Losh #define  BIT10    0x00000400
3590d1ba665SWarner Losh #define  BIT11    0x00000800
3600d1ba665SWarner Losh #define  BIT12    0x00001000
3610d1ba665SWarner Losh #define  BIT13    0x00002000
3620d1ba665SWarner Losh #define  BIT14    0x00004000
3630d1ba665SWarner Losh #define  BIT15    0x00008000
3640d1ba665SWarner Losh #define  BIT16    0x00010000
3650d1ba665SWarner Losh #define  BIT17    0x00020000
3660d1ba665SWarner Losh #define  BIT18    0x00040000
3670d1ba665SWarner Losh #define  BIT19    0x00080000
3680d1ba665SWarner Losh #define  BIT20    0x00100000
3690d1ba665SWarner Losh #define  BIT21    0x00200000
3700d1ba665SWarner Losh #define  BIT22    0x00400000
3710d1ba665SWarner Losh #define  BIT23    0x00800000
3720d1ba665SWarner Losh #define  BIT24    0x01000000
3730d1ba665SWarner Losh #define  BIT25    0x02000000
3740d1ba665SWarner Losh #define  BIT26    0x04000000
3750d1ba665SWarner Losh #define  BIT27    0x08000000
3760d1ba665SWarner Losh #define  BIT28    0x10000000
3770d1ba665SWarner Losh #define  BIT29    0x20000000
3780d1ba665SWarner Losh #define  BIT30    0x40000000
3790d1ba665SWarner Losh #define  BIT31    0x80000000
3800d1ba665SWarner Losh #define  BIT32    0x0000000100000000ULL
3810d1ba665SWarner Losh #define  BIT33    0x0000000200000000ULL
3820d1ba665SWarner Losh #define  BIT34    0x0000000400000000ULL
3830d1ba665SWarner Losh #define  BIT35    0x0000000800000000ULL
3840d1ba665SWarner Losh #define  BIT36    0x0000001000000000ULL
3850d1ba665SWarner Losh #define  BIT37    0x0000002000000000ULL
3860d1ba665SWarner Losh #define  BIT38    0x0000004000000000ULL
3870d1ba665SWarner Losh #define  BIT39    0x0000008000000000ULL
3880d1ba665SWarner Losh #define  BIT40    0x0000010000000000ULL
3890d1ba665SWarner Losh #define  BIT41    0x0000020000000000ULL
3900d1ba665SWarner Losh #define  BIT42    0x0000040000000000ULL
3910d1ba665SWarner Losh #define  BIT43    0x0000080000000000ULL
3920d1ba665SWarner Losh #define  BIT44    0x0000100000000000ULL
3930d1ba665SWarner Losh #define  BIT45    0x0000200000000000ULL
3940d1ba665SWarner Losh #define  BIT46    0x0000400000000000ULL
3950d1ba665SWarner Losh #define  BIT47    0x0000800000000000ULL
3960d1ba665SWarner Losh #define  BIT48    0x0001000000000000ULL
3970d1ba665SWarner Losh #define  BIT49    0x0002000000000000ULL
3980d1ba665SWarner Losh #define  BIT50    0x0004000000000000ULL
3990d1ba665SWarner Losh #define  BIT51    0x0008000000000000ULL
4000d1ba665SWarner Losh #define  BIT52    0x0010000000000000ULL
4010d1ba665SWarner Losh #define  BIT53    0x0020000000000000ULL
4020d1ba665SWarner Losh #define  BIT54    0x0040000000000000ULL
4030d1ba665SWarner Losh #define  BIT55    0x0080000000000000ULL
4040d1ba665SWarner Losh #define  BIT56    0x0100000000000000ULL
4050d1ba665SWarner Losh #define  BIT57    0x0200000000000000ULL
4060d1ba665SWarner Losh #define  BIT58    0x0400000000000000ULL
4070d1ba665SWarner Losh #define  BIT59    0x0800000000000000ULL
4080d1ba665SWarner Losh #define  BIT60    0x1000000000000000ULL
4090d1ba665SWarner Losh #define  BIT61    0x2000000000000000ULL
4100d1ba665SWarner Losh #define  BIT62    0x4000000000000000ULL
4110d1ba665SWarner Losh #define  BIT63    0x8000000000000000ULL
4120d1ba665SWarner Losh 
4130d1ba665SWarner Losh #define  SIZE_1KB    0x00000400
4140d1ba665SWarner Losh #define  SIZE_2KB    0x00000800
4150d1ba665SWarner Losh #define  SIZE_4KB    0x00001000
4160d1ba665SWarner Losh #define  SIZE_8KB    0x00002000
4170d1ba665SWarner Losh #define  SIZE_16KB   0x00004000
4180d1ba665SWarner Losh #define  SIZE_32KB   0x00008000
4190d1ba665SWarner Losh #define  SIZE_64KB   0x00010000
4200d1ba665SWarner Losh #define  SIZE_128KB  0x00020000
4210d1ba665SWarner Losh #define  SIZE_256KB  0x00040000
4220d1ba665SWarner Losh #define  SIZE_512KB  0x00080000
4230d1ba665SWarner Losh #define  SIZE_1MB    0x00100000
4240d1ba665SWarner Losh #define  SIZE_2MB    0x00200000
4250d1ba665SWarner Losh #define  SIZE_4MB    0x00400000
4260d1ba665SWarner Losh #define  SIZE_8MB    0x00800000
4270d1ba665SWarner Losh #define  SIZE_16MB   0x01000000
4280d1ba665SWarner Losh #define  SIZE_32MB   0x02000000
4290d1ba665SWarner Losh #define  SIZE_64MB   0x04000000
4300d1ba665SWarner Losh #define  SIZE_128MB  0x08000000
4310d1ba665SWarner Losh #define  SIZE_256MB  0x10000000
4320d1ba665SWarner Losh #define  SIZE_512MB  0x20000000
4330d1ba665SWarner Losh #define  SIZE_1GB    0x40000000
4340d1ba665SWarner Losh #define  SIZE_2GB    0x80000000
4350d1ba665SWarner Losh #define  SIZE_4GB    0x0000000100000000ULL
4360d1ba665SWarner Losh #define  SIZE_8GB    0x0000000200000000ULL
4370d1ba665SWarner Losh #define  SIZE_16GB   0x0000000400000000ULL
4380d1ba665SWarner Losh #define  SIZE_32GB   0x0000000800000000ULL
4390d1ba665SWarner Losh #define  SIZE_64GB   0x0000001000000000ULL
4400d1ba665SWarner Losh #define  SIZE_128GB  0x0000002000000000ULL
4410d1ba665SWarner Losh #define  SIZE_256GB  0x0000004000000000ULL
4420d1ba665SWarner Losh #define  SIZE_512GB  0x0000008000000000ULL
4430d1ba665SWarner Losh #define  SIZE_1TB    0x0000010000000000ULL
4440d1ba665SWarner Losh #define  SIZE_2TB    0x0000020000000000ULL
4450d1ba665SWarner Losh #define  SIZE_4TB    0x0000040000000000ULL
4460d1ba665SWarner Losh #define  SIZE_8TB    0x0000080000000000ULL
4470d1ba665SWarner Losh #define  SIZE_16TB   0x0000100000000000ULL
4480d1ba665SWarner Losh #define  SIZE_32TB   0x0000200000000000ULL
4490d1ba665SWarner Losh #define  SIZE_64TB   0x0000400000000000ULL
4500d1ba665SWarner Losh #define  SIZE_128TB  0x0000800000000000ULL
4510d1ba665SWarner Losh #define  SIZE_256TB  0x0001000000000000ULL
4520d1ba665SWarner Losh #define  SIZE_512TB  0x0002000000000000ULL
4530d1ba665SWarner Losh #define  SIZE_1PB    0x0004000000000000ULL
4540d1ba665SWarner Losh #define  SIZE_2PB    0x0008000000000000ULL
4550d1ba665SWarner Losh #define  SIZE_4PB    0x0010000000000000ULL
4560d1ba665SWarner Losh #define  SIZE_8PB    0x0020000000000000ULL
4570d1ba665SWarner Losh #define  SIZE_16PB   0x0040000000000000ULL
4580d1ba665SWarner Losh #define  SIZE_32PB   0x0080000000000000ULL
4590d1ba665SWarner Losh #define  SIZE_64PB   0x0100000000000000ULL
4600d1ba665SWarner Losh #define  SIZE_128PB  0x0200000000000000ULL
4610d1ba665SWarner Losh #define  SIZE_256PB  0x0400000000000000ULL
4620d1ba665SWarner Losh #define  SIZE_512PB  0x0800000000000000ULL
4630d1ba665SWarner Losh #define  SIZE_1EB    0x1000000000000000ULL
4640d1ba665SWarner Losh #define  SIZE_2EB    0x2000000000000000ULL
4650d1ba665SWarner Losh #define  SIZE_4EB    0x4000000000000000ULL
4660d1ba665SWarner Losh #define  SIZE_8EB    0x8000000000000000ULL
4670d1ba665SWarner Losh 
4680d1ba665SWarner Losh #define  BASE_1KB    0x00000400
4690d1ba665SWarner Losh #define  BASE_2KB    0x00000800
4700d1ba665SWarner Losh #define  BASE_4KB    0x00001000
4710d1ba665SWarner Losh #define  BASE_8KB    0x00002000
4720d1ba665SWarner Losh #define  BASE_16KB   0x00004000
4730d1ba665SWarner Losh #define  BASE_32KB   0x00008000
4740d1ba665SWarner Losh #define  BASE_64KB   0x00010000
4750d1ba665SWarner Losh #define  BASE_128KB  0x00020000
4760d1ba665SWarner Losh #define  BASE_256KB  0x00040000
4770d1ba665SWarner Losh #define  BASE_512KB  0x00080000
4780d1ba665SWarner Losh #define  BASE_1MB    0x00100000
4790d1ba665SWarner Losh #define  BASE_2MB    0x00200000
4800d1ba665SWarner Losh #define  BASE_4MB    0x00400000
4810d1ba665SWarner Losh #define  BASE_8MB    0x00800000
4820d1ba665SWarner Losh #define  BASE_16MB   0x01000000
4830d1ba665SWarner Losh #define  BASE_32MB   0x02000000
4840d1ba665SWarner Losh #define  BASE_64MB   0x04000000
4850d1ba665SWarner Losh #define  BASE_128MB  0x08000000
4860d1ba665SWarner Losh #define  BASE_256MB  0x10000000
4870d1ba665SWarner Losh #define  BASE_512MB  0x20000000
4880d1ba665SWarner Losh #define  BASE_1GB    0x40000000
4890d1ba665SWarner Losh #define  BASE_2GB    0x80000000
4900d1ba665SWarner Losh #define  BASE_4GB    0x0000000100000000ULL
4910d1ba665SWarner Losh #define  BASE_8GB    0x0000000200000000ULL
4920d1ba665SWarner Losh #define  BASE_16GB   0x0000000400000000ULL
4930d1ba665SWarner Losh #define  BASE_32GB   0x0000000800000000ULL
4940d1ba665SWarner Losh #define  BASE_64GB   0x0000001000000000ULL
4950d1ba665SWarner Losh #define  BASE_128GB  0x0000002000000000ULL
4960d1ba665SWarner Losh #define  BASE_256GB  0x0000004000000000ULL
4970d1ba665SWarner Losh #define  BASE_512GB  0x0000008000000000ULL
4980d1ba665SWarner Losh #define  BASE_1TB    0x0000010000000000ULL
4990d1ba665SWarner Losh #define  BASE_2TB    0x0000020000000000ULL
5000d1ba665SWarner Losh #define  BASE_4TB    0x0000040000000000ULL
5010d1ba665SWarner Losh #define  BASE_8TB    0x0000080000000000ULL
5020d1ba665SWarner Losh #define  BASE_16TB   0x0000100000000000ULL
5030d1ba665SWarner Losh #define  BASE_32TB   0x0000200000000000ULL
5040d1ba665SWarner Losh #define  BASE_64TB   0x0000400000000000ULL
5050d1ba665SWarner Losh #define  BASE_128TB  0x0000800000000000ULL
5060d1ba665SWarner Losh #define  BASE_256TB  0x0001000000000000ULL
5070d1ba665SWarner Losh #define  BASE_512TB  0x0002000000000000ULL
5080d1ba665SWarner Losh #define  BASE_1PB    0x0004000000000000ULL
5090d1ba665SWarner Losh #define  BASE_2PB    0x0008000000000000ULL
5100d1ba665SWarner Losh #define  BASE_4PB    0x0010000000000000ULL
5110d1ba665SWarner Losh #define  BASE_8PB    0x0020000000000000ULL
5120d1ba665SWarner Losh #define  BASE_16PB   0x0040000000000000ULL
5130d1ba665SWarner Losh #define  BASE_32PB   0x0080000000000000ULL
5140d1ba665SWarner Losh #define  BASE_64PB   0x0100000000000000ULL
5150d1ba665SWarner Losh #define  BASE_128PB  0x0200000000000000ULL
5160d1ba665SWarner Losh #define  BASE_256PB  0x0400000000000000ULL
5170d1ba665SWarner Losh #define  BASE_512PB  0x0800000000000000ULL
5180d1ba665SWarner Losh #define  BASE_1EB    0x1000000000000000ULL
5190d1ba665SWarner Losh #define  BASE_2EB    0x2000000000000000ULL
5200d1ba665SWarner Losh #define  BASE_4EB    0x4000000000000000ULL
5210d1ba665SWarner Losh #define  BASE_8EB    0x8000000000000000ULL
5220d1ba665SWarner Losh 
5230d1ba665SWarner Losh //
524*3245fa21SMitchell Horne //  Support for variable argument lists in freestanding edk2 modules.
5250d1ba665SWarner Losh //
526*3245fa21SMitchell Horne //  For modules that use the ISO C library interfaces for variable
527*3245fa21SMitchell Horne //  argument lists, refer to "StdLib/Include/stdarg.h".
5280d1ba665SWarner Losh //
5290d1ba665SWarner Losh //  VA_LIST  - typedef for argument list.
5300d1ba665SWarner Losh //  VA_START (VA_LIST Marker, argument before the ...) - Init Marker for use.
5310d1ba665SWarner Losh //  VA_END (VA_LIST Marker) - Clear Marker
532*3245fa21SMitchell Horne //  VA_ARG (VA_LIST Marker, var arg type) - Use Marker to get an argument from
533*3245fa21SMitchell Horne //    the ... list. You must know the type and pass it in this macro.  Type
534*3245fa21SMitchell Horne //    must be compatible with the type of the actual next argument (as promoted
535*3245fa21SMitchell Horne //    according to the default argument promotions.)
5360d1ba665SWarner Losh //  VA_COPY (VA_LIST Dest, VA_LIST Start) - Initialize Dest as a copy of Start.
5370d1ba665SWarner Losh //
538*3245fa21SMitchell Horne //  Example:
5390d1ba665SWarner Losh //
5400d1ba665SWarner Losh //  UINTN
541*3245fa21SMitchell Horne //  EFIAPI
5420d1ba665SWarner Losh //  ExampleVarArg (
5430d1ba665SWarner Losh //    IN UINTN  NumberOfArgs,
5440d1ba665SWarner Losh //    ...
5450d1ba665SWarner Losh //    )
5460d1ba665SWarner Losh //  {
5470d1ba665SWarner Losh //    VA_LIST Marker;
5480d1ba665SWarner Losh //    UINTN   Index;
5490d1ba665SWarner Losh //    UINTN   Result;
5500d1ba665SWarner Losh //
5510d1ba665SWarner Losh //    //
5520d1ba665SWarner Losh //    // Initialize the Marker
5530d1ba665SWarner Losh //    //
5540d1ba665SWarner Losh //    VA_START (Marker, NumberOfArgs);
5550d1ba665SWarner Losh //    for (Index = 0, Result = 0; Index < NumberOfArgs; Index++) {
5560d1ba665SWarner Losh //      //
557*3245fa21SMitchell Horne //      // The ... list is a series of UINTN values, so sum them up.
5580d1ba665SWarner Losh //      //
5590d1ba665SWarner Losh //      Result += VA_ARG (Marker, UINTN);
5600d1ba665SWarner Losh //    }
5610d1ba665SWarner Losh //
5620d1ba665SWarner Losh //    VA_END (Marker);
563*3245fa21SMitchell Horne //    return Result;
5640d1ba665SWarner Losh //  }
5650d1ba665SWarner Losh //
566*3245fa21SMitchell Horne //  Notes:
567*3245fa21SMitchell Horne //  - Functions that call VA_START() / VA_END() must have a variable
568*3245fa21SMitchell Horne //    argument list and must be declared EFIAPI.
569*3245fa21SMitchell Horne //  - Functions that call VA_COPY() / VA_END() must be declared EFIAPI.
570*3245fa21SMitchell Horne //  - Functions that only use VA_LIST and VA_ARG() need not be EFIAPI.
571*3245fa21SMitchell Horne //
5720d1ba665SWarner Losh 
5730d1ba665SWarner Losh /**
5740d1ba665SWarner Losh   Return the size of argument that has been aligned to sizeof (UINTN).
5750d1ba665SWarner Losh 
5760d1ba665SWarner Losh   @param  n    The parameter size to be aligned.
5770d1ba665SWarner Losh 
5780d1ba665SWarner Losh   @return The aligned size.
5790d1ba665SWarner Losh **/
5800d1ba665SWarner Losh #define _INT_SIZE_OF(n) ((sizeof (n) + sizeof (UINTN) - 1) &~(sizeof (UINTN) - 1))
5810d1ba665SWarner Losh 
5820d1ba665SWarner Losh #if defined(__CC_ARM)
5830d1ba665SWarner Losh //
5840d1ba665SWarner Losh // RVCT ARM variable argument list support.
5850d1ba665SWarner Losh //
5860d1ba665SWarner Losh 
5870d1ba665SWarner Losh ///
5880d1ba665SWarner Losh /// Variable used to traverse the list of arguments. This type can vary by
5890d1ba665SWarner Losh /// implementation and could be an array or structure.
5900d1ba665SWarner Losh ///
5910d1ba665SWarner Losh #ifdef __APCS_ADSABI
5920d1ba665SWarner Losh   typedef int         *va_list[1];
5930d1ba665SWarner Losh   #define VA_LIST     va_list
5940d1ba665SWarner Losh #else
5950d1ba665SWarner Losh   typedef struct __va_list { void *__ap; } va_list;
5960d1ba665SWarner Losh   #define VA_LIST                          va_list
5970d1ba665SWarner Losh #endif
5980d1ba665SWarner Losh 
5990d1ba665SWarner Losh #define VA_START(Marker, Parameter)   __va_start(Marker, Parameter)
6000d1ba665SWarner Losh 
6010d1ba665SWarner Losh #define VA_ARG(Marker, TYPE)          __va_arg(Marker, TYPE)
6020d1ba665SWarner Losh 
6030d1ba665SWarner Losh #define VA_END(Marker)                ((void)0)
6040d1ba665SWarner Losh 
6050d1ba665SWarner Losh // For some ARM RVCT compilers, __va_copy is not defined
6060d1ba665SWarner Losh #ifndef __va_copy
6070d1ba665SWarner Losh   #define __va_copy(dest, src) ((void)((dest) = (src)))
6080d1ba665SWarner Losh #endif
6090d1ba665SWarner Losh 
6100d1ba665SWarner Losh #define VA_COPY(Dest, Start)          __va_copy (Dest, Start)
6110d1ba665SWarner Losh 
612*3245fa21SMitchell Horne #elif defined(_M_ARM) || defined(_M_ARM64)
613*3245fa21SMitchell Horne //
614*3245fa21SMitchell Horne // MSFT ARM variable argument list support.
615*3245fa21SMitchell Horne //
616*3245fa21SMitchell Horne 
617*3245fa21SMitchell Horne typedef char* VA_LIST;
618*3245fa21SMitchell Horne 
619*3245fa21SMitchell Horne #define VA_START(Marker, Parameter)     __va_start (&Marker, &Parameter, _INT_SIZE_OF (Parameter), __alignof(Parameter), &Parameter)
620*3245fa21SMitchell Horne #define VA_ARG(Marker, TYPE)            (*(TYPE *) ((Marker += _INT_SIZE_OF (TYPE) + ((-(INTN)Marker) & (sizeof(TYPE) - 1))) - _INT_SIZE_OF (TYPE)))
621*3245fa21SMitchell Horne #define VA_END(Marker)                  (Marker = (VA_LIST) 0)
622*3245fa21SMitchell Horne #define VA_COPY(Dest, Start)            ((void)((Dest) = (Start)))
623*3245fa21SMitchell Horne 
624*3245fa21SMitchell Horne #elif defined(__GNUC__) || defined(__clang__)
6250d1ba665SWarner Losh 
6260d1ba665SWarner Losh #if defined(MDE_CPU_X64) && !defined(NO_MSABI_VA_FUNCS)
6270d1ba665SWarner Losh //
6280d1ba665SWarner Losh // X64 only. Use MS ABI version of GCC built-in macros for variable argument lists.
6290d1ba665SWarner Losh //
6300d1ba665SWarner Losh ///
6310d1ba665SWarner Losh /// Both GCC and LLVM 3.8 for X64 support new variable argument intrinsics for Microsoft ABI
6320d1ba665SWarner Losh ///
6330d1ba665SWarner Losh 
6340d1ba665SWarner Losh ///
6350d1ba665SWarner Losh /// Variable used to traverse the list of arguments. This type can vary by
6360d1ba665SWarner Losh /// implementation and could be an array or structure.
6370d1ba665SWarner Losh ///
6380d1ba665SWarner Losh typedef __builtin_ms_va_list VA_LIST;
6390d1ba665SWarner Losh 
6400d1ba665SWarner Losh #define VA_START(Marker, Parameter)  __builtin_ms_va_start (Marker, Parameter)
6410d1ba665SWarner Losh 
6420d1ba665SWarner Losh #define VA_ARG(Marker, TYPE)         ((sizeof (TYPE) < sizeof (UINTN)) ? (TYPE)(__builtin_va_arg (Marker, UINTN)) : (TYPE)(__builtin_va_arg (Marker, TYPE)))
6430d1ba665SWarner Losh 
6440d1ba665SWarner Losh #define VA_END(Marker)               __builtin_ms_va_end (Marker)
6450d1ba665SWarner Losh 
6460d1ba665SWarner Losh #define VA_COPY(Dest, Start)         __builtin_ms_va_copy (Dest, Start)
6470d1ba665SWarner Losh 
6480d1ba665SWarner Losh #else
6490d1ba665SWarner Losh //
6500d1ba665SWarner Losh // Use GCC built-in macros for variable argument lists.
6510d1ba665SWarner Losh //
6520d1ba665SWarner Losh 
6530d1ba665SWarner Losh ///
6540d1ba665SWarner Losh /// Variable used to traverse the list of arguments. This type can vary by
6550d1ba665SWarner Losh /// implementation and could be an array or structure.
6560d1ba665SWarner Losh ///
6570d1ba665SWarner Losh typedef __builtin_va_list VA_LIST;
6580d1ba665SWarner Losh 
6590d1ba665SWarner Losh #define VA_START(Marker, Parameter)  __builtin_va_start (Marker, Parameter)
6600d1ba665SWarner Losh 
6610d1ba665SWarner Losh #define VA_ARG(Marker, TYPE)         ((sizeof (TYPE) < sizeof (UINTN)) ? (TYPE)(__builtin_va_arg (Marker, UINTN)) : (TYPE)(__builtin_va_arg (Marker, TYPE)))
6620d1ba665SWarner Losh 
6630d1ba665SWarner Losh #define VA_END(Marker)               __builtin_va_end (Marker)
6640d1ba665SWarner Losh 
6650d1ba665SWarner Losh #define VA_COPY(Dest, Start)         __builtin_va_copy (Dest, Start)
6660d1ba665SWarner Losh 
6670d1ba665SWarner Losh #endif
6680d1ba665SWarner Losh 
6690d1ba665SWarner Losh #else
6700d1ba665SWarner Losh ///
6710d1ba665SWarner Losh /// Variable used to traverse the list of arguments. This type can vary by
6720d1ba665SWarner Losh /// implementation and could be an array or structure.
6730d1ba665SWarner Losh ///
6740d1ba665SWarner Losh typedef CHAR8 *VA_LIST;
6750d1ba665SWarner Losh 
6760d1ba665SWarner Losh /**
6770d1ba665SWarner Losh   Retrieves a pointer to the beginning of a variable argument list, based on
6780d1ba665SWarner Losh   the name of the parameter that immediately precedes the variable argument list.
6790d1ba665SWarner Losh 
6800d1ba665SWarner Losh   This function initializes Marker to point to the beginning of the variable
6810d1ba665SWarner Losh   argument list that immediately follows Parameter.  The method for computing the
6820d1ba665SWarner Losh   pointer to the next argument in the argument list is CPU-specific following the
6830d1ba665SWarner Losh   EFIAPI ABI.
6840d1ba665SWarner Losh 
6850d1ba665SWarner Losh   @param   Marker       The VA_LIST used to traverse the list of arguments.
6860d1ba665SWarner Losh   @param   Parameter    The name of the parameter that immediately precedes
6870d1ba665SWarner Losh                         the variable argument list.
6880d1ba665SWarner Losh 
6890d1ba665SWarner Losh   @return  A pointer to the beginning of a variable argument list.
6900d1ba665SWarner Losh 
6910d1ba665SWarner Losh **/
6920d1ba665SWarner Losh #define VA_START(Marker, Parameter) (Marker = (VA_LIST) ((UINTN) & (Parameter) + _INT_SIZE_OF (Parameter)))
6930d1ba665SWarner Losh 
6940d1ba665SWarner Losh /**
6950d1ba665SWarner Losh   Returns an argument of a specified type from a variable argument list and updates
6960d1ba665SWarner Losh   the pointer to the variable argument list to point to the next argument.
6970d1ba665SWarner Losh 
6980d1ba665SWarner Losh   This function returns an argument of the type specified by TYPE from the beginning
6990d1ba665SWarner Losh   of the variable argument list specified by Marker.  Marker is then updated to point
7000d1ba665SWarner Losh   to the next argument in the variable argument list.  The method for computing the
7010d1ba665SWarner Losh   pointer to the next argument in the argument list is CPU-specific following the EFIAPI ABI.
7020d1ba665SWarner Losh 
7030d1ba665SWarner Losh   @param   Marker   VA_LIST used to traverse the list of arguments.
7040d1ba665SWarner Losh   @param   TYPE     The type of argument to retrieve from the beginning
7050d1ba665SWarner Losh                     of the variable argument list.
7060d1ba665SWarner Losh 
7070d1ba665SWarner Losh   @return  An argument of the type specified by TYPE.
7080d1ba665SWarner Losh 
7090d1ba665SWarner Losh **/
7100d1ba665SWarner Losh #define VA_ARG(Marker, TYPE)   (*(TYPE *) ((Marker += _INT_SIZE_OF (TYPE)) - _INT_SIZE_OF (TYPE)))
7110d1ba665SWarner Losh 
7120d1ba665SWarner Losh /**
7130d1ba665SWarner Losh   Terminates the use of a variable argument list.
7140d1ba665SWarner Losh 
7150d1ba665SWarner Losh   This function initializes Marker so it can no longer be used with VA_ARG().
7160d1ba665SWarner Losh   After this macro is used, the only way to access the variable argument list is
7170d1ba665SWarner Losh   by using VA_START() again.
7180d1ba665SWarner Losh 
7190d1ba665SWarner Losh   @param   Marker   VA_LIST used to traverse the list of arguments.
7200d1ba665SWarner Losh 
7210d1ba665SWarner Losh **/
7220d1ba665SWarner Losh #define VA_END(Marker)      (Marker = (VA_LIST) 0)
7230d1ba665SWarner Losh 
7240d1ba665SWarner Losh /**
7250d1ba665SWarner Losh   Initializes a VA_LIST as a copy of an existing VA_LIST.
7260d1ba665SWarner Losh 
7270d1ba665SWarner Losh   This macro initializes Dest as a copy of Start, as if the VA_START macro had been applied to Dest
7280d1ba665SWarner Losh   followed by the same sequence of uses of the VA_ARG macro as had previously been used to reach
7290d1ba665SWarner Losh   the present state of Start.
7300d1ba665SWarner Losh 
7310d1ba665SWarner Losh   @param   Dest   VA_LIST used to traverse the list of arguments.
7320d1ba665SWarner Losh   @param   Start  VA_LIST used to traverse the list of arguments.
7330d1ba665SWarner Losh 
7340d1ba665SWarner Losh **/
7350d1ba665SWarner Losh #define VA_COPY(Dest, Start)  ((void)((Dest) = (Start)))
7360d1ba665SWarner Losh 
7370d1ba665SWarner Losh #endif
7380d1ba665SWarner Losh 
7390d1ba665SWarner Losh ///
7400d1ba665SWarner Losh /// Pointer to the start of a variable argument list stored in a memory buffer. Same as UINT8 *.
7410d1ba665SWarner Losh ///
7420d1ba665SWarner Losh typedef UINTN  *BASE_LIST;
7430d1ba665SWarner Losh 
7440d1ba665SWarner Losh /**
7450d1ba665SWarner Losh   Returns the size of a data type in sizeof(UINTN) units rounded up to the nearest UINTN boundary.
7460d1ba665SWarner Losh 
7470d1ba665SWarner Losh   @param  TYPE  The date type to determine the size of.
7480d1ba665SWarner Losh 
7490d1ba665SWarner Losh   @return The size of TYPE in sizeof (UINTN) units rounded up to the nearest UINTN boundary.
7500d1ba665SWarner Losh **/
7510d1ba665SWarner Losh #define _BASE_INT_SIZE_OF(TYPE) ((sizeof (TYPE) + sizeof (UINTN) - 1) / sizeof (UINTN))
7520d1ba665SWarner Losh 
7530d1ba665SWarner Losh /**
7540d1ba665SWarner Losh   Returns an argument of a specified type from a variable argument list and updates
7550d1ba665SWarner Losh   the pointer to the variable argument list to point to the next argument.
7560d1ba665SWarner Losh 
7570d1ba665SWarner Losh   This function returns an argument of the type specified by TYPE from the beginning
7580d1ba665SWarner Losh   of the variable argument list specified by Marker.  Marker is then updated to point
7590d1ba665SWarner Losh   to the next argument in the variable argument list.  The method for computing the
7600d1ba665SWarner Losh   pointer to the next argument in the argument list is CPU specific following the EFIAPI ABI.
7610d1ba665SWarner Losh 
7620d1ba665SWarner Losh   @param   Marker   The pointer to the beginning of a variable argument list.
7630d1ba665SWarner Losh   @param   TYPE     The type of argument to retrieve from the beginning
7640d1ba665SWarner Losh                     of the variable argument list.
7650d1ba665SWarner Losh 
7660d1ba665SWarner Losh   @return  An argument of the type specified by TYPE.
7670d1ba665SWarner Losh 
7680d1ba665SWarner Losh **/
7690d1ba665SWarner Losh #define BASE_ARG(Marker, TYPE)   (*(TYPE *) ((Marker += _BASE_INT_SIZE_OF (TYPE)) - _BASE_INT_SIZE_OF (TYPE)))
7700d1ba665SWarner Losh 
7710d1ba665SWarner Losh /**
7720d1ba665SWarner Losh   The macro that returns the byte offset of a field in a data structure.
7730d1ba665SWarner Losh 
7740d1ba665SWarner Losh   This function returns the offset, in bytes, of field specified by Field from the
7750d1ba665SWarner Losh   beginning of the  data structure specified by TYPE. If TYPE does not contain Field,
7760d1ba665SWarner Losh   the module will not compile.
7770d1ba665SWarner Losh 
7780d1ba665SWarner Losh   @param   TYPE     The name of the data structure that contains the field specified by Field.
7790d1ba665SWarner Losh   @param   Field    The name of the field in the data structure.
7800d1ba665SWarner Losh 
7810d1ba665SWarner Losh   @return  Offset, in bytes, of field.
7820d1ba665SWarner Losh 
7830d1ba665SWarner Losh **/
784*3245fa21SMitchell Horne #if (defined(__GNUC__) && __GNUC__ >= 4) || defined(__clang__)
7850d1ba665SWarner Losh #define OFFSET_OF(TYPE, Field) ((UINTN) __builtin_offsetof(TYPE, Field))
7860d1ba665SWarner Losh #endif
7870d1ba665SWarner Losh 
7880d1ba665SWarner Losh #ifndef OFFSET_OF
7890d1ba665SWarner Losh #define OFFSET_OF(TYPE, Field) ((UINTN) &(((TYPE *)0)->Field))
7900d1ba665SWarner Losh #endif
7910d1ba665SWarner Losh 
7920d1ba665SWarner Losh /**
793*3245fa21SMitchell Horne   Portable definition for compile time assertions.
794*3245fa21SMitchell Horne   Equivalent to C11 static_assert macro from assert.h.
795*3245fa21SMitchell Horne 
796*3245fa21SMitchell Horne   @param  Expression  Boolean expression.
797*3245fa21SMitchell Horne   @param  Message     Raised compiler diagnostic message when expression is false.
798*3245fa21SMitchell Horne 
799*3245fa21SMitchell Horne **/
800*3245fa21SMitchell Horne #ifdef MDE_CPU_EBC
801*3245fa21SMitchell Horne   #define STATIC_ASSERT(Expression, Message)
802*3245fa21SMitchell Horne #elif defined(_MSC_EXTENSIONS)
803*3245fa21SMitchell Horne   #define STATIC_ASSERT static_assert
804*3245fa21SMitchell Horne #else
805*3245fa21SMitchell Horne   #define STATIC_ASSERT _Static_assert
806*3245fa21SMitchell Horne #endif
807*3245fa21SMitchell Horne 
808*3245fa21SMitchell Horne //
809*3245fa21SMitchell Horne // Verify that ProcessorBind.h produced UEFI Data Types that are compliant with
810*3245fa21SMitchell Horne // Section 2.3.1 of the UEFI 2.3 Specification.
811*3245fa21SMitchell Horne //
812*3245fa21SMitchell Horne 
813*3245fa21SMitchell Horne STATIC_ASSERT (sizeof (BOOLEAN) == 1, "sizeof (BOOLEAN) does not meet UEFI Specification Data Type requirements");
814*3245fa21SMitchell Horne STATIC_ASSERT (sizeof (INT8)    == 1, "sizeof (INT8) does not meet UEFI Specification Data Type requirements");
815*3245fa21SMitchell Horne STATIC_ASSERT (sizeof (UINT8)   == 1, "sizeof (UINT8) does not meet UEFI Specification Data Type requirements");
816*3245fa21SMitchell Horne STATIC_ASSERT (sizeof (INT16)   == 2, "sizeof (INT16) does not meet UEFI Specification Data Type requirements");
817*3245fa21SMitchell Horne STATIC_ASSERT (sizeof (UINT16)  == 2, "sizeof (UINT16) does not meet UEFI Specification Data Type requirements");
818*3245fa21SMitchell Horne STATIC_ASSERT (sizeof (INT32)   == 4, "sizeof (INT32) does not meet UEFI Specification Data Type requirements");
819*3245fa21SMitchell Horne STATIC_ASSERT (sizeof (UINT32)  == 4, "sizeof (UINT32) does not meet UEFI Specification Data Type requirements");
820*3245fa21SMitchell Horne STATIC_ASSERT (sizeof (INT64)   == 8, "sizeof (INT64) does not meet UEFI Specification Data Type requirements");
821*3245fa21SMitchell Horne STATIC_ASSERT (sizeof (UINT64)  == 8, "sizeof (UINT64) does not meet UEFI Specification Data Type requirements");
822*3245fa21SMitchell Horne STATIC_ASSERT (sizeof (CHAR8)   == 1, "sizeof (CHAR8) does not meet UEFI Specification Data Type requirements");
823*3245fa21SMitchell Horne STATIC_ASSERT (sizeof (CHAR16)  == 2, "sizeof (CHAR16) does not meet UEFI Specification Data Type requirements");
824*3245fa21SMitchell Horne 
825*3245fa21SMitchell Horne //
826*3245fa21SMitchell Horne // The following three enum types are used to verify that the compiler
827*3245fa21SMitchell Horne // configuration for enum types is compliant with Section 2.3.1 of the
828*3245fa21SMitchell Horne // UEFI 2.3 Specification. These enum types and enum values are not
829*3245fa21SMitchell Horne // intended to be used. A prefix of '__' is used avoid conflicts with
830*3245fa21SMitchell Horne // other types.
831*3245fa21SMitchell Horne //
832*3245fa21SMitchell Horne typedef enum {
833*3245fa21SMitchell Horne   __VerifyUint8EnumValue = 0xff
834*3245fa21SMitchell Horne } __VERIFY_UINT8_ENUM_SIZE;
835*3245fa21SMitchell Horne 
836*3245fa21SMitchell Horne typedef enum {
837*3245fa21SMitchell Horne   __VerifyUint16EnumValue = 0xffff
838*3245fa21SMitchell Horne } __VERIFY_UINT16_ENUM_SIZE;
839*3245fa21SMitchell Horne 
840*3245fa21SMitchell Horne typedef enum {
841*3245fa21SMitchell Horne   __VerifyUint32EnumValue = 0xffffffff
842*3245fa21SMitchell Horne } __VERIFY_UINT32_ENUM_SIZE;
843*3245fa21SMitchell Horne 
844*3245fa21SMitchell Horne STATIC_ASSERT (sizeof (__VERIFY_UINT8_ENUM_SIZE) == 4, "Size of enum does not meet UEFI Specification Data Type requirements");
845*3245fa21SMitchell Horne STATIC_ASSERT (sizeof (__VERIFY_UINT16_ENUM_SIZE) == 4, "Size of enum does not meet UEFI Specification Data Type requirements");
846*3245fa21SMitchell Horne STATIC_ASSERT (sizeof (__VERIFY_UINT32_ENUM_SIZE) == 4, "Size of enum does not meet UEFI Specification Data Type requirements");
847*3245fa21SMitchell Horne 
848*3245fa21SMitchell Horne /**
8490d1ba665SWarner Losh   Macro that returns a pointer to the data structure that contains a specified field of
8500d1ba665SWarner Losh   that data structure.  This is a lightweight method to hide information by placing a
8510d1ba665SWarner Losh   public data structure inside a larger private data structure and using a pointer to
8520d1ba665SWarner Losh   the public data structure to retrieve a pointer to the private data structure.
8530d1ba665SWarner Losh 
8540d1ba665SWarner Losh   This function computes the offset, in bytes, of field specified by Field from the beginning
8550d1ba665SWarner Losh   of the  data structure specified by TYPE.  This offset is subtracted from Record, and is
8560d1ba665SWarner Losh   used to return a pointer to a data structure of the type specified by TYPE. If the data type
8570d1ba665SWarner Losh   specified by TYPE does not contain the field specified by Field, then the module will not compile.
8580d1ba665SWarner Losh 
8590d1ba665SWarner Losh   @param   Record   Pointer to the field specified by Field within a data structure of type TYPE.
8600d1ba665SWarner Losh   @param   TYPE     The name of the data structure type to return.  This data structure must
8610d1ba665SWarner Losh                     contain the field specified by Field.
8620d1ba665SWarner Losh   @param   Field    The name of the field in the data structure specified by TYPE to which Record points.
8630d1ba665SWarner Losh 
8640d1ba665SWarner Losh   @return  A pointer to the structure from one of it's elements.
8650d1ba665SWarner Losh 
8660d1ba665SWarner Losh **/
867*3245fa21SMitchell Horne #define BASE_CR(Record, TYPE, Field)  ((TYPE *) ((CHAR8 *) (Record) - OFFSET_OF (TYPE, Field)))
8680d1ba665SWarner Losh 
8690d1ba665SWarner Losh /**
8700d1ba665SWarner Losh   Rounds a value up to the next boundary using a specified alignment.
8710d1ba665SWarner Losh 
8720d1ba665SWarner Losh   This function rounds Value up to the next boundary using the specified Alignment.
8730d1ba665SWarner Losh   This aligned value is returned.
8740d1ba665SWarner Losh 
8750d1ba665SWarner Losh   @param   Value      The value to round up.
8760d1ba665SWarner Losh   @param   Alignment  The alignment boundary used to return the aligned value.
8770d1ba665SWarner Losh 
8780d1ba665SWarner Losh   @return  A value up to the next boundary.
8790d1ba665SWarner Losh 
8800d1ba665SWarner Losh **/
8810d1ba665SWarner Losh #define ALIGN_VALUE(Value, Alignment) ((Value) + (((Alignment) - (Value)) & ((Alignment) - 1)))
8820d1ba665SWarner Losh 
8830d1ba665SWarner Losh /**
8840d1ba665SWarner Losh   Adjust a pointer by adding the minimum offset required for it to be aligned on
8850d1ba665SWarner Losh   a specified alignment boundary.
8860d1ba665SWarner Losh 
8870d1ba665SWarner Losh   This function rounds the pointer specified by Pointer to the next alignment boundary
8880d1ba665SWarner Losh   specified by Alignment. The pointer to the aligned address is returned.
8890d1ba665SWarner Losh 
8900d1ba665SWarner Losh   @param   Pointer    The pointer to round up.
8910d1ba665SWarner Losh   @param   Alignment  The alignment boundary to use to return an aligned pointer.
8920d1ba665SWarner Losh 
8930d1ba665SWarner Losh   @return  Pointer to the aligned address.
8940d1ba665SWarner Losh 
8950d1ba665SWarner Losh **/
8960d1ba665SWarner Losh #define ALIGN_POINTER(Pointer, Alignment) ((VOID *) (ALIGN_VALUE ((UINTN)(Pointer), (Alignment))))
8970d1ba665SWarner Losh 
8980d1ba665SWarner Losh /**
8990d1ba665SWarner Losh   Rounds a value up to the next natural boundary for the current CPU.
9000d1ba665SWarner Losh   This is 4-bytes for 32-bit CPUs and 8-bytes for 64-bit CPUs.
9010d1ba665SWarner Losh 
9020d1ba665SWarner Losh   This function rounds the value specified by Value up to the next natural boundary for the
9030d1ba665SWarner Losh   current CPU. This rounded value is returned.
9040d1ba665SWarner Losh 
9050d1ba665SWarner Losh   @param   Value      The value to round up.
9060d1ba665SWarner Losh 
9070d1ba665SWarner Losh   @return  Rounded value specified by Value.
9080d1ba665SWarner Losh 
9090d1ba665SWarner Losh **/
9100d1ba665SWarner Losh #define ALIGN_VARIABLE(Value)  ALIGN_VALUE ((Value), sizeof (UINTN))
9110d1ba665SWarner Losh 
9120d1ba665SWarner Losh 
9130d1ba665SWarner Losh /**
9140d1ba665SWarner Losh   Return the maximum of two operands.
9150d1ba665SWarner Losh 
9160d1ba665SWarner Losh   This macro returns the maximum of two operand specified by a and b.
9170d1ba665SWarner Losh   Both a and b must be the same numerical types, signed or unsigned.
9180d1ba665SWarner Losh 
9190d1ba665SWarner Losh   @param   a        The first operand with any numerical type.
9200d1ba665SWarner Losh   @param   b        The second operand. Can be any numerical type as long as is
9210d1ba665SWarner Losh                     the same type as a.
9220d1ba665SWarner Losh 
9230d1ba665SWarner Losh   @return  Maximum of two operands.
9240d1ba665SWarner Losh 
9250d1ba665SWarner Losh **/
9260d1ba665SWarner Losh #define MAX(a, b)                       \
9270d1ba665SWarner Losh   (((a) > (b)) ? (a) : (b))
9280d1ba665SWarner Losh 
9290d1ba665SWarner Losh /**
9300d1ba665SWarner Losh   Return the minimum of two operands.
9310d1ba665SWarner Losh 
9320d1ba665SWarner Losh   This macro returns the minimal of two operand specified by a and b.
9330d1ba665SWarner Losh   Both a and b must be the same numerical types, signed or unsigned.
9340d1ba665SWarner Losh 
9350d1ba665SWarner Losh   @param   a        The first operand with any numerical type.
9360d1ba665SWarner Losh   @param   b        The second operand. It should be the same any numerical type with a.
9370d1ba665SWarner Losh 
9380d1ba665SWarner Losh   @return  Minimum of two operands.
9390d1ba665SWarner Losh 
9400d1ba665SWarner Losh **/
9410d1ba665SWarner Losh #define MIN(a, b)                       \
9420d1ba665SWarner Losh   (((a) < (b)) ? (a) : (b))
9430d1ba665SWarner Losh 
9440d1ba665SWarner Losh /**
9450d1ba665SWarner Losh   Return the absolute value of a signed operand.
9460d1ba665SWarner Losh 
9470d1ba665SWarner Losh   This macro returns the absolute value of the signed operand specified by a.
9480d1ba665SWarner Losh 
9490d1ba665SWarner Losh   @param   a        The signed operand.
9500d1ba665SWarner Losh 
9510d1ba665SWarner Losh   @return  The absolute value of the signed operand.
9520d1ba665SWarner Losh 
9530d1ba665SWarner Losh **/
9540d1ba665SWarner Losh #define ABS(a)                          \
9550d1ba665SWarner Losh   (((a) < 0) ? (-(a)) : (a))
9560d1ba665SWarner Losh 
9570d1ba665SWarner Losh //
9580d1ba665SWarner Losh // Status codes common to all execution phases
9590d1ba665SWarner Losh //
9600d1ba665SWarner Losh typedef UINTN RETURN_STATUS;
9610d1ba665SWarner Losh 
9620d1ba665SWarner Losh /**
9630d1ba665SWarner Losh   Produces a RETURN_STATUS code with the highest bit set.
9640d1ba665SWarner Losh 
9650d1ba665SWarner Losh   @param  StatusCode    The status code value to convert into a warning code.
9660d1ba665SWarner Losh                         StatusCode must be in the range 0x00000000..0x7FFFFFFF.
9670d1ba665SWarner Losh 
9680d1ba665SWarner Losh   @return The value specified by StatusCode with the highest bit set.
9690d1ba665SWarner Losh 
9700d1ba665SWarner Losh **/
9710d1ba665SWarner Losh #define ENCODE_ERROR(StatusCode)     ((RETURN_STATUS)(MAX_BIT | (StatusCode)))
9720d1ba665SWarner Losh 
9730d1ba665SWarner Losh /**
9740d1ba665SWarner Losh   Produces a RETURN_STATUS code with the highest bit clear.
9750d1ba665SWarner Losh 
9760d1ba665SWarner Losh   @param  StatusCode    The status code value to convert into a warning code.
9770d1ba665SWarner Losh                         StatusCode must be in the range 0x00000000..0x7FFFFFFF.
9780d1ba665SWarner Losh 
9790d1ba665SWarner Losh   @return The value specified by StatusCode with the highest bit clear.
9800d1ba665SWarner Losh 
9810d1ba665SWarner Losh **/
9820d1ba665SWarner Losh #define ENCODE_WARNING(StatusCode)   ((RETURN_STATUS)(StatusCode))
9830d1ba665SWarner Losh 
9840d1ba665SWarner Losh /**
9850d1ba665SWarner Losh   Returns TRUE if a specified RETURN_STATUS code is an error code.
9860d1ba665SWarner Losh 
9870d1ba665SWarner Losh   This function returns TRUE if StatusCode has the high bit set.  Otherwise, FALSE is returned.
9880d1ba665SWarner Losh 
9890d1ba665SWarner Losh   @param  StatusCode    The status code value to evaluate.
9900d1ba665SWarner Losh 
9910d1ba665SWarner Losh   @retval TRUE          The high bit of StatusCode is set.
9920d1ba665SWarner Losh   @retval FALSE         The high bit of StatusCode is clear.
9930d1ba665SWarner Losh 
9940d1ba665SWarner Losh **/
9950d1ba665SWarner Losh #define RETURN_ERROR(StatusCode)     (((INTN)(RETURN_STATUS)(StatusCode)) < 0)
9960d1ba665SWarner Losh 
9970d1ba665SWarner Losh ///
9980d1ba665SWarner Losh /// The operation completed successfully.
9990d1ba665SWarner Losh ///
10000d1ba665SWarner Losh #define RETURN_SUCCESS               0
10010d1ba665SWarner Losh 
10020d1ba665SWarner Losh ///
10030d1ba665SWarner Losh /// The image failed to load.
10040d1ba665SWarner Losh ///
10050d1ba665SWarner Losh #define RETURN_LOAD_ERROR            ENCODE_ERROR (1)
10060d1ba665SWarner Losh 
10070d1ba665SWarner Losh ///
10080d1ba665SWarner Losh /// The parameter was incorrect.
10090d1ba665SWarner Losh ///
10100d1ba665SWarner Losh #define RETURN_INVALID_PARAMETER     ENCODE_ERROR (2)
10110d1ba665SWarner Losh 
10120d1ba665SWarner Losh ///
10130d1ba665SWarner Losh /// The operation is not supported.
10140d1ba665SWarner Losh ///
10150d1ba665SWarner Losh #define RETURN_UNSUPPORTED           ENCODE_ERROR (3)
10160d1ba665SWarner Losh 
10170d1ba665SWarner Losh ///
10180d1ba665SWarner Losh /// The buffer was not the proper size for the request.
10190d1ba665SWarner Losh ///
10200d1ba665SWarner Losh #define RETURN_BAD_BUFFER_SIZE       ENCODE_ERROR (4)
10210d1ba665SWarner Losh 
10220d1ba665SWarner Losh ///
10230d1ba665SWarner Losh /// The buffer was not large enough to hold the requested data.
10240d1ba665SWarner Losh /// The required buffer size is returned in the appropriate
10250d1ba665SWarner Losh /// parameter when this error occurs.
10260d1ba665SWarner Losh ///
10270d1ba665SWarner Losh #define RETURN_BUFFER_TOO_SMALL      ENCODE_ERROR (5)
10280d1ba665SWarner Losh 
10290d1ba665SWarner Losh ///
10300d1ba665SWarner Losh /// There is no data pending upon return.
10310d1ba665SWarner Losh ///
10320d1ba665SWarner Losh #define RETURN_NOT_READY             ENCODE_ERROR (6)
10330d1ba665SWarner Losh 
10340d1ba665SWarner Losh ///
10350d1ba665SWarner Losh /// The physical device reported an error while attempting the
10360d1ba665SWarner Losh /// operation.
10370d1ba665SWarner Losh ///
10380d1ba665SWarner Losh #define RETURN_DEVICE_ERROR          ENCODE_ERROR (7)
10390d1ba665SWarner Losh 
10400d1ba665SWarner Losh ///
10410d1ba665SWarner Losh /// The device can not be written to.
10420d1ba665SWarner Losh ///
10430d1ba665SWarner Losh #define RETURN_WRITE_PROTECTED       ENCODE_ERROR (8)
10440d1ba665SWarner Losh 
10450d1ba665SWarner Losh ///
10460d1ba665SWarner Losh /// The resource has run out.
10470d1ba665SWarner Losh ///
10480d1ba665SWarner Losh #define RETURN_OUT_OF_RESOURCES      ENCODE_ERROR (9)
10490d1ba665SWarner Losh 
10500d1ba665SWarner Losh ///
10510d1ba665SWarner Losh /// An inconsistency was detected on the file system causing the
10520d1ba665SWarner Losh /// operation to fail.
10530d1ba665SWarner Losh ///
10540d1ba665SWarner Losh #define RETURN_VOLUME_CORRUPTED      ENCODE_ERROR (10)
10550d1ba665SWarner Losh 
10560d1ba665SWarner Losh ///
10570d1ba665SWarner Losh /// There is no more space on the file system.
10580d1ba665SWarner Losh ///
10590d1ba665SWarner Losh #define RETURN_VOLUME_FULL           ENCODE_ERROR (11)
10600d1ba665SWarner Losh 
10610d1ba665SWarner Losh ///
10620d1ba665SWarner Losh /// The device does not contain any medium to perform the
10630d1ba665SWarner Losh /// operation.
10640d1ba665SWarner Losh ///
10650d1ba665SWarner Losh #define RETURN_NO_MEDIA              ENCODE_ERROR (12)
10660d1ba665SWarner Losh 
10670d1ba665SWarner Losh ///
10680d1ba665SWarner Losh /// The medium in the device has changed since the last
10690d1ba665SWarner Losh /// access.
10700d1ba665SWarner Losh ///
10710d1ba665SWarner Losh #define RETURN_MEDIA_CHANGED         ENCODE_ERROR (13)
10720d1ba665SWarner Losh 
10730d1ba665SWarner Losh ///
10740d1ba665SWarner Losh /// The item was not found.
10750d1ba665SWarner Losh ///
10760d1ba665SWarner Losh #define RETURN_NOT_FOUND             ENCODE_ERROR (14)
10770d1ba665SWarner Losh 
10780d1ba665SWarner Losh ///
10790d1ba665SWarner Losh /// Access was denied.
10800d1ba665SWarner Losh ///
10810d1ba665SWarner Losh #define RETURN_ACCESS_DENIED         ENCODE_ERROR (15)
10820d1ba665SWarner Losh 
10830d1ba665SWarner Losh ///
10840d1ba665SWarner Losh /// The server was not found or did not respond to the request.
10850d1ba665SWarner Losh ///
10860d1ba665SWarner Losh #define RETURN_NO_RESPONSE           ENCODE_ERROR (16)
10870d1ba665SWarner Losh 
10880d1ba665SWarner Losh ///
10890d1ba665SWarner Losh /// A mapping to the device does not exist.
10900d1ba665SWarner Losh ///
10910d1ba665SWarner Losh #define RETURN_NO_MAPPING            ENCODE_ERROR (17)
10920d1ba665SWarner Losh 
10930d1ba665SWarner Losh ///
10940d1ba665SWarner Losh /// A timeout time expired.
10950d1ba665SWarner Losh ///
10960d1ba665SWarner Losh #define RETURN_TIMEOUT               ENCODE_ERROR (18)
10970d1ba665SWarner Losh 
10980d1ba665SWarner Losh ///
10990d1ba665SWarner Losh /// The protocol has not been started.
11000d1ba665SWarner Losh ///
11010d1ba665SWarner Losh #define RETURN_NOT_STARTED           ENCODE_ERROR (19)
11020d1ba665SWarner Losh 
11030d1ba665SWarner Losh ///
11040d1ba665SWarner Losh /// The protocol has already been started.
11050d1ba665SWarner Losh ///
11060d1ba665SWarner Losh #define RETURN_ALREADY_STARTED       ENCODE_ERROR (20)
11070d1ba665SWarner Losh 
11080d1ba665SWarner Losh ///
11090d1ba665SWarner Losh /// The operation was aborted.
11100d1ba665SWarner Losh ///
11110d1ba665SWarner Losh #define RETURN_ABORTED               ENCODE_ERROR (21)
11120d1ba665SWarner Losh 
11130d1ba665SWarner Losh ///
11140d1ba665SWarner Losh /// An ICMP error occurred during the network operation.
11150d1ba665SWarner Losh ///
11160d1ba665SWarner Losh #define RETURN_ICMP_ERROR            ENCODE_ERROR (22)
11170d1ba665SWarner Losh 
11180d1ba665SWarner Losh ///
11190d1ba665SWarner Losh /// A TFTP error occurred during the network operation.
11200d1ba665SWarner Losh ///
11210d1ba665SWarner Losh #define RETURN_TFTP_ERROR            ENCODE_ERROR (23)
11220d1ba665SWarner Losh 
11230d1ba665SWarner Losh ///
11240d1ba665SWarner Losh /// A protocol error occurred during the network operation.
11250d1ba665SWarner Losh ///
11260d1ba665SWarner Losh #define RETURN_PROTOCOL_ERROR        ENCODE_ERROR (24)
11270d1ba665SWarner Losh 
11280d1ba665SWarner Losh ///
11290d1ba665SWarner Losh /// A function encountered an internal version that was
11300d1ba665SWarner Losh /// incompatible with a version requested by the caller.
11310d1ba665SWarner Losh ///
11320d1ba665SWarner Losh #define RETURN_INCOMPATIBLE_VERSION  ENCODE_ERROR (25)
11330d1ba665SWarner Losh 
11340d1ba665SWarner Losh ///
11350d1ba665SWarner Losh /// The function was not performed due to a security violation.
11360d1ba665SWarner Losh ///
11370d1ba665SWarner Losh #define RETURN_SECURITY_VIOLATION    ENCODE_ERROR (26)
11380d1ba665SWarner Losh 
11390d1ba665SWarner Losh ///
11400d1ba665SWarner Losh /// A CRC error was detected.
11410d1ba665SWarner Losh ///
11420d1ba665SWarner Losh #define RETURN_CRC_ERROR             ENCODE_ERROR (27)
11430d1ba665SWarner Losh 
11440d1ba665SWarner Losh ///
11450d1ba665SWarner Losh /// The beginning or end of media was reached.
11460d1ba665SWarner Losh ///
11470d1ba665SWarner Losh #define RETURN_END_OF_MEDIA          ENCODE_ERROR (28)
11480d1ba665SWarner Losh 
11490d1ba665SWarner Losh ///
11500d1ba665SWarner Losh /// The end of the file was reached.
11510d1ba665SWarner Losh ///
11520d1ba665SWarner Losh #define RETURN_END_OF_FILE           ENCODE_ERROR (31)
11530d1ba665SWarner Losh 
11540d1ba665SWarner Losh ///
11550d1ba665SWarner Losh /// The language specified was invalid.
11560d1ba665SWarner Losh ///
11570d1ba665SWarner Losh #define RETURN_INVALID_LANGUAGE      ENCODE_ERROR (32)
11580d1ba665SWarner Losh 
11590d1ba665SWarner Losh ///
11600d1ba665SWarner Losh /// The security status of the data is unknown or compromised
11610d1ba665SWarner Losh /// and the data must be updated or replaced to restore a valid
11620d1ba665SWarner Losh /// security status.
11630d1ba665SWarner Losh ///
11640d1ba665SWarner Losh #define RETURN_COMPROMISED_DATA      ENCODE_ERROR (33)
11650d1ba665SWarner Losh 
11660d1ba665SWarner Losh ///
11670d1ba665SWarner Losh /// A HTTP error occurred during the network operation.
11680d1ba665SWarner Losh ///
11690d1ba665SWarner Losh #define RETURN_HTTP_ERROR            ENCODE_ERROR (35)
11700d1ba665SWarner Losh 
11710d1ba665SWarner Losh ///
11720d1ba665SWarner Losh /// The string contained one or more characters that
11730d1ba665SWarner Losh /// the device could not render and were skipped.
11740d1ba665SWarner Losh ///
11750d1ba665SWarner Losh #define RETURN_WARN_UNKNOWN_GLYPH    ENCODE_WARNING (1)
11760d1ba665SWarner Losh 
11770d1ba665SWarner Losh ///
11780d1ba665SWarner Losh /// The handle was closed, but the file was not deleted.
11790d1ba665SWarner Losh ///
11800d1ba665SWarner Losh #define RETURN_WARN_DELETE_FAILURE   ENCODE_WARNING (2)
11810d1ba665SWarner Losh 
11820d1ba665SWarner Losh ///
11830d1ba665SWarner Losh /// The handle was closed, but the data to the file was not
11840d1ba665SWarner Losh /// flushed properly.
11850d1ba665SWarner Losh ///
11860d1ba665SWarner Losh #define RETURN_WARN_WRITE_FAILURE    ENCODE_WARNING (3)
11870d1ba665SWarner Losh 
11880d1ba665SWarner Losh ///
11890d1ba665SWarner Losh /// The resulting buffer was too small, and the data was
11900d1ba665SWarner Losh /// truncated to the buffer size.
11910d1ba665SWarner Losh ///
11920d1ba665SWarner Losh #define RETURN_WARN_BUFFER_TOO_SMALL ENCODE_WARNING (4)
11930d1ba665SWarner Losh 
11940d1ba665SWarner Losh ///
11950d1ba665SWarner Losh /// The data has not been updated within the timeframe set by
11960d1ba665SWarner Losh /// local policy for this type of data.
11970d1ba665SWarner Losh ///
11980d1ba665SWarner Losh #define RETURN_WARN_STALE_DATA       ENCODE_WARNING (5)
11990d1ba665SWarner Losh 
12000d1ba665SWarner Losh ///
12010d1ba665SWarner Losh /// The resulting buffer contains UEFI-compliant file system.
12020d1ba665SWarner Losh ///
12030d1ba665SWarner Losh #define RETURN_WARN_FILE_SYSTEM      ENCODE_WARNING (6)
12040d1ba665SWarner Losh 
12050d1ba665SWarner Losh 
12060d1ba665SWarner Losh /**
12070d1ba665SWarner Losh   Returns a 16-bit signature built from 2 ASCII characters.
12080d1ba665SWarner Losh 
12090d1ba665SWarner Losh   This macro returns a 16-bit value built from the two ASCII characters specified
12100d1ba665SWarner Losh   by A and B.
12110d1ba665SWarner Losh 
12120d1ba665SWarner Losh   @param  A    The first ASCII character.
12130d1ba665SWarner Losh   @param  B    The second ASCII character.
12140d1ba665SWarner Losh 
12150d1ba665SWarner Losh   @return A 16-bit value built from the two ASCII characters specified by A and B.
12160d1ba665SWarner Losh 
12170d1ba665SWarner Losh **/
12180d1ba665SWarner Losh #define SIGNATURE_16(A, B)        ((A) | (B << 8))
12190d1ba665SWarner Losh 
12200d1ba665SWarner Losh /**
12210d1ba665SWarner Losh   Returns a 32-bit signature built from 4 ASCII characters.
12220d1ba665SWarner Losh 
12230d1ba665SWarner Losh   This macro returns a 32-bit value built from the four ASCII characters specified
12240d1ba665SWarner Losh   by A, B, C, and D.
12250d1ba665SWarner Losh 
12260d1ba665SWarner Losh   @param  A    The first ASCII character.
12270d1ba665SWarner Losh   @param  B    The second ASCII character.
12280d1ba665SWarner Losh   @param  C    The third ASCII character.
12290d1ba665SWarner Losh   @param  D    The fourth ASCII character.
12300d1ba665SWarner Losh 
12310d1ba665SWarner Losh   @return A 32-bit value built from the two ASCII characters specified by A, B,
12320d1ba665SWarner Losh           C and D.
12330d1ba665SWarner Losh 
12340d1ba665SWarner Losh **/
12350d1ba665SWarner Losh #define SIGNATURE_32(A, B, C, D)  (SIGNATURE_16 (A, B) | (SIGNATURE_16 (C, D) << 16))
12360d1ba665SWarner Losh 
12370d1ba665SWarner Losh /**
12380d1ba665SWarner Losh   Returns a 64-bit signature built from 8 ASCII characters.
12390d1ba665SWarner Losh 
12400d1ba665SWarner Losh   This macro returns a 64-bit value built from the eight ASCII characters specified
12410d1ba665SWarner Losh   by A, B, C, D, E, F, G,and H.
12420d1ba665SWarner Losh 
12430d1ba665SWarner Losh   @param  A    The first ASCII character.
12440d1ba665SWarner Losh   @param  B    The second ASCII character.
12450d1ba665SWarner Losh   @param  C    The third ASCII character.
12460d1ba665SWarner Losh   @param  D    The fourth ASCII character.
12470d1ba665SWarner Losh   @param  E    The fifth ASCII character.
12480d1ba665SWarner Losh   @param  F    The sixth ASCII character.
12490d1ba665SWarner Losh   @param  G    The seventh ASCII character.
12500d1ba665SWarner Losh   @param  H    The eighth ASCII character.
12510d1ba665SWarner Losh 
12520d1ba665SWarner Losh   @return A 64-bit value built from the two ASCII characters specified by A, B,
12530d1ba665SWarner Losh           C, D, E, F, G and H.
12540d1ba665SWarner Losh 
12550d1ba665SWarner Losh **/
12560d1ba665SWarner Losh #define SIGNATURE_64(A, B, C, D, E, F, G, H) \
12570d1ba665SWarner Losh     (SIGNATURE_32 (A, B, C, D) | ((UINT64) (SIGNATURE_32 (E, F, G, H)) << 32))
12580d1ba665SWarner Losh 
12590d1ba665SWarner Losh #if defined(_MSC_EXTENSIONS) && !defined (__INTEL_COMPILER) && !defined (MDE_CPU_EBC)
1260*3245fa21SMitchell Horne   void * _ReturnAddress(void);
12610d1ba665SWarner Losh   #pragma intrinsic(_ReturnAddress)
12620d1ba665SWarner Losh   /**
12630d1ba665SWarner Losh     Get the return address of the calling function.
12640d1ba665SWarner Losh 
12650d1ba665SWarner Losh     Based on intrinsic function _ReturnAddress that provides the address of
12660d1ba665SWarner Losh     the instruction in the calling function that will be executed after
12670d1ba665SWarner Losh     control returns to the caller.
12680d1ba665SWarner Losh 
12690d1ba665SWarner Losh     @param L    Return Level.
12700d1ba665SWarner Losh 
12710d1ba665SWarner Losh     @return The return address of the calling function or 0 if L != 0.
12720d1ba665SWarner Losh 
12730d1ba665SWarner Losh   **/
12740d1ba665SWarner Losh   #define RETURN_ADDRESS(L)     ((L == 0) ? _ReturnAddress() : (VOID *) 0)
1275*3245fa21SMitchell Horne #elif defined (__GNUC__) || defined (__clang__)
12760d1ba665SWarner Losh   void * __builtin_return_address (unsigned int level);
12770d1ba665SWarner Losh   /**
12780d1ba665SWarner Losh     Get the return address of the calling function.
12790d1ba665SWarner Losh 
12800d1ba665SWarner Losh     Based on built-in Function __builtin_return_address that returns
12810d1ba665SWarner Losh     the return address of the current function, or of one of its callers.
12820d1ba665SWarner Losh 
12830d1ba665SWarner Losh     @param L    Return Level.
12840d1ba665SWarner Losh 
12850d1ba665SWarner Losh     @return The return address of the calling function.
12860d1ba665SWarner Losh 
12870d1ba665SWarner Losh   **/
12880d1ba665SWarner Losh   #define RETURN_ADDRESS(L)     __builtin_return_address (L)
12890d1ba665SWarner Losh #else
12900d1ba665SWarner Losh   /**
12910d1ba665SWarner Losh     Get the return address of the calling function.
12920d1ba665SWarner Losh 
12930d1ba665SWarner Losh     @param L    Return Level.
12940d1ba665SWarner Losh 
12950d1ba665SWarner Losh     @return 0 as compilers don't support this feature.
12960d1ba665SWarner Losh 
12970d1ba665SWarner Losh   **/
12980d1ba665SWarner Losh   #define RETURN_ADDRESS(L)     ((VOID *) 0)
12990d1ba665SWarner Losh #endif
13000d1ba665SWarner Losh 
13010d1ba665SWarner Losh /**
13020d1ba665SWarner Losh   Return the number of elements in an array.
13030d1ba665SWarner Losh 
13040d1ba665SWarner Losh   @param  Array  An object of array type. Array is only used as an argument to
13050d1ba665SWarner Losh                  the sizeof operator, therefore Array is never evaluated. The
13060d1ba665SWarner Losh                  caller is responsible for ensuring that Array's type is not
13070d1ba665SWarner Losh                  incomplete; that is, Array must have known constant size.
13080d1ba665SWarner Losh 
13090d1ba665SWarner Losh   @return The number of elements in Array. The result has type UINTN.
13100d1ba665SWarner Losh 
13110d1ba665SWarner Losh **/
13120d1ba665SWarner Losh #define ARRAY_SIZE(Array) (sizeof (Array) / sizeof ((Array)[0]))
13130d1ba665SWarner Losh 
13140d1ba665SWarner Losh #endif
13150d1ba665SWarner Losh 
1316