1 /*++
2 
3 Copyright (c)  1999 - 2003 Intel Corporation. All rights reserved
4 This software and associated documentation (if any) is furnished
5 under a license and may only be used or copied in accordance
6 with the terms of the license. Except as permitted by such
7 license, no part of this software or documentation may be
8 reproduced, stored in a retrieval system, or transmitted in any
9 form or by any means without the express written consent of
10 Intel Corporation.
11 
12 Module Name:
13 
14     efefind.h
15 
16 Abstract:
17 
18     EFI to compile bindings
19 
20 
21 
22 
23 Revision History
24 
25 --*/
26 
27 #pragma pack()
28 
29 
30 #include <sys/stdint.h>
31 
32 //
33 // Basic EFI types of various widths
34 //
35 
36 #ifndef ACPI_THREAD_ID		/* ACPI's definitions are fine, use those */
37 #define ACPI_USE_SYSTEM_INTTYPES 1	/* Tell ACPI we've defined types */
38 
39 typedef uint64_t   UINT64;
40 typedef int64_t    INT64;
41 
42 #ifndef _BASETSD_H_
43     typedef uint32_t   UINT32;
44     typedef int32_t    INT32;
45 #endif
46 
47 typedef uint16_t   UINT16;
48 typedef int16_t    INT16;
49 typedef uint8_t    UINT8;
50 typedef int8_t     INT8;
51 
52 #endif
53 
54 #undef VOID
55 #define VOID    void
56 
57 
58 typedef int32_t    INTN;
59 typedef uint32_t   UINTN;
60 
61 #ifdef EFI_NT_EMULATOR
62     #define POST_CODE(_Data)
63 #else
64     #ifdef EFI_DEBUG
65 #define POST_CODE(_Data)    __asm mov eax,(_Data) __asm out 0x80,al
66     #else
67         #define POST_CODE(_Data)
68     #endif
69 #endif
70 
71 #define EFIERR(a)           (0x80000000 | a)
72 #define EFI_ERROR_MASK      0x80000000
73 #define EFIERR_OEM(a)       (0xc0000000 | a)
74 
75 
76 #define BAD_POINTER         0xFBFBFBFB
77 #define MAX_ADDRESS         0xFFFFFFFF
78 
79 #define BREAKPOINT()        __asm { int 3 }
80 
81 //
82 // Pointers must be aligned to these address to function
83 //
84 
85 #define MIN_ALIGNMENT_SIZE  4
86 
87 #define ALIGN_VARIABLE(Value ,Adjustment) \
88             (UINTN)Adjustment = 0; \
89             if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
90                 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
91             Value = (UINTN)Value + (UINTN)Adjustment
92 
93 
94 //
95 // Define macros to build data structure signatures from characters.
96 //
97 
98 #define EFI_SIGNATURE_16(A,B)             ((A) | (B<<8))
99 #define EFI_SIGNATURE_32(A,B,C,D)         (EFI_SIGNATURE_16(A,B)     | (EFI_SIGNATURE_16(C,D)     << 16))
100 #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))
101 
102 //
103 // EFIAPI - prototype calling convention for EFI function pointers
104 // BOOTSERVICE - prototype for implementation of a boot service interface
105 // RUNTIMESERVICE - prototype for implementation of a runtime service interface
106 // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
107 // RUNTIME_CODE - pragma macro for declaring runtime code
108 //
109 
110 #ifndef EFIAPI                  // Forces EFI calling conventions reguardless of compiler options
111     #ifdef _MSC_EXTENSIONS
112         #define EFIAPI __cdecl  // Force C calling convention for Microsoft C compiler
113     #else
114         #define EFIAPI          // Substitute expresion to force C calling convention
115     #endif
116 #endif
117 
118 #define BOOTSERVICE
119 //#define RUNTIMESERVICE(proto,a)    alloc_text("rtcode",a); proto a
120 //#define RUNTIMEFUNCTION(proto,a)   alloc_text("rtcode",a); proto a
121 #define RUNTIMESERVICE
122 #define RUNTIMEFUNCTION
123 
124 
125 #define RUNTIME_CODE(a)         alloc_text("rtcode", a)
126 #define BEGIN_RUNTIME_DATA()    data_seg("rtdata")
127 #define END_RUNTIME_DATA()      data_seg()
128 
129 #define VOLATILE    volatile
130 
131 #define MEMORY_FENCE()
132 
133 #ifdef EFI_NO_INTERFACE_DECL
134   #define EFI_FORWARD_DECLARATION(x)
135   #define EFI_INTERFACE_DECL(x)
136 #else
137   #define EFI_FORWARD_DECLARATION(x) typedef struct _##x x
138   #define EFI_INTERFACE_DECL(x) typedef struct x
139 #endif
140 
141 #ifdef EFI_NT_EMULATOR
142 
143 //
144 // To help ensure proper coding of integrated drivers, they are
145 // compiled as DLLs.  In NT they require a dll init entry pointer.
146 // The macro puts a stub entry point into the DLL so it will load.
147 //
148 
149 #define EFI_DRIVER_ENTRY_POINT(InitFunction)            \
150     EFI_STATUS                                          \
151     InitFunction (                                      \
152       EFI_HANDLE  ImageHandle,                          \
153       EFI_SYSTEM_TABLE  *SystemTable                    \
154       );                                                \
155                                                         \
156     UINTN                                               \
157     __stdcall                                           \
158     _DllMainCRTStartup (                                \
159         UINTN    Inst,                                  \
160         UINTN    reason_for_call,                       \
161         VOID    *rserved                                \
162         )                                               \
163     {                                                   \
164         return 1;                                       \
165     }                                                   \
166                                                         \
167     int                                                 \
168     __declspec( dllexport )                             \
169     __cdecl                                             \
170     InitializeDriver (                                  \
171         void *ImageHandle,                              \
172         void *SystemTable                               \
173         )                                               \
174     {                                                   \
175         return InitFunction(ImageHandle, SystemTable);  \
176     }
177 
178 
179     #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)      \
180         (_if)->LoadInternal(type, name, NULL)
181 
182 #else // EFI_NT_EMULATOR
183 
184 //
185 // When building similar to FW, link everything together as
186 // one big module.
187 //
188 
189     #define EFI_DRIVER_ENTRY_POINT(InitFunction)
190 
191     #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
192             (_if)->LoadInternal(type, name, entry)
193 
194 #endif // EFI_FW_NT
195 
196 #define INTERFACE_DECL(x) struct x
197 
198 #ifdef _MSC_EXTENSIONS
199 #pragma warning ( disable : 4731 )  // Suppress warnings about modification of EBP
200 #endif
201