xref: /DragonStub/inc/aarch64/efibind.h (revision 333bf05da904010c4df3fbc002f6b829c67bd545)
1*333bf05dSNigel Croxon /*
2*333bf05dSNigel Croxon  * Copright (C) 2014 - 2015 Linaro Ltd.
3*333bf05dSNigel Croxon  * Author: Ard Biesheuvel <ard.biesheuvel@linaro.org>
4*333bf05dSNigel Croxon  *
5*333bf05dSNigel Croxon  * Redistribution and use in source and binary forms, with or without
6*333bf05dSNigel Croxon  * modification, are permitted provided that the following conditions
7*333bf05dSNigel Croxon  * are met:
8*333bf05dSNigel Croxon  * 1. Redistributions of source code must retain the above copyright
9*333bf05dSNigel Croxon  *    notice and this list of conditions, without modification.
10*333bf05dSNigel Croxon  * 2. The name of the author may not be used to endorse or promote products
11*333bf05dSNigel Croxon  *    derived from this software without specific prior written permission.
12*333bf05dSNigel Croxon  *
13*333bf05dSNigel Croxon  * Alternatively, this software may be distributed under the terms of the
14*333bf05dSNigel Croxon  * GNU General Public License as published by the Free Software Foundation;
15*333bf05dSNigel Croxon  * either version 2 of the License, or (at your option) any later version.
16*333bf05dSNigel Croxon  */
17530d68baSNigel Croxon 
18*333bf05dSNigel Croxon #if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L )
19*333bf05dSNigel Croxon 
20*333bf05dSNigel Croxon // ANSI C 1999/2000 stdint.h integer width declarations
21*333bf05dSNigel Croxon 
22*333bf05dSNigel Croxon typedef unsigned long       uint64_t;
23*333bf05dSNigel Croxon typedef long                int64_t;
24*333bf05dSNigel Croxon typedef unsigned int        uint32_t;
25*333bf05dSNigel Croxon typedef int                 int32_t;
26*333bf05dSNigel Croxon typedef unsigned short      uint16_t;
27*333bf05dSNigel Croxon typedef short               int16_t;
28*333bf05dSNigel Croxon typedef unsigned char       uint8_t;
29*333bf05dSNigel Croxon typedef signed char         int8_t;   // unqualified 'char' is unsigned on ARM
30*333bf05dSNigel Croxon 
31*333bf05dSNigel Croxon #else
32530d68baSNigel Croxon #include <stdint.h>
33*333bf05dSNigel Croxon #endif
34530d68baSNigel Croxon 
35530d68baSNigel Croxon //
36530d68baSNigel Croxon // Basic EFI types of various widths
37530d68baSNigel Croxon //
38530d68baSNigel Croxon 
39530d68baSNigel Croxon #ifndef __WCHAR_TYPE__
40530d68baSNigel Croxon # define __WCHAR_TYPE__ short
41530d68baSNigel Croxon #endif
42530d68baSNigel Croxon 
43530d68baSNigel Croxon typedef uint64_t   UINT64;
44530d68baSNigel Croxon typedef int64_t    INT64;
45530d68baSNigel Croxon 
46530d68baSNigel Croxon typedef uint32_t   UINT32;
47530d68baSNigel Croxon typedef int32_t    INT32;
48530d68baSNigel Croxon 
49530d68baSNigel Croxon typedef uint16_t   UINT16;
50530d68baSNigel Croxon typedef int16_t    INT16;
51530d68baSNigel Croxon typedef uint8_t    UINT8;
52530d68baSNigel Croxon typedef int8_t     INT8;
53530d68baSNigel Croxon typedef __WCHAR_TYPE__ WCHAR;
54530d68baSNigel Croxon 
55530d68baSNigel Croxon #undef VOID
56530d68baSNigel Croxon #define VOID    void
57530d68baSNigel Croxon 
58530d68baSNigel Croxon typedef int64_t    INTN;
59530d68baSNigel Croxon typedef uint64_t   UINTN;
60530d68baSNigel Croxon 
61530d68baSNigel Croxon #define EFIERR(a)           (0x8000000000000000 | a)
62530d68baSNigel Croxon #define EFI_ERROR_MASK      0x8000000000000000
63530d68baSNigel Croxon #define EFIERR_OEM(a)       (0xc000000000000000 | a)
64530d68baSNigel Croxon 
65530d68baSNigel Croxon #define BAD_POINTER         0xFBFBFBFBFBFBFBFB
66530d68baSNigel Croxon #define MAX_ADDRESS         0xFFFFFFFFFFFFFFFF
67530d68baSNigel Croxon 
68530d68baSNigel Croxon #define BREAKPOINT()        while (TRUE);    // Make it hang on Bios[Dbg]32
69530d68baSNigel Croxon 
70530d68baSNigel Croxon //
71530d68baSNigel Croxon // Pointers must be aligned to these address to function
72530d68baSNigel Croxon //
73530d68baSNigel Croxon 
74530d68baSNigel Croxon #define MIN_ALIGNMENT_SIZE  8
75530d68baSNigel Croxon 
76530d68baSNigel Croxon #define ALIGN_VARIABLE(Value ,Adjustment) \
77530d68baSNigel Croxon             (UINTN)Adjustment = 0; \
78530d68baSNigel Croxon             if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
79530d68baSNigel Croxon                 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
80530d68baSNigel Croxon             Value = (UINTN)Value + (UINTN)Adjustment
81530d68baSNigel Croxon 
82530d68baSNigel Croxon 
83530d68baSNigel Croxon //
84530d68baSNigel Croxon // Define macros to build data structure signatures from characters.
85530d68baSNigel Croxon //
86530d68baSNigel Croxon 
87530d68baSNigel Croxon #define EFI_SIGNATURE_16(A,B)             ((A) | (B<<8))
88530d68baSNigel Croxon #define EFI_SIGNATURE_32(A,B,C,D)         (EFI_SIGNATURE_16(A,B)     | (EFI_SIGNATURE_16(C,D)     << 16))
89530d68baSNigel 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))
90530d68baSNigel Croxon 
91530d68baSNigel Croxon //
92530d68baSNigel Croxon // EFIAPI - prototype calling convention for EFI function pointers
93530d68baSNigel Croxon // BOOTSERVICE - prototype for implementation of a boot service interface
94530d68baSNigel Croxon // RUNTIMESERVICE - prototype for implementation of a runtime service interface
95530d68baSNigel Croxon // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
96530d68baSNigel Croxon // RUNTIME_CODE - pragma macro for declaring runtime code
97530d68baSNigel Croxon //
98530d68baSNigel Croxon 
99530d68baSNigel Croxon #ifndef EFIAPI          // Forces EFI calling conventions reguardless of compiler options
100530d68baSNigel Croxon #define EFIAPI          // Substitute expresion to force C calling convention
101530d68baSNigel Croxon #endif
102530d68baSNigel Croxon 
103530d68baSNigel Croxon #define BOOTSERVICE
104530d68baSNigel Croxon #define RUNTIMESERVICE
105530d68baSNigel Croxon #define RUNTIMEFUNCTION
106530d68baSNigel Croxon 
107530d68baSNigel Croxon 
108530d68baSNigel Croxon #define RUNTIME_CODE(a)         alloc_text("rtcode", a)
109530d68baSNigel Croxon #define BEGIN_RUNTIME_DATA()    data_seg("rtdata")
110530d68baSNigel Croxon #define END_RUNTIME_DATA()      data_seg("")
111530d68baSNigel Croxon 
112530d68baSNigel Croxon #define VOLATILE                volatile
113530d68baSNigel Croxon 
114530d68baSNigel Croxon #define MEMORY_FENCE            __sync_synchronize
115530d68baSNigel Croxon 
116530d68baSNigel Croxon //
117530d68baSNigel Croxon // When build similiar to FW, then link everything together as
118530d68baSNigel Croxon // one big module.
119530d68baSNigel Croxon //
120530d68baSNigel Croxon 
121530d68baSNigel Croxon #define EFI_DRIVER_ENTRY_POINT(InitFunction)    \
122530d68baSNigel Croxon     UINTN                                       \
123530d68baSNigel Croxon     InitializeDriver (                          \
124530d68baSNigel Croxon         VOID    *ImageHandle,                   \
125530d68baSNigel Croxon         VOID    *SystemTable                    \
126530d68baSNigel Croxon         )                                       \
127530d68baSNigel Croxon     {                                           \
128530d68baSNigel Croxon         return InitFunction(ImageHandle,        \
129530d68baSNigel Croxon                 SystemTable);                   \
130530d68baSNigel Croxon     }                                           \
131530d68baSNigel Croxon                                                 \
132530d68baSNigel Croxon     EFI_STATUS efi_main(                        \
133530d68baSNigel Croxon         EFI_HANDLE image,                       \
134530d68baSNigel Croxon         EFI_SYSTEM_TABLE *systab                \
135530d68baSNigel Croxon         ) __attribute__((weak,                  \
136530d68baSNigel Croxon                 alias ("InitializeDriver")));
137530d68baSNigel Croxon 
138530d68baSNigel Croxon #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
139530d68baSNigel Croxon         (_if)->LoadInternal(type, name, entry)
140530d68baSNigel Croxon 
141530d68baSNigel Croxon 
142530d68baSNigel Croxon //
143530d68baSNigel Croxon // Some compilers don't support the forward reference construct:
144530d68baSNigel Croxon //  typedef struct XXXXX
145530d68baSNigel Croxon //
146530d68baSNigel Croxon // The following macro provide a workaround for such cases.
147530d68baSNigel Croxon 
148530d68baSNigel Croxon #define INTERFACE_DECL(x) struct x
149530d68baSNigel Croxon 
150530d68baSNigel Croxon #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__)
151530d68baSNigel Croxon #define EFI_FUNCTION
152