xref: /DragonStub/inc/aarch64/efibind.h (revision d857a968f4de4d9d549c11515b9df34aae2def76)
1 /*
2  * Copright (C) 2014 - 2015 Linaro Ltd.
3  * Author: Ard Biesheuvel <ard.biesheuvel@linaro.org>
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice and this list of conditions, without modification.
10  * 2. The name of the author may not be used to endorse or promote products
11  *    derived from this software without specific prior written permission.
12  *
13  * Alternatively, this software may be distributed under the terms of the
14  * GNU General Public License as published by the Free Software Foundation;
15  * either version 2 of the License, or (at your option) any later version.
16  */
17 
18 #if !defined(_MSC_VER) && (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L )) && !defined(__cplusplus)
19 
20 // ANSI C 1999/2000 stdint.h integer width declarations
21 
22 typedef unsigned long       uint64_t;
23 typedef long                int64_t;
24 typedef unsigned int        uint32_t;
25 typedef int                 int32_t;
26 typedef unsigned short      uint16_t;
27 typedef short               int16_t;
28 typedef unsigned char       uint8_t;
29 typedef signed char         int8_t;   // unqualified 'char' is unsigned on ARM
30 typedef uint64_t            uintptr_t;
31 typedef int64_t             intptr_t;
32 
33 #else
34 #include <stdint.h>
35 #endif
36 
37 //
38 // Basic EFI types of various widths
39 //
40 
41 #ifndef __WCHAR_TYPE__
42 # define __WCHAR_TYPE__ short
43 #endif
44 
45 typedef uint64_t   UINT64;
46 typedef int64_t    INT64;
47 
48 typedef uint32_t   UINT32;
49 typedef int32_t    INT32;
50 
51 typedef uint16_t   UINT16;
52 typedef int16_t    INT16;
53 typedef uint8_t    UINT8;
54 typedef int8_t     INT8;
55 typedef __WCHAR_TYPE__ WCHAR;
56 
57 #undef VOID
58 #define VOID    void
59 
60 typedef int64_t    INTN;
61 typedef uint64_t   UINTN;
62 
63 #define EFIERR(a)           (0x8000000000000000 | a)
64 #define EFI_ERROR_MASK      0x8000000000000000
65 #define EFIERR_OEM(a)       (0xc000000000000000 | a)
66 
67 #define BAD_POINTER         0xFBFBFBFBFBFBFBFB
68 #define MAX_ADDRESS         0xFFFFFFFFFFFFFFFF
69 
70 #define BREAKPOINT()        while (TRUE);    // Make it hang on Bios[Dbg]32
71 
72 //
73 // Pointers must be aligned to these address to function
74 //
75 
76 #define MIN_ALIGNMENT_SIZE  8
77 
78 #define ALIGN_VARIABLE(Value ,Adjustment) \
79             (UINTN)Adjustment = 0; \
80             if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
81                 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
82             Value = (UINTN)Value + (UINTN)Adjustment
83 
84 
85 //
86 // Define macros to build data structure signatures from characters.
87 //
88 
89 #define EFI_SIGNATURE_16(A,B)             ((A) | (B<<8))
90 #define EFI_SIGNATURE_32(A,B,C,D)         (EFI_SIGNATURE_16(A,B)     | (EFI_SIGNATURE_16(C,D)     << 16))
91 #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))
92 
93 //
94 // EFIAPI - prototype calling convention for EFI function pointers
95 // BOOTSERVICE - prototype for implementation of a boot service interface
96 // RUNTIMESERVICE - prototype for implementation of a runtime service interface
97 // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
98 // RUNTIME_CODE - pragma macro for declaring runtime code
99 //
100 
101 #ifndef EFIAPI          // Forces EFI calling conventions reguardless of compiler options
102 #define EFIAPI          // Substitute expresion to force C calling convention
103 #endif
104 
105 #define BOOTSERVICE
106 #define RUNTIMESERVICE
107 #define RUNTIMEFUNCTION
108 
109 
110 #define RUNTIME_CODE(a)         alloc_text("rtcode", a)
111 #define BEGIN_RUNTIME_DATA()    data_seg("rtdata")
112 #define END_RUNTIME_DATA()      data_seg("")
113 
114 #define VOLATILE                volatile
115 
116 #define MEMORY_FENCE            __sync_synchronize
117 
118 //
119 // When build similiar to FW, then link everything together as
120 // one big module. For the MSVC toolchain, we simply tell the
121 // linker what our driver init function is using /ENTRY.
122 //
123 #if defined(_MSC_EXTENSIONS)
124 #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
125     __pragma(comment(linker, "/ENTRY:" # InitFunction))
126 #else
127 #define EFI_DRIVER_ENTRY_POINT(InitFunction)    \
128     UINTN                                       \
129     InitializeDriver (                          \
130         VOID    *ImageHandle,                   \
131         VOID    *SystemTable                    \
132         )                                       \
133     {                                           \
134         return InitFunction(ImageHandle,        \
135                 SystemTable);                   \
136     }                                           \
137                                                 \
138     EFI_STATUS efi_main(                        \
139         EFI_HANDLE image,                       \
140         EFI_SYSTEM_TABLE *systab                \
141         ) __attribute__((weak,                  \
142                 alias ("InitializeDriver")));
143 #endif
144 
145 #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
146         (_if)->LoadInternal(type, name, entry)
147 
148 
149 //
150 // Some compilers don't support the forward reference construct:
151 //  typedef struct XXXXX
152 //
153 // The following macro provide a workaround for such cases.
154 
155 #define INTERFACE_DECL(x) struct x
156 
157 #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__)
158 #define EFI_FUNCTION
159