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