xref: /DragonStub/inc/ia64/efibind.h (revision dcced03469f3ef51b581a7cfd54884e3198bbc33)
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 
75 #include <stddef.h>
76 
77 typedef wchar_t CHAR16;
78 #define WCHAR CHAR16
79 
80 typedef uint64_t   UINT64;
81 typedef int64_t    INT64;
82 
83 typedef uint32_t   UINT32;
84 typedef int32_t    INT32;
85 
86 typedef uint16_t   UINT16;
87 typedef int16_t    INT16;
88 
89 typedef uint8_t    UINT8;
90 typedef char       CHAR8;
91 typedef int8_t     INT8;
92 
93 #undef VOID
94 typedef void       VOID;
95 
96 
97 typedef int64_t    INTN;
98 typedef uint64_t   UINTN;
99 
100 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
101 // BugBug: Code to debug
102 //
103 #define BIT63   0x8000000000000000
104 
105 #define PLATFORM_IOBASE_ADDRESS   (0xffffc000000 | BIT63)
106 #define PORT_TO_MEMD(_Port) (PLATFORM_IOBASE_ADDRESS | ( ( ( (_Port) & 0xfffc) << 10 ) | ( (_Port) & 0x0fff) ) )
107 
108 //
109 // Macro's with casts make this much easier to use and read.
110 //
111 #define PORT_TO_MEM8D(_Port)  (*(UINT8  *)(PORT_TO_MEMD(_Port)))
112 #define POST_CODE(_Data)  (PORT_TO_MEM8D(0x80) = (_Data))
113 //
114 // BugBug: End Debug Code!!!
115 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
116 
117 #define EFIERR(a)           (0x8000000000000000 | a)
118 #define EFI_ERROR_MASK      0x8000000000000000
119 #define EFIERR_OEM(a)       (0xc000000000000000 | a)
120 
121 #define BAD_POINTER         0xFBFBFBFBFBFBFBFB
122 #define MAX_ADDRESS         0xFFFFFFFFFFFFFFFF
123 
124 #define BREAKPOINT()        while (TRUE)
125 
126 //
127 // Pointers must be aligned to these address to function
128 //  you will get an alignment fault if this value is less than 8
129 //
130 #define MIN_ALIGNMENT_SIZE  8
131 
132 #define ALIGN_VARIABLE(Value , Adjustment) \
133             (UINTN) Adjustment = 0; \
134             if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
135                 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
136             Value = (UINTN)Value + (UINTN)Adjustment
137 
138 //
139 // Define macros to create data structure signatures.
140 //
141 
142 #define EFI_SIGNATURE_16(A,B)             ((A) | (B<<8))
143 #define EFI_SIGNATURE_32(A,B,C,D)         (EFI_SIGNATURE_16(A,B)     | (EFI_SIGNATURE_16(C,D)     << 16))
144 #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))
145 //
146 // To export & import functions in the EFI emulator environment
147 //
148 
149     #define EXPORTAPI
150 
151 //
152 // EFIAPI - prototype calling convention for EFI function pointers
153 // BOOTSERVICE - prototype for implementation of a boot service interface
154 // RUNTIMESERVICE - prototype for implementation of a runtime service interface
155 // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
156 // RUNTIME_CODE - pragma macro for declaring runtime code
157 //
158 
159 #ifndef EFIAPI                  // Forces EFI calling conventions reguardless of compiler options
160     #ifdef _MSC_EXTENSIONS
161         #define EFIAPI __cdecl  // Force C calling convention for Microsoft C compiler
162     #else
163         #define EFIAPI          // Substitute expresion to force C calling convention
164     #endif
165 #endif
166 
167 #define BOOTSERVICE
168 #define RUNTIMESERVICE
169 #define RUNTIMEFUNCTION
170 
171 #define RUNTIME_CODE(a)         alloc_text("rtcode", a)
172 #define BEGIN_RUNTIME_DATA()    data_seg("rtdata")
173 #define END_RUNTIME_DATA()      data_seg("")
174 
175 #define VOLATILE    volatile
176 
177 //
178 // BugBug: Need to find out if this is portable accross compliers.
179 //
180 #ifdef __GNUC__
181 #define MEMORY_FENCE()    __asm__ __volatile__ ("mf.a" ::: "memory")
182 #else
183 void __mf (void);
184 #pragma intrinsic (__mf)
185 #define MEMORY_FENCE()    __mf()
186 #endif
187 
188 //
189 // When build similiar to FW, then link everything together as
190 // one big module. For the MSVC toolchain, we simply tell the
191 // linker what our driver init function is using /ENTRY.
192 //
193 #if defined(_MSC_EXTENSIONS)
194     #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
195         __pragma(comment(linker, "/ENTRY:" # InitFunction))
196 #else
197     #define EFI_DRIVER_ENTRY_POINT(InitFunction)    \
198         UINTN                                       \
199         InitializeDriver (                          \
200             VOID    *ImageHandle,                   \
201             VOID    *SystemTable                    \
202             )                                       \
203         {                                           \
204             return InitFunction(ImageHandle,        \
205                     SystemTable);                   \
206         }                                           \
207                                                     \
208         EFI_STATUS efi_main(                        \
209             EFI_HANDLE image,                       \
210             EFI_SYSTEM_TABLE *systab                \
211             ) __attribute__((weak,                  \
212                     alias ("InitializeDriver")));
213 #endif
214 
215 #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
216         (_if)->LoadInternal(type, name, entry)
217 
218 //
219 // Some compilers don't support the forward reference construct:
220 //  typedef struct XXXXX
221 //
222 // The following macro provide a workaround for such cases.
223 //
224 #ifdef NO_INTERFACE_DECL
225 #define INTERFACE_DECL(x)
226 #else
227 #if defined(__GNUC__) || defined(_MSC_EXTENSIONS)
228 #define INTERFACE_DECL(x) struct x
229 #else
230 #define INTERFACE_DECL(x) typedef struct x
231 #endif
232 #endif
233 
234 /* No efi call wrapper for IA32 architecture */
235 #define uefi_call_wrapper(func, va_num, ...)	func(__VA_ARGS__)
236 #define EFI_FUNCTION
237