efibind.h revision 1.1
1/*	$NetBSD: efibind.h,v 1.1 2014/04/01 16:16:07 jakllsch Exp $	*/
2
3/*++
4
5Copyright (c) 1998  Intel Corporation
6
7Module Name:
8
9    efefind.h
10
11Abstract:
12
13    EFI to compile bindings
14
15
16
17
18Revision History
19
20--*/
21
22#pragma pack()
23
24
25//
26// Basic int types of various widths
27//
28
29#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L )
30
31    // No ANSI C 1999/2000 stdint.h integer width declarations
32
33    #ifdef _MSC_EXTENSIONS
34        // Use Microsoft C compiler integer width declarations
35
36        typedef unsigned __int64    uint64_t;
37        typedef __int64             int64_t;
38        typedef unsigned __int32    uint32_t;
39        typedef __int32             int32_t;
40        typedef unsigned __int16    uint16_t;
41        typedef __int16             int16_t;
42        typedef unsigned __int8     uint8_t;
43        typedef __int8              int8_t;
44    #elif defined(UNIX_LP64)
45        // Use LP64 programming model from C_FLAGS for integer width declarations
46
47        typedef unsigned long       uint64_t;
48        typedef long                int64_t;
49        typedef unsigned int        uint32_t;
50        typedef int                 int32_t;
51        typedef unsigned short      uint16_t;
52        typedef short               int16_t;
53        typedef unsigned char       uint8_t;
54        typedef char                int8_t;
55    #else
56        // Assume P64 programming model from C_FLAGS for integer width declarations
57
58        typedef unsigned long long  uint64_t;
59        typedef long long           int64_t;
60        typedef unsigned int        uint32_t;
61        typedef int                 int32_t;
62        typedef unsigned short      uint16_t;
63        typedef short               int16_t;
64        typedef unsigned char       uint8_t;
65        typedef char                int8_t;
66    #endif
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
79typedef uint64_t   UINT64;
80typedef int64_t    INT64;
81typedef uint32_t   UINT32;
82typedef int32_t    INT32;
83typedef uint16_t   UINT16;
84typedef int16_t    INT16;
85typedef uint8_t    UINT8;
86typedef int8_t     INT8;
87typedef __WCHAR_TYPE__ WCHAR;
88
89
90#undef VOID
91#define VOID    void
92
93
94typedef int64_t    INTN;
95typedef 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
180void __mf (void);
181#pragma intrinsic (__mf)
182#define MEMORY_FENCE()    __mf()
183#endif
184//
185// When build similiar to FW, then link everything together as
186// one big module.
187//
188
189#define EFI_DRIVER_ENTRY_POINT(InitFunction)    \
190    UINTN                                       \
191    InitializeDriver (                          \
192        VOID    *ImageHandle,                   \
193        VOID    *SystemTable                    \
194        )                                       \
195    {                                           \
196        return InitFunction(ImageHandle,        \
197                SystemTable);                   \
198    }                                           \
199                                                \
200    EFI_STATUS efi_main(                        \
201        EFI_HANDLE image,                       \
202        EFI_SYSTEM_TABLE *systab                \
203        ) __attribute__((weak,                  \
204                alias ("InitializeDriver")));
205
206#define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
207        (_if)->LoadInternal(type, name, entry)
208
209//
210// Some compilers don't support the forward reference construct:
211//  typedef struct XXXXX
212//
213// The following macro provide a workaround for such cases.
214//
215#ifdef NO_INTERFACE_DECL
216#define INTERFACE_DECL(x)
217#else
218#ifdef __GNUC__
219#define INTERFACE_DECL(x) struct x
220#else
221#define INTERFACE_DECL(x) typedef struct x
222#endif
223#endif
224
225/* No efi call wrapper for IA32 architecture */
226#define uefi_call_wrapper(func, va_num, ...)	func(__VA_ARGS__)
227#define EFI_FUNCTION
228