]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/X64/ProcessorBind.h
9310f9f334a65ab025472b396bbe15f72fac905b
[mirror_edk2.git] / MdePkg / Include / X64 / ProcessorBind.h
1 /** @file
2 Processor or Compiler specific defines and types x64 (Intel(r) EM64T, AMD64).
3
4 Copyright (c) 2006 - 2009, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #ifndef __PROCESSOR_BIND_H__
16 #define __PROCESSOR_BIND_H__
17
18 ///
19 /// Define the processor type so other code can make processor based choices
20 ///
21 #define MDE_CPU_X64
22
23
24 //
25 // Make sure we are using the correct packing rules per EFI specification
26 //
27 #if !defined(__GNUC__)
28 #pragma pack()
29 #endif
30
31
32 #if defined(__INTEL_COMPILER)
33 //
34 // Disable ICC's remark #869: "Parameter" was never referenced warning.
35 // This is legal ANSI C code so we disable the remark that is turned on with -Wall
36 //
37 #pragma warning ( disable : 869 )
38
39 //
40 // Disable ICC's remark #1418: external function definition with no prior declaration.
41 // This is legal ANSI C code so we disable the remark that is turned on with /W4
42 //
43 #pragma warning ( disable : 1418 )
44
45 //
46 // Disable ICC's remark #1419: external declaration in primary source file
47 // This is legal ANSI C code so we disable the remark that is turned on with /W4
48 //
49 #pragma warning ( disable : 1419 )
50
51 #endif
52
53
54 #if defined(_MSC_EXTENSIONS)
55
56 //
57 // Disable warning that make it impossible to compile at /W4
58 // This only works for Microsoft* tools
59 //
60
61 //
62 // Disabling bitfield type checking warnings.
63 //
64 #pragma warning ( disable : 4214 )
65
66 //
67 // Disabling the unreferenced formal parameter warnings.
68 //
69 #pragma warning ( disable : 4100 )
70
71 //
72 // Disable slightly different base types warning as CHAR8 * can not be set
73 // to a constant string.
74 //
75 #pragma warning ( disable : 4057 )
76
77 //
78 // ASSERT(FALSE) or while (TRUE) are legal constructes so supress this warning
79 //
80 #pragma warning ( disable : 4127 )
81
82 //
83 // This warning is caused by functions defined but not used. For precompiled header only.
84 //
85 #pragma warning ( disable : 4505 )
86
87 //
88 // This warning is caused by empty (after preprocessing) source file. For precompiled header only.
89 //
90 #pragma warning ( disable : 4206 )
91
92 #endif
93
94
95 #if !defined(__GNUC__) && (__STDC_VERSION__ < 199901L)
96 //
97 // No ANSI C 2000 stdint.h integer width declarations, so define equivalents
98 //
99
100 #if defined(_MSC_EXTENSIONS)
101 //
102 // use Microsoft C complier dependent integer width types
103 //
104
105 ///
106 /// 8-byte unsigned value
107 ///
108 typedef unsigned __int64 UINT64;
109 ///
110 /// 8-byte signed value
111 ///
112 typedef __int64 INT64;
113 ///
114 /// 4-byte unsigned value
115 ///
116 typedef unsigned __int32 UINT32;
117 ///
118 /// 4-byte signed value
119 ///
120 typedef __int32 INT32;
121 ///
122 /// 2-byte unsigned value
123 ///
124 typedef unsigned short UINT16;
125 ///
126 /// 2-byte Character. Unless otherwise specified all strings are stored in the
127 /// UTF-16 encoding format as defined by Unicode 2.1 and ISO/IEC 10646 standards.
128 ///
129 typedef unsigned short CHAR16;
130 ///
131 /// 2-byte signed value
132 ///
133 typedef short INT16;
134 ///
135 /// Logical Boolean. 1-byte value containing 0 for FALSE or a 1 for TRUE. Other
136 /// values are undefined.
137 ///
138 typedef unsigned char BOOLEAN;
139 ///
140 /// 1-byte unsigned value
141 ///
142 typedef unsigned char UINT8;
143 ///
144 /// 1-byte Character
145 ///
146 typedef char CHAR8;
147 ///
148 /// 1-byte signed value
149 ///
150 typedef char INT8;
151 #else
152 #if defined(_EFI_P64)
153 //
154 // P64 - pointers being 64-bit and longs and ints are 32-bits.
155 //
156
157 ///
158 /// 8-byte unsigned value
159 ///
160 typedef unsigned long long UINT64;
161 ///
162 /// 8-byte signed value
163 ///
164 typedef long long INT64;
165 ///
166 /// 4-byte unsigned value
167 ///
168 typedef unsigned int UINT32;
169 ///
170 /// 4-byte signed value
171 ///
172 typedef int INT32;
173 ///
174 /// 2-byte Character. Unless otherwise specified all strings are stored in the
175 /// UTF-16 encoding format as defined by Unicode 2.1 and ISO/IEC 10646 standards.
176 ///
177 typedef unsigned short CHAR16;
178 ///
179 /// 2-byte unsigned value
180 ///
181 typedef unsigned short UINT16;
182 ///
183 /// 2-byte signed value
184 ///
185 typedef short INT16;
186 ///
187 /// Logical Boolean. 1-byte value containing 0 for FALSE or a 1 for TRUE. Other
188 /// values are undefined.
189 ///
190 typedef unsigned char BOOLEAN;
191 ///
192 /// 1-byte unsigned value
193 ///
194 typedef unsigned char UINT8;
195 ///
196 /// 1-byte Character
197 ///
198 typedef char CHAR8;
199 ///
200 /// 1-byte signed value
201 ///
202 typedef char INT8;
203 #else
204 //
205 // Assume LP64 - longs and pointers are 64-bit. Ints are 32-bit.
206 //
207
208 ///
209 /// 8-byte unsigned value
210 ///
211 typedef unsigned long UINT64;
212 ///
213 /// 8-byte signed value
214 ///
215 typedef long INT64;
216 ///
217 /// 4-byte unsigned value
218 ///
219 typedef unsigned int UINT32;
220 ///
221 /// 4-byte signed value
222 ///
223 typedef int INT32;
224 ///
225 /// 2-byte unsigned value
226 ///
227 typedef unsigned short UINT16;
228 ///
229 /// 2-byte Character. Unless otherwise specified all strings are stored in the
230 /// UTF-16 encoding format as defined by Unicode 2.1 and ISO/IEC 10646 standards.
231 ///
232 typedef unsigned short CHAR16;
233 ///
234 /// 2-byte signed value
235 ///
236 typedef short INT16;
237 ///
238 /// Logical Boolean. 1-byte value containing 0 for FALSE or a 1 for TRUE. Other
239 /// values are undefined.
240 ///
241 typedef unsigned char BOOLEAN;
242 ///
243 /// 1-byte unsigned value
244 ///
245 typedef unsigned char UINT8;
246 ///
247 /// 1-byte Character
248 ///
249 typedef char CHAR8;
250 ///
251 /// 1-byte signed value
252 ///
253 typedef char INT8;
254 #endif
255 #endif
256 #else
257 //
258 // Use ANSI C 2000 stdint.h integer width declarations
259 //
260 #include <stdint.h>
261
262 ///
263 /// Logical Boolean. 1-byte value containing 0 for FALSE or a 1 for TRUE. Other
264 /// values are undefined.
265 ///
266 typedef uint8_t BOOLEAN;
267 ///
268 /// 1-byte signed value
269 ///
270 typedef int8_t INT8;
271 ///
272 /// 1-byte unsigned value
273 ///
274 typedef uint8_t UINT8;
275 ///
276 /// 2-byte signed value
277 ///
278 typedef int16_t INT16;
279 ///
280 /// 2-byte unsigned value
281 ///
282 typedef uint16_t UINT16;
283 ///
284 /// 4-byte signed value
285 ///
286 typedef int32_t INT32;
287 ///
288 /// 4-byte unsigned value
289 ///
290 typedef uint32_t UINT32;
291 ///
292 /// 8-byte signed value
293 ///
294 typedef int64_t INT64;
295 ///
296 /// 8-byte unsigned value
297 ///
298 typedef uint64_t UINT64;
299 ///
300 /// 1-byte Character
301 ///
302 typedef char CHAR8;
303 ///
304 /// 2-byte Character. Unless otherwise specified all strings are stored in the
305 /// UTF-16 encoding format as defined by Unicode 2.1 and ISO/IEC 10646 standards.
306 ///
307 typedef uint16_t CHAR16;
308
309 #endif
310
311 ///
312 /// Unsigned value of native width. (4 bytes on supported 32-bit processor instructions,
313 /// 8 bytes on supported 64-bit processor instructions)
314 ///
315 typedef UINT64 UINTN;
316 ///
317 /// Signed value of native width. (4 bytes on supported 32-bit processor instructions,
318 /// 8 bytes on supported 64-bit processor instructions)
319 ///
320 typedef INT64 INTN;
321
322
323 //
324 // Processor specific defines
325 //
326
327 ///
328 /// A value of native width with the highest bit set.
329 ///
330 #define MAX_BIT 0x8000000000000000ULL
331 ///
332 /// A value of native width with the two highest bits set.
333 ///
334 #define MAX_2_BITS 0xC000000000000000ULL
335
336 ///
337 /// Maximum legal x64 address
338 ///
339 #define MAX_ADDRESS 0xFFFFFFFFFFFFFFFFULL
340
341 ///
342 /// The stack alignment required for x64
343 ///
344 #define CPU_STACK_ALIGNMENT 16
345
346 //
347 // Modifier to ensure that all protocol member functions and EFI intrinsics
348 // use the correct C calling convention. All protocol member functions and
349 // EFI intrinsics are required to modify their member functions with EFIAPI.
350 //
351 #ifdef EFIAPI
352 ///
353 /// If EFIAPI is already defined, then we use that definition.
354 ///
355 #elif defined(_MSC_EXTENSIONS)
356 ///
357 /// Microsoft* compiler specific method for EFIAPI calling convension
358 ///
359 #define EFIAPI __cdecl
360 #elif defined(__GNUC__)
361 ///
362 /// Define the standard calling convention reguardless of optimization level.
363 /// The GCC support assumes a GCC compiler that supports the EFI ABI. The EFI
364 /// ABI is much closer to the x64 Microsoft* ABI than standard x64 (x86-64)
365 /// GCC ABI. Thus a standard x64 (x86-64) GCC compiler can not be used for
366 /// x64. Warning the assembly code in the MDE x64 does not follow the correct
367 /// ABI for the standard x64 (x86-64) GCC.
368 ///
369 #define EFIAPI
370 #else
371 ///
372 /// The default for a non Microsoft* or GCC compiler is to assume the EFI ABI
373 /// is the standard.
374 ///
375 #define EFIAPI
376 #endif
377
378 //
379 // The Microsoft* C compiler can removed references to unreferenced data items
380 // if the /OPT:REF linker option is used. We defined a macro as this is a
381 // a non standard extension
382 //
383 #if defined(_MSC_EXTENSIONS)
384 ///
385 /// Remove global variable from the linked image if there are no references to
386 /// it after all compiler and linker optimizations have been performed.
387 ///
388 ///
389 #define GLOBAL_REMOVE_IF_UNREFERENCED __declspec(selectany)
390 #else
391 ///
392 /// Remove global variable from the linked image if there are no references to
393 /// it after all compiler and linker optimizations have been performed.
394 ///
395 ///
396 #define GLOBAL_REMOVE_IF_UNREFERENCED
397 #endif
398
399 //
400 // For symbol name in GNU assembly code, an extra "_" is necessary
401 //
402 #if defined(__GNUC__)
403 #if defined(linux)
404 #define ASM_PFX(name) name
405 #else
406 #define ASM_PFX(name) _##name
407 #endif
408 #endif
409
410 /**
411 Return the pointer to the first instruction of a function given a function pointer.
412 On x64 CPU architectures, these two pointer values are the same,
413 so the implementation of this macro is very simple.
414
415 @param FunctionPointer A pointer to a function.
416
417 @return The pointer to the first instruction of a function given a function pointer.
418
419 **/
420 #define FUNCTION_ENTRY_POINT(FunctionPointer) (VOID *)(UINTN)(FunctionPointer)
421
422 #endif
423