1 /** @file
2   Processor or Compiler specific defines and types for AArch64.
3 
4   Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5   Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
6   Portions copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.<BR>
7 
8   SPDX-License-Identifier: BSD-2-Clause-Patent
9 
10 **/
11 
12 #ifndef __PROCESSOR_BIND_H__
13 #define __PROCESSOR_BIND_H__
14 
15 ///
16 /// Define the processor type so other code can make processor based choices
17 ///
18 #define MDE_CPU_AARCH64
19 
20 //
21 // Make sure we are using the correct packing rules per EFI specification
22 //
23 #if !defined (__GNUC__) && !defined (__ASSEMBLER__)
24   #pragma pack()
25 #endif
26 
27 #if defined (_MSC_EXTENSIONS)
28 
29 //
30 // Disable some level 4 compilation warnings (same as IA32 and X64)
31 //
32 
33 //
34 // Disabling bitfield type checking warnings.
35 //
36   #pragma warning ( disable : 4214 )
37 
38 //
39 // Disabling the unreferenced formal parameter warnings.
40 //
41   #pragma warning ( disable : 4100 )
42 
43 //
44 // Disable slightly different base types warning as CHAR8 * can not be set
45 // to a constant string.
46 //
47   #pragma warning ( disable : 4057 )
48 
49 //
50 // ASSERT(FALSE) or while (TRUE) are legal constructs so suppress this warning
51 //
52   #pragma warning ( disable : 4127 )
53 
54 //
55 // This warning is caused by functions defined but not used. For precompiled header only.
56 //
57   #pragma warning ( disable : 4505 )
58 
59 //
60 // This warning is caused by empty (after preprocessing) source file. For precompiled header only.
61 //
62   #pragma warning ( disable : 4206 )
63 
64 //
65 // Disable 'potentially uninitialized local variable X used' warnings
66 //
67   #pragma warning ( disable : 4701 )
68 
69 //
70 // Disable 'potentially uninitialized local pointer variable X used' warnings
71 //
72   #pragma warning ( disable : 4703 )
73 
74 //
75 // use Microsoft* C compiler dependent integer width types
76 //
77 typedef unsigned __int64  UINT64;
78 typedef __int64           INT64;
79 typedef unsigned __int32  UINT32;
80 typedef __int32           INT32;
81 typedef unsigned short    UINT16;
82 typedef unsigned short    CHAR16;
83 typedef short             INT16;
84 typedef unsigned char     BOOLEAN;
85 typedef unsigned char     UINT8;
86 typedef char              CHAR8;
87 typedef signed char       INT8;
88 
89 #else
90 
91 //
92 // Assume standard AARCH64 alignment.
93 //
94 typedef unsigned long long  UINT64;
95 typedef long long           INT64;
96 typedef unsigned int        UINT32;
97 typedef int                 INT32;
98 typedef unsigned short      UINT16;
99 typedef unsigned short      CHAR16;
100 typedef short               INT16;
101 typedef unsigned char       BOOLEAN;
102 typedef unsigned char       UINT8;
103 typedef char                CHAR8;
104 typedef signed char         INT8;
105 
106 #endif
107 
108 ///
109 /// Unsigned value of native width.  (4 bytes on supported 32-bit processor instructions,
110 /// 8 bytes on supported 64-bit processor instructions)
111 ///
112 typedef UINT64 UINTN;
113 
114 ///
115 /// Signed value of native width.  (4 bytes on supported 32-bit processor instructions,
116 /// 8 bytes on supported 64-bit processor instructions)
117 ///
118 typedef INT64 INTN;
119 
120 //
121 // Processor specific defines
122 //
123 
124 ///
125 /// A value of native width with the highest bit set.
126 ///
127 #define MAX_BIT  0x8000000000000000ULL
128 
129 ///
130 /// A value of native width with the two highest bits set.
131 ///
132 #define MAX_2_BITS  0xC000000000000000ULL
133 
134 ///
135 /// Maximum legal AARCH64  address
136 ///
137 #define MAX_ADDRESS  0xFFFFFFFFFFFFFFFFULL
138 
139 ///
140 /// Maximum usable address at boot time (48 bits using 4 KB pages)
141 ///
142 #define MAX_ALLOC_ADDRESS  0xFFFFFFFFFFFFULL
143 
144 ///
145 /// Maximum legal AArch64 INTN and UINTN values.
146 ///
147 #define MAX_INTN   ((INTN)0x7FFFFFFFFFFFFFFFULL)
148 #define MAX_UINTN  ((UINTN)0xFFFFFFFFFFFFFFFFULL)
149 
150 ///
151 /// Minimum legal AArch64 INTN value.
152 ///
153 #define MIN_INTN  (((INTN)-9223372036854775807LL) - 1)
154 
155 ///
156 /// The stack alignment required for AARCH64
157 ///
158 #define CPU_STACK_ALIGNMENT  16
159 
160 ///
161 /// Page allocation granularity for AARCH64
162 ///
163 #define DEFAULT_PAGE_ALLOCATION_GRANULARITY  (0x1000)
164 #define RUNTIME_PAGE_ALLOCATION_GRANULARITY  (0x10000)
165 
166 //
167 // Modifier to ensure that all protocol member functions and EFI intrinsics
168 // use the correct C calling convention. All protocol member functions and
169 // EFI intrinsics are required to modify their member functions with EFIAPI.
170 //
171 #define EFIAPI
172 
173 // When compiling with Clang, we still use GNU as for the assembler, so we still
174 // need to define the GCC_ASM* macros.
175 #if defined (__GNUC__) || defined (__clang__)
176 ///
177 /// For GNU assembly code, .global or .globl can declare global symbols.
178 /// Define this macro to unify the usage.
179 ///
180 #define ASM_GLOBAL  .globl
181 
182 #define GCC_ASM_EXPORT(func__)  \
183          .global  _CONCATENATE (__USER_LABEL_PREFIX__, func__)    ;\
184          .type ASM_PFX(func__), %function
185 
186 #define GCC_ASM_IMPORT(func__)  \
187          .extern  _CONCATENATE (__USER_LABEL_PREFIX__, func__)
188 
189 #endif
190 
191 /**
192   Return the pointer to the first instruction of a function given a function pointer.
193   On ARM CPU architectures, these two pointer values are the same,
194   so the implementation of this macro is very simple.
195 
196   @param  FunctionPointer   A pointer to a function.
197 
198   @return The pointer to the first instruction of a function given a function pointer.
199 
200 **/
201 #define FUNCTION_ENTRY_POINT(FunctionPointer)  (VOID *)(UINTN)(FunctionPointer)
202 
203 #ifndef __USER_LABEL_PREFIX__
204 #define __USER_LABEL_PREFIX__
205 #endif
206 
207 #endif
208