AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Porting.h
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 02:16:51 -0700 (Wed, 22 Dec 2010) $
13  */
14 /*****************************************************************************
15  *
16  * Copyright (C) 2012 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  ***************************************************************************/
43
44 #ifndef _PORTING_H_
45 #define _PORTING_H_
46
47 #if defined (_MSC_VER)
48   #include <intrin.h>
49   void _disable (void);
50   void _enable (void);
51   #pragma warning(disable: 4103 4001 4733)
52   #pragma intrinsic (_disable, _enable)
53 #pragma warning(push)
54   // -----------------------------------------------------------------------
55   //   Define a code_seg MACRO
56   //
57   #define MAKE_AS_A_STRING(arg) #arg
58
59   #define CODE_GROUP(arg) __pragma (code_seg (MAKE_AS_A_STRING (.t##arg)))
60
61   #define RDATA_GROUP(arg) __pragma (const_seg (MAKE_AS_A_STRING (.d##arg)))
62
63   //#include <intrin.h>  // MS has built-in functions
64
65   #if _MSC_VER < 900
66     // -----------------------------------------------------------------------
67     //    Assume MSVC 1.52C (16-bit)
68     //
69     //    NOTE: When using MSVC 1.52C use the following command line:
70     //
71     //       CL.EXE /G3 /AL /O1i /Fa <FILENAME.C>
72     //
73     //    This will produce 32-bit code in USE16 segment that is optimized for code
74     //    size.
75     typedef void          VOID;
76
77     // Create the universal 32, 16, and 8-bit data types
78     typedef unsigned long   UINTN;
79     typedef          long   INT32;
80     typedef unsigned long   UINT32;
81     typedef          int    INT16;
82     typedef unsigned int    UINT16;
83     typedef          char   INT8;
84     typedef unsigned char   UINT8;
85     typedef          char   CHAR8;
86     typedef unsigned short  CHAR16;
87
88     /// struct for 16-bit environment handling of 64-bit value
89     typedef struct _UINT64 {
90       IN OUT  UINT32 lo;      ///< lower 32-bits of 64-bit value
91       IN OUT  UINT32 hi;      ///< highest 32-bits of 64-bit value
92     } UINT64;
93
94     // Create the Boolean type
95     #define TRUE  1
96     #define FALSE 0
97     typedef unsigned char BOOLEAN;
98
99     #define CONST const
100     #define STATIC static
101     #define VOLATILE volatile
102     #define CALLCONV __pascal
103     #define ROMDATA __based( __segname( "_CODE" ) )
104     #define _16BYTE_ALIGN   __declspec(align(16))
105
106     // Force tight packing of structures
107     // Note: Entire AGESA (Project / Solution) will be using pragma pack 1
108     #pragma warning( disable : 4103 ) // Disable '#pragma pack' in .h warning
109     #pragma pack(1)
110
111     //   Disable WORD->BYTE automatic conversion warnings.  Example:
112     //   BYTE LocalByte;
113     //   void MyFunc(BYTE val);
114     //
115     //   MyFunc(LocalByte*2+1); // Warning, automatic conversion
116     //
117     //   The problem is any time math is performed on a BYTE, it is converted to a
118     //   WORD by MSVC 1.52c, and then when it is converted back to a BYTE, a warning
119     //   is generated.  Disable warning C4761
120     #pragma warning( disable : 4761 )
121
122   #else
123     // -----------------------------------------------------------------------
124     //   Assume a 32-bit MSVC++
125     //
126     // Disable the following warnings:
127     // 4100 - 'identifier' : unreferenced formal parameter
128     // 4276 - 'function' : no prototype provided; assumed no parameters
129     // 4214 - non standard extension used : bit field types other than int
130     // 4001 - nonstandard extension 'single line comment' was used
131     // 4142 - benign redefinition of type for following declaration
132     //      - typedef char    INT8
133     #if defined (_M_IX86)
134       #pragma warning (disable: 4100 4276 4214 4001 4142 4305 4306)
135
136       #ifndef VOID
137         typedef void VOID;
138       #endif
139     // Create the universal 32, 16, and 8-bit data types
140       #ifndef UINTN
141         typedef unsigned __w64 UINTN;
142       #endif
143       typedef          __int64 INT64;
144       typedef unsigned __int64 UINT64;
145       typedef          int   INT32;
146       typedef unsigned int   UINT32;
147       typedef          short INT16;
148       typedef unsigned short UINT16;
149       typedef          char  INT8;
150       typedef unsigned char  UINT8;
151       typedef          char  CHAR8;
152       typedef unsigned short CHAR16;
153
154     // Create the Boolean type
155       #ifndef TRUE
156         #define TRUE  1
157       #endif
158       #ifndef FALSE
159         #define FALSE 0
160       #endif
161       typedef unsigned char BOOLEAN;
162
163       // Force tight packing of structures
164       // Note: Entire AGESA (Project / Solution) will be using pragma pack 1
165       #pragma pack(1)
166
167       #define CONST const
168       #define STATIC static
169       #define VOLATILE volatile
170       #define CALLCONV
171       #define ROMDATA
172       #define _16BYTE_ALIGN __declspec(align(64))
173       // 64 bit of compiler
174     #else
175       #pragma warning (disable: 4100 4276 4214 4001 4142 4305 4306 4366)
176
177       #ifndef VOID
178         typedef void VOID;
179       #endif
180       // Create the universal 32, 16, and 8-bit data types
181       #ifndef UINTN
182         typedef unsigned __int64 UINTN;
183       #endif
184       typedef          __int64 INT64;
185       typedef unsigned __int64 UINT64;
186       typedef          int   INT32;
187       typedef unsigned int   UINT32;
188       typedef          short INT16;
189       typedef unsigned short UINT16;
190       typedef          char  INT8;
191       typedef unsigned char  UINT8;
192       typedef          char  CHAR8;
193       typedef unsigned short CHAR16;
194
195       // Create the Boolean type
196       #ifndef TRUE
197         #define TRUE  1
198       #endif
199       #ifndef FALSE
200         #define FALSE 0
201       #endif
202       typedef unsigned char BOOLEAN;
203
204       // Force tight packing of structures
205       // Note: Entire AGESA (Project / Solution) will be using pragma pack 1
206       #pragma pack(1)
207
208       #define CONST const
209       #define STATIC static
210       #define VOLATILE volatile
211       #define CALLCONV
212       #define ROMDATA
213     #endif
214   #endif
215   // -----------------------------------------------------------------------
216   // End of MS compiler versions
217
218
219 #elif defined __GNUC__
220
221   #define IN
222   #define OUT
223   #define STATIC static
224   #define VOLATILE volatile
225   #define TRUE 1
226   #define FALSE 0
227   #define CONST const
228   #define ROMDATA
229   #define CALLCONV
230   #define _16BYTE_ALIGN __attribute__ ((aligned (16)))
231
232   typedef unsigned char  BOOLEAN;
233   typedef   signed char  INT8;
234   typedef   signed short INT16;
235   typedef   signed long  INT32;
236   typedef unsigned char  CHAR8;
237   typedef unsigned char  UINT8;
238   typedef unsigned short UINT16;
239   typedef unsigned long  UINT32;
240   typedef unsigned long  UINTN;
241   typedef unsigned long  long UINT64;
242   typedef void VOID;
243   //typedef unsigned long  size_t;
244 //typedef unsigned int   uintptr_t;
245 // Force tight packing of structures
246 // Note: Entire AGESA (Project / Solution) will be using pragma pack 1
247 #pragma pack(1)
248
249   #define CODE_GROUP(arg)
250   #define RDATA_GROUP(arg)
251
252 #define FUNC_ATTRIBUTE(arg) __attribute__((arg))
253 #define MAKE_AS_A_STRING(arg) #arg
254
255 // -----------------------------------------------------------------------
256 // Common definitions for all compilers
257 //
258 #include <stddef.h>
259 #include "gcc-intrin.h"
260
261 #include <assert.h>
262 #include <console/console.h>
263 #include <console/loglevel.h>
264 #ifndef NULL
265   #define NULL              (void *)0
266 #endif
267
268 #else
269   // -----------------------------------------------------------------------
270   // Unknown or unsupported compiler
271   //
272   #error "Unknown compiler in use"
273 #endif
274
275
276
277 // -----------------------------------------------------------------------
278 // Common definitions for all compilers
279 //
280
281 //Support forward reference construct
282 #define AGESA_FORWARD_DECLARATION(x) typedef struct _##x x
283
284
285 // The following are use in conformance to the UEFI style guide
286 #define IN
287 #define OUT
288
289 #endif // _PORTING_H_