Subversion Repositories HelenOS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2726 vana 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
#ifndef __GNUC__
21
#pragma pack()
22
#endif
23
 
24
//
25
// Basic int types of various widths
26
//
27
 
28
#if (__STDC_VERSION__ < 199901L )
29
 
30
    // No ANSI C 1999/2000 stdint.h integer width declarations 
31
 
32
    #if _MSC_EXTENSIONS
33
 
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 short      uint16_t;
41
        typedef short               int16_t;
42
        typedef unsigned char       uint8_t;
43
        typedef char                int8_t;
44
    #elif defined(__GNUC__)
45
        typedef unsigned long long  uint64_t __attribute__((aligned (8)));
46
        typedef long long           int64_t __attribute__((aligned (8)));
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
    #elif defined(UNIX_LP64)
54
 
55
        /*  Use LP64 programming model from C_FLAGS for integer width declarations */
56
 
57
       typedef unsigned long       uint64_t;
58
       typedef long                int64_t;
59
       typedef unsigned int        uint32_t;
60
       typedef int                 int32_t;
61
       typedef unsigned short      uint16_t;
62
       typedef short               int16_t;
63
       typedef unsigned char       uint8_t;
64
       typedef char                int8_t;
65
    #else
66
 
67
       /*  Assume P64 programming model from C_FLAGS for integer width declarations */
68
 
69
       typedef unsigned long long  uint64_t __attribute__((aligned (8)));
70
       typedef long long           int64_t __attribute__((aligned (8)));
71
       typedef unsigned int        uint32_t;
72
       typedef int                 int32_t;
73
       typedef unsigned short      uint16_t;
74
       typedef short               int16_t;
75
       typedef unsigned char       uint8_t;
76
       typedef char                int8_t;
77
    #endif
78
#endif
79
 
80
//
81
// Basic EFI types of various widths
82
//
83
 
84
#ifndef __WCHAR_TYPE__
85
# define __WCHAR_TYPE__ short
86
#endif
87
 
88
typedef uint64_t   UINT64;
89
typedef int64_t    INT64;
90
 
91
#ifndef _BASETSD_H_
92
    typedef uint32_t   UINT32;
93
    typedef int32_t    INT32;
94
#endif
95
 
96
typedef uint16_t   UINT16;
97
typedef int16_t    INT16;
98
typedef uint8_t    UINT8;
99
typedef int8_t     INT8;
100
typedef __WCHAR_TYPE__ WCHAR;
101
 
102
#undef VOID
103
#define VOID    void
104
 
105
 
106
typedef int32_t    INTN;
107
typedef uint32_t   UINTN;
108
 
109
#ifdef EFI_NT_EMULATOR
110
    #define POST_CODE(_Data)
111
#else    
112
    #ifdef EFI_DEBUG
113
#define POST_CODE(_Data)    __asm mov eax,(_Data) __asm out 0x80,al
114
    #else
115
        #define POST_CODE(_Data)
116
    #endif  
117
#endif
118
 
119
#define EFIERR(a)           (0x80000000 | a)
120
#define EFI_ERROR_MASK      0x80000000
121
#define EFIERR_OEM(a)       (0xc0000000 | a)      
122
 
123
 
124
#define BAD_POINTER         0xFBFBFBFB
125
#define MAX_ADDRESS         0xFFFFFFFF
126
 
127
#ifdef EFI_NT_EMULATOR
128
    #define BREAKPOINT()        __asm { int 3 }
129
#else
130
    #define BREAKPOINT()        while (TRUE);    // Make it hang on Bios[Dbg]32
131
#endif
132
 
133
//
134
// Pointers must be aligned to these address to function
135
//
136
 
137
#define MIN_ALIGNMENT_SIZE  4
138
 
139
#define ALIGN_VARIABLE(Value ,Adjustment) \
140
            (UINTN)Adjustment = 0; \
141
            if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
