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