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