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 #include <sys/stdint.h> 30 31 // 32 // Basic EFI types of various widths 33 // 34 35 #ifndef ACPI_THREAD_ID /* ACPI's definitions are fine */ 36 #define ACPI_USE_SYSTEM_INTTYPES 1 /* Tell ACPI we've defined types */ 37 38 typedef uint64_t UINT64; 39 typedef int64_t INT64; 40 41 #ifndef _BASETSD_H_ 42 typedef uint32_t UINT32; 43 typedef int32_t INT32; 44 #endif 45 46 typedef uint16_t UINT16; 47 typedef int16_t INT16; 48 typedef uint8_t UINT8; 49 typedef int8_t INT8; 50 51 #endif 52 53 #undef VOID 54 #define VOID void 55 56 57 typedef int64_t INTN; 58 typedef uint64_t UINTN; 59 60 #ifdef EFI_NT_EMULATOR 61 #define POST_CODE(_Data) 62 #else 63 #ifdef EFI_DEBUG 64 #define POST_CODE(_Data) __asm mov eax,(_Data) __asm out 0x80,al 65 #else 66 #define POST_CODE(_Data) 67 #endif 68 #endif 69 70 #define EFIERR(a) (0x8000000000000000 | a) 71 #define EFI_ERROR_MASK 0x8000000000000000 72 #define EFIERR_OEM(a) (0xc000000000000000 | a) 73 74 75 #define BAD_POINTER 0xFBFBFBFBFBFBFBFB 76 #define MAX_ADDRESS 0xFFFFFFFFFFFFFFFF 77 78 #define BREAKPOINT() __asm { int 3 } 79 80 // 81 // Pointers must be aligned to these address to function 82 // 83 84 #define MIN_ALIGNMENT_SIZE 4 85 86 #define ALIGN_VARIABLE(Value ,Adjustment) \ 87 (UINTN)Adjustment = 0; \ 88 if((UINTN)Value % MIN_ALIGNMENT_SIZE) \ 89 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \ 90 Value = (UINTN)Value + (UINTN)Adjustment 91 92 93 // 94 // Define macros to build data structure signatures from characters. 95 // 96 97 #define EFI_SIGNATURE_16(A,B) ((A) | (B<<8)) 98 #define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16)) 99 #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)) 100 101 // 102 // EFIAPI - prototype calling convention for EFI function pointers 103 // BOOTSERVICE - prototype for implementation of a boot service interface 104 // RUNTIMESERVICE - prototype for implementation of a runtime service interface 105 // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service 106 // RUNTIME_CODE - pragma macro for declaring runtime code 107 // 108 109 #ifdef __amd64__ 110 #define EFIAPI __attribute__((ms_abi)) 111 #endif 112 113 #ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options 114 #ifdef _MSC_EXTENSIONS 115 #define EFIAPI __cdecl // Force C calling convention for Microsoft C compiler 116 #else 117 #define EFIAPI // Substitute expresion to force C calling convention 118 #endif 119 #endif 120 121 #define BOOTSERVICE 122 //#define RUNTIMESERVICE(proto,a) alloc_text("rtcode",a); proto a 123 //#define RUNTIMEFUNCTION(proto,a) alloc_text("rtcode",a); proto a 124 #define RUNTIMESERVICE 125 #define RUNTIMEFUNCTION 126 127 128 #define RUNTIME_CODE(a) alloc_text("rtcode", a) 129 #define BEGIN_RUNTIME_DATA() data_seg("rtdata") 130 #define END_RUNTIME_DATA() data_seg("") 131 132 #define VOLATILE volatile 133 134 #define MEMORY_FENCE() 135 136 #ifdef EFI_NO_INTERFACE_DECL 137 #define EFI_FORWARD_DECLARATION(x) 138 #define EFI_INTERFACE_DECL(x) 139 #else 140 #define EFI_FORWARD_DECLARATION(x) typedef struct _##x x 141 #define EFI_INTERFACE_DECL(x) typedef struct x 142 #endif 143 144 #ifdef EFI_NT_EMULATOR 145 146 // 147 // To help ensure proper coding of integrated drivers, they are 148 // compiled as DLLs. In NT they require a dll init entry pointer. 149 // The macro puts a stub entry point into the DLL so it will load. 150 // 151 152 #define EFI_DRIVER_ENTRY_POINT(InitFunction) \ 153 EFI_STATUS \ 154 InitFunction ( \ 155 EFI_HANDLE ImageHandle, \ 156 EFI_SYSTEM_TABLE *SystemTable \ 157 ); \ 158 \ 159 UINTN \ 160 __stdcall \ 161 _DllMainCRTStartup ( \ 162 UINTN Inst, \ 163 UINTN reason_for_call, \ 164 VOID *rserved \ 165 ) \ 166 { \ 167 return 1; \ 168 } \ 169 \ 170 int \ 171 __declspec( dllexport ) \ 172 __cdecl \ 173 InitializeDriver ( \ 174 void *ImageHandle, \ 175 void *SystemTable \ 176 ) \ 177 { \ 178 return InitFunction(ImageHandle, SystemTable); \ 179 } 180 181 182 #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \ 183 (_if)->LoadInternal(type, name, NULL) 184 185 #else // EFI_NT_EMULATOR 186 187 // 188 // When building similar to FW, link everything together as 189 // one big module. 190 // 191 192 #define EFI_DRIVER_ENTRY_POINT(InitFunction) 193 194 #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \ 195 (_if)->LoadInternal(type, name, entry) 196 197 #endif // EFI_FW_NT 198 199 #define INTERFACE_DECL(x) struct x 200 201 #ifdef _MSC_EXTENSIONS 202 #pragma warning ( disable : 4731 ) // Suppress warnings about modification of EBP 203 #endif 204