1 /*++ 2 3 Copyright (c) 1999 - 2003 Intel Corporation. All rights reserved 4 This software and associated documentation (if any) is furnished 5 under a license and may only be used or copied in accordance 6 with the terms of the license. Except as permitted by such 7 license, no part of this software or documentation may be 8 reproduced, stored in a retrieval system, or transmitted in any 9 form or by any means without the express written consent of 10 Intel Corporation. 11 12 Module Name: 13 14 efefind.h 15 16 Abstract: 17 18 EFI to compile bindings 19 20 21 22 23 Revision History 24 25 --*/ 26 27 #pragma pack() 28 29 #ifdef EFI_NT_EMULATOR 30 #define POST_CODE(_Data) 31 #else 32 #ifdef EFI_DEBUG 33 #define POST_CODE(_Data) __asm mov eax,(_Data) __asm out 0x80,al 34 #else 35 #define POST_CODE(_Data) 36 #endif 37 #endif 38 39 #define EFIERR(a) (0x8000000000000000 | a) 40 #define EFI_ERROR_MASK 0x8000000000000000 41 #define EFIERR_OEM(a) (0xc000000000000000 | a) 42 43 44 #define BAD_POINTER 0xFBFBFBFBFBFBFBFB 45 #define MAX_ADDRESS 0xFFFFFFFFFFFFFFFF 46 47 #define BREAKPOINT() __asm { int 3 } 48 49 // 50 // Pointers must be aligned to these address to function 51 // 52 53 #define MIN_ALIGNMENT_SIZE 4 54 55 #define ALIGN_VARIABLE(Value ,Adjustment) \ 56 (UINTN)Adjustment = 0; \ 57 if((UINTN)Value % MIN_ALIGNMENT_SIZE) \ 58 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \ 59 Value = (UINTN)Value + (UINTN)Adjustment 60 61 62 // 63 // Define macros to build data structure signatures from characters. 64 // 65 66 #define EFI_SIGNATURE_16(A,B) ((A) | (B<<8)) 67 #define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16)) 68 #define EFI_SIGNATURE_64(A,B,C,D,E,F,G,H) (EFI_SIGNATURE_32(A,B,C,D) | ((UINT64)(EFI_SIGNATURE_32(E,F,G,H)) << 32)) 69 70 // 71 // EFIAPI - prototype calling convention for EFI function pointers 72 // BOOTSERVICE - prototype for implementation of a boot service interface 73 // RUNTIMESERVICE - prototype for implementation of a runtime service interface 74 // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service 75 // RUNTIME_CODE - pragma macro for declaring runtime code 76 // 77 78 #ifdef __amd64__ 79 #define EFIAPI __attribute__((ms_abi)) 80 #endif 81 82 #ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options 83 #ifdef _MSC_EXTENSIONS 84 #define EFIAPI __cdecl // Force C calling convention for Microsoft C compiler 85 #else 86 #define EFIAPI // Substitute expresion to force C calling convention 87 #endif 88 #endif 89 90 #define BOOTSERVICE 91 //#define RUNTIMESERVICE(proto,a) alloc_text("rtcode",a); proto a 92 //#define RUNTIMEFUNCTION(proto,a) alloc_text("rtcode",a); proto a 93 #define RUNTIMESERVICE 94 #define RUNTIMEFUNCTION 95 96 97 #define RUNTIME_CODE(a) alloc_text("rtcode", a) 98 #define BEGIN_RUNTIME_DATA() data_seg("rtdata") 99 #define END_RUNTIME_DATA() data_seg("") 100 101 #define VOLATILE volatile 102 103 #define MEMORY_FENCE() 104 105 #ifdef EFI_NO_INTERFACE_DECL 106 #define EFI_FORWARD_DECLARATION(x) 107 #define EFI_INTERFACE_DECL(x) 108 #else 109 #define EFI_FORWARD_DECLARATION(x) typedef struct _##x x 110 #define EFI_INTERFACE_DECL(x) typedef struct x 111 #endif 112 113 #ifdef EFI_NT_EMULATOR 114 115 // 116 // To help ensure proper coding of integrated drivers, they are 117 // compiled as DLLs. In NT they require a dll init entry pointer. 118 // The macro puts a stub entry point into the DLL so it will load. 119 // 120 121 #define EFI_DRIVER_ENTRY_POINT(InitFunction) \ 122 EFI_STATUS \ 123 InitFunction ( \ 124 EFI_HANDLE ImageHandle, \ 125 EFI_SYSTEM_TABLE *SystemTable \ 126 ); \ 127 \ 128 UINTN \ 129 __stdcall \ 130 _DllMainCRTStartup ( \ 131 UINTN Inst, \ 132 UINTN reason_for_call, \ 133 VOID *rserved \ 134 ) \ 135 { \ 136 return 1; \ 137 } \ 138 \ 139 int \ 140 __declspec( dllexport ) \ 141 __cdecl \ 142 InitializeDriver ( \ 143 void *ImageHandle, \ 144 void *SystemTable \ 145 ) \ 146 { \ 147 return InitFunction(ImageHandle, SystemTable); \ 148 } 149 150 151 #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \ 152 (_if)->LoadInternal(type, name, NULL) 153 154 #else // EFI_NT_EMULATOR 155 156 // 157 // When building similar to FW, link everything together as 158 // one big module. 159 // 160 161 #define EFI_DRIVER_ENTRY_POINT(InitFunction) 162 163 #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \ 164 (_if)->LoadInternal(type, name, entry) 165 166 #endif // EFI_FW_NT 167 168 #ifdef __FreeBSD__ 169 #define INTERFACE_DECL(x) struct x 170 #else 171 // 172 // Some compilers don't support the forward reference construct: 173 // typedef struct XXXXX 174 // 175 // The following macro provide a workaround for such cases. 176 // 177 #ifdef NO_INTERFACE_DECL 178 #define INTERFACE_DECL(x) 179 #else 180 #define INTERFACE_DECL(x) typedef struct x 181 #endif 182 #endif /* __FreeBSD__ */ 183 184 #ifdef _MSC_EXTENSIONS 185 #pragma warning ( disable : 4731 ) // Suppress warnings about modification of EBP 186 #endif 187 188