1*f334afcfSToomas Soome /** @file 2*f334afcfSToomas Soome Root include file for Mde Package Base type modules 3*f334afcfSToomas Soome 4*f334afcfSToomas Soome This is the include file for any module of type base. Base modules only use 5*f334afcfSToomas Soome types defined via this include file and can be ported easily to any 6*f334afcfSToomas Soome environment. There are a set of base libraries in the Mde Package that can 7*f334afcfSToomas Soome be used to implement base modules. 8*f334afcfSToomas Soome 9*f334afcfSToomas Soome Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR> 10*f334afcfSToomas Soome Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> 11*f334afcfSToomas Soome SPDX-License-Identifier: BSD-2-Clause-Patent 12*f334afcfSToomas Soome 13*f334afcfSToomas Soome **/ 14*f334afcfSToomas Soome 15*f334afcfSToomas Soome #ifndef __BASE_H__ 16*f334afcfSToomas Soome #define __BASE_H__ 17*f334afcfSToomas Soome 18*f334afcfSToomas Soome // 19*f334afcfSToomas Soome // Include processor specific binding 20*f334afcfSToomas Soome // 21*f334afcfSToomas Soome #include <ProcessorBind.h> 22*f334afcfSToomas Soome 23*f334afcfSToomas Soome #if defined (_MSC_EXTENSIONS) 24*f334afcfSToomas Soome // 25*f334afcfSToomas Soome // Disable warning when last field of data structure is a zero sized array. 26*f334afcfSToomas Soome // 27*f334afcfSToomas Soome #pragma warning ( disable : 4200 ) 28*f334afcfSToomas Soome #endif 29*f334afcfSToomas Soome 30*f334afcfSToomas Soome // 31*f334afcfSToomas Soome // The Microsoft* C compiler can removed references to unreferenced data items 32*f334afcfSToomas Soome // if the /OPT:REF linker option is used. We defined a macro as this is a 33*f334afcfSToomas Soome // a non standard extension 34*f334afcfSToomas Soome // 35*f334afcfSToomas Soome #if defined (_MSC_VER) && _MSC_VER < 1800 && !defined (MDE_CPU_EBC) 36*f334afcfSToomas Soome /// 37*f334afcfSToomas Soome /// Remove global variable from the linked image if there are no references to 38*f334afcfSToomas Soome /// it after all compiler and linker optimizations have been performed. 39*f334afcfSToomas Soome /// 40*f334afcfSToomas Soome /// 41*f334afcfSToomas Soome #define GLOBAL_REMOVE_IF_UNREFERENCED __declspec(selectany) 42*f334afcfSToomas Soome #else 43*f334afcfSToomas Soome /// 44*f334afcfSToomas Soome /// Remove the global variable from the linked image if there are no references 45*f334afcfSToomas Soome /// to it after all compiler and linker optimizations have been performed. 46*f334afcfSToomas Soome /// 47*f334afcfSToomas Soome /// 48*f334afcfSToomas Soome #define GLOBAL_REMOVE_IF_UNREFERENCED 49*f334afcfSToomas Soome #endif 50*f334afcfSToomas Soome 51*f334afcfSToomas Soome // 52*f334afcfSToomas Soome // Should be used in combination with NORETURN to avoid 'noreturn' returns 53*f334afcfSToomas Soome // warnings. 54*f334afcfSToomas Soome // 55*f334afcfSToomas Soome #ifndef UNREACHABLE 56*f334afcfSToomas Soome #ifdef __GNUC__ 57*f334afcfSToomas Soome /// 58*f334afcfSToomas Soome /// Signal compilers and analyzers that this call is not reachable. It is 59*f334afcfSToomas Soome /// up to the compiler to remove any code past that point. 60*f334afcfSToomas Soome /// 61*f334afcfSToomas Soome #define UNREACHABLE() __builtin_unreachable () 62*f334afcfSToomas Soome #elif defined (__has_feature) 63*f334afcfSToomas Soome #if __has_builtin (__builtin_unreachable) 64*f334afcfSToomas Soome /// 65*f334afcfSToomas Soome /// Signal compilers and analyzers that this call is not reachable. It is 66*f334afcfSToomas Soome /// up to the compiler to remove any code past that point. 67*f334afcfSToomas Soome /// 68*f334afcfSToomas Soome #define UNREACHABLE() __builtin_unreachable () 69*f334afcfSToomas Soome #endif 70*f334afcfSToomas Soome #endif 71*f334afcfSToomas Soome 72*f334afcfSToomas Soome #ifndef UNREACHABLE 73*f334afcfSToomas Soome /// 74*f334afcfSToomas Soome /// Signal compilers and analyzers that this call is not reachable. It is 75*f334afcfSToomas Soome /// up to the compiler to remove any code past that point. 76*f334afcfSToomas Soome /// 77*f334afcfSToomas Soome #define UNREACHABLE() 78*f334afcfSToomas Soome #endif 79*f334afcfSToomas Soome #endif 80*f334afcfSToomas Soome 81*f334afcfSToomas Soome // 82*f334afcfSToomas Soome // Signaling compilers and analyzers that a certain function cannot return may 83*f334afcfSToomas Soome // remove all following code and thus lead to better optimization and less 84*f334afcfSToomas Soome // false positives. 85*f334afcfSToomas Soome // 86*f334afcfSToomas Soome #ifndef NORETURN 87*f334afcfSToomas Soome #if defined (__GNUC__) || defined (__clang__) 88*f334afcfSToomas Soome /// 89*f334afcfSToomas Soome /// Signal compilers and analyzers that the function cannot return. 90*f334afcfSToomas Soome /// It is up to the compiler to remove any code past a call to functions 91*f334afcfSToomas Soome /// flagged with this attribute. 92*f334afcfSToomas Soome /// 93*f334afcfSToomas Soome #define NORETURN __attribute__((noreturn)) 94*f334afcfSToomas Soome #elif defined (_MSC_EXTENSIONS) && !defined (MDE_CPU_EBC) 95*f334afcfSToomas Soome /// 96*f334afcfSToomas Soome /// Signal compilers and analyzers that the function cannot return. 97*f334afcfSToomas Soome /// It is up to the compiler to remove any code past a call to functions 98*f334afcfSToomas Soome /// flagged with this attribute. 99*f334afcfSToomas Soome /// 100*f334afcfSToomas Soome #define NORETURN __declspec(noreturn) 101*f334afcfSToomas Soome #else 102*f334afcfSToomas Soome /// 103*f334afcfSToomas Soome /// Signal compilers and analyzers that the function cannot return. 104*f334afcfSToomas Soome /// It is up to the compiler to remove any code past a call to functions 105*f334afcfSToomas Soome /// flagged with this attribute. 106*f334afcfSToomas Soome /// 107*f334afcfSToomas Soome #define NORETURN 108*f334afcfSToomas Soome #endif 109*f334afcfSToomas Soome #endif 110*f334afcfSToomas Soome 111*f334afcfSToomas Soome // 112*f334afcfSToomas Soome // Should be used in combination with ANALYZER_NORETURN to avoid 'noreturn' 113*f334afcfSToomas Soome // returns warnings. 114*f334afcfSToomas Soome // 115*f334afcfSToomas Soome #ifndef ANALYZER_UNREACHABLE 116*f334afcfSToomas Soome #ifdef __clang_analyzer__ 117*f334afcfSToomas Soome #if __has_builtin (__builtin_unreachable) 118*f334afcfSToomas Soome /// 119*f334afcfSToomas Soome /// Signal the analyzer that this call is not reachable. 120*f334afcfSToomas Soome /// This excludes compilers. 121*f334afcfSToomas Soome /// 122*f334afcfSToomas Soome #define ANALYZER_UNREACHABLE() __builtin_unreachable () 123*f334afcfSToomas Soome #endif 124*f334afcfSToomas Soome #endif 125*f334afcfSToomas Soome 126*f334afcfSToomas Soome #ifndef ANALYZER_UNREACHABLE 127*f334afcfSToomas Soome /// 128*f334afcfSToomas Soome /// Signal the analyzer that this call is not reachable. 129*f334afcfSToomas Soome /// This excludes compilers. 130*f334afcfSToomas Soome /// 131*f334afcfSToomas Soome #define ANALYZER_UNREACHABLE() 132*f334afcfSToomas Soome #endif 133*f334afcfSToomas Soome #endif 134*f334afcfSToomas Soome 135*f334afcfSToomas Soome // 136*f334afcfSToomas Soome // Static Analyzers may issue errors about potential NULL-dereferences when 137*f334afcfSToomas Soome // dereferencing a pointer, that has been checked before, outside of a 138*f334afcfSToomas Soome // NULL-check. This may lead to false positives, such as when using ASSERT() 139*f334afcfSToomas Soome // for verification. 140*f334afcfSToomas Soome // 141*f334afcfSToomas Soome #ifndef ANALYZER_NORETURN 142*f334afcfSToomas Soome #ifdef __has_feature 143*f334afcfSToomas Soome #if __has_feature (attribute_analyzer_noreturn) 144*f334afcfSToomas Soome /// 145*f334afcfSToomas Soome /// Signal analyzers that the function cannot return. 146*f334afcfSToomas Soome /// This excludes compilers. 147*f334afcfSToomas Soome /// 148*f334afcfSToomas Soome #define ANALYZER_NORETURN __attribute__((analyzer_noreturn)) 149*f334afcfSToomas Soome #endif 150*f334afcfSToomas Soome #endif 151*f334afcfSToomas Soome 152*f334afcfSToomas Soome #ifndef ANALYZER_NORETURN 153*f334afcfSToomas Soome /// 154*f334afcfSToomas Soome /// Signal the analyzer that the function cannot return. 155*f334afcfSToomas Soome /// This excludes compilers. 156*f334afcfSToomas Soome /// 157*f334afcfSToomas Soome #define ANALYZER_NORETURN 158*f334afcfSToomas Soome #endif 159*f334afcfSToomas Soome #endif 160*f334afcfSToomas Soome 161*f334afcfSToomas Soome /// 162*f334afcfSToomas Soome /// Tell the code optimizer that the function will return twice. 163*f334afcfSToomas Soome /// This prevents wrong optimizations which can cause bugs. 164*f334afcfSToomas Soome /// 165*f334afcfSToomas Soome #ifndef RETURNS_TWICE 166*f334afcfSToomas Soome #if defined (__GNUC__) || defined (__clang__) 167*f334afcfSToomas Soome /// 168*f334afcfSToomas Soome /// Tell the code optimizer that the function will return twice. 169*f334afcfSToomas Soome /// This prevents wrong optimizations which can cause bugs. 170*f334afcfSToomas Soome /// 171*f334afcfSToomas Soome #define RETURNS_TWICE __attribute__((returns_twice)) 172*f334afcfSToomas Soome #else 173*f334afcfSToomas Soome /// 174*f334afcfSToomas Soome /// Tell the code optimizer that the function will return twice. 175*f334afcfSToomas Soome /// This prevents wrong optimizations which can cause bugs. 176*f334afcfSToomas Soome /// 177*f334afcfSToomas Soome #define RETURNS_TWICE 178*f334afcfSToomas Soome #endif 179*f334afcfSToomas Soome #endif 180*f334afcfSToomas Soome 181*f334afcfSToomas Soome // 182*f334afcfSToomas Soome // For symbol name in assembly code, an extra "_" is sometimes necessary 183*f334afcfSToomas Soome // 184*f334afcfSToomas Soome 185*f334afcfSToomas Soome /// 186*f334afcfSToomas Soome /// Private worker functions for ASM_PFX() 187*f334afcfSToomas Soome /// 188*f334afcfSToomas Soome #define _CONCATENATE(a, b) __CONCATENATE(a, b) 189*f334afcfSToomas Soome #define __CONCATENATE(a, b) a ## b 190*f334afcfSToomas Soome 191*f334afcfSToomas Soome /// 192*f334afcfSToomas Soome /// The __USER_LABEL_PREFIX__ macro predefined by GNUC represents the prefix 193*f334afcfSToomas Soome /// on symbols in assembly language. 194*f334afcfSToomas Soome /// 195*f334afcfSToomas Soome #define ASM_PFX(name) _CONCATENATE (__USER_LABEL_PREFIX__, name) 196*f334afcfSToomas Soome 197*f334afcfSToomas Soome #ifdef __APPLE__ 198*f334afcfSToomas Soome // 199*f334afcfSToomas Soome // Apple extension that is used by the linker to optimize code size 200*f334afcfSToomas Soome // with assembly functions. Put at the end of your .S files 201*f334afcfSToomas Soome // 202*f334afcfSToomas Soome #define ASM_FUNCTION_REMOVE_IF_UNREFERENCED .subsections_via_symbols 203*f334afcfSToomas Soome #else 204*f334afcfSToomas Soome #define ASM_FUNCTION_REMOVE_IF_UNREFERENCED 205*f334afcfSToomas Soome #endif 206*f334afcfSToomas Soome 207*f334afcfSToomas Soome #ifdef __CC_ARM 208*f334afcfSToomas Soome // 209*f334afcfSToomas Soome // Older RVCT ARM compilers don't fully support #pragma pack and require __packed 210*f334afcfSToomas Soome // as a prefix for the structure. 211*f334afcfSToomas Soome // 212*f334afcfSToomas Soome #define PACKED __packed 213*f334afcfSToomas Soome #else 214*f334afcfSToomas Soome #define PACKED 215*f334afcfSToomas Soome #endif 216*f334afcfSToomas Soome 217*f334afcfSToomas Soome /// 218*f334afcfSToomas Soome /// 128 bit buffer containing a unique identifier value. 219*f334afcfSToomas Soome /// Unless otherwise specified, aligned on a 64 bit boundary. 220*f334afcfSToomas Soome /// 221*f334afcfSToomas Soome typedef struct { 222*f334afcfSToomas Soome UINT32 Data1; 223*f334afcfSToomas Soome UINT16 Data2; 224*f334afcfSToomas Soome UINT16 Data3; 225*f334afcfSToomas Soome UINT8 Data4[8]; 226*f334afcfSToomas Soome } GUID; 227*f334afcfSToomas Soome 228*f334afcfSToomas Soome /// 229*f334afcfSToomas Soome /// 4-byte buffer. An IPv4 internet protocol address. 230*f334afcfSToomas Soome /// 231*f334afcfSToomas Soome typedef struct { 232*f334afcfSToomas Soome UINT8 Addr[4]; 233*f334afcfSToomas Soome } IPv4_ADDRESS; 234*f334afcfSToomas Soome 235*f334afcfSToomas Soome /// 236*f334afcfSToomas Soome /// 16-byte buffer. An IPv6 internet protocol address. 237*f334afcfSToomas Soome /// 238*f334afcfSToomas Soome typedef struct { 239*f334afcfSToomas Soome UINT8 Addr[16]; 240*f334afcfSToomas Soome } IPv6_ADDRESS; 241*f334afcfSToomas Soome 242*f334afcfSToomas Soome // 243*f334afcfSToomas Soome // 8-bytes unsigned value that represents a physical system address. 244*f334afcfSToomas Soome // 245*f334afcfSToomas Soome typedef UINT64 PHYSICAL_ADDRESS; 246*f334afcfSToomas Soome 247*f334afcfSToomas Soome /// 248*f334afcfSToomas Soome /// LIST_ENTRY structure definition. 249*f334afcfSToomas Soome /// 250*f334afcfSToomas Soome typedef struct _LIST_ENTRY LIST_ENTRY; 251*f334afcfSToomas Soome 252*f334afcfSToomas Soome /// 253*f334afcfSToomas Soome /// _LIST_ENTRY structure definition. 254*f334afcfSToomas Soome /// 255*f334afcfSToomas Soome struct _LIST_ENTRY { 256*f334afcfSToomas Soome LIST_ENTRY *ForwardLink; 257*f334afcfSToomas Soome LIST_ENTRY *BackLink; 258*f334afcfSToomas Soome }; 259*f334afcfSToomas Soome 260*f334afcfSToomas Soome // 261*f334afcfSToomas Soome // Modifiers to abstract standard types to aid in debug of problems 262*f334afcfSToomas Soome // 263*f334afcfSToomas Soome 264*f334afcfSToomas Soome /// 265*f334afcfSToomas Soome /// Datum is read-only. 266*f334afcfSToomas Soome /// 267*f334afcfSToomas Soome #define CONST const 268*f334afcfSToomas Soome 269*f334afcfSToomas Soome /// 270*f334afcfSToomas Soome /// Datum is scoped to the current file or function. 271*f334afcfSToomas Soome /// 272*f334afcfSToomas Soome #define STATIC static 273*f334afcfSToomas Soome 274*f334afcfSToomas Soome /// 275*f334afcfSToomas Soome /// Undeclared type. 276*f334afcfSToomas Soome /// 277*f334afcfSToomas Soome #define VOID void 278*f334afcfSToomas Soome 279*f334afcfSToomas Soome // 280*f334afcfSToomas Soome // Modifiers for Data Types used to self document code. 281*f334afcfSToomas Soome // This concept is borrowed for UEFI specification. 282*f334afcfSToomas Soome // 283*f334afcfSToomas Soome 284*f334afcfSToomas Soome /// 285*f334afcfSToomas Soome /// Datum is passed to the function. 286*f334afcfSToomas Soome /// 287*f334afcfSToomas Soome #define IN 288*f334afcfSToomas Soome 289*f334afcfSToomas Soome /// 290*f334afcfSToomas Soome /// Datum is returned from the function. 291*f334afcfSToomas Soome /// 292*f334afcfSToomas Soome #define OUT 293*f334afcfSToomas Soome 294*f334afcfSToomas Soome /// 295*f334afcfSToomas Soome /// Passing the datum to the function is optional, and a NULL 296*f334afcfSToomas Soome /// is passed if the value is not supplied. 297*f334afcfSToomas Soome /// 298*f334afcfSToomas Soome #define OPTIONAL 299*f334afcfSToomas Soome 300*f334afcfSToomas Soome // 301*f334afcfSToomas Soome // UEFI specification claims 1 and 0. We are concerned about the 302*f334afcfSToomas Soome // compiler portability so we did it this way. 303*f334afcfSToomas Soome // 304*f334afcfSToomas Soome 305*f334afcfSToomas Soome /// 306*f334afcfSToomas Soome /// Boolean true value. UEFI Specification defines this value to be 1, 307*f334afcfSToomas Soome /// but this form is more portable. 308*f334afcfSToomas Soome /// 309*f334afcfSToomas Soome #define TRUE ((BOOLEAN)(1==1)) 310*f334afcfSToomas Soome 311*f334afcfSToomas Soome /// 312*f334afcfSToomas Soome /// Boolean false value. UEFI Specification defines this value to be 0, 313*f334afcfSToomas Soome /// but this form is more portable. 314*f334afcfSToomas Soome /// 315*f334afcfSToomas Soome #define FALSE ((BOOLEAN)(0==1)) 316*f334afcfSToomas Soome 317*f334afcfSToomas Soome /// 318*f334afcfSToomas Soome /// NULL pointer (VOID *) 319*f334afcfSToomas Soome /// 320*f334afcfSToomas Soome #ifndef NULL 321*f334afcfSToomas Soome #define NULL ((VOID *) 0) 322*f334afcfSToomas Soome #endif 323*f334afcfSToomas Soome 324*f334afcfSToomas Soome // 325*f334afcfSToomas Soome // Null character 326*f334afcfSToomas Soome // 327*f334afcfSToomas Soome #define CHAR_NULL 0x0000 328*f334afcfSToomas Soome 329*f334afcfSToomas Soome /// 330*f334afcfSToomas Soome /// Maximum values for common UEFI Data Types 331*f334afcfSToomas Soome /// 332*f334afcfSToomas Soome #define MAX_INT8 ((INT8)0x7F) 333*f334afcfSToomas Soome #define MAX_UINT8 ((UINT8)0xFF) 334*f334afcfSToomas Soome #define MAX_INT16 ((INT16)0x7FFF) 335*f334afcfSToomas Soome #define MAX_UINT16 ((UINT16)0xFFFF) 336*f334afcfSToomas Soome #define MAX_INT32 ((INT32)0x7FFFFFFF) 337*f334afcfSToomas Soome #define MAX_UINT32 ((UINT32)0xFFFFFFFF) 338*f334afcfSToomas Soome #define MAX_INT64 ((INT64)0x7FFFFFFFFFFFFFFFULL) 339*f334afcfSToomas Soome #define MAX_UINT64 ((UINT64)0xFFFFFFFFFFFFFFFFULL) 340*f334afcfSToomas Soome 341*f334afcfSToomas Soome /// 342*f334afcfSToomas Soome /// Minimum values for the signed UEFI Data Types 343*f334afcfSToomas Soome /// 344*f334afcfSToomas Soome #define MIN_INT8 (((INT8) -127) - 1) 345*f334afcfSToomas Soome #define MIN_INT16 (((INT16) -32767) - 1) 346*f334afcfSToomas Soome #define MIN_INT32 (((INT32) -2147483647) - 1) 347*f334afcfSToomas Soome #define MIN_INT64 (((INT64) -9223372036854775807LL) - 1) 348*f334afcfSToomas Soome 349*f334afcfSToomas Soome #define BIT0 0x00000001 350*f334afcfSToomas Soome #define BIT1 0x00000002 351*f334afcfSToomas Soome #define BIT2 0x00000004 352*f334afcfSToomas Soome #define BIT3 0x00000008 353*f334afcfSToomas Soome #define BIT4 0x00000010 354*f334afcfSToomas Soome #define BIT5 0x00000020 355*f334afcfSToomas Soome #define BIT6 0x00000040 356*f334afcfSToomas Soome #define BIT7 0x00000080 357*f334afcfSToomas Soome #define BIT8 0x00000100 358*f334afcfSToomas Soome #define BIT9 0x00000200 359*f334afcfSToomas Soome #define BIT10 0x00000400 360*f334afcfSToomas Soome #define BIT11 0x00000800 361*f334afcfSToomas Soome #define BIT12 0x00001000 362*f334afcfSToomas Soome #define BIT13 0x00002000 363*f334afcfSToomas Soome #define BIT14 0x00004000 364*f334afcfSToomas Soome #define BIT15 0x00008000 365*f334afcfSToomas Soome #define BIT16 0x00010000 366*f334afcfSToomas Soome #define BIT17 0x00020000 367*f334afcfSToomas Soome #define BIT18 0x00040000 368*f334afcfSToomas Soome #define BIT19 0x00080000 369*f334afcfSToomas Soome #define BIT20 0x00100000 370*f334afcfSToomas Soome #define BIT21 0x00200000 371*f334afcfSToomas Soome #define BIT22 0x00400000 372*f334afcfSToomas Soome #define BIT23 0x00800000 373*f334afcfSToomas Soome #define BIT24 0x01000000 374*f334afcfSToomas Soome #define BIT25 0x02000000 375*f334afcfSToomas Soome #define BIT26 0x04000000 376*f334afcfSToomas Soome #define BIT27 0x08000000 377*f334afcfSToomas Soome #define BIT28 0x10000000 378*f334afcfSToomas Soome #define BIT29 0x20000000 379*f334afcfSToomas Soome #define BIT30 0x40000000 380*f334afcfSToomas Soome #define BIT31 0x80000000 381*f334afcfSToomas Soome #define BIT32 0x0000000100000000ULL 382*f334afcfSToomas Soome #define BIT33 0x0000000200000000ULL 383*f334afcfSToomas Soome #define BIT34 0x0000000400000000ULL 384*f334afcfSToomas Soome #define BIT35 0x0000000800000000ULL 385*f334afcfSToomas Soome #define BIT36 0x0000001000000000ULL 386*f334afcfSToomas Soome #define BIT37 0x0000002000000000ULL 387*f334afcfSToomas Soome #define BIT38 0x0000004000000000ULL 388*f334afcfSToomas Soome #define BIT39 0x0000008000000000ULL 389*f334afcfSToomas Soome #define BIT40 0x0000010000000000ULL 390*f334afcfSToomas Soome #define BIT41 0x0000020000000000ULL 391*f334afcfSToomas Soome #define BIT42 0x0000040000000000ULL 392*f334afcfSToomas Soome #define BIT43 0x0000080000000000ULL 393*f334afcfSToomas Soome #define BIT44 0x0000100000000000ULL 394*f334afcfSToomas Soome #define BIT45 0x0000200000000000ULL 395*f334afcfSToomas Soome #define BIT46 0x0000400000000000ULL 396*f334afcfSToomas Soome #define BIT47 0x0000800000000000ULL 397*f334afcfSToomas Soome #define BIT48 0x0001000000000000ULL 398*f334afcfSToomas Soome #define BIT49 0x0002000000000000ULL 399*f334afcfSToomas Soome #define BIT50 0x0004000000000000ULL 400*f334afcfSToomas Soome #define BIT51 0x0008000000000000ULL 401*f334afcfSToomas Soome #define BIT52 0x0010000000000000ULL 402*f334afcfSToomas Soome #define BIT53 0x0020000000000000ULL 403*f334afcfSToomas Soome #define BIT54 0x0040000000000000ULL 404*f334afcfSToomas Soome #define BIT55 0x0080000000000000ULL 405*f334afcfSToomas Soome #define BIT56 0x0100000000000000ULL 406*f334afcfSToomas Soome #define BIT57 0x0200000000000000ULL 407*f334afcfSToomas Soome #define BIT58 0x0400000000000000ULL 408*f334afcfSToomas Soome #define BIT59 0x0800000000000000ULL 409*f334afcfSToomas Soome #define BIT60 0x1000000000000000ULL 410*f334afcfSToomas Soome #define BIT61 0x2000000000000000ULL 411*f334afcfSToomas Soome #define BIT62 0x4000000000000000ULL 412*f334afcfSToomas Soome #define BIT63 0x8000000000000000ULL 413*f334afcfSToomas Soome 414*f334afcfSToomas Soome #define SIZE_1KB 0x00000400 415*f334afcfSToomas Soome #define SIZE_2KB 0x00000800 416*f334afcfSToomas Soome #define SIZE_4KB 0x00001000 417*f334afcfSToomas Soome #define SIZE_8KB 0x00002000 418*f334afcfSToomas Soome #define SIZE_16KB 0x00004000 419*f334afcfSToomas Soome #define SIZE_32KB 0x00008000 420*f334afcfSToomas Soome #define SIZE_64KB 0x00010000 421*f334afcfSToomas Soome #define SIZE_128KB 0x00020000 422*f334afcfSToomas Soome #define SIZE_256KB 0x00040000 423*f334afcfSToomas Soome #define SIZE_512KB 0x00080000 424*f334afcfSToomas Soome #define SIZE_1MB 0x00100000 425*f334afcfSToomas Soome #define SIZE_2MB 0x00200000 426*f334afcfSToomas Soome #define SIZE_4MB 0x00400000 427*f334afcfSToomas Soome #define SIZE_8MB 0x00800000 428*f334afcfSToomas Soome #define SIZE_16MB 0x01000000 429*f334afcfSToomas Soome #define SIZE_32MB 0x02000000 430*f334afcfSToomas Soome #define SIZE_64MB 0x04000000 431*f334afcfSToomas Soome #define SIZE_128MB 0x08000000 432*f334afcfSToomas Soome #define SIZE_256MB 0x10000000 433*f334afcfSToomas Soome #define SIZE_512MB 0x20000000 434*f334afcfSToomas Soome #define SIZE_1GB 0x40000000 435*f334afcfSToomas Soome #define SIZE_2GB 0x80000000 436*f334afcfSToomas Soome #define SIZE_4GB 0x0000000100000000ULL 437*f334afcfSToomas Soome #define SIZE_8GB 0x0000000200000000ULL 438*f334afcfSToomas Soome #define SIZE_16GB 0x0000000400000000ULL 439*f334afcfSToomas Soome #define SIZE_32GB 0x0000000800000000ULL 440*f334afcfSToomas Soome #define SIZE_64GB 0x0000001000000000ULL 441*f334afcfSToomas Soome #define SIZE_128GB 0x0000002000000000ULL 442*f334afcfSToomas Soome #define SIZE_256GB 0x0000004000000000ULL 443*f334afcfSToomas Soome #define SIZE_512GB 0x0000008000000000ULL 444*f334afcfSToomas Soome #define SIZE_1TB 0x0000010000000000ULL 445*f334afcfSToomas Soome #define SIZE_2TB 0x0000020000000000ULL 446*f334afcfSToomas Soome #define SIZE_4TB 0x0000040000000000ULL 447*f334afcfSToomas Soome #define SIZE_8TB 0x0000080000000000ULL 448*f334afcfSToomas Soome #define SIZE_16TB 0x0000100000000000ULL 449*f334afcfSToomas Soome #define SIZE_32TB 0x0000200000000000ULL 450*f334afcfSToomas Soome #define SIZE_64TB 0x0000400000000000ULL 451*f334afcfSToomas Soome #define SIZE_128TB 0x0000800000000000ULL 452*f334afcfSToomas Soome #define SIZE_256TB 0x0001000000000000ULL 453*f334afcfSToomas Soome #define SIZE_512TB 0x0002000000000000ULL 454*f334afcfSToomas Soome #define SIZE_1PB 0x0004000000000000ULL 455*f334afcfSToomas Soome #define SIZE_2PB 0x0008000000000000ULL 456*f334afcfSToomas Soome #define SIZE_4PB 0x0010000000000000ULL 457*f334afcfSToomas Soome #define SIZE_8PB 0x0020000000000000ULL 458*f334afcfSToomas Soome #define SIZE_16PB 0x0040000000000000ULL 459*f334afcfSToomas Soome #define SIZE_32PB 0x0080000000000000ULL 460*f334afcfSToomas Soome #define SIZE_64PB 0x0100000000000000ULL 461*f334afcfSToomas Soome #define SIZE_128PB 0x0200000000000000ULL 462*f334afcfSToomas Soome #define SIZE_256PB 0x0400000000000000ULL 463*f334afcfSToomas Soome #define SIZE_512PB 0x0800000000000000ULL 464*f334afcfSToomas Soome #define SIZE_1EB 0x1000000000000000ULL 465*f334afcfSToomas Soome #define SIZE_2EB 0x2000000000000000ULL 466*f334afcfSToomas Soome #define SIZE_4EB 0x4000000000000000ULL 467*f334afcfSToomas Soome #define SIZE_8EB 0x8000000000000000ULL 468*f334afcfSToomas Soome 469*f334afcfSToomas Soome #define BASE_1KB 0x00000400 470*f334afcfSToomas Soome #define BASE_2KB 0x00000800 471*f334afcfSToomas Soome #define BASE_4KB 0x00001000 472*f334afcfSToomas Soome #define BASE_8KB 0x00002000 473*f334afcfSToomas Soome #define BASE_16KB 0x00004000 474*f334afcfSToomas Soome #define BASE_32KB 0x00008000 475*f334afcfSToomas Soome #define BASE_64KB 0x00010000 476*f334afcfSToomas Soome #define BASE_128KB 0x00020000 477*f334afcfSToomas Soome #define BASE_256KB 0x00040000 478*f334afcfSToomas Soome #define BASE_512KB 0x00080000 479*f334afcfSToomas Soome #define BASE_1MB 0x00100000 480*f334afcfSToomas Soome #define BASE_2MB 0x00200000 481*f334afcfSToomas Soome #define BASE_4MB 0x00400000 482*f334afcfSToomas Soome #define BASE_8MB 0x00800000 483*f334afcfSToomas Soome #define BASE_16MB 0x01000000 484*f334afcfSToomas Soome #define BASE_32MB 0x02000000 485*f334afcfSToomas Soome #define BASE_64MB 0x04000000 486*f334afcfSToomas Soome #define BASE_128MB 0x08000000 487*f334afcfSToomas Soome #define BASE_256MB 0x10000000 488*f334afcfSToomas Soome #define BASE_512MB 0x20000000 489*f334afcfSToomas Soome #define BASE_1GB 0x40000000 490*f334afcfSToomas Soome #define BASE_2GB 0x80000000 491*f334afcfSToomas Soome #define BASE_4GB 0x0000000100000000ULL 492*f334afcfSToomas Soome #define BASE_8GB 0x0000000200000000ULL 493*f334afcfSToomas Soome #define BASE_16GB 0x0000000400000000ULL 494*f334afcfSToomas Soome #define BASE_32GB 0x0000000800000000ULL 495*f334afcfSToomas Soome #define BASE_64GB 0x0000001000000000ULL 496*f334afcfSToomas Soome #define BASE_128GB 0x0000002000000000ULL 497*f334afcfSToomas Soome #define BASE_256GB 0x0000004000000000ULL 498*f334afcfSToomas Soome #define BASE_512GB 0x0000008000000000ULL 499*f334afcfSToomas Soome #define BASE_1TB 0x0000010000000000ULL 500*f334afcfSToomas Soome #define BASE_2TB 0x0000020000000000ULL 501*f334afcfSToomas Soome #define BASE_4TB 0x0000040000000000ULL 502*f334afcfSToomas Soome #define BASE_8TB 0x0000080000000000ULL 503*f334afcfSToomas Soome #define BASE_16TB 0x0000100000000000ULL 504*f334afcfSToomas Soome #define BASE_32TB 0x0000200000000000ULL 505*f334afcfSToomas Soome #define BASE_64TB 0x0000400000000000ULL 506*f334afcfSToomas Soome #define BASE_128TB 0x0000800000000000ULL 507*f334afcfSToomas Soome #define BASE_256TB 0x0001000000000000ULL 508*f334afcfSToomas Soome #define BASE_512TB 0x0002000000000000ULL 509*f334afcfSToomas Soome #define BASE_1PB 0x0004000000000000ULL 510*f334afcfSToomas Soome #define BASE_2PB 0x0008000000000000ULL 511*f334afcfSToomas Soome #define BASE_4PB 0x0010000000000000ULL 512*f334afcfSToomas Soome #define BASE_8PB 0x0020000000000000ULL 513*f334afcfSToomas Soome #define BASE_16PB 0x0040000000000000ULL 514*f334afcfSToomas Soome #define BASE_32PB 0x0080000000000000ULL 515*f334afcfSToomas Soome #define BASE_64PB 0x0100000000000000ULL 516*f334afcfSToomas Soome #define BASE_128PB 0x0200000000000000ULL 517*f334afcfSToomas Soome #define BASE_256PB 0x0400000000000000ULL 518*f334afcfSToomas Soome #define BASE_512PB 0x0800000000000000ULL 519*f334afcfSToomas Soome #define BASE_1EB 0x1000000000000000ULL 520*f334afcfSToomas Soome #define BASE_2EB 0x2000000000000000ULL 521*f334afcfSToomas Soome #define BASE_4EB 0x4000000000000000ULL 522*f334afcfSToomas Soome #define BASE_8EB 0x8000000000000000ULL 523*f334afcfSToomas Soome 524*f334afcfSToomas Soome // 525*f334afcfSToomas Soome // Support for variable argument lists in freestanding edk2 modules. 526*f334afcfSToomas Soome // 527*f334afcfSToomas Soome // For modules that use the ISO C library interfaces for variable 528*f334afcfSToomas Soome // argument lists, refer to "StdLib/Include/stdarg.h". 529*f334afcfSToomas Soome // 530*f334afcfSToomas Soome // VA_LIST - typedef for argument list. 531*f334afcfSToomas Soome // VA_START (VA_LIST Marker, argument before the ...) - Init Marker for use. 532*f334afcfSToomas Soome // VA_END (VA_LIST Marker) - Clear Marker 533*f334afcfSToomas Soome // VA_ARG (VA_LIST Marker, var arg type) - Use Marker to get an argument from 534*f334afcfSToomas Soome // the ... list. You must know the type and pass it in this macro. Type 535*f334afcfSToomas Soome // must be compatible with the type of the actual next argument (as promoted 536*f334afcfSToomas Soome // according to the default argument promotions.) 537*f334afcfSToomas Soome // VA_COPY (VA_LIST Dest, VA_LIST Start) - Initialize Dest as a copy of Start. 538*f334afcfSToomas Soome // 539*f334afcfSToomas Soome // Example: 540*f334afcfSToomas Soome // 541*f334afcfSToomas Soome // UINTN 542*f334afcfSToomas Soome // EFIAPI 543*f334afcfSToomas Soome // ExampleVarArg ( 544*f334afcfSToomas Soome // IN UINTN NumberOfArgs, 545*f334afcfSToomas Soome // ... 546*f334afcfSToomas Soome // ) 547*f334afcfSToomas Soome // { 548*f334afcfSToomas Soome // VA_LIST Marker; 549*f334afcfSToomas Soome // UINTN Index; 550*f334afcfSToomas Soome // UINTN Result; 551*f334afcfSToomas Soome // 552*f334afcfSToomas Soome // // 553*f334afcfSToomas Soome // // Initialize the Marker 554*f334afcfSToomas Soome // // 555*f334afcfSToomas Soome // VA_START (Marker, NumberOfArgs); 556*f334afcfSToomas Soome // for (Index = 0, Result = 0; Index < NumberOfArgs; Index++) { 557*f334afcfSToomas Soome // // 558*f334afcfSToomas Soome // // The ... list is a series of UINTN values, so sum them up. 559*f334afcfSToomas Soome // // 560*f334afcfSToomas Soome // Result += VA_ARG (Marker, UINTN); 561*f334afcfSToomas Soome // } 562*f334afcfSToomas Soome // 563*f334afcfSToomas Soome // VA_END (Marker); 564*f334afcfSToomas Soome // return Result; 565*f334afcfSToomas Soome // } 566*f334afcfSToomas Soome // 567*f334afcfSToomas Soome // Notes: 568*f334afcfSToomas Soome // - Functions that call VA_START() / VA_END() must have a variable 569*f334afcfSToomas Soome // argument list and must be declared EFIAPI. 570*f334afcfSToomas Soome // - Functions that call VA_COPY() / VA_END() must be declared EFIAPI. 571*f334afcfSToomas Soome // - Functions that only use VA_LIST and VA_ARG() need not be EFIAPI. 572*f334afcfSToomas Soome // 573*f334afcfSToomas Soome 574*f334afcfSToomas Soome /** 575*f334afcfSToomas Soome Return the size of argument that has been aligned to sizeof (UINTN). 576*f334afcfSToomas Soome 577*f334afcfSToomas Soome @param n The parameter size to be aligned. 578*f334afcfSToomas Soome 579*f334afcfSToomas Soome @return The aligned size. 580*f334afcfSToomas Soome **/ 581*f334afcfSToomas Soome #define _INT_SIZE_OF(n) ((sizeof (n) + sizeof (UINTN) - 1) &~(sizeof (UINTN) - 1)) 582*f334afcfSToomas Soome 583*f334afcfSToomas Soome #if defined (__CC_ARM) 584*f334afcfSToomas Soome // 585*f334afcfSToomas Soome // RVCT ARM variable argument list support. 586*f334afcfSToomas Soome // 587*f334afcfSToomas Soome 588*f334afcfSToomas Soome /// 589*f334afcfSToomas Soome /// Variable used to traverse the list of arguments. This type can vary by 590*f334afcfSToomas Soome /// implementation and could be an array or structure. 591*f334afcfSToomas Soome /// 592*f334afcfSToomas Soome #ifdef __APCS_ADSABI 593*f334afcfSToomas Soome typedef int *va_list[1]; 594*f334afcfSToomas Soome #define VA_LIST va_list 595*f334afcfSToomas Soome #else 596*f334afcfSToomas Soome typedef struct __va_list { 597*f334afcfSToomas Soome void *__ap; 598*f334afcfSToomas Soome } va_list; 599*f334afcfSToomas Soome #define VA_LIST va_list 600*f334afcfSToomas Soome #endif 601*f334afcfSToomas Soome 602*f334afcfSToomas Soome #define VA_START(Marker, Parameter) __va_start(Marker, Parameter) 603*f334afcfSToomas Soome 604*f334afcfSToomas Soome #define VA_ARG(Marker, TYPE) __va_arg(Marker, TYPE) 605*f334afcfSToomas Soome 606*f334afcfSToomas Soome #define VA_END(Marker) ((void)0) 607*f334afcfSToomas Soome 608*f334afcfSToomas Soome // For some ARM RVCT compilers, __va_copy is not defined 609*f334afcfSToomas Soome #ifndef __va_copy 610*f334afcfSToomas Soome #define __va_copy(dest, src) ((void)((dest) = (src))) 611*f334afcfSToomas Soome #endif 612*f334afcfSToomas Soome 613*f334afcfSToomas Soome #define VA_COPY(Dest, Start) __va_copy (Dest, Start) 614*f334afcfSToomas Soome 615*f334afcfSToomas Soome #elif defined (_M_ARM) || defined (_M_ARM64) 616*f334afcfSToomas Soome // 617*f334afcfSToomas Soome // MSFT ARM variable argument list support. 618*f334afcfSToomas Soome // 619*f334afcfSToomas Soome 620*f334afcfSToomas Soome typedef char *VA_LIST; 621*f334afcfSToomas Soome 622*f334afcfSToomas Soome #define VA_START(Marker, Parameter) __va_start (&Marker, &Parameter, _INT_SIZE_OF (Parameter), __alignof(Parameter), &Parameter) 623*f334afcfSToomas Soome #define VA_ARG(Marker, TYPE) (*(TYPE *) ((Marker += _INT_SIZE_OF (TYPE) + ((-(INTN)Marker) & (sizeof(TYPE) - 1))) - _INT_SIZE_OF (TYPE))) 624*f334afcfSToomas Soome #define VA_END(Marker) (Marker = (VA_LIST) 0) 625*f334afcfSToomas Soome #define VA_COPY(Dest, Start) ((void)((Dest) = (Start))) 626*f334afcfSToomas Soome 627*f334afcfSToomas Soome #elif defined (__GNUC__) || defined (__clang__) 628*f334afcfSToomas Soome 629*f334afcfSToomas Soome #if defined (MDE_CPU_X64) && !defined (NO_MSABI_VA_FUNCS) 630*f334afcfSToomas Soome // 631*f334afcfSToomas Soome // X64 only. Use MS ABI version of GCC built-in macros for variable argument lists. 632*f334afcfSToomas Soome // 633*f334afcfSToomas Soome /// 634*f334afcfSToomas Soome /// Both GCC and LLVM 3.8 for X64 support new variable argument intrinsics for Microsoft ABI 635*f334afcfSToomas Soome /// 636*f334afcfSToomas Soome 637*f334afcfSToomas Soome /// 638*f334afcfSToomas Soome /// Variable used to traverse the list of arguments. This type can vary by 639*f334afcfSToomas Soome /// implementation and could be an array or structure. 640*f334afcfSToomas Soome /// 641*f334afcfSToomas Soome typedef __builtin_ms_va_list VA_LIST; 642*f334afcfSToomas Soome 643*f334afcfSToomas Soome #define VA_START(Marker, Parameter) __builtin_ms_va_start (Marker, Parameter) 644*f334afcfSToomas Soome 645*f334afcfSToomas Soome #define VA_ARG(Marker, TYPE) ((sizeof (TYPE) < sizeof (UINTN)) ? (TYPE)(__builtin_va_arg (Marker, UINTN)) : (TYPE)(__builtin_va_arg (Marker, TYPE))) 646*f334afcfSToomas Soome 647*f334afcfSToomas Soome #define VA_END(Marker) __builtin_ms_va_end (Marker) 648*f334afcfSToomas Soome 649*f334afcfSToomas Soome #define VA_COPY(Dest, Start) __builtin_ms_va_copy (Dest, Start) 650*f334afcfSToomas Soome 651*f334afcfSToomas Soome #else 652*f334afcfSToomas Soome // 653*f334afcfSToomas Soome // Use GCC built-in macros for variable argument lists. 654*f334afcfSToomas Soome // 655*f334afcfSToomas Soome 656*f334afcfSToomas Soome /// 657*f334afcfSToomas Soome /// Variable used to traverse the list of arguments. This type can vary by 658*f334afcfSToomas Soome /// implementation and could be an array or structure. 659*f334afcfSToomas Soome /// 660*f334afcfSToomas Soome typedef __builtin_va_list VA_LIST; 661*f334afcfSToomas Soome 662*f334afcfSToomas Soome #define VA_START(Marker, Parameter) __builtin_va_start (Marker, Parameter) 663*f334afcfSToomas Soome 664*f334afcfSToomas Soome #define VA_ARG(Marker, TYPE) ((sizeof (TYPE) < sizeof (UINTN)) ? (TYPE)(__builtin_va_arg (Marker, UINTN)) : (TYPE)(__builtin_va_arg (Marker, TYPE))) 665*f334afcfSToomas Soome 666*f334afcfSToomas Soome #define VA_END(Marker) __builtin_va_end (Marker) 667*f334afcfSToomas Soome 668*f334afcfSToomas Soome #define VA_COPY(Dest, Start) __builtin_va_copy (Dest, Start) 669*f334afcfSToomas Soome 670*f334afcfSToomas Soome #endif 671*f334afcfSToomas Soome 672*f334afcfSToomas Soome #else 673*f334afcfSToomas Soome /// 674*f334afcfSToomas Soome /// Variable used to traverse the list of arguments. This type can vary by 675*f334afcfSToomas Soome /// implementation and could be an array or structure. 676*f334afcfSToomas Soome /// 677*f334afcfSToomas Soome typedef CHAR8 *VA_LIST; 678*f334afcfSToomas Soome 679*f334afcfSToomas Soome /** 680*f334afcfSToomas Soome Retrieves a pointer to the beginning of a variable argument list, based on 681*f334afcfSToomas Soome the name of the parameter that immediately precedes the variable argument list. 682*f334afcfSToomas Soome 683*f334afcfSToomas Soome This function initializes Marker to point to the beginning of the variable 684*f334afcfSToomas Soome argument list that immediately follows Parameter. The method for computing the 685*f334afcfSToomas Soome pointer to the next argument in the argument list is CPU-specific following the 686*f334afcfSToomas Soome EFIAPI ABI. 687*f334afcfSToomas Soome 688*f334afcfSToomas Soome @param Marker The VA_LIST used to traverse the list of arguments. 689*f334afcfSToomas Soome @param Parameter The name of the parameter that immediately precedes 690*f334afcfSToomas Soome the variable argument list. 691*f334afcfSToomas Soome 692*f334afcfSToomas Soome @return A pointer to the beginning of a variable argument list. 693*f334afcfSToomas Soome 694*f334afcfSToomas Soome **/ 695*f334afcfSToomas Soome #define VA_START(Marker, Parameter) (Marker = (VA_LIST) ((UINTN) & (Parameter) + _INT_SIZE_OF (Parameter))) 696*f334afcfSToomas Soome 697*f334afcfSToomas Soome /** 698*f334afcfSToomas Soome Returns an argument of a specified type from a variable argument list and updates 699*f334afcfSToomas Soome the pointer to the variable argument list to point to the next argument. 700*f334afcfSToomas Soome 701*f334afcfSToomas Soome This function returns an argument of the type specified by TYPE from the beginning 702*f334afcfSToomas Soome of the variable argument list specified by Marker. Marker is then updated to point 703*f334afcfSToomas Soome to the next argument in the variable argument list. The method for computing the 704*f334afcfSToomas Soome pointer to the next argument in the argument list is CPU-specific following the EFIAPI ABI. 705*f334afcfSToomas Soome 706*f334afcfSToomas Soome @param Marker VA_LIST used to traverse the list of arguments. 707*f334afcfSToomas Soome @param TYPE The type of argument to retrieve from the beginning 708*f334afcfSToomas Soome of the variable argument list. 709*f334afcfSToomas Soome 710*f334afcfSToomas Soome @return An argument of the type specified by TYPE. 711*f334afcfSToomas Soome 712*f334afcfSToomas Soome **/ 713*f334afcfSToomas Soome #define VA_ARG(Marker, TYPE) (*(TYPE *) ((Marker += _INT_SIZE_OF (TYPE)) - _INT_SIZE_OF (TYPE))) 714*f334afcfSToomas Soome 715*f334afcfSToomas Soome /** 716*f334afcfSToomas Soome Terminates the use of a variable argument list. 717*f334afcfSToomas Soome 718*f334afcfSToomas Soome This function initializes Marker so it can no longer be used with VA_ARG(). 719*f334afcfSToomas Soome After this macro is used, the only way to access the variable argument list is 720*f334afcfSToomas Soome by using VA_START() again. 721*f334afcfSToomas Soome 722*f334afcfSToomas Soome @param Marker VA_LIST used to traverse the list of arguments. 723*f334afcfSToomas Soome 724*f334afcfSToomas Soome **/ 725*f334afcfSToomas Soome #define VA_END(Marker) (Marker = (VA_LIST) 0) 726*f334afcfSToomas Soome 727*f334afcfSToomas Soome /** 728*f334afcfSToomas Soome Initializes a VA_LIST as a copy of an existing VA_LIST. 729*f334afcfSToomas Soome 730*f334afcfSToomas Soome This macro initializes Dest as a copy of Start, as if the VA_START macro had been applied to Dest 731*f334afcfSToomas Soome followed by the same sequence of uses of the VA_ARG macro as had previously been used to reach 732*f334afcfSToomas Soome the present state of Start. 733*f334afcfSToomas Soome 734*f334afcfSToomas Soome @param Dest VA_LIST used to traverse the list of arguments. 735*f334afcfSToomas Soome @param Start VA_LIST used to traverse the list of arguments. 736*f334afcfSToomas Soome 737*f334afcfSToomas Soome **/ 738*f334afcfSToomas Soome #define VA_COPY(Dest, Start) ((void)((Dest) = (Start))) 739*f334afcfSToomas Soome 740*f334afcfSToomas Soome #endif 741*f334afcfSToomas Soome 742*f334afcfSToomas Soome /// 743*f334afcfSToomas Soome /// Pointer to the start of a variable argument list stored in a memory buffer. Same as UINT8 *. 744*f334afcfSToomas Soome /// 745*f334afcfSToomas Soome typedef UINTN *BASE_LIST; 746*f334afcfSToomas Soome 747*f334afcfSToomas Soome /** 748*f334afcfSToomas Soome Returns the size of a data type in sizeof(UINTN) units rounded up to the nearest UINTN boundary. 749*f334afcfSToomas Soome 750*f334afcfSToomas Soome @param TYPE The date type to determine the size of. 751*f334afcfSToomas Soome 752*f334afcfSToomas Soome @return The size of TYPE in sizeof (UINTN) units rounded up to the nearest UINTN boundary. 753*f334afcfSToomas Soome **/ 754*f334afcfSToomas Soome #define _BASE_INT_SIZE_OF(TYPE) ((sizeof (TYPE) + sizeof (UINTN) - 1) / sizeof (UINTN)) 755*f334afcfSToomas Soome 756*f334afcfSToomas Soome /** 757*f334afcfSToomas Soome Returns an argument of a specified type from a variable argument list and updates 758*f334afcfSToomas Soome the pointer to the variable argument list to point to the next argument. 759*f334afcfSToomas Soome 760*f334afcfSToomas Soome This function returns an argument of the type specified by TYPE from the beginning 761*f334afcfSToomas Soome of the variable argument list specified by Marker. Marker is then updated to point 762*f334afcfSToomas Soome to the next argument in the variable argument list. The method for computing the 763*f334afcfSToomas Soome pointer to the next argument in the argument list is CPU specific following the EFIAPI ABI. 764*f334afcfSToomas Soome 765*f334afcfSToomas Soome @param Marker The pointer to the beginning of a variable argument list. 766*f334afcfSToomas Soome @param TYPE The type of argument to retrieve from the beginning 767*f334afcfSToomas Soome of the variable argument list. 768*f334afcfSToomas Soome 769*f334afcfSToomas Soome @return An argument of the type specified by TYPE. 770*f334afcfSToomas Soome 771*f334afcfSToomas Soome **/ 772*f334afcfSToomas Soome #define BASE_ARG(Marker, TYPE) (*(TYPE *) ((Marker += _BASE_INT_SIZE_OF (TYPE)) - _BASE_INT_SIZE_OF (TYPE))) 773*f334afcfSToomas Soome 774*f334afcfSToomas Soome /** 775*f334afcfSToomas Soome The macro that returns the byte offset of a field in a data structure. 776*f334afcfSToomas Soome 777*f334afcfSToomas Soome This function returns the offset, in bytes, of field specified by Field from the 778*f334afcfSToomas Soome beginning of the data structure specified by TYPE. If TYPE does not contain Field, 779*f334afcfSToomas Soome the module will not compile. 780*f334afcfSToomas Soome 781*f334afcfSToomas Soome @param TYPE The name of the data structure that contains the field specified by Field. 782*f334afcfSToomas Soome @param Field The name of the field in the data structure. 783*f334afcfSToomas Soome 784*f334afcfSToomas Soome @return Offset, in bytes, of field. 785*f334afcfSToomas Soome 786*f334afcfSToomas Soome **/ 787*f334afcfSToomas Soome #if (defined (__GNUC__) && __GNUC__ >= 4) || defined (__clang__) 788*f334afcfSToomas Soome #define OFFSET_OF(TYPE, Field) ((UINTN) __builtin_offsetof(TYPE, Field)) 789*f334afcfSToomas Soome #endif 790*f334afcfSToomas Soome 791*f334afcfSToomas Soome #ifndef OFFSET_OF 792*f334afcfSToomas Soome #define OFFSET_OF(TYPE, Field) ((UINTN) &(((TYPE *)0)->Field)) 793*f334afcfSToomas Soome #endif 794*f334afcfSToomas Soome 795*f334afcfSToomas Soome /** 796*f334afcfSToomas Soome Portable definition for compile time assertions. 797*f334afcfSToomas Soome Equivalent to C11 static_assert macro from assert.h. 798*f334afcfSToomas Soome 799*f334afcfSToomas Soome @param Expression Boolean expression. 800*f334afcfSToomas Soome @param Message Raised compiler diagnostic message when expression is false. 801*f334afcfSToomas Soome 802*f334afcfSToomas Soome **/ 803*f334afcfSToomas Soome #ifdef MDE_CPU_EBC 804*f334afcfSToomas Soome #define STATIC_ASSERT(Expression, Message) 805*f334afcfSToomas Soome #elif defined (_MSC_EXTENSIONS) 806*f334afcfSToomas Soome #define STATIC_ASSERT static_assert 807*f334afcfSToomas Soome #else 808*f334afcfSToomas Soome #define STATIC_ASSERT _Static_assert 809*f334afcfSToomas Soome #endif 810*f334afcfSToomas Soome 811*f334afcfSToomas Soome // 812*f334afcfSToomas Soome // Verify that ProcessorBind.h produced UEFI Data Types that are compliant with 813*f334afcfSToomas Soome // Section 2.3.1 of the UEFI 2.3 Specification. 814*f334afcfSToomas Soome // 815*f334afcfSToomas Soome 816*f334afcfSToomas Soome STATIC_ASSERT (sizeof (BOOLEAN) == 1, "sizeof (BOOLEAN) does not meet UEFI Specification Data Type requirements"); 817*f334afcfSToomas Soome STATIC_ASSERT (sizeof (INT8) == 1, "sizeof (INT8) does not meet UEFI Specification Data Type requirements"); 818*f334afcfSToomas Soome STATIC_ASSERT (sizeof (UINT8) == 1, "sizeof (UINT8) does not meet UEFI Specification Data Type requirements"); 819*f334afcfSToomas Soome STATIC_ASSERT (sizeof (INT16) == 2, "sizeof (INT16) does not meet UEFI Specification Data Type requirements"); 820*f334afcfSToomas Soome STATIC_ASSERT (sizeof (UINT16) == 2, "sizeof (UINT16) does not meet UEFI Specification Data Type requirements"); 821*f334afcfSToomas Soome STATIC_ASSERT (sizeof (INT32) == 4, "sizeof (INT32) does not meet UEFI Specification Data Type requirements"); 822*f334afcfSToomas Soome STATIC_ASSERT (sizeof (UINT32) == 4, "sizeof (UINT32) does not meet UEFI Specification Data Type requirements"); 823*f334afcfSToomas Soome STATIC_ASSERT (sizeof (INT64) == 8, "sizeof (INT64) does not meet UEFI Specification Data Type requirements"); 824*f334afcfSToomas Soome STATIC_ASSERT (sizeof (UINT64) == 8, "sizeof (UINT64) does not meet UEFI Specification Data Type requirements"); 825*f334afcfSToomas Soome STATIC_ASSERT (sizeof (CHAR8) == 1, "sizeof (CHAR8) does not meet UEFI Specification Data Type requirements"); 826*f334afcfSToomas Soome STATIC_ASSERT (sizeof (CHAR16) == 2, "sizeof (CHAR16) does not meet UEFI Specification Data Type requirements"); 827*f334afcfSToomas Soome // Apparently, gcc 7 and gcc 10 fail with those, gcc 12 seems to be ok. 828*f334afcfSToomas Soome // STATIC_ASSERT (sizeof (L'A') == 2, "sizeof (L'A') does not meet UEFI Specification Data Type requirements"); 829*f334afcfSToomas Soome // STATIC_ASSERT (sizeof (L"A") == 4, "sizeof (L\"A\") does not meet UEFI Specification Data Type requirements"); 830*f334afcfSToomas Soome 831*f334afcfSToomas Soome // 832*f334afcfSToomas Soome // The following three enum types are used to verify that the compiler 833*f334afcfSToomas Soome // configuration for enum types is compliant with Section 2.3.1 of the 834*f334afcfSToomas Soome // UEFI 2.3 Specification. These enum types and enum values are not 835*f334afcfSToomas Soome // intended to be used. A prefix of '__' is used avoid conflicts with 836*f334afcfSToomas Soome // other types. 837*f334afcfSToomas Soome // 838*f334afcfSToomas Soome typedef enum { 839*f334afcfSToomas Soome __VerifyUint8EnumValue = 0xff 840*f334afcfSToomas Soome } __VERIFY_UINT8_ENUM_SIZE; 841*f334afcfSToomas Soome 842*f334afcfSToomas Soome typedef enum { 843*f334afcfSToomas Soome __VerifyUint16EnumValue = 0xffff 844*f334afcfSToomas Soome } __VERIFY_UINT16_ENUM_SIZE; 845*f334afcfSToomas Soome 846*f334afcfSToomas Soome typedef enum { 847*f334afcfSToomas Soome __VerifyUint32EnumValue = 0xffffffff 848*f334afcfSToomas Soome } __VERIFY_UINT32_ENUM_SIZE; 849*f334afcfSToomas Soome 850*f334afcfSToomas Soome STATIC_ASSERT (sizeof (__VERIFY_UINT8_ENUM_SIZE) == 4, "Size of enum does not meet UEFI Specification Data Type requirements"); 851*f334afcfSToomas Soome STATIC_ASSERT (sizeof (__VERIFY_UINT16_ENUM_SIZE) == 4, "Size of enum does not meet UEFI Specification Data Type requirements"); 852*f334afcfSToomas Soome STATIC_ASSERT (sizeof (__VERIFY_UINT32_ENUM_SIZE) == 4, "Size of enum does not meet UEFI Specification Data Type requirements"); 853*f334afcfSToomas Soome 854*f334afcfSToomas Soome /** 855*f334afcfSToomas Soome Macro that returns a pointer to the data structure that contains a specified field of 856*f334afcfSToomas Soome that data structure. This is a lightweight method to hide information by placing a 857*f334afcfSToomas Soome public data structure inside a larger private data structure and using a pointer to 858*f334afcfSToomas Soome the public data structure to retrieve a pointer to the private data structure. 859*f334afcfSToomas Soome 860*f334afcfSToomas Soome This function computes the offset, in bytes, of field specified by Field from the beginning 861*f334afcfSToomas Soome of the data structure specified by TYPE. This offset is subtracted from Record, and is 862*f334afcfSToomas Soome used to return a pointer to a data structure of the type specified by TYPE. If the data type 863*f334afcfSToomas Soome specified by TYPE does not contain the field specified by Field, then the module will not compile. 864*f334afcfSToomas Soome 865*f334afcfSToomas Soome @param Record Pointer to the field specified by Field within a data structure of type TYPE. 866*f334afcfSToomas Soome @param TYPE The name of the data structure type to return. This data structure must 867*f334afcfSToomas Soome contain the field specified by Field. 868*f334afcfSToomas Soome @param Field The name of the field in the data structure specified by TYPE to which Record points. 869*f334afcfSToomas Soome 870*f334afcfSToomas Soome @return A pointer to the structure from one of it's elements. 871*f334afcfSToomas Soome 872*f334afcfSToomas Soome **/ 873*f334afcfSToomas Soome #define BASE_CR(Record, TYPE, Field) ((TYPE *) ((CHAR8 *) (Record) - OFFSET_OF (TYPE, Field))) 874*f334afcfSToomas Soome 875*f334afcfSToomas Soome /** 876*f334afcfSToomas Soome Rounds a value up to the next boundary using a specified alignment. 877*f334afcfSToomas Soome 878*f334afcfSToomas Soome This function rounds Value up to the next boundary using the specified Alignment. 879*f334afcfSToomas Soome This aligned value is returned. 880*f334afcfSToomas Soome 881*f334afcfSToomas Soome @param Value The value to round up. 882*f334afcfSToomas Soome @param Alignment The alignment boundary used to return the aligned value. 883*f334afcfSToomas Soome 884*f334afcfSToomas Soome @return A value up to the next boundary. 885*f334afcfSToomas Soome 886*f334afcfSToomas Soome **/ 887*f334afcfSToomas Soome #define ALIGN_VALUE(Value, Alignment) ((Value) + (((Alignment) - (Value)) & ((Alignment) - 1))) 888*f334afcfSToomas Soome 889*f334afcfSToomas Soome /** 890*f334afcfSToomas Soome Adjust a pointer by adding the minimum offset required for it to be aligned on 891*f334afcfSToomas Soome a specified alignment boundary. 892*f334afcfSToomas Soome 893*f334afcfSToomas Soome This function rounds the pointer specified by Pointer to the next alignment boundary 894*f334afcfSToomas Soome specified by Alignment. The pointer to the aligned address is returned. 895*f334afcfSToomas Soome 896*f334afcfSToomas Soome @param Pointer The pointer to round up. 897*f334afcfSToomas Soome @param Alignment The alignment boundary to use to return an aligned pointer. 898*f334afcfSToomas Soome 899*f334afcfSToomas Soome @return Pointer to the aligned address. 900*f334afcfSToomas Soome 901*f334afcfSToomas Soome **/ 902*f334afcfSToomas Soome #define ALIGN_POINTER(Pointer, Alignment) ((VOID *) (ALIGN_VALUE ((UINTN)(Pointer), (Alignment)))) 903*f334afcfSToomas Soome 904*f334afcfSToomas Soome /** 905*f334afcfSToomas Soome Rounds a value up to the next natural boundary for the current CPU. 906*f334afcfSToomas Soome This is 4-bytes for 32-bit CPUs and 8-bytes for 64-bit CPUs. 907*f334afcfSToomas Soome 908*f334afcfSToomas Soome This function rounds the value specified by Value up to the next natural boundary for the 909*f334afcfSToomas Soome current CPU. This rounded value is returned. 910*f334afcfSToomas Soome 911*f334afcfSToomas Soome @param Value The value to round up. 912*f334afcfSToomas Soome 913*f334afcfSToomas Soome @return Rounded value specified by Value. 914*f334afcfSToomas Soome 915*f334afcfSToomas Soome **/ 916*f334afcfSToomas Soome #define ALIGN_VARIABLE(Value) ALIGN_VALUE ((Value), sizeof (UINTN)) 917*f334afcfSToomas Soome 918*f334afcfSToomas Soome /** 919*f334afcfSToomas Soome Return the absolute value of a signed operand. 920*f334afcfSToomas Soome 921*f334afcfSToomas Soome This macro returns the absolute value of the signed operand specified by a. 922*f334afcfSToomas Soome 923*f334afcfSToomas Soome @param a The signed operand. 924*f334afcfSToomas Soome 925*f334afcfSToomas Soome @return The absolute value of the signed operand. 926*f334afcfSToomas Soome 927*f334afcfSToomas Soome **/ 928*f334afcfSToomas Soome #define ABS(a) \ 929*f334afcfSToomas Soome (((a) < 0) ? (-(a)) : (a)) 930*f334afcfSToomas Soome 931*f334afcfSToomas Soome // 932*f334afcfSToomas Soome // Status codes common to all execution phases 933*f334afcfSToomas Soome // 934*f334afcfSToomas Soome typedef UINTN RETURN_STATUS; 935*f334afcfSToomas Soome 936*f334afcfSToomas Soome /** 937*f334afcfSToomas Soome Produces a RETURN_STATUS code with the highest bit set. 938*f334afcfSToomas Soome 939*f334afcfSToomas Soome @param StatusCode The status code value to convert into a warning code. 940*f334afcfSToomas Soome StatusCode must be in the range 0x00000000..0x7FFFFFFF. 941*f334afcfSToomas Soome 942*f334afcfSToomas Soome @return The value specified by StatusCode with the highest bit set. 943*f334afcfSToomas Soome 944*f334afcfSToomas Soome **/ 945*f334afcfSToomas Soome #define ENCODE_ERROR(StatusCode) ((RETURN_STATUS)(MAX_BIT | (StatusCode))) 946*f334afcfSToomas Soome 947*f334afcfSToomas Soome /** 948*f334afcfSToomas Soome Produces a RETURN_STATUS code with the highest bit clear. 949*f334afcfSToomas Soome 950*f334afcfSToomas Soome @param StatusCode The status code value to convert into a warning code. 951*f334afcfSToomas Soome StatusCode must be in the range 0x00000000..0x7FFFFFFF. 952*f334afcfSToomas Soome 953*f334afcfSToomas Soome @return The value specified by StatusCode with the highest bit clear. 954*f334afcfSToomas Soome 955*f334afcfSToomas Soome **/ 956*f334afcfSToomas Soome #define ENCODE_WARNING(StatusCode) ((RETURN_STATUS)(StatusCode)) 957*f334afcfSToomas Soome 958*f334afcfSToomas Soome /** 959*f334afcfSToomas Soome Returns TRUE if a specified RETURN_STATUS code is an error code. 960*f334afcfSToomas Soome 961*f334afcfSToomas Soome This function returns TRUE if StatusCode has the high bit set. Otherwise, FALSE is returned. 962*f334afcfSToomas Soome 963*f334afcfSToomas Soome @param StatusCode The status code value to evaluate. 964*f334afcfSToomas Soome 965*f334afcfSToomas Soome @retval TRUE The high bit of StatusCode is set. 966*f334afcfSToomas Soome @retval FALSE The high bit of StatusCode is clear. 967*f334afcfSToomas Soome 968*f334afcfSToomas Soome **/ 969*f334afcfSToomas Soome #define RETURN_ERROR(StatusCode) (((INTN)(RETURN_STATUS)(StatusCode)) < 0) 970*f334afcfSToomas Soome 971*f334afcfSToomas Soome /// 972*f334afcfSToomas Soome /// The operation completed successfully. 973*f334afcfSToomas Soome /// 974*f334afcfSToomas Soome #define RETURN_SUCCESS 0 975*f334afcfSToomas Soome 976*f334afcfSToomas Soome /// 977*f334afcfSToomas Soome /// The image failed to load. 978*f334afcfSToomas Soome /// 979*f334afcfSToomas Soome #define RETURN_LOAD_ERROR ENCODE_ERROR (1) 980*f334afcfSToomas Soome 981*f334afcfSToomas Soome /// 982*f334afcfSToomas Soome /// The parameter was incorrect. 983*f334afcfSToomas Soome /// 984*f334afcfSToomas Soome #define RETURN_INVALID_PARAMETER ENCODE_ERROR (2) 985*f334afcfSToomas Soome 986*f334afcfSToomas Soome /// 987*f334afcfSToomas Soome /// The operation is not supported. 988*f334afcfSToomas Soome /// 989*f334afcfSToomas Soome #define RETURN_UNSUPPORTED ENCODE_ERROR (3) 990*f334afcfSToomas Soome 991*f334afcfSToomas Soome /// 992*f334afcfSToomas Soome /// The buffer was not the proper size for the request. 993*f334afcfSToomas Soome /// 994*f334afcfSToomas Soome #define RETURN_BAD_BUFFER_SIZE ENCODE_ERROR (4) 995*f334afcfSToomas Soome 996*f334afcfSToomas Soome /// 997*f334afcfSToomas Soome /// The buffer was not large enough to hold the requested data. 998*f334afcfSToomas Soome /// The required buffer size is returned in the appropriate 999*f334afcfSToomas Soome /// parameter when this error occurs. 1000*f334afcfSToomas Soome /// 1001*f334afcfSToomas Soome #define RETURN_BUFFER_TOO_SMALL ENCODE_ERROR (5) 1002*f334afcfSToomas Soome 1003*f334afcfSToomas Soome /// 1004*f334afcfSToomas Soome /// There is no data pending upon return. 1005*f334afcfSToomas Soome /// 1006*f334afcfSToomas Soome #define RETURN_NOT_READY ENCODE_ERROR (6) 1007*f334afcfSToomas Soome 1008*f334afcfSToomas Soome /// 1009*f334afcfSToomas Soome /// The physical device reported an error while attempting the 1010*f334afcfSToomas Soome /// operation. 1011*f334afcfSToomas Soome /// 1012*f334afcfSToomas Soome #define RETURN_DEVICE_ERROR ENCODE_ERROR (7) 1013*f334afcfSToomas Soome 1014*f334afcfSToomas Soome /// 1015*f334afcfSToomas Soome /// The device can not be written to. 1016*f334afcfSToomas Soome /// 1017*f334afcfSToomas Soome #define RETURN_WRITE_PROTECTED ENCODE_ERROR (8) 1018*f334afcfSToomas Soome 1019*f334afcfSToomas Soome /// 1020*f334afcfSToomas Soome /// The resource has run out. 1021*f334afcfSToomas Soome /// 1022*f334afcfSToomas Soome #define RETURN_OUT_OF_RESOURCES ENCODE_ERROR (9) 1023*f334afcfSToomas Soome 1024*f334afcfSToomas Soome /// 1025*f334afcfSToomas Soome /// An inconsistency was detected on the file system causing the 1026*f334afcfSToomas Soome /// operation to fail. 1027*f334afcfSToomas Soome /// 1028*f334afcfSToomas Soome #define RETURN_VOLUME_CORRUPTED ENCODE_ERROR (10) 1029*f334afcfSToomas Soome 1030*f334afcfSToomas Soome /// 1031*f334afcfSToomas Soome /// There is no more space on the file system. 1032*f334afcfSToomas Soome /// 1033*f334afcfSToomas Soome #define RETURN_VOLUME_FULL ENCODE_ERROR (11) 1034*f334afcfSToomas Soome 1035*f334afcfSToomas Soome /// 1036*f334afcfSToomas Soome /// The device does not contain any medium to perform the 1037*f334afcfSToomas Soome /// operation. 1038*f334afcfSToomas Soome /// 1039*f334afcfSToomas Soome #define RETURN_NO_MEDIA ENCODE_ERROR (12) 1040*f334afcfSToomas Soome 1041*f334afcfSToomas Soome /// 1042*f334afcfSToomas Soome /// The medium in the device has changed since the last 1043*f334afcfSToomas Soome /// access. 1044*f334afcfSToomas Soome /// 1045*f334afcfSToomas Soome #define RETURN_MEDIA_CHANGED ENCODE_ERROR (13) 1046*f334afcfSToomas Soome 1047*f334afcfSToomas Soome /// 1048*f334afcfSToomas Soome /// The item was not found. 1049*f334afcfSToomas Soome /// 1050*f334afcfSToomas Soome #define RETURN_NOT_FOUND ENCODE_ERROR (14) 1051*f334afcfSToomas Soome 1052*f334afcfSToomas Soome /// 1053*f334afcfSToomas Soome /// Access was denied. 1054*f334afcfSToomas Soome /// 1055*f334afcfSToomas Soome #define RETURN_ACCESS_DENIED ENCODE_ERROR (15) 1056*f334afcfSToomas Soome 1057*f334afcfSToomas Soome /// 1058*f334afcfSToomas Soome /// The server was not found or did not respond to the request. 1059*f334afcfSToomas Soome /// 1060*f334afcfSToomas Soome #define RETURN_NO_RESPONSE ENCODE_ERROR (16) 1061*f334afcfSToomas Soome 1062*f334afcfSToomas Soome /// 1063*f334afcfSToomas Soome /// A mapping to the device does not exist. 1064*f334afcfSToomas Soome /// 1065*f334afcfSToomas Soome #define RETURN_NO_MAPPING ENCODE_ERROR (17) 1066*f334afcfSToomas Soome 1067*f334afcfSToomas Soome /// 1068*f334afcfSToomas Soome /// A timeout time expired. 1069*f334afcfSToomas Soome /// 1070*f334afcfSToomas Soome #define RETURN_TIMEOUT ENCODE_ERROR (18) 1071*f334afcfSToomas Soome 1072*f334afcfSToomas Soome /// 1073*f334afcfSToomas Soome /// The protocol has not been started. 1074*f334afcfSToomas Soome /// 1075*f334afcfSToomas Soome #define RETURN_NOT_STARTED ENCODE_ERROR (19) 1076*f334afcfSToomas Soome 1077*f334afcfSToomas Soome /// 1078*f334afcfSToomas Soome /// The protocol has already been started. 1079*f334afcfSToomas Soome /// 1080*f334afcfSToomas Soome #define RETURN_ALREADY_STARTED ENCODE_ERROR (20) 1081*f334afcfSToomas Soome 1082*f334afcfSToomas Soome /// 1083*f334afcfSToomas Soome /// The operation was aborted. 1084*f334afcfSToomas Soome /// 1085*f334afcfSToomas Soome #define RETURN_ABORTED ENCODE_ERROR (21) 1086*f334afcfSToomas Soome 1087*f334afcfSToomas Soome /// 1088*f334afcfSToomas Soome /// An ICMP error occurred during the network operation. 1089*f334afcfSToomas Soome /// 1090*f334afcfSToomas Soome #define RETURN_ICMP_ERROR ENCODE_ERROR (22) 1091*f334afcfSToomas Soome 1092*f334afcfSToomas Soome /// 1093*f334afcfSToomas Soome /// A TFTP error occurred during the network operation. 1094*f334afcfSToomas Soome /// 1095*f334afcfSToomas Soome #define RETURN_TFTP_ERROR ENCODE_ERROR (23) 1096*f334afcfSToomas Soome 1097*f334afcfSToomas Soome /// 1098*f334afcfSToomas Soome /// A protocol error occurred during the network operation. 1099*f334afcfSToomas Soome /// 1100*f334afcfSToomas Soome #define RETURN_PROTOCOL_ERROR ENCODE_ERROR (24) 1101*f334afcfSToomas Soome 1102*f334afcfSToomas Soome /// 1103*f334afcfSToomas Soome /// A function encountered an internal version that was 1104*f334afcfSToomas Soome /// incompatible with a version requested by the caller. 1105*f334afcfSToomas Soome /// 1106*f334afcfSToomas Soome #define RETURN_INCOMPATIBLE_VERSION ENCODE_ERROR (25) 1107*f334afcfSToomas Soome 1108*f334afcfSToomas Soome /// 1109*f334afcfSToomas Soome /// The function was not performed due to a security violation. 1110*f334afcfSToomas Soome /// 1111*f334afcfSToomas Soome #define RETURN_SECURITY_VIOLATION ENCODE_ERROR (26) 1112*f334afcfSToomas Soome 1113*f334afcfSToomas Soome /// 1114*f334afcfSToomas Soome /// A CRC error was detected. 1115*f334afcfSToomas Soome /// 1116*f334afcfSToomas Soome #define RETURN_CRC_ERROR ENCODE_ERROR (27) 1117*f334afcfSToomas Soome 1118*f334afcfSToomas Soome /// 1119*f334afcfSToomas Soome /// The beginning or end of media was reached. 1120*f334afcfSToomas Soome /// 1121*f334afcfSToomas Soome #define RETURN_END_OF_MEDIA ENCODE_ERROR (28) 1122*f334afcfSToomas Soome 1123*f334afcfSToomas Soome /// 1124*f334afcfSToomas Soome /// The end of the file was reached. 1125*f334afcfSToomas Soome /// 1126*f334afcfSToomas Soome #define RETURN_END_OF_FILE ENCODE_ERROR (31) 1127*f334afcfSToomas Soome 1128*f334afcfSToomas Soome /// 1129*f334afcfSToomas Soome /// The language specified was invalid. 1130*f334afcfSToomas Soome /// 1131*f334afcfSToomas Soome #define RETURN_INVALID_LANGUAGE ENCODE_ERROR (32) 1132*f334afcfSToomas Soome 1133*f334afcfSToomas Soome /// 1134*f334afcfSToomas Soome /// The security status of the data is unknown or compromised 1135*f334afcfSToomas Soome /// and the data must be updated or replaced to restore a valid 1136*f334afcfSToomas Soome /// security status. 1137*f334afcfSToomas Soome /// 1138*f334afcfSToomas Soome #define RETURN_COMPROMISED_DATA ENCODE_ERROR (33) 1139*f334afcfSToomas Soome 1140*f334afcfSToomas Soome /// 1141*f334afcfSToomas Soome /// A HTTP error occurred during the network operation. 1142*f334afcfSToomas Soome /// 1143*f334afcfSToomas Soome #define RETURN_HTTP_ERROR ENCODE_ERROR (35) 1144*f334afcfSToomas Soome 1145*f334afcfSToomas Soome /// 1146*f334afcfSToomas Soome /// The string contained one or more characters that 1147*f334afcfSToomas Soome /// the device could not render and were skipped. 1148*f334afcfSToomas Soome /// 1149*f334afcfSToomas Soome #define RETURN_WARN_UNKNOWN_GLYPH ENCODE_WARNING (1) 1150*f334afcfSToomas Soome 1151*f334afcfSToomas Soome /// 1152*f334afcfSToomas Soome /// The handle was closed, but the file was not deleted. 1153*f334afcfSToomas Soome /// 1154*f334afcfSToomas Soome #define RETURN_WARN_DELETE_FAILURE ENCODE_WARNING (2) 1155*f334afcfSToomas Soome 1156*f334afcfSToomas Soome /// 1157*f334afcfSToomas Soome /// The handle was closed, but the data to the file was not 1158*f334afcfSToomas Soome /// flushed properly. 1159*f334afcfSToomas Soome /// 1160*f334afcfSToomas Soome #define RETURN_WARN_WRITE_FAILURE ENCODE_WARNING (3) 1161*f334afcfSToomas Soome 1162*f334afcfSToomas Soome /// 1163*f334afcfSToomas Soome /// The resulting buffer was too small, and the data was 1164*f334afcfSToomas Soome /// truncated to the buffer size. 1165*f334afcfSToomas Soome /// 1166*f334afcfSToomas Soome #define RETURN_WARN_BUFFER_TOO_SMALL ENCODE_WARNING (4) 1167*f334afcfSToomas Soome 1168*f334afcfSToomas Soome /// 1169*f334afcfSToomas Soome /// The data has not been updated within the timeframe set by 1170*f334afcfSToomas Soome /// local policy for this type of data. 1171*f334afcfSToomas Soome /// 1172*f334afcfSToomas Soome #define RETURN_WARN_STALE_DATA ENCODE_WARNING (5) 1173*f334afcfSToomas Soome 1174*f334afcfSToomas Soome /// 1175*f334afcfSToomas Soome /// The resulting buffer contains UEFI-compliant file system. 1176*f334afcfSToomas Soome /// 1177*f334afcfSToomas Soome #define RETURN_WARN_FILE_SYSTEM ENCODE_WARNING (6) 1178*f334afcfSToomas Soome 1179*f334afcfSToomas Soome /** 1180*f334afcfSToomas Soome Returns a 16-bit signature built from 2 ASCII characters. 1181*f334afcfSToomas Soome 1182*f334afcfSToomas Soome This macro returns a 16-bit value built from the two ASCII characters specified 1183*f334afcfSToomas Soome by A and B. 1184*f334afcfSToomas Soome 1185*f334afcfSToomas Soome @param A The first ASCII character. 1186*f334afcfSToomas Soome @param B The second ASCII character. 1187*f334afcfSToomas Soome 1188*f334afcfSToomas Soome @return A 16-bit value built from the two ASCII characters specified by A and B. 1189*f334afcfSToomas Soome 1190*f334afcfSToomas Soome **/ 1191*f334afcfSToomas Soome #define SIGNATURE_16(A, B) ((A) | (B << 8)) 1192*f334afcfSToomas Soome 1193*f334afcfSToomas Soome /** 1194*f334afcfSToomas Soome Returns a 32-bit signature built from 4 ASCII characters. 1195*f334afcfSToomas Soome 1196*f334afcfSToomas Soome This macro returns a 32-bit value built from the four ASCII characters specified 1197*f334afcfSToomas Soome by A, B, C, and D. 1198*f334afcfSToomas Soome 1199*f334afcfSToomas Soome @param A The first ASCII character. 1200*f334afcfSToomas Soome @param B The second ASCII character. 1201*f334afcfSToomas Soome @param C The third ASCII character. 1202*f334afcfSToomas Soome @param D The fourth ASCII character. 1203*f334afcfSToomas Soome 1204*f334afcfSToomas Soome @return A 32-bit value built from the two ASCII characters specified by A, B, 1205*f334afcfSToomas Soome C and D. 1206*f334afcfSToomas Soome 1207*f334afcfSToomas Soome **/ 1208*f334afcfSToomas Soome #define SIGNATURE_32(A, B, C, D) (SIGNATURE_16 (A, B) | (SIGNATURE_16 (C, D) << 16)) 1209*f334afcfSToomas Soome 1210*f334afcfSToomas Soome /** 1211*f334afcfSToomas Soome Returns a 64-bit signature built from 8 ASCII characters. 1212*f334afcfSToomas Soome 1213*f334afcfSToomas Soome This macro returns a 64-bit value built from the eight ASCII characters specified 1214*f334afcfSToomas Soome by A, B, C, D, E, F, G,and H. 1215*f334afcfSToomas Soome 1216*f334afcfSToomas Soome @param A The first ASCII character. 1217*f334afcfSToomas Soome @param B The second ASCII character. 1218*f334afcfSToomas Soome @param C The third ASCII character. 1219*f334afcfSToomas Soome @param D The fourth ASCII character. 1220*f334afcfSToomas Soome @param E The fifth ASCII character. 1221*f334afcfSToomas Soome @param F The sixth ASCII character. 1222*f334afcfSToomas Soome @param G The seventh ASCII character. 1223*f334afcfSToomas Soome @param H The eighth ASCII character. 1224*f334afcfSToomas Soome 1225*f334afcfSToomas Soome @return A 64-bit value built from the two ASCII characters specified by A, B, 1226*f334afcfSToomas Soome C, D, E, F, G and H. 1227*f334afcfSToomas Soome 1228*f334afcfSToomas Soome **/ 1229*f334afcfSToomas Soome #define SIGNATURE_64(A, B, C, D, E, F, G, H) \ 1230*f334afcfSToomas Soome (SIGNATURE_32 (A, B, C, D) | ((UINT64) (SIGNATURE_32 (E, F, G, H)) << 32)) 1231*f334afcfSToomas Soome 1232*f334afcfSToomas Soome #if defined (_MSC_EXTENSIONS) && !defined (__INTEL_COMPILER) && !defined (MDE_CPU_EBC) 1233*f334afcfSToomas Soome void * 1234*f334afcfSToomas Soome _ReturnAddress ( 1235*f334afcfSToomas Soome void 1236*f334afcfSToomas Soome ); 1237*f334afcfSToomas Soome 1238*f334afcfSToomas Soome #pragma intrinsic(_ReturnAddress) 1239*f334afcfSToomas Soome 1240*f334afcfSToomas Soome /** 1241*f334afcfSToomas Soome Get the return address of the calling function. 1242*f334afcfSToomas Soome 1243*f334afcfSToomas Soome Based on intrinsic function _ReturnAddress that provides the address of 1244*f334afcfSToomas Soome the instruction in the calling function that will be executed after 1245*f334afcfSToomas Soome control returns to the caller. 1246*f334afcfSToomas Soome 1247*f334afcfSToomas Soome @param L Return Level. 1248*f334afcfSToomas Soome 1249*f334afcfSToomas Soome @return The return address of the calling function or 0 if L != 0. 1250*f334afcfSToomas Soome 1251*f334afcfSToomas Soome **/ 1252*f334afcfSToomas Soome #define RETURN_ADDRESS(L) ((L == 0) ? _ReturnAddress() : (VOID *) 0) 1253*f334afcfSToomas Soome #elif defined (__GNUC__) || defined (__clang__) 1254*f334afcfSToomas Soome 1255*f334afcfSToomas Soome /** 1256*f334afcfSToomas Soome Get the return address of the calling function. 1257*f334afcfSToomas Soome 1258*f334afcfSToomas Soome Based on built-in Function __builtin_return_address that returns 1259*f334afcfSToomas Soome the return address of the current function, or of one of its callers. 1260*f334afcfSToomas Soome 1261*f334afcfSToomas Soome @param L Return Level. 1262*f334afcfSToomas Soome 1263*f334afcfSToomas Soome @return The return address of the calling function. 1264*f334afcfSToomas Soome 1265*f334afcfSToomas Soome **/ 1266*f334afcfSToomas Soome #define RETURN_ADDRESS(L) __builtin_return_address (L) 1267*f334afcfSToomas Soome #else 1268*f334afcfSToomas Soome 1269*f334afcfSToomas Soome /** 1270*f334afcfSToomas Soome Get the return address of the calling function. 1271*f334afcfSToomas Soome 1272*f334afcfSToomas Soome @param L Return Level. 1273*f334afcfSToomas Soome 1274*f334afcfSToomas Soome @return 0 as compilers don't support this feature. 1275*f334afcfSToomas Soome 1276*f334afcfSToomas Soome **/ 1277*f334afcfSToomas Soome #define RETURN_ADDRESS(L) ((VOID *) 0) 1278*f334afcfSToomas Soome #endif 1279*f334afcfSToomas Soome 1280*f334afcfSToomas Soome /** 1281*f334afcfSToomas Soome Return the number of elements in an array. 1282*f334afcfSToomas Soome 1283*f334afcfSToomas Soome @param Array An object of array type. Array is only used as an argument to 1284*f334afcfSToomas Soome the sizeof operator, therefore Array is never evaluated. The 1285*f334afcfSToomas Soome caller is responsible for ensuring that Array's type is not 1286*f334afcfSToomas Soome incomplete; that is, Array must have known constant size. 1287*f334afcfSToomas Soome 1288*f334afcfSToomas Soome @return The number of elements in Array. The result has type UINTN. 1289*f334afcfSToomas Soome 1290*f334afcfSToomas Soome **/ 1291*f334afcfSToomas Soome #define ARRAY_SIZE(Array) (sizeof (Array) / sizeof ((Array)[0])) 1292*f334afcfSToomas Soome 1293*f334afcfSToomas Soome #endif /* __BASE_H__ */ 1294