MdePkg/BaseSafeIntLib: Add SafeIntLib class and instance
[mirror_edk2.git] / MdePkg / Include / Arm / ProcessorBind.h
1 /** @file
2 Processor or Compiler specific defines and types for ARM.
3
4 Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
5 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #ifndef __PROCESSOR_BIND_H__
17 #define __PROCESSOR_BIND_H__
18
19 ///
20 /// Define the processor type so other code can make processor based choices
21 ///
22 #define MDE_CPU_ARM
23
24 //
25 // Make sure we are using the correct packing rules per EFI specification
26 //
27 #if !defined(__GNUC__) && !defined(__ASSEMBLER__)
28 #pragma pack()
29 #endif
30
31 //
32 // RVCT does not support the __builtin_unreachable() macro
33 //
34 #ifdef __ARMCC_VERSION
35 #define UNREACHABLE()
36 #endif
37
38 #if _MSC_EXTENSIONS
39 //
40 // use Microsoft* C compiler dependent integer width types
41 //
42 typedef unsigned __int64 UINT64;
43 typedef __int64 INT64;
44 typedef unsigned __int32 UINT32;
45 typedef __int32 INT32;
46 typedef unsigned short UINT16;
47 typedef unsigned short CHAR16;
48 typedef short INT16;
49 typedef unsigned char BOOLEAN;
50 typedef unsigned char UINT8;
51 typedef char CHAR8;
52 typedef signed char INT8;
53 #else
54 //
55 // Assume standard ARM alignment.
56 // Need to check portability of long long
57 //
58 typedef unsigned long long UINT64;
59 typedef long long INT64;
60 typedef unsigned int UINT32;
61 typedef int INT32;
62 typedef unsigned short UINT16;
63 typedef unsigned short CHAR16;
64 typedef short INT16;
65 typedef unsigned char BOOLEAN;
66 typedef unsigned char UINT8;
67 typedef char CHAR8;
68 typedef signed char INT8;
69 #endif
70
71 ///
72 /// Unsigned value of native width. (4 bytes on supported 32-bit processor instructions,
73 /// 8 bytes on supported 64-bit processor instructions)
74 ///
75 typedef UINT32 UINTN;
76
77 ///
78 /// Signed value of native width. (4 bytes on supported 32-bit processor instructions,
79 /// 8 bytes on supported 64-bit processor instructions)
80 ///
81 typedef INT32 INTN;
82
83 //
84 // Processor specific defines
85 //
86
87 ///
88 /// A value of native width with the highest bit set.
89 ///
90 #define MAX_BIT 0x80000000
91
92 ///
93 /// A value of native width with the two highest bits set.
94 ///
95 #define MAX_2_BITS 0xC0000000
96
97 ///
98 /// Maximum legal ARM address
99 ///
100 #define MAX_ADDRESS 0xFFFFFFFF
101
102 ///
103 /// Maximum legal ARM INTN and UINTN values.
104 ///
105 #define MAX_INTN ((INTN)0x7FFFFFFF)
106 #define MAX_UINTN ((UINTN)0xFFFFFFFF)
107
108 ///
109 /// Minimum legal ARM INTN value.
110 ///
111 #define MIN_INTN (((INTN)-2147483647) - 1)
112
113 ///
114 /// The stack alignment required for ARM
115 ///
116 #define CPU_STACK_ALIGNMENT sizeof(UINT64)
117
118 ///
119 /// Page allocation granularity for ARM
120 ///
121 #define DEFAULT_PAGE_ALLOCATION_GRANULARITY (0x1000)
122 #define RUNTIME_PAGE_ALLOCATION_GRANULARITY (0x1000)
123
124 //
125 // Modifier to ensure that all protocol member functions and EFI intrinsics
126 // use the correct C calling convention. All protocol member functions and
127 // EFI intrinsics are required to modify their member functions with EFIAPI.
128 //
129 #define EFIAPI
130
131 // When compiling with Clang, we still use GNU as for the assembler, so we still
132 // need to define the GCC_ASM* macros.
133 #if defined(__GNUC__) || defined(__clang__)
134 ///
135 /// For GNU assembly code, .global or .globl can declare global symbols.
136 /// Define this macro to unify the usage.
137 ///
138 #define ASM_GLOBAL .globl
139
140 #if !defined(__APPLE__)
141 ///
142 /// ARM EABI defines that the linker should not manipulate call relocations
143 /// (do bl/blx conversion) unless the target symbol has function type.
144 /// CodeSourcery 2010.09 started requiring the .type to function properly
145 ///
146 #define INTERWORK_FUNC(func__) .type ASM_PFX(func__), %function
147
148 #define GCC_ASM_EXPORT(func__) \
149 .global _CONCATENATE (__USER_LABEL_PREFIX__, func__) ;\
150 .type ASM_PFX(func__), %function
151
152 #define GCC_ASM_IMPORT(func__) \
153 .extern _CONCATENATE (__USER_LABEL_PREFIX__, func__)
154
155 #else
156 //
157 // .type not supported by Apple Xcode tools
158 //
159 #define INTERWORK_FUNC(func__)
160
161 #define GCC_ASM_EXPORT(func__) \
162 .globl _CONCATENATE (__USER_LABEL_PREFIX__, func__) \
163
164 #define GCC_ASM_IMPORT(name)
165
166 #endif
167 #endif
168
169 /**
170 Return the pointer to the first instruction of a function given a function pointer.
171 On ARM CPU architectures, these two pointer values are the same,
172 so the implementation of this macro is very simple.
173
174 @param FunctionPointer A pointer to a function.
175
176 @return The pointer to the first instruction of a function given a function pointer.
177
178 **/
179 #define FUNCTION_ENTRY_POINT(FunctionPointer) (VOID *)(UINTN)(FunctionPointer)
180
181 #ifndef __USER_LABEL_PREFIX__
182 #define __USER_LABEL_PREFIX__
183 #endif
184
185 #endif
186
187