Subversion Repositories HelenOS

Rev

Rev 2726 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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