177943Sdfr/* $FreeBSD$ */
277943Sdfr/*++
377943Sdfr
4163898SmarcelCopyright (c)  1999 - 2003 Intel Corporation. All rights reserved
5163898SmarcelThis software and associated documentation (if any) is furnished
6163898Smarcelunder a license and may only be used or copied in accordance
7163898Smarcelwith the terms of the license. Except as permitted by such
8163898Smarcellicense, no part of this software or documentation may be
9163898Smarcelreproduced, stored in a retrieval system, or transmitted in any
10163898Smarcelform or by any means without the express written consent of
11163898SmarcelIntel Corporation.
1277943Sdfr
1377943SdfrModule Name:
1477943Sdfr
1577943Sdfr    efefind.h
1677943Sdfr
1777943SdfrAbstract:
1877943Sdfr
1977943Sdfr    EFI to compile bindings
2077943Sdfr
2177943Sdfr
2277943Sdfr
2377943Sdfr
2477943SdfrRevision History
2577943Sdfr
2677943Sdfr--*/
2777943Sdfr
2877943Sdfr#pragma pack()
2977943Sdfr
3077943Sdfr
31163898Smarcel#ifdef __FreeBSD__
32163898Smarcel#include <sys/stdint.h>
33163898Smarcel#else
34163898Smarcel//
35163898Smarcel// Basic int types of various widths
36163898Smarcel//
3777943Sdfr
3877943Sdfr#if (__STDC_VERSION__ < 199901L )
3977943Sdfr
40163898Smarcel    // No ANSI C 1999/2000 stdint.h integer width declarations
4177943Sdfr
4277943Sdfr    #if _MSC_EXTENSIONS
4377943Sdfr
44163898Smarcel        // Use Microsoft C compiler integer width declarations
4577943Sdfr
4677943Sdfr        typedef unsigned __int64    uint64_t;
4777943Sdfr        typedef __int64             int64_t;
4877943Sdfr        typedef unsigned __int32    uint32_t;
4977943Sdfr        typedef __int32             int32_t;
5077943Sdfr        typedef unsigned short      uint16_t;
5177943Sdfr        typedef short               int16_t;
5277943Sdfr        typedef unsigned char       uint8_t;
5377943Sdfr        typedef char                int8_t;
5477943Sdfr    #else
5577943Sdfr        #ifdef UNIX_LP64
5677943Sdfr
57163898Smarcel            // Use LP64 programming model from C_FLAGS for integer width declarations
5877943Sdfr
5977943Sdfr            typedef unsigned long       uint64_t;
6077943Sdfr            typedef long                int64_t;
6177943Sdfr            typedef unsigned int        uint32_t;
6277943Sdfr            typedef int                 int32_t;
6377943Sdfr            typedef unsigned short      uint16_t;
6477943Sdfr            typedef short               int16_t;
6577943Sdfr            typedef unsigned char       uint8_t;
6677943Sdfr            typedef char                int8_t;
6777943Sdfr        #else
6877943Sdfr
69163898Smarcel            // Assume P64 programming model from C_FLAGS for integer width declarations
7077943Sdfr
7177943Sdfr            typedef unsigned long long  uint64_t;
7277943Sdfr            typedef long long           int64_t;
7377943Sdfr            typedef unsigned int        uint32_t;
7477943Sdfr            typedef int                 int32_t;
7577943Sdfr            typedef unsigned short      uint16_t;
7677943Sdfr            typedef short               int16_t;
7777943Sdfr            typedef unsigned char       uint8_t;
7877943Sdfr            typedef char                int8_t;
7977943Sdfr        #endif
8077943Sdfr    #endif
8177943Sdfr#endif
82163898Smarcel#endif	/* __FreeBSD__ */
8377943Sdfr
84163898Smarcel//
85163898Smarcel// Basic EFI types of various widths
86163898Smarcel//
8777943Sdfr
8877943Sdfrtypedef uint64_t   UINT64;
8977943Sdfrtypedef int64_t    INT64;
9077943Sdfr
9177943Sdfr#ifndef _BASETSD_H_
9277943Sdfr    typedef uint32_t   UINT32;
9377943Sdfr    typedef int32_t    INT32;
9477943Sdfr#endif
9577943Sdfr
9677943Sdfrtypedef uint16_t   UINT16;
9777943Sdfrtypedef int16_t    INT16;
9877943Sdfrtypedef uint8_t    UINT8;
9977943Sdfrtypedef int8_t     INT8;
10077943Sdfr
10177943Sdfr
10277943Sdfr#undef VOID
10377943Sdfr#define VOID    void
10477943Sdfr
10577943Sdfr
10677943Sdfrtypedef int32_t    INTN;
10777943Sdfrtypedef uint32_t   UINTN;
10877943Sdfr
10977943Sdfr#ifdef EFI_NT_EMULATOR
11077943Sdfr    #define POST_CODE(_Data)
11177943Sdfr#else
11277943Sdfr    #ifdef EFI_DEBUG
11377943Sdfr#define POST_CODE(_Data)    __asm mov eax,(_Data) __asm out 0x80,al
11477943Sdfr    #else
11577943Sdfr        #define POST_CODE(_Data)
11677943Sdfr    #endif
11777943Sdfr#endif
11877943Sdfr
11977943Sdfr#define EFIERR(a)           (0x80000000 | a)
12077943Sdfr#define EFI_ERROR_MASK      0x80000000
12177943Sdfr#define EFIERR_OEM(a)       (0xc0000000 | a)
12277943Sdfr
12377943Sdfr
12477943Sdfr#define BAD_POINTER         0xFBFBFBFB
12577943Sdfr#define MAX_ADDRESS         0xFFFFFFFF
12677943Sdfr
127163898Smarcel#define BREAKPOINT()        __asm { int 3 }
12877943Sdfr
129163898Smarcel//
130163898Smarcel// Pointers must be aligned to these address to function
131163898Smarcel//
13277943Sdfr
13377943Sdfr#define MIN_ALIGNMENT_SIZE  4
13477943Sdfr
13577943Sdfr#define ALIGN_VARIABLE(Value ,Adjustment) \
13677943Sdfr            (UINTN)Adjustment = 0; \
13777943Sdfr            if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
13877943Sdfr                (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
13977943Sdfr            Value = (UINTN)Value + (UINTN)Adjustment
14077943Sdfr
14177943Sdfr
142163898Smarcel//
143163898Smarcel// Define macros to build data structure signatures from characters.
144163898Smarcel//
14577943Sdfr
14677943Sdfr#define EFI_SIGNATURE_16(A,B)             ((A) | (B<<8))
14777943Sdfr#define EFI_SIGNATURE_32(A,B,C,D)         (EFI_SIGNATURE_16(A,B)     | (EFI_SIGNATURE_16(C,D)     << 16))
14877943Sdfr#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))
14977943Sdfr
150163898Smarcel//
151163898Smarcel// EFIAPI - prototype calling convention for EFI function pointers
152163898Smarcel// BOOTSERVICE - prototype for implementation of a boot service interface
153163898Smarcel// RUNTIMESERVICE - prototype for implementation of a runtime service interface
154163898Smarcel// RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
155163898Smarcel// RUNTIME_CODE - pragma macro for declaring runtime code
156163898Smarcel//
15796893Smarcel
158163898Smarcel#ifndef EFIAPI                  // Forces EFI calling conventions reguardless of compiler options
15977943Sdfr    #if _MSC_EXTENSIONS
160163898Smarcel        #define EFIAPI __cdecl  // Force C calling convention for Microsoft C compiler
16177943Sdfr    #else
162163898Smarcel        #define EFIAPI          // Substitute expresion to force C calling convention
16377943Sdfr    #endif
16477943Sdfr#endif
16577943Sdfr
16677943Sdfr#define BOOTSERVICE
167163898Smarcel//#define RUNTIMESERVICE(proto,a)    alloc_text("rtcode",a); proto a
168163898Smarcel//#define RUNTIMEFUNCTION(proto,a)   alloc_text("rtcode",a); proto a
16977943Sdfr#define RUNTIMESERVICE
17077943Sdfr#define RUNTIMEFUNCTION
17177943Sdfr
17277943Sdfr
17377943Sdfr#define RUNTIME_CODE(a)         alloc_text("rtcode", a)
17477943Sdfr#define BEGIN_RUNTIME_DATA()    data_seg("rtdata")
175163898Smarcel#define END_RUNTIME_DATA()      data_seg()
17677943Sdfr
17777943Sdfr#define VOLATILE    volatile
17877943Sdfr
17977943Sdfr#define MEMORY_FENCE()
18077943Sdfr
181163898Smarcel#ifdef EFI_NO_INTERFACE_DECL
182163898Smarcel  #define EFI_FORWARD_DECLARATION(x)
183163898Smarcel  #define EFI_INTERFACE_DECL(x)
184163898Smarcel#else
185163898Smarcel  #define EFI_FORWARD_DECLARATION(x) typedef struct _##x x
186163898Smarcel  #define EFI_INTERFACE_DECL(x) typedef struct x
187163898Smarcel#endif
188163898Smarcel
18977943Sdfr#ifdef EFI_NT_EMULATOR
19077943Sdfr
191163898Smarcel//
192163898Smarcel// To help ensure proper coding of integrated drivers, they are
193163898Smarcel// compiled as DLLs.  In NT they require a dll init entry pointer.
194163898Smarcel// The macro puts a stub entry point into the DLL so it will load.
195163898Smarcel//
19677943Sdfr
197163898Smarcel#define EFI_DRIVER_ENTRY_POINT(InitFunction)            \
198163898Smarcel    EFI_STATUS                                          \
199163898Smarcel    InitFunction (                                      \
200163898Smarcel      EFI_HANDLE  ImageHandle,                          \
201163898Smarcel      EFI_SYSTEM_TABLE  *SystemTable                    \
202163898Smarcel      );                                                \
203163898Smarcel                                                        \
204163898Smarcel    UINTN                                               \
205163898Smarcel    __stdcall                                           \
206163898Smarcel    _DllMainCRTStartup (                                \
207163898Smarcel        UINTN    Inst,                                  \
208163898Smarcel        UINTN    reason_for_call,                       \
209163898Smarcel        VOID    *rserved                                \
210163898Smarcel        )                                               \
211163898Smarcel    {                                                   \
212163898Smarcel        return 1;                                       \
213163898Smarcel    }                                                   \
214163898Smarcel                                                        \
215163898Smarcel    int                                                 \
216163898Smarcel    __declspec( dllexport )                             \
217163898Smarcel    __cdecl                                             \
218163898Smarcel    InitializeDriver (                                  \
219163898Smarcel        void *ImageHandle,                              \
220163898Smarcel        void *SystemTable                               \
221163898Smarcel        )                                               \
222163898Smarcel    {                                                   \
223163898Smarcel        return InitFunction(ImageHandle, SystemTable);  \
22477943Sdfr    }
22577943Sdfr
22677943Sdfr
22777943Sdfr    #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)      \
22877943Sdfr        (_if)->LoadInternal(type, name, NULL)
22977943Sdfr
230163898Smarcel#else // EFI_NT_EMULATOR
23177943Sdfr
232163898Smarcel//
233163898Smarcel// When build similiar to FW, then link everything together as
234163898Smarcel// one big module.
235163898Smarcel//
23677943Sdfr
23777943Sdfr    #define EFI_DRIVER_ENTRY_POINT(InitFunction)
23877943Sdfr
23977943Sdfr    #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
24077943Sdfr            (_if)->LoadInternal(type, name, entry)
24177943Sdfr
242163898Smarcel#endif // EFI_FW_NT
24377943Sdfr
244163898Smarcel#ifdef __FreeBSD__
245143250Sstefanf#define INTERFACE_DECL(x) struct x
246163898Smarcel#else
247163898Smarcel//
248163898Smarcel// Some compilers don't support the forward reference construct:
249163898Smarcel//  typedef struct XXXXX
250163898Smarcel//
251163898Smarcel// The following macro provide a workaround for such cases.
252163898Smarcel//
253163898Smarcel#ifdef NO_INTERFACE_DECL
254163898Smarcel#define INTERFACE_DECL(x)
255163898Smarcel#else
256163898Smarcel#define INTERFACE_DECL(x) typedef struct x
257163898Smarcel#endif
258163898Smarcel#endif	/* __FreeBSD__ */
25977943Sdfr
26077943Sdfr#if _MSC_EXTENSIONS
261163898Smarcel#pragma warning ( disable : 4731 )  // Suppress warnings about modification of EBP
26277943Sdfr#endif
26377943Sdfr
264