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