xref: /DragonStub/inc/aarch64/efibind.h (revision 530d68ba191850edafc6da22cb2df55bec0c5fa5)
1*530d68baSNigel Croxon 
2*530d68baSNigel Croxon #include <stdint.h>
3*530d68baSNigel Croxon 
4*530d68baSNigel Croxon //
5*530d68baSNigel Croxon // Basic EFI types of various widths
6*530d68baSNigel Croxon //
7*530d68baSNigel Croxon 
8*530d68baSNigel Croxon #ifndef __WCHAR_TYPE__
9*530d68baSNigel Croxon # define __WCHAR_TYPE__ short
10*530d68baSNigel Croxon #endif
11*530d68baSNigel Croxon 
12*530d68baSNigel Croxon typedef uint64_t   UINT64;
13*530d68baSNigel Croxon typedef int64_t    INT64;
14*530d68baSNigel Croxon 
15*530d68baSNigel Croxon typedef uint32_t   UINT32;
16*530d68baSNigel Croxon typedef int32_t    INT32;
17*530d68baSNigel Croxon 
18*530d68baSNigel Croxon typedef uint16_t   UINT16;
19*530d68baSNigel Croxon typedef int16_t    INT16;
20*530d68baSNigel Croxon typedef uint8_t    UINT8;
21*530d68baSNigel Croxon typedef int8_t     INT8;
22*530d68baSNigel Croxon typedef __WCHAR_TYPE__ WCHAR;
23*530d68baSNigel Croxon 
24*530d68baSNigel Croxon #undef VOID
25*530d68baSNigel Croxon #define VOID    void
26*530d68baSNigel Croxon 
27*530d68baSNigel Croxon typedef int64_t    INTN;
28*530d68baSNigel Croxon typedef uint64_t   UINTN;
29*530d68baSNigel Croxon 
30*530d68baSNigel Croxon #define EFIERR(a)           (0x8000000000000000 | a)
31*530d68baSNigel Croxon #define EFI_ERROR_MASK      0x8000000000000000
32*530d68baSNigel Croxon #define EFIERR_OEM(a)       (0xc000000000000000 | a)
33*530d68baSNigel Croxon 
34*530d68baSNigel Croxon #define BAD_POINTER         0xFBFBFBFBFBFBFBFB
35*530d68baSNigel Croxon #define MAX_ADDRESS         0xFFFFFFFFFFFFFFFF
36*530d68baSNigel Croxon 
37*530d68baSNigel Croxon #define BREAKPOINT()        while (TRUE);    // Make it hang on Bios[Dbg]32
38*530d68baSNigel Croxon 
39*530d68baSNigel Croxon //
40*530d68baSNigel Croxon // Pointers must be aligned to these address to function
41*530d68baSNigel Croxon //
42*530d68baSNigel Croxon 
43*530d68baSNigel Croxon #define MIN_ALIGNMENT_SIZE  8
44*530d68baSNigel Croxon 
45*530d68baSNigel Croxon #define ALIGN_VARIABLE(Value ,Adjustment) \
46*530d68baSNigel Croxon             (UINTN)Adjustment = 0; \
47*530d68baSNigel Croxon             if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
48*530d68baSNigel Croxon                 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
49*530d68baSNigel Croxon             Value = (UINTN)Value + (UINTN)Adjustment
50*530d68baSNigel Croxon 
51*530d68baSNigel Croxon 
52*530d68baSNigel Croxon //
53*530d68baSNigel Croxon // Define macros to build data structure signatures from characters.
54*530d68baSNigel Croxon //
55*530d68baSNigel Croxon 
56*530d68baSNigel Croxon #define EFI_SIGNATURE_16(A,B)             ((A) | (B<<8))
57*530d68baSNigel Croxon #define EFI_SIGNATURE_32(A,B,C,D)         (EFI_SIGNATURE_16(A,B)     | (EFI_SIGNATURE_16(C,D)     << 16))
58*530d68baSNigel Croxon #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))
59*530d68baSNigel Croxon 
60*530d68baSNigel Croxon //
61*530d68baSNigel Croxon // EFIAPI - prototype calling convention for EFI function pointers
62*530d68baSNigel Croxon // BOOTSERVICE - prototype for implementation of a boot service interface
63*530d68baSNigel Croxon // RUNTIMESERVICE - prototype for implementation of a runtime service interface
64*530d68baSNigel Croxon // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
65*530d68baSNigel Croxon // RUNTIME_CODE - pragma macro for declaring runtime code
66*530d68baSNigel Croxon //
67*530d68baSNigel Croxon 
68*530d68baSNigel Croxon #ifndef EFIAPI          // Forces EFI calling conventions reguardless of compiler options
69*530d68baSNigel Croxon #define EFIAPI          // Substitute expresion to force C calling convention
70*530d68baSNigel Croxon #endif
71*530d68baSNigel Croxon 
72*530d68baSNigel Croxon #define BOOTSERVICE
73*530d68baSNigel Croxon #define RUNTIMESERVICE
74*530d68baSNigel Croxon #define RUNTIMEFUNCTION
75*530d68baSNigel Croxon 
76*530d68baSNigel Croxon 
77*530d68baSNigel Croxon #define RUNTIME_CODE(a)         alloc_text("rtcode", a)
78*530d68baSNigel Croxon #define BEGIN_RUNTIME_DATA()    data_seg("rtdata")
79*530d68baSNigel Croxon #define END_RUNTIME_DATA()      data_seg("")
80*530d68baSNigel Croxon 
81*530d68baSNigel Croxon #define VOLATILE                volatile
82*530d68baSNigel Croxon 
83*530d68baSNigel Croxon #define MEMORY_FENCE            __sync_synchronize
84*530d68baSNigel Croxon 
85*530d68baSNigel Croxon //
86*530d68baSNigel Croxon // When build similiar to FW, then link everything together as
87*530d68baSNigel Croxon // one big module.
88*530d68baSNigel Croxon //
89*530d68baSNigel Croxon 
90*530d68baSNigel Croxon #define EFI_DRIVER_ENTRY_POINT(InitFunction)    \
91*530d68baSNigel Croxon     UINTN                                       \
92*530d68baSNigel Croxon     InitializeDriver (                          \
93*530d68baSNigel Croxon         VOID    *ImageHandle,                   \
94*530d68baSNigel Croxon         VOID    *SystemTable                    \
95*530d68baSNigel Croxon         )                                       \
96*530d68baSNigel Croxon     {                                           \
97*530d68baSNigel Croxon         return InitFunction(ImageHandle,        \
98*530d68baSNigel Croxon                 SystemTable);                   \
99*530d68baSNigel Croxon     }                                           \
100*530d68baSNigel Croxon                                                 \
101*530d68baSNigel Croxon     EFI_STATUS efi_main(                        \
102*530d68baSNigel Croxon         EFI_HANDLE image,                       \
103*530d68baSNigel Croxon         EFI_SYSTEM_TABLE *systab                \
104*530d68baSNigel Croxon         ) __attribute__((weak,                  \
105*530d68baSNigel Croxon                 alias ("InitializeDriver")));
106*530d68baSNigel Croxon 
107*530d68baSNigel Croxon #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
108*530d68baSNigel Croxon         (_if)->LoadInternal(type, name, entry)
109*530d68baSNigel Croxon 
110*530d68baSNigel Croxon 
111*530d68baSNigel Croxon //
112*530d68baSNigel Croxon // Some compilers don't support the forward reference construct:
113*530d68baSNigel Croxon //  typedef struct XXXXX
114*530d68baSNigel Croxon //
115*530d68baSNigel Croxon // The following macro provide a workaround for such cases.
116*530d68baSNigel Croxon 
117*530d68baSNigel Croxon #define INTERFACE_DECL(x) struct x
118*530d68baSNigel Croxon 
119*530d68baSNigel Croxon #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__)
120*530d68baSNigel Croxon #define EFI_FUNCTION
121