142
                (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
143
            Value = (UINTN)Value + (UINTN)Adjustment
144
 
145
 
146
//
147
// Define macros to build data structure signatures from characters.
148
//
149
 
150
#define EFI_SIGNATURE_16(A,B)             ((A) | (B<<8))
151
#define EFI_SIGNATURE_32(A,B,C,D)         (EFI_SIGNATURE_16(A,B)     | (EFI_SIGNATURE_16(C,D)     << 16))
152
#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))
153
//
154
// To export & import functions in the EFI emulator environment
155
//
156
 
157
#if EFI_NT_EMULATOR
158
    #define EXPORTAPI           __declspec( dllexport )
159
#else
160
    #define EXPORTAPI
161
#endif
162
 
163
 
164
//
165
// EFIAPI - prototype calling convention for EFI function pointers
166
// BOOTSERVICE - prototype for implementation of a boot service interface
167
// RUNTIMESERVICE - prototype for implementation of a runtime service interface
168
// RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
169
// RUNTIME_CODE - pragma macro for declaring runtime code    
170
//
171
 
172
#ifndef EFIAPI                  // Forces EFI calling conventions reguardless of compiler options 
173
    #if _MSC_EXTENSIONS
174
        #define EFIAPI __cdecl  // Force C calling convention for Microsoft C compiler 
175
    #else
176
        #define EFIAPI          // Substitute expresion to force C calling convention 
177
    #endif
178
#endif
179
 
180
#define BOOTSERVICE
181
//#define RUNTIMESERVICE(proto,a)    alloc_text("rtcode",a); proto a
182
//#define RUNTIMEFUNCTION(proto,a)   alloc_text("rtcode",a); proto a
183
#define RUNTIMESERVICE
184
#define RUNTIMEFUNCTION
185
 
186
 
187
#define RUNTIME_CODE(a)         alloc_text("rtcode", a)
188
#define BEGIN_RUNTIME_DATA()    data_seg("rtdata")
189
#define END_RUNTIME_DATA()      data_seg("")
190
 
191
#define VOLATILE    volatile
192
 
193
#define MEMORY_FENCE()    
194
 
195
#ifdef EFI_NT_EMULATOR
196
 
197
//
198
// To help ensure proper coding of integrated drivers, they are
199
// compiled as DLLs.  In NT they require a dll init entry pointer.
200
// The macro puts a stub entry point into the DLL so it will load.
201
//
202
 
203
#define EFI_DRIVER_ENTRY_POINT(InitFunction)    \
204
    UINTN                                       \
205
    __stdcall                                   \
206
    _DllMainCRTStartup (                        \
207
        UINTN    Inst,                          \
208
        UINTN    reason_for_call,               \
209
        VOID    *rserved                        \
210
        )                                       \
211
    {                                           \
212
        return 1;                               \
213
    }                                           \
214
                                                \
215
    int                                         \
216
    EXPORTAPI                                   \
217
    __cdecl                                     \
218
    InitializeDriver (                          \
219
        void *ImageHandle,                      \
220
        void *SystemTable                       \
221
        )                                       \
222
    {                                           \
223
        return InitFunction(ImageHandle, SystemTable);       \
224
    }
225
 
226
 
227
    #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)      \
228
        (_if)->LoadInternal(type, name, NULL)             
229
 
230
#else // EFI_NT_EMULATOR 
231
 
232
//
233
// When build similiar to FW, then link everything together as
234
// one big module.
235
//
236
 
237
    #define EFI_DRIVER_ENTRY_POINT(InitFunction)
238
 
239
    #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
240
            (_if)->LoadInternal(type, name, entry)
241
 
242
#endif // EFI_FW_NT 
243
 
244
//
245
// Some compilers don't support the forward reference construct:
246
//  typedef struct XXXXX
247
//
248
// The following macro provide a workaround for such cases.
249
//
250
#ifdef NO_INTERFACE_DECL
251
#define INTERFACE_DECL(x)
252
#else
253
#ifdef __GNUC__
254
#define INTERFACE_DECL(x) struct x
255
#else
256
#define INTERFACE_DECL(x) typedef struct x
257
#endif
258
#endif
259
 
260
#if _MSC_EXTENSIONS
261
#pragma warning ( disable : 4731 )  // Suppress warnings about modification of EBP
262
#endif
263