3 Copyright (c) 1998 Intel Corporation
11 EFI to compile bindings
24 // Basic int types of various widths
27 #if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L )
29 // No ANSI C 1999/2000 stdint.h integer width declarations
31 #ifdef _MSC_EXTENSIONS
32 // Use Microsoft C compiler integer width declarations
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
45 typedef unsigned long uint64_t;
47 typedef unsigned int uint32_t;
49 typedef unsigned short uint16_t;
50 typedef short int16_t;
51 typedef unsigned char uint8_t;
54 // Assume P64 programming model from C_FLAGS for integer width declarations
56 typedef unsigned long long uint64_t;
57 typedef long long int64_t;
58 typedef unsigned int uint32_t;
60 typedef unsigned short uint16_t;
61 typedef short int16_t;
62 typedef unsigned char uint8_t;
65 #elif defined(__GNUC__)
66 #include <stdint-gcc.h>
70 // Basic EFI types of various widths
72 #ifndef __WCHAR_TYPE__
73 # define __WCHAR_TYPE__ short
77 typedef uint64_t UINT64;
78 typedef int64_t INT64;
79 typedef uint32_t UINT32;
80 typedef int32_t INT32;
81 typedef uint16_t UINT16;
82 typedef int16_t INT16;
83 typedef uint8_t UINT8;
85 typedef __WCHAR_TYPE__ WCHAR;
93 typedef uint64_t UINTN;
95 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
96 // BugBug: Code to debug
98 #define BIT63 0x8000000000000000
100 #define PLATFORM_IOBASE_ADDRESS (0xffffc000000 | BIT63)
101 #define PORT_TO_MEMD(_Port) (PLATFORM_IOBASE_ADDRESS | ( ( ( (_Port) & 0xfffc) << 10 ) | ( (_Port) & 0x0fff) ) )
104 // Macro's with casts make this much easier to use and read.
106 #define PORT_TO_MEM8D(_Port) (*(UINT8 *)(PORT_TO_MEMD(_Port)))
107 #define POST_CODE(_Data) (PORT_TO_MEM8D(0x80) = (_Data))
109 // BugBug: End Debug Code!!!
110 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
112 #define EFIERR(a) (0x8000000000000000 | a)
113 #define EFI_ERROR_MASK 0x8000000000000000
114 #define EFIERR_OEM(a) (0xc000000000000000 | a)
116 #define BAD_POINTER 0xFBFBFBFBFBFBFBFB
117 #define MAX_ADDRESS 0xFFFFFFFFFFFFFFFF
119 #define BREAKPOINT() while (TRUE)
122 // Pointers must be aligned to these address to function
123 // you will get an alignment fault if this value is less than 8
125 #define MIN_ALIGNMENT_SIZE 8
127 #define ALIGN_VARIABLE(Value , Adjustment) \
128 (UINTN) Adjustment = 0; \
129 if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
130 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
131 Value = (UINTN)Value + (UINTN)Adjustment
134 // Define macros to create data structure signatures.
137 #define EFI_SIGNATURE_16(A,B) ((A) | (B<<8))
138 #define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16))
139 #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))
141 // To export & import functions in the EFI emulator environment
147 // EFIAPI - prototype calling convention for EFI function pointers
148 // BOOTSERVICE - prototype for implementation of a boot service interface
149 // RUNTIMESERVICE - prototype for implementation of a runtime service interface
150 // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
151 // RUNTIME_CODE - pragma macro for declaring runtime code
154 #ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options
155 #ifdef _MSC_EXTENSIONS
156 #define EFIAPI __cdecl // Force C calling convention for Microsoft C compiler
158 #define EFIAPI // Substitute expresion to force C calling convention
163 #define RUNTIMESERVICE
164 #define RUNTIMEFUNCTION
166 #define RUNTIME_CODE(a) alloc_text("rtcode", a)
167 #define BEGIN_RUNTIME_DATA() data_seg("rtdata")
168 #define END_RUNTIME_DATA() data_seg("")
170 #define VOLATILE volatile
173 // BugBug: Need to find out if this is portable accross compliers.
176 #define MEMORY_FENCE() __asm__ __volatile__ ("mf.a" ::: "memory")
179 #pragma intrinsic (__mf)
180 #define MEMORY_FENCE() __mf()
183 // When build similiar to FW, then link everything together as
187 #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
194 return InitFunction(ImageHandle, \
198 EFI_STATUS efi_main( \
200 EFI_SYSTEM_TABLE *systab \
201 ) __attribute__((weak, \
202 alias ("InitializeDriver")));
204 #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \
205 (_if)->LoadInternal(type, name, entry)
208 // Some compilers don't support the forward reference construct:
209 // typedef struct XXXXX
211 // The following macro provide a workaround for such cases.
213 #ifdef NO_INTERFACE_DECL
214 #define INTERFACE_DECL(x)
217 #define INTERFACE_DECL(x) struct x
219 #define INTERFACE_DECL(x) typedef struct x
223 /* No efi call wrapper for IA32 architecture */
224 #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__)