Ronak Kanabar | 1ae366f | 2023-06-07 01:21:56 +0530 | [diff] [blame^] | 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 | #if defined (_MSC_EXTENSIONS) |
| 66 | |
| 67 | // |
| 68 | // Disable warning that make it impossible to compile at /W4 |
| 69 | // This only works for Microsoft* tools |
| 70 | // |
| 71 | |
| 72 | // |
| 73 | // Disabling bitfield type checking warnings. |
| 74 | // |
| 75 | #pragma warning ( disable : 4214 ) |
| 76 | |
| 77 | // |
| 78 | // Disabling the unreferenced formal parameter warnings. |
| 79 | // |
| 80 | #pragma warning ( disable : 4100 ) |
| 81 | |
| 82 | // |
| 83 | // Disable slightly different base types warning as CHAR8 * can not be set |
| 84 | // to a constant string. |
| 85 | // |
| 86 | #pragma warning ( disable : 4057 ) |
| 87 | |
| 88 | // |
| 89 | // ASSERT(FALSE) or while (TRUE) are legal constructs so suppress this warning |
| 90 | // |
| 91 | #pragma warning ( disable : 4127 ) |
| 92 | |
| 93 | // |
| 94 | // This warning is caused by functions defined but not used. For precompiled header only. |
| 95 | // |
| 96 | #pragma warning ( disable : 4505 ) |
| 97 | |
| 98 | // |
| 99 | // This warning is caused by empty (after preprocessing) source file. For precompiled header only. |
| 100 | // |
| 101 | #pragma warning ( disable : 4206 ) |
| 102 | |
| 103 | #if defined (_MSC_VER) && _MSC_VER >= 1800 |
| 104 | |
| 105 | // |
| 106 | // Disable these warnings for VS2013. |
| 107 | // |
| 108 | |
| 109 | // |
| 110 | // This warning is for potentially uninitialized local variable, and it may cause false |
| 111 | // positive issues in VS2013 and VS2015 build |
| 112 | // |
| 113 | #pragma warning ( disable : 4701 ) |
| 114 | |
| 115 | // |
| 116 | // This warning is for potentially uninitialized local pointer variable, and it may cause |
| 117 | // false positive issues in VS2013 and VS2015 build |
| 118 | // |
| 119 | #pragma warning ( disable : 4703 ) |
| 120 | |
| 121 | #endif |
| 122 | |
| 123 | #endif |
| 124 | |
| 125 | #if defined (_MSC_EXTENSIONS) |
| 126 | // |
| 127 | // use Microsoft C compiler dependent integer width types |
| 128 | // |
| 129 | |
| 130 | /// |
| 131 | /// 8-byte unsigned value |
| 132 | /// |
| 133 | typedef unsigned __int64 UINT64; |
| 134 | /// |
| 135 | /// 8-byte signed value |
| 136 | /// |
| 137 | typedef __int64 INT64; |
| 138 | /// |
| 139 | /// 4-byte unsigned value |
| 140 | /// |
| 141 | typedef unsigned __int32 UINT32; |
| 142 | /// |
| 143 | /// 4-byte signed value |
| 144 | /// |
| 145 | typedef __int32 INT32; |
| 146 | /// |
| 147 | /// 2-byte unsigned value |
| 148 | /// |
| 149 | typedef unsigned short UINT16; |
| 150 | /// |
| 151 | /// 2-byte Character. Unless otherwise specified all strings are stored in the |
| 152 | /// UTF-16 encoding format as defined by Unicode 2.1 and ISO/IEC 10646 standards. |
| 153 | /// |
| 154 | typedef unsigned short CHAR16; |
| 155 | /// |
| 156 | /// 2-byte signed value |
| 157 | /// |
| 158 | typedef short INT16; |
| 159 | /// |
| 160 | /// Logical Boolean. 1-byte value containing 0 for FALSE or a 1 for TRUE. Other |
| 161 | /// values are undefined. |
| 162 | /// |
| 163 | typedef unsigned char BOOLEAN; |
| 164 | /// |
| 165 | /// 1-byte unsigned value |
| 166 | /// |
| 167 | typedef unsigned char UINT8; |
| 168 | /// |
| 169 | /// 1-byte Character |
| 170 | /// |
| 171 | typedef char CHAR8; |
| 172 | /// |
| 173 | /// 1-byte signed value |
| 174 | /// |
| 175 | typedef signed char INT8; |
| 176 | #else |
| 177 | /// |
| 178 | /// 8-byte unsigned value |
| 179 | /// |
| 180 | typedef unsigned long long UINT64; |
| 181 | /// |
| 182 | /// 8-byte signed value |
| 183 | /// |
| 184 | typedef long long INT64; |
| 185 | /// |
| 186 | /// 4-byte unsigned value |
| 187 | /// |
| 188 | typedef unsigned int UINT32; |
| 189 | /// |
| 190 | /// 4-byte signed value |
| 191 | /// |
| 192 | typedef int INT32; |
| 193 | /// |
| 194 | /// 2-byte unsigned value |
| 195 | /// |
| 196 | typedef unsigned short UINT16; |
| 197 | /// |
| 198 | /// 2-byte Character. Unless otherwise specified all strings are stored in the |
| 199 | /// UTF-16 encoding format as defined by Unicode 2.1 and ISO/IEC 10646 standards. |
| 200 | /// |
| 201 | typedef unsigned short CHAR16; |
| 202 | /// |
| 203 | /// 2-byte signed value |
| 204 | /// |
| 205 | typedef short INT16; |
| 206 | /// |
| 207 | /// Logical Boolean. 1-byte value containing 0 for FALSE or a 1 for TRUE. Other |
| 208 | /// values are undefined. |
| 209 | /// |
| 210 | typedef unsigned char BOOLEAN; |
| 211 | /// |
| 212 | /// 1-byte unsigned value |
| 213 | /// |
| 214 | typedef unsigned char UINT8; |
| 215 | /// |
| 216 | /// 1-byte Character |
| 217 | /// |
| 218 | typedef char CHAR8; |
| 219 | /// |
| 220 | /// 1-byte signed value |
| 221 | /// |
| 222 | typedef signed char INT8; |
| 223 | #endif |
| 224 | |
| 225 | /// |
| 226 | /// Unsigned value of native width. (4 bytes on supported 32-bit processor instructions, |
| 227 | /// 8 bytes on supported 64-bit processor instructions) |
| 228 | /// |
| 229 | typedef UINT64 UINTN; |
| 230 | /// |
| 231 | /// Signed value of native width. (4 bytes on supported 32-bit processor instructions, |
| 232 | /// 8 bytes on supported 64-bit processor instructions) |
| 233 | /// |
| 234 | typedef INT64 INTN; |
| 235 | |
| 236 | // |
| 237 | // Processor specific defines |
| 238 | // |
| 239 | |
| 240 | /// |
| 241 | /// A value of native width with the highest bit set. |
| 242 | /// |
| 243 | #define MAX_BIT 0x8000000000000000ULL |
| 244 | /// |
| 245 | /// A value of native width with the two highest bits set. |
| 246 | /// |
| 247 | #define MAX_2_BITS 0xC000000000000000ULL |
| 248 | |
| 249 | /// |
| 250 | /// Maximum legal x64 address |
| 251 | /// |
| 252 | #define MAX_ADDRESS 0xFFFFFFFFFFFFFFFFULL |
| 253 | |
| 254 | /// |
| 255 | /// Maximum usable address at boot time |
| 256 | /// |
| 257 | #define MAX_ALLOC_ADDRESS MAX_ADDRESS |
| 258 | |
| 259 | /// |
| 260 | /// Maximum legal x64 INTN and UINTN values. |
| 261 | /// |
| 262 | #define MAX_INTN ((INTN)0x7FFFFFFFFFFFFFFFULL) |
| 263 | #define MAX_UINTN ((UINTN)0xFFFFFFFFFFFFFFFFULL) |
| 264 | |
| 265 | /// |
| 266 | /// Minimum legal x64 INTN value. |
| 267 | /// |
| 268 | #define MIN_INTN (((INTN)-9223372036854775807LL) - 1) |
| 269 | |
| 270 | /// |
| 271 | /// The stack alignment required for x64 |
| 272 | /// |
| 273 | #define CPU_STACK_ALIGNMENT 16 |
| 274 | |
| 275 | /// |
| 276 | /// Page allocation granularity for x64 |
| 277 | /// |
| 278 | #define DEFAULT_PAGE_ALLOCATION_GRANULARITY (0x1000) |
| 279 | #define RUNTIME_PAGE_ALLOCATION_GRANULARITY (0x1000) |
| 280 | |
| 281 | // |
| 282 | // Modifier to ensure that all protocol member functions and EFI intrinsics |
| 283 | // use the correct C calling convention. All protocol member functions and |
| 284 | // EFI intrinsics are required to modify their member functions with EFIAPI. |
| 285 | // |
| 286 | #ifdef EFIAPI |
| 287 | /// |
| 288 | /// If EFIAPI is already defined, then we use that definition. |
| 289 | /// |
| 290 | #elif defined (_MSC_EXTENSIONS) |
| 291 | /// |
| 292 | /// Microsoft* compiler specific method for EFIAPI calling convention. |
| 293 | /// |
| 294 | #define EFIAPI __cdecl |
| 295 | #elif defined (__GNUC__) |
| 296 | /// |
| 297 | /// Define the standard calling convention regardless of optimization level. |
| 298 | /// The GCC support assumes a GCC compiler that supports the EFI ABI. The EFI |
| 299 | /// ABI is much closer to the x64 Microsoft* ABI than standard x64 (x86-64) |
| 300 | /// GCC ABI. Thus a standard x64 (x86-64) GCC compiler can not be used for |
| 301 | /// x64. Warning the assembly code in the MDE x64 does not follow the correct |
| 302 | /// ABI for the standard x64 (x86-64) GCC. |
| 303 | /// |
| 304 | #define EFIAPI |
| 305 | #else |
| 306 | /// |
| 307 | /// The default for a non Microsoft* or GCC compiler is to assume the EFI ABI |
| 308 | /// is the standard. |
| 309 | /// |
| 310 | #define EFIAPI |
| 311 | #endif |
| 312 | |
| 313 | #if defined (__GNUC__) || defined (__clang__) |
| 314 | /// |
| 315 | /// For GNU assembly code, .global or .globl can declare global symbols. |
| 316 | /// Define this macro to unify the usage. |
| 317 | /// |
| 318 | #define ASM_GLOBAL .globl |
| 319 | #endif |
| 320 | |
| 321 | /** |
| 322 | Return the pointer to the first instruction of a function given a function pointer. |
| 323 | On x64 CPU architectures, these two pointer values are the same, |
| 324 | so the implementation of this macro is very simple. |
| 325 | |
| 326 | @param FunctionPointer A pointer to a function. |
| 327 | |
| 328 | @return The pointer to the first instruction of a function given a function pointer. |
| 329 | |
| 330 | **/ |
| 331 | #define FUNCTION_ENTRY_POINT(FunctionPointer) (VOID *)(UINTN)(FunctionPointer) |
| 332 | |
| 333 | #ifndef __USER_LABEL_PREFIX__ |
| 334 | #define __USER_LABEL_PREFIX__ |
| 335 | #endif |
| 336 | |
| 337 | #endif |