1 /** @file 2 Processor or Compiler specific defines and types x64 (Intel 64, AMD64). 3 4 Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR> 5 SPDX-License-Identifier: BSD-2-Clause-Patent 6 7 **/ 8 9 #ifndef __PROCESSOR_BIND_H__ 10 #define __PROCESSOR_BIND_H__ 11 12 /// 13 /// Define the processor type so other code can make processor based choices 14 /// 15 #define MDE_CPU_X64 16 17 // 18 // Make sure we are using the correct packing rules per EFI specification 19 // 20 #if !defined(__GNUC__) 21 #pragma pack() 22 #endif 23 24 #if defined(__GNUC__) && defined(__pic__) && !defined(USING_LTO) && !defined(__APPLE__) 25 // 26 // Mark all symbol declarations and references as hidden, meaning they will 27 // not be subject to symbol preemption. This allows the compiler to refer to 28 // symbols directly using relative references rather than via the GOT, which 29 // contains absolute symbol addresses that are subject to runtime relocation. 30 // 31 // The LTO linker will not emit GOT based relocations when all symbol 32 // references can be resolved locally, and so there is no need to set the 33 // pragma in that case (and doing so will cause other issues). 34 // 35 #pragma GCC visibility push (hidden) 36 #endif 37 38 #if defined(__INTEL_COMPILER) 39 // 40 // Disable ICC's remark #869: "Parameter" was never referenced warning. 41 // This is legal ANSI C code so we disable the remark that is turned on with -Wall 42 // 43 #pragma warning ( disable : 869 ) 44 45 // 46 // Disable ICC's remark #1418: external function definition with no prior declaration. 47 // This is legal ANSI C code so we disable the remark that is turned on with /W4 48 // 49 #pragma warning ( disable : 1418 ) 50 51 // 52 // Disable ICC's remark #1419: external declaration in primary source file 53 // This is legal ANSI C code so we disable the remark that is turned on with /W4 54 // 55 #pragma warning ( disable : 1419 ) 56 57 // 58 // Disable ICC's remark #593: "Variable" was set but never used. 59 // This is legal ANSI C code so we disable the remark that is turned on with /W4 60 // 61 #pragma warning ( disable : 593 ) 62 63 #endif 64 65 66 #if defined(_MSC_EXTENSIONS) 67 68 // 69 // Disable warning that make it impossible to compile at /W4 70 // This only works for Microsoft* tools 71 // 72 73 // 74 // Disabling bitfield type checking warnings. 75 // 76 #pragma warning ( disable : 4214 ) 77 78 // 79 // Disabling the unreferenced formal parameter warnings. 80 // 81 #pragma warning ( disable : 4100 ) 82 83 // 84 // Disable slightly different base types warning as CHAR8 * can not be set 85 // to a constant string. 86 // 87 #pragma warning ( disable : 4057 ) 88 89 // 90 // ASSERT(FALSE) or while (TRUE) are legal constructs so suppress this warning 91 // 92 #pragma warning ( disable : 4127 ) 93 94 // 95 // This warning is caused by functions defined but not used. For precompiled header only. 96 // 97 #pragma warning ( disable : 4505 ) 98 99 // 100 // This warning is caused by empty (after preprocessing) source file. For precompiled header only. 101 // 102 #pragma warning ( disable : 4206 ) 103 104 #if defined(_MSC_VER) && _MSC_VER >= 1800 105 106 // 107 // Disable these warnings for VS2013. 108 // 109 110 // 111 // This warning is for potentially uninitialized local variable, and it may cause false 112 // positive issues in VS2013 and VS2015 build 113 // 114 #pragma warning ( disable : 4701 ) 115 116 // 117 // This warning is for potentially uninitialized local pointer variable, and it may cause 118 // false positive issues in VS2013 and VS2015 build 119 // 120 #pragma warning ( disable : 4703 ) 121 122 #endif 123 124 #endif 125 126 127 #if defined(_MSC_EXTENSIONS) 128 // 129 // use Microsoft C compiler dependent integer width types 130 // 131 132 /// 133 /// 8-byte unsigned value 134 /// 135 typedef unsigned __int64 UINT64; 136 /// 137 /// 8-byte signed value 138 /// 139 typedef __int64 INT64; 140 /// 141 /// 4-byte unsigned value 142 /// 143 typedef unsigned __int32 UINT32; 144 /// 145 /// 4-byte signed value 146 /// 147 typedef __int32 INT32; 148 /// 149 /// 2-byte unsigned value 150 /// 151 typedef unsigned short UINT16; 152 /// 153 /// 2-byte Character. Unless otherwise specified all strings are stored in the 154 /// UTF-16 encoding format as defined by Unicode 2.1 and ISO/IEC 10646 standards. 155 /// 156 typedef unsigned short CHAR16; 157 /// 158 /// 2-byte signed value 159 /// 160 typedef short INT16; 161 /// 162 /// Logical Boolean. 1-byte value containing 0 for FALSE or a 1 for TRUE. Other 163 /// values are undefined. 164 /// 165 typedef unsigned char BOOLEAN; 166 /// 167 /// 1-byte unsigned value 168 /// 169 typedef unsigned char UINT8; 170 /// 171 /// 1-byte Character 172 /// 173 typedef char CHAR8; 174 /// 175 /// 1-byte signed value 176 /// 177 typedef signed char INT8; 178 #else 179 /// 180 /// 8-byte unsigned value 181 /// 182 typedef unsigned long long UINT64; 183 /// 184 /// 8-byte signed value 185 /// 186 typedef long long INT64; 187 /// 188 /// 4-byte unsigned value 189 /// 190 typedef unsigned int UINT32; 191 /// 192 /// 4-byte signed value 193 /// 194 typedef int INT32; 195 /// 196 /// 2-byte unsigned value 197 /// 198 typedef unsigned short UINT16; 199 /// 200 /// 2-byte Character. Unless otherwise specified all strings are stored in the 201 /// UTF-16 encoding format as defined by Unicode 2.1 and ISO/IEC 10646 standards. 202 /// 203 typedef unsigned short CHAR16; 204 /// 205 /// 2-byte signed value 206 /// 207 typedef short INT16; 208 /// 209 /// Logical Boolean. 1-byte value containing 0 for FALSE or a 1 for TRUE. Other 210 /// values are undefined. 211 /// 212 typedef unsigned char BOOLEAN; 213 /// 214 /// 1-byte unsigned value 215 /// 216 typedef unsigned char UINT8; 217 /// 218 /// 1-byte Character 219 /// 220 typedef char CHAR8; 221 /// 222 /// 1-byte signed value 223 /// 224 typedef signed char INT8; 225 #endif 226 227 /// 228 /// Unsigned value of native width. (4 bytes on supported 32-bit processor instructions, 229 /// 8 bytes on supported 64-bit processor instructions) 230 /// 231 typedef UINT64 UINTN; 232 /// 233 /// Signed value of native width. (4 bytes on supported 32-bit processor instructions, 234 /// 8 bytes on supported 64-bit processor instructions) 235 /// 236 typedef INT64 INTN; 237 238 239 // 240 // Processor specific defines 241 // 242 243 /// 244 /// A value of native width with the highest bit set. 245 /// 246 #define MAX_BIT 0x8000000000000000ULL 247 /// 248 /// A value of native width with the two highest bits set. 249 /// 250 #define MAX_2_BITS 0xC000000000000000ULL 251 252 /// 253 /// Maximum legal x64 address 254 /// 255 #define MAX_ADDRESS 0xFFFFFFFFFFFFFFFFULL 256 257 /// 258 /// Maximum usable address at boot time 259 /// 260 #define MAX_ALLOC_ADDRESS MAX_ADDRESS 261 262 /// 263 /// Maximum legal x64 INTN and UINTN values. 264 /// 265 #define MAX_INTN ((INTN)0x7FFFFFFFFFFFFFFFULL) 266 #define MAX_UINTN ((UINTN)0xFFFFFFFFFFFFFFFFULL) 267 268 /// 269 /// Minimum legal x64 INTN value. 270 /// 271 #define MIN_INTN (((INTN)-9223372036854775807LL) - 1) 272 273 /// 274 /// The stack alignment required for x64 275 /// 276 #define CPU_STACK_ALIGNMENT 16 277 278 /// 279 /// Page allocation granularity for x64 280 /// 281 #define DEFAULT_PAGE_ALLOCATION_GRANULARITY (0x1000) 282 #define RUNTIME_PAGE_ALLOCATION_GRANULARITY (0x1000) 283 284 // 285 // Modifier to ensure that all protocol member functions and EFI intrinsics 286 // use the correct C calling convention. All protocol member functions and 287 // EFI intrinsics are required to modify their member functions with EFIAPI. 288 // 289 #ifdef EFIAPI 290 /// 291 /// If EFIAPI is already defined, then we use that definition. 292 /// 293 #elif defined(_MSC_EXTENSIONS) 294 /// 295 /// Microsoft* compiler specific method for EFIAPI calling convention. 296 /// 297 #define EFIAPI __cdecl 298 #elif defined(__GNUC__) 299 /// 300 /// Define the standard calling convention regardless of optimization level. 301 /// The GCC support assumes a GCC compiler that supports the EFI ABI. The EFI 302 /// ABI is much closer to the x64 Microsoft* ABI than standard x64 (x86-64) 303 /// GCC ABI. Thus a standard x64 (x86-64) GCC compiler can not be used for 304 /// x64. Warning the assembly code in the MDE x64 does not follow the correct 305 /// ABI for the standard x64 (x86-64) GCC. 306 /// 307 #define EFIAPI 308 #else 309 /// 310 /// The default for a non Microsoft* or GCC compiler is to assume the EFI ABI 311 /// is the standard. 312 /// 313 #define EFIAPI 314 #endif 315 316 #if defined(__GNUC__) || defined(__clang__) 317 /// 318 /// For GNU assembly code, .global or .globl can declare global symbols. 319 /// Define this macro to unify the usage. 320 /// 321 #define ASM_GLOBAL .globl 322 #endif 323 324 /** 325 Return the pointer to the first instruction of a function given a function pointer. 326 On x64 CPU architectures, these two pointer values are the same, 327 so the implementation of this macro is very simple. 328 329 @param FunctionPointer A pointer to a function. 330 331 @return The pointer to the first instruction of a function given a function pointer. 332 333 **/ 334 #define FUNCTION_ENTRY_POINT(FunctionPointer) (VOID *)(UINTN)(FunctionPointer) 335 336 #ifndef __USER_LABEL_PREFIX__ 337 #define __USER_LABEL_PREFIX__ 338 #endif 339 340 #endif 341 342