xref: /freebsd/stand/efi/include/i386/efibind.h (revision 61e21613)
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 #ifdef EFI_NT_EMULATOR
30     #define POST_CODE(_Data)
31 #else
32     #ifdef EFI_DEBUG
33 #define POST_CODE(_Data)    __asm mov eax,(_Data) __asm out 0x80,al
34     #else
35         #define POST_CODE(_Data)
36     #endif
37 #endif
38 
39 #define EFIERR(a)           (0x80000000 | a)
40 #define EFI_ERROR_MASK      0x80000000
41 #define EFIERR_OEM(a)       (0xc0000000 | a)
42 
43 
44 #define BAD_POINTER         0xFBFBFBFB
45 #define MAX_ADDRESS         0xFFFFFFFF
46 
47 #define BREAKPOINT()        __asm { int 3 }
48 
49 //
50 // Pointers must be aligned to these address to function
51 //
52 
53 #define MIN_ALIGNMENT_SIZE  4
54 
55 #define ALIGN_VARIABLE(Value ,Adjustment) \
56             (UINTN)Adjustment = 0; \
57             if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
58                 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
59             Value = (UINTN)Value + (UINTN)Adjustment
60 
61 
62 //
63 // Define macros to build data structure signatures from characters.
64 //
65 
66 #define EFI_SIGNATURE_16(A,B)             ((A) | (B<<8))
67 #define EFI_SIGNATURE_32(A,B,C,D)         (EFI_SIGNATURE_16(A,B)     | (EFI_SIGNATURE_16(C,D)     << 16))
68 #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))
69 
70 //
71 // EFIAPI - prototype calling convention for EFI function pointers
72 // BOOTSERVICE - prototype for implementation of a boot service interface
73 // RUNTIMESERVICE - prototype for implementation of a runtime service interface
74 // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
75 // RUNTIME_CODE - pragma macro for declaring runtime code
76 //
77 
78 #ifndef EFIAPI                  // Forces EFI calling conventions reguardless of compiler options
79     #ifdef _MSC_EXTENSIONS
80         #define EFIAPI __cdecl  // Force C calling convention for Microsoft C compiler
81     #else
82         #define EFIAPI          // Substitute expresion to force C calling convention
83     #endif
84 #endif
85 
86 #define BOOTSERVICE
87 //#define RUNTIMESERVICE(proto,a)    alloc_text("rtcode",a); proto a
88 //#define RUNTIMEFUNCTION(proto,a)   alloc_text("rtcode",a); proto a
89 #define RUNTIMESERVICE
90 #define RUNTIMEFUNCTION
91 
92 
93 #define RUNTIME_CODE(a)         alloc_text("rtcode", a)
94 #define BEGIN_RUNTIME_DATA()    data_seg("rtdata")
95 #define END_RUNTIME_DATA()      data_seg()
96 
97 #define VOLATILE    volatile
98 
99 #define MEMORY_FENCE()
100 
101 #ifdef EFI_NO_INTERFACE_DECL
102   #define EFI_FORWARD_DECLARATION(x)
103   #define EFI_INTERFACE_DECL(x)
104 #else
105   #define EFI_FORWARD_DECLARATION(x) typedef struct _##x x
106   #define EFI_INTERFACE_DECL(x) typedef struct x
107 #endif
108 
109 #ifdef EFI_NT_EMULATOR
110 
111 //
112 // To help ensure proper coding of integrated drivers, they are
113 // compiled as DLLs.  In NT they require a dll init entry pointer.
114 // The macro puts a stub entry point into the DLL so it will load.
115 //
116 
117 #define EFI_DRIVER_ENTRY_POINT(InitFunction)            \
118     EFI_STATUS                                          \
119     InitFunction (                                      \
120       EFI_HANDLE  ImageHandle,                          \
121       EFI_SYSTEM_TABLE  *SystemTable                    \
122       );                                                \
123                                                         \
124     UINTN                                               \
125     __stdcall                                           \
126     _DllMainCRTStartup (                                \
127         UINTN    Inst,                                  \
128         UINTN    reason_for_call,                       \
129         VOID    *rserved                                \
130         )                                               \
131     {                                                   \
132         return 1;                                       \
133     }                                                   \
134                                                         \
135     int                                                 \
136     __declspec( dllexport )                             \
137     __cdecl                                             \
138     InitializeDriver (                                  \
139         void *ImageHandle,                              \
140         void *SystemTable                               \
141         )                                               \
142     {                                                   \
143         return InitFunction(ImageHandle, SystemTable);  \
144     }
145 
146 
147     #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)      \
148         (_if)->LoadInternal(type, name, NULL)
149 
150 #else // EFI_NT_EMULATOR
151 
152 //
153 // When build similar to FW, then link everything together as
154 // one big module.
155 //
156 
157     #define EFI_DRIVER_ENTRY_POINT(InitFunction)
158 
159     #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
160             (_if)->LoadInternal(type, name, entry)
161 
162 #endif // EFI_FW_NT
163 
164 #ifdef __FreeBSD__
165 #define INTERFACE_DECL(x) struct x
166 #else
167 //
168 // Some compilers don't support the forward reference construct:
169 //  typedef struct XXXXX
170 //
171 // The following macro provide a workaround for such cases.
172 //
173 #ifdef NO_INTERFACE_DECL
174 #define INTERFACE_DECL(x)
175 #else
176 #define INTERFACE_DECL(x) typedef struct x
177 #endif
178 #endif	/* __FreeBSD__ */
179 
180 #ifdef _MSC_EXTENSIONS
181 #pragma warning ( disable : 4731 )  // Suppress warnings about modification of EBP
182 #endif
183 
184