Martin Roth | 2413918 | 2017-11-16 16:00:53 -0700 | [diff] [blame] | 1 | /* $NoKeywords:$ */ |
| 2 | /** |
| 3 | * @file |
| 4 | * |
| 5 | * Describes compiler dependencies - to support several compile time environments |
| 6 | * |
| 7 | * Contains compiler environment porting descriptions |
| 8 | * |
| 9 | * @xrefitem bom "File Content Label" "Release Content" |
| 10 | * @e project: AGESA |
| 11 | * @e sub-project: Includes |
| 12 | * @e \$Revision: 44324 $ @e \$Date: 2010-12-22 03:16:51 -0600 (Wed, 22 Dec 2010) $ |
| 13 | */ |
| 14 | /***************************************************************************** |
| 15 | * |
| 16 | * Copyright (c) 2008 - 2013, Advanced Micro Devices, Inc. |
| 17 | * All rights reserved. |
| 18 | * |
| 19 | * Redistribution and use in source and binary forms, with or without |
| 20 | * modification, are permitted provided that the following conditions are met: |
| 21 | * * Redistributions of source code must retain the above copyright |
| 22 | * notice, this list of conditions and the following disclaimer. |
| 23 | * * Redistributions in binary form must reproduce the above copyright |
| 24 | * notice, this list of conditions and the following disclaimer in the |
| 25 | * documentation and/or other materials provided with the distribution. |
| 26 | * * Neither the name of Advanced Micro Devices, Inc. nor the names of |
| 27 | * its contributors may be used to endorse or promote products derived |
| 28 | * from this software without specific prior written permission. |
| 29 | * |
| 30 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 31 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 32 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 33 | * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY |
| 34 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 35 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 36 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 37 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 38 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 39 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 40 | * |
| 41 | ***************************************************************************/ |
| 42 | |
Martin Roth | ae01634 | 2017-11-16 22:46:56 -0700 | [diff] [blame] | 43 | #include <check_for_wrapper.h> |
| 44 | |
Martin Roth | 2413918 | 2017-11-16 16:00:53 -0700 | [diff] [blame] | 45 | #ifndef _PORTING_H_ |
| 46 | #define _PORTING_H_ |
| 47 | |
| 48 | #if defined (_MSC_VER) |
| 49 | #include <intrin.h> |
| 50 | void _disable (void); |
| 51 | void _enable (void); |
| 52 | #pragma warning(disable: 4103 4001 4733) |
| 53 | #pragma intrinsic (_disable, _enable) |
| 54 | #pragma warning(push) |
| 55 | // ----------------------------------------------------------------------- |
| 56 | // Define a code_seg MACRO |
| 57 | // |
| 58 | #define MAKE_AS_A_STRING(arg) #arg |
| 59 | |
| 60 | #define CODE_GROUP(arg) __pragma (code_seg (MAKE_AS_A_STRING (.t##arg))) |
| 61 | |
| 62 | #define RDATA_GROUP(arg) __pragma (const_seg (MAKE_AS_A_STRING (.d##arg))) |
| 63 | #define FUNC_ATTRIBUTE(arg) __declspec(arg) |
| 64 | //#include <intrin.h> // MS has built-in functions |
| 65 | |
| 66 | #if _MSC_VER < 900 |
| 67 | // ----------------------------------------------------------------------- |
| 68 | // Assume MSVC 1.52C (16-bit) |
| 69 | // |
| 70 | // NOTE: When using MSVC 1.52C use the following command line: |
| 71 | // |
| 72 | // CL.EXE /G3 /AL /O1i /Fa <FILENAME.C> |
| 73 | // |
| 74 | // This will produce 32-bit code in USE16 segment that is optimized for code |
| 75 | // size. |
| 76 | typedef void VOID; |
| 77 | |
| 78 | // Create the universal 32, 16, and 8-bit data types |
| 79 | typedef unsigned long UINTN; |
| 80 | typedef long INT32; |
| 81 | typedef unsigned long UINT32; |
| 82 | typedef int INT16; |
| 83 | typedef unsigned int UINT16; |
| 84 | typedef char INT8; |
| 85 | typedef unsigned char UINT8; |
| 86 | typedef char CHAR8; |
| 87 | typedef unsigned short CHAR16; |
| 88 | |
| 89 | /// struct for 16-bit environment handling of 64-bit value |
| 90 | typedef struct _UINT64 { |
| 91 | IN OUT UINT32 lo; ///< lower 32-bits of 64-bit value |
| 92 | IN OUT UINT32 hi; ///< highest 32-bits of 64-bit value |
| 93 | } UINT64; |
| 94 | |
| 95 | // Create the Boolean type |
| 96 | #define TRUE 1 |
| 97 | #define FALSE 0 |
| 98 | typedef unsigned char BOOLEAN; |
| 99 | |
| 100 | #define CONST const |
| 101 | #define STATIC static |
| 102 | #define VOLATILE volatile |
| 103 | #define CALLCONV __pascal |
| 104 | #define ROMDATA __based( __segname( "_CODE" ) ) |
| 105 | #define _16BYTE_ALIGN __declspec(align(16)) |
| 106 | #define _8BYTE_ALIGN __declspec(align(8)) |
| 107 | #define _4BYTE_ALIGN __declspec(align(4)) |
| 108 | #define _2BYTE_ALIGN __declspec(align(2)) |
| 109 | #define _1BYTE_ALIGN __declspec(align(1)) |
| 110 | |
| 111 | // Force tight packing of structures |
| 112 | // Note: Entire AGESA (Project / Solution) will be using pragma pack 1 |
| 113 | #pragma warning( disable : 4103 ) // Disable '#pragma pack' in .h warning |
| 114 | #pragma pack(1) |
| 115 | |
| 116 | // Disable WORD->BYTE automatic conversion warnings. Example: |
| 117 | // BYTE LocalByte; |
| 118 | // void MyFunc(BYTE val); |
| 119 | // |
| 120 | // MyFunc(LocalByte*2+1); // Warning, automatic conversion |
| 121 | // |
| 122 | // The problem is any time math is performed on a BYTE, it is converted to a |
| 123 | // WORD by MSVC 1.52c, and then when it is converted back to a BYTE, a warning |
| 124 | // is generated. Disable warning C4761 |
| 125 | #pragma warning( disable : 4761 ) |
| 126 | |
| 127 | #else |
| 128 | // ----------------------------------------------------------------------- |
| 129 | // Assume a 32-bit MSVC++ |
| 130 | // |
| 131 | // Disable the following warnings: |
| 132 | // 4100 - 'identifier' : unreferenced formal parameter |
| 133 | // 4276 - 'function' : no prototype provided; assumed no parameters |
| 134 | // 4214 - non standard extension used : bit field types other than int |
| 135 | // 4001 - nonstandard extension 'single line comment' was used |
| 136 | // 4142 - benign redefinition of type for following declaration |
| 137 | // - typedef char INT8 |
| 138 | #if defined (_M_IX86) |
| 139 | #pragma warning (disable: 4100 4276 4214 4001 4142 4305 4306) |
| 140 | |
| 141 | #ifndef VOID |
| 142 | typedef void VOID; |
| 143 | #endif |
| 144 | // Create the universal 32, 16, and 8-bit data types |
| 145 | #ifndef UINTN |
| 146 | typedef unsigned __w64 UINTN; |
| 147 | #endif |
| 148 | typedef __int64 INT64; |
| 149 | typedef unsigned __int64 UINT64; |
| 150 | typedef int INT32; |
| 151 | typedef unsigned int UINT32; |
| 152 | typedef short INT16; |
| 153 | typedef unsigned short UINT16; |
| 154 | typedef char INT8; |
| 155 | typedef unsigned char UINT8; |
| 156 | typedef char CHAR8; |
| 157 | typedef unsigned short CHAR16; |
| 158 | |
| 159 | // Create the Boolean type |
| 160 | #ifndef TRUE |
| 161 | #define TRUE 1 |
| 162 | #endif |
| 163 | #ifndef FALSE |
| 164 | #define FALSE 0 |
| 165 | #endif |
| 166 | typedef unsigned char BOOLEAN; |
| 167 | |
| 168 | // Force tight packing of structures |
| 169 | // Note: Entire AGESA (Project / Solution) will be using pragma pack 1 |
| 170 | #pragma pack(1) |
| 171 | |
| 172 | #define CONST const |
| 173 | #define STATIC static |
| 174 | #define VOLATILE volatile |
| 175 | #define CALLCONV |
| 176 | #define ROMDATA |
| 177 | #define _16BYTE_ALIGN __declspec(align(64)) |
| 178 | #define _8BYTE_ALIGN __declspec(align(8)) |
| 179 | #define _4BYTE_ALIGN __declspec(align(4)) |
| 180 | #define _2BYTE_ALIGN __declspec(align(2)) |
| 181 | #define _1BYTE_ALIGN __declspec(align(1)) |
| 182 | //Support for variadic macros was introduced in Visual C++ 2005. |
| 183 | #if _MSC_VER >= 1400 |
| 184 | #define VA_ARGS_SUPPORTED |
| 185 | #endif |
| 186 | // 64 bit of compiler |
| 187 | #else |
| 188 | #pragma warning (disable: 4100 4276 4214 4001 4142 4305 4306 4366) |
| 189 | |
| 190 | #ifndef VOID |
| 191 | typedef void VOID; |
| 192 | #endif |
| 193 | // Create the universal 32, 16, and 8-bit data types |
| 194 | #ifndef UINTN |
| 195 | typedef unsigned __int64 UINTN; |
| 196 | #endif |
| 197 | typedef __int64 INT64; |
| 198 | typedef unsigned __int64 UINT64; |
| 199 | typedef int INT32; |
| 200 | typedef unsigned int UINT32; |
| 201 | typedef short INT16; |
| 202 | typedef unsigned short UINT16; |
| 203 | typedef char INT8; |
| 204 | typedef unsigned char UINT8; |
| 205 | typedef char CHAR8; |
| 206 | typedef unsigned short CHAR16; |
| 207 | |
| 208 | // Create the Boolean type |
| 209 | #ifndef TRUE |
| 210 | #define TRUE 1 |
| 211 | #endif |
| 212 | #ifndef FALSE |
| 213 | #define FALSE 0 |
| 214 | #endif |
| 215 | typedef unsigned char BOOLEAN; |
| 216 | #define _16BYTE_ALIGN __declspec(align(16)) |
| 217 | #define _8BYTE_ALIGN __declspec(align(8)) |
| 218 | #define _4BYTE_ALIGN __declspec(align(4)) |
| 219 | #define _2BYTE_ALIGN __declspec(align(2)) |
| 220 | #define _1BYTE_ALIGN __declspec(align(1)) |
| 221 | // Force tight packing of structures |
| 222 | // Note: Entire AGESA (Project / Solution) will be using pragma pack 1 |
| 223 | #pragma pack(1) |
| 224 | |
| 225 | #define CONST const |
| 226 | #define STATIC static |
| 227 | #define VOLATILE volatile |
| 228 | #define CALLCONV |
| 229 | #define ROMDATA |
| 230 | #endif |
| 231 | #endif |
| 232 | // ----------------------------------------------------------------------- |
| 233 | // End of MS compiler versions |
| 234 | |
| 235 | #elif defined __GNUC__ |
| 236 | |
| 237 | #include <stdint.h> |
| 238 | |
| 239 | #define IN |
| 240 | #define OUT |
| 241 | #define STATIC static |
| 242 | #define VOLATILE volatile |
| 243 | #define TRUE 1 |
| 244 | #define FALSE 0 |
| 245 | #define CONST const |
| 246 | #define ROMDATA |
| 247 | #define CALLCONV |
| 248 | #define _16BYTE_ALIGN __attribute__((aligned (16))) |
| 249 | #define _8BYTE_ALIGN __attribute__((aligned (8))) |
| 250 | #define _4BYTE_ALIGN __attribute__((aligned (4))) |
| 251 | #define _2BYTE_ALIGN __attribute__((aligned (2))) |
| 252 | #define _1BYTE_ALIGN __attribute__((aligned (1))) |
| 253 | |
| 254 | typedef uintptr_t UINTN; |
| 255 | typedef int64_t INT64; |
| 256 | typedef uint64_t UINT64; |
| 257 | typedef int32_t INT32; |
| 258 | typedef uint32_t UINT32; |
| 259 | typedef int16_t INT16; |
| 260 | typedef uint16_t UINT16; |
| 261 | typedef int8_t INT8; |
| 262 | typedef uint8_t UINT8; |
| 263 | typedef char CHAR8; |
| 264 | typedef unsigned short CHAR16; |
| 265 | typedef unsigned char BOOLEAN; |
| 266 | typedef void VOID; |
| 267 | |
| 268 | #define CODE_GROUP(arg) |
| 269 | #define RDATA_GROUP(arg) |
| 270 | |
| 271 | #pragma pack(1) |
| 272 | |
| 273 | #define FUNC_ATTRIBUTE(arg) __attribute__((arg)) |
| 274 | #define MAKE_AS_A_STRING(arg) #arg |
| 275 | #include <stddef.h> |
| 276 | #include <gcc-intrin.h> |
| 277 | |
| 278 | #include <assert.h> |
| 279 | //#include <console/console.h> |
| 280 | //#include <commonlib/loglevel.h> |
| 281 | |
| 282 | #ifndef NULL |
| 283 | #define NULL ((void *)0) |
| 284 | #endif |
| 285 | |
| 286 | #else |
| 287 | // ----------------------------------------------------------------------- |
| 288 | // Unknown or unsupported compiler |
| 289 | // |
| 290 | #error "Unknown compiler in use" |
| 291 | #endif |
| 292 | |
| 293 | // ----------------------------------------------------------------------- |
| 294 | // Common definitions for all compilers |
| 295 | // |
| 296 | |
| 297 | //Support forward reference construct |
| 298 | #define AGESA_FORWARD_DECLARATION(x) typedef struct _##x x |
| 299 | |
| 300 | // The following are use in conformance to the UEFI style guide |
| 301 | #define IN |
| 302 | #define OUT |
| 303 | |
| 304 | #endif // _PORTING_H_ |