xref: /DragonStub/inc/ia64/efibind.h (revision 14899d899b230eff3e3ff41011405f742aad6724)
1 /*++
2 
3 Copyright (c) 1998  Intel Corporation
4 
5 Module Name:
6 
7     efefind.h
8 
9 Abstract:
10 
11     EFI to compile bindings
12 
13 
14 
15 
16 Revision History
17 
18 --*/
19 
20 #pragma pack()
21 
22 
23 //
24 // Basic int types of various widths
25 //
26 
27 #if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L ) && !defined(__cplusplus)
28 
29     // No ANSI C 1999/2000 stdint.h integer width declarations
30 
31     #ifdef _MSC_EXTENSIONS
32         // Use Microsoft C compiler integer width declarations
33 
34         typedef unsigned __int64    uint64_t;
35         typedef __int64             int64_t;
36         typedef unsigned __int32    uint32_t;
37         typedef __int32             int32_t;
38         typedef unsigned __int16    uint16_t;
39         typedef __int16             int16_t;
40         typedef unsigned __int8     uint8_t;
41         typedef __int8              int8_t;
42     #elif defined(UNIX_LP64)
43         // Use LP64 programming model from C_FLAGS for integer width declarations
44 
45         typedef unsigned long       uint64_t;
46         typedef long                int64_t;
47         typedef unsigned int        uint32_t;
48         typedef int                 int32_t;
49         typedef unsigned short      uint16_t;
50         typedef short               int16_t;
51         typedef unsigned char       uint8_t;
52         typedef char                int8_t;
53     #else
54         // Assume P64 programming model from C_FLAGS for integer width declarations
55 
56         typedef unsigned long long  uint64_t;
57         typedef long long           int64_t;
58         typedef unsigned int        uint32_t;
59         typedef int                 int32_t;
60         typedef unsigned short      uint16_t;
61         typedef short               int16_t;
62         typedef unsigned char       uint8_t;
63         typedef char                int8_t;
64     #endif
65     typedef uint64_t            uintptr_t;
66     typedef int64_t             intptr_t;
67 #elif defined(__GNUC__)
68     #include <stdint.h>
69 #endif
70 
71 //
72 // Basic EFI types of various widths
73 //
74 #ifndef __WCHAR_TYPE__
75 # define __WCHAR_TYPE__	short
76 #endif
77 #ifndef __CHAR16_TYPE__
78 # define __CHAR16_TYPE__ unsigned short
79 #endif
80 
81 typedef uint64_t   UINT64;
82 typedef int64_t    INT64;
83 
84 typedef uint32_t   UINT32;
85 typedef int32_t    INT32;
86 
87 typedef uint16_t   UINT16;
88 typedef __CHAR16_TYPE__ CHAR16;
89 typedef int16_t    INT16;
90 
91 typedef uint8_t    UINT8;
92 typedef char       CHAR8;
93 typedef int8_t     INT8;
94 
95 typedef __WCHAR_TYPE__ WCHAR;
96 
97 #undef VOID
98 #define VOID    void
99 
100 
101 typedef int64_t    INTN;
102 typedef uint64_t   UINTN;
103 
104 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
105 // BugBug: Code to debug
106 //
107 #define BIT63   0x8000000000000000
108 
109 #define PLATFORM_IOBASE_ADDRESS   (0xffffc000000 | BIT63)
110 #define PORT_TO_MEMD(_Port) (PLATFORM_IOBASE_ADDRESS | ( ( ( (_Port) & 0xfffc) << 10 ) | ( (_Port) & 0x0fff) ) )
111 
112 //
113 // Macro's with casts make this much easier to use and read.
114 //
115 #define PORT_TO_MEM8D(_Port)  (*(UINT8  *)(PORT_TO_MEMD(_Port)))
116 #define POST_CODE(_Data)  (PORT_TO_MEM8D(0x80) = (_Data))
117 //
118 // BugBug: End Debug Code!!!
119 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
120 
121 #define EFIERR(a)           (0x8000000000000000 | a)
122 #define EFI_ERROR_MASK      0x8000000000000000
123 #define EFIERR_OEM(a)       (0xc000000000000000 | a)
124 
125 #define BAD_POINTER         0xFBFBFBFBFBFBFBFB
126 #define MAX_ADDRESS         0xFFFFFFFFFFFFFFFF
127 
128 #define BREAKPOINT()        while (TRUE)
129 
130 //
131 // Pointers must be aligned to these address to function
132 //  you will get an alignment fault if this value is less than 8
133 //
134 #define MIN_ALIGNMENT_SIZE  8
135 
136 #define ALIGN_VARIABLE(Value , Adjustment) \
137             (UINTN) Adjustment = 0; \
138             if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
139                 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
140             Value = (UINTN)Value + (UINTN)Adjustment
141 
142 //
143 // Define macros to create data structure signatures.
144 //
145 
146 #define EFI_SIGNATURE_16(A,B)             ((A) | (B<<8))
147 #define EFI_SIGNATURE_32(A,B,C,D)         (EFI_SIGNATURE_16(A,B)     | (EFI_SIGNATURE_16(C,D)     << 16))
148 #define EFI_SIGNATURE_64(A,B,C,D,E,F,G,H) (EFI_SIGNATURE_32(A,B,C,D) | ((UINT64)(EFI_SIGNATURE_32(E,F,G,H)) << 32))
149 //
150 // To export & import functions in the EFI emulator environment
151 //
152 
153     #define EXPORTAPI
154 
155 //
156 // EFIAPI - prototype calling convention for EFI function pointers
157 // BOOTSERVICE - prototype for implementation of a boot service interface
158 // RUNTIMESERVICE - prototype for implementation of a runtime service interface
159 // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
160 // RUNTIME_CODE - pragma macro for declaring runtime code
161 //
162 
163 #ifndef EFIAPI                  // Forces EFI calling conventions reguardless of compiler options
164     #ifdef _MSC_EXTENSIONS
165         #define EFIAPI __cdecl  // Force C calling convention for Microsoft C compiler
166     #else
167         #define EFIAPI          // Substitute expresion to force C calling convention
168     #endif
169 #endif
170 
171 #define BOOTSERVICE
172 #define RUNTIMESERVICE
173 #define RUNTIMEFUNCTION
174 
175 #define RUNTIME_CODE(a)         alloc_text("rtcode", a)
176 #define BEGIN_RUNTIME_DATA()    data_seg("rtdata")
177 #define END_RUNTIME_DATA()      data_seg("")
178 
179 #define VOLATILE    volatile
180 
181 //
182 // BugBug: Need to find out if this is portable accross compliers.
183 //
184 #ifdef __GNUC__
185 #define MEMORY_FENCE()    __asm__ __volatile__ ("mf.a" ::: "memory")
186 #else
187 void __mf (void);
188 #pragma intrinsic (__mf)
189 #define MEMORY_FENCE()    __mf()
190 #endif
191 
192 //
193 // When build similiar to FW, then link everything together as
194 // one big module. For the MSVC toolchain, we simply tell the
195 // linker what our driver init function is using /ENTRY.
196 //
197 #if defined(_MSC_EXTENSIONS)
198     #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
199         __pragma(comment(linker, "/ENTRY:" # InitFunction))
200 #else
201     #define EFI_DRIVER_ENTRY_POINT(InitFunction)    \
202         UINTN                                       \
203         InitializeDriver (                          \
204             VOID    *ImageHandle,                   \
205             VOID    *SystemTable                    \
206             )                                       \
207         {                                           \
208             return InitFunction(ImageHandle,        \
209                     SystemTable);                   \
210         }                                           \
211                                                     \
212         EFI_STATUS efi_main(                        \
213             EFI_HANDLE image,                       \
214             EFI_SYSTEM_TABLE *systab                \
215             ) __attribute__((weak,                  \
216                     alias ("InitializeDriver")));
217 #endif
218 
219 #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
220         (_if)->LoadInternal(type, name, entry)
221 
222 //
223 // Some compilers don't support the forward reference construct:
224 //  typedef struct XXXXX
225 //
226 // The following macro provide a workaround for such cases.
227 //
228 #ifdef NO_INTERFACE_DECL
229 #define INTERFACE_DECL(x)
230 #else
231 #if defined(__GNUC__) || defined(_MSC_EXTENSIONS)
232 #define INTERFACE_DECL(x) struct x
233 #else
234 #define INTERFACE_DECL(x) typedef struct x
235 #endif
236 #endif
237 
238 /* No efi call wrapper for IA32 architecture */
239 #define uefi_call_wrapper(func, va_num, ...)	func(__VA_ARGS__)
240 #define EFI_FUNCTION
241