xref: /freebsd/stand/efi/include/riscv/efibind.h (revision 22cf89c938886d14f5796fc49f9f020c23ea8eaf)
1 /*++
2 
3 Copyright (c)  1999 - 2003 Intel Corporation. All rights reserved
4 This software and associated documentation (if any) is furnished
5 under a license and may only be used or copied in accordance
6 with the terms of the license. Except as permitted by such
7 license, no part of this software or documentation may be
8 reproduced, stored in a retrieval system, or transmitted in any
9 form or by any means without the express written consent of
10 Intel Corporation.
11 
12 Module Name:
13 
14     efefind.h
15 
16 Abstract:
17 
18     EFI to compile bindings
19 
20 
21 
22 
23 Revision History
24 
25 --*/
26 
27 #pragma pack()
28 
29 
30 #ifdef __FreeBSD__
31 #include <sys/stdint.h>
32 #else
33 //
34 // Basic int types of various widths
35 //
36 
37 #if (__STDC_VERSION__ < 199901L )
38 
39     // No ANSI C 1999/2000 stdint.h integer width declarations
40 
41     #ifdef _MSC_EXTENSIONS
42 
43         // Use Microsoft C compiler integer width declarations
44 
45         typedef unsigned __int64    uint64_t;
46         typedef __int64             int64_t;
47         typedef unsigned __int32    uint32_t;
48         typedef __int32             int32_t;
49         typedef unsigned __int16    uint16_t;
50         typedef __int16             int16_t;
51         typedef unsigned __int8     uint8_t;
52         typedef __int8              int8_t;
53     #else
54         #ifdef UNIX_LP64
55 
56             // Use LP64 programming model from C_FLAGS for integer width declarations
57 
58             typedef unsigned long       uint64_t;
59             typedef long                int64_t;
60             typedef unsigned int        uint32_t;
61             typedef int                 int32_t;
62             typedef unsigned short      uint16_t;
63             typedef short               int16_t;
64             typedef unsigned char       uint8_t;
65             typedef char                int8_t;
66         #else
67 
68             // Assume P64 programming model from C_FLAGS for integer width declarations
69 
70             typedef unsigned long long  uint64_t;
71             typedef long long           int64_t;
72             typedef unsigned int        uint32_t;
73             typedef int                 int32_t;
74             typedef unsigned short      uint16_t;
75             typedef short               int16_t;
76             typedef unsigned char       uint8_t;
77             typedef char                int8_t;
78         #endif
79     #endif
80 #endif
81 #endif	/* __FreeBSD__ */
82 
83 //
84 // Basic EFI types of various widths
85 //
86 
87 
88 typedef uint64_t   UINT64;
89 typedef int64_t    INT64;
90 typedef uint32_t   UINT32;
91 typedef int32_t    INT32;
92 typedef uint16_t   UINT16;
93 typedef int16_t    INT16;
94 typedef uint8_t    UINT8;
95 typedef int8_t     INT8;
96 
97 
98 #undef VOID
99 #define VOID    void
100 
101 
102 typedef int64_t    INTN;
103 typedef uint64_t   UINTN;
104 
105 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
106 // BugBug: Code to debug
107 //
108 #define BIT63   0x8000000000000000
109 
110 #define PLATFORM_IOBASE_ADDRESS   (0xffffc000000 | BIT63)
111 #define PORT_TO_MEMD(_Port) (PLATFORM_IOBASE_ADDRESS | ( ( ( (_Port) & 0xfffc) << 10 ) | ( (_Port) & 0x0fff) ) )
112 
113 //
114 // Macro's with casts make this much easier to use and read.
115 //
116 #define PORT_TO_MEM8D(_Port)  (*(UINT8  *)(PORT_TO_MEMD(_Port)))
117 #define POST_CODE(_Data)  (PORT_TO_MEM8D(0x80) = (_Data))
118 //
119 // BugBug: End Debug Code!!!
120 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
121 
122 #define EFIERR(a)           (0x8000000000000000 | a)
123 #define EFI_ERROR_MASK      0x8000000000000000
124 #define EFIERR_OEM(a)       (0xc000000000000000 | a)
125 
126 #define BAD_POINTER         0xFBFBFBFBFBFBFBFB
127 #define MAX_ADDRESS         0xFFFFFFFFFFFFFFFF
128 
129 #define BREAKPOINT()  __break(0)
130 
131 //
132 // Pointers must be aligned to these address to function
133 //  you will get an alignment fault if this value is less than 8
134 //
135 #define MIN_ALIGNMENT_SIZE  8
136 
137 #define ALIGN_VARIABLE(Value , Adjustment) \
138             (UINTN) Adjustment = 0; \
139             if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
140                 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
141             Value = (UINTN)Value + (UINTN)Adjustment
142 
143 //
144 // Define macros to create data structure signatures.
145 //
146 
147 #define EFI_SIGNATURE_16(A,B)             ((A) | (B<<8))
148 #define EFI_SIGNATURE_32(A,B,C,D)         (EFI_SIGNATURE_16(A,B)     | (EFI_SIGNATURE_16(C,D)     << 16))
149 #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))
150 
151 //
152 // EFIAPI - prototype calling convention for EFI function pointers
153 // BOOTSERVICE - prototype for implementation of a boot service interface
154 // RUNTIMESERVICE - prototype for implementation of a runtime service interface
155 // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
156 // RUNTIME_CODE - pragma macro for declaring runtime code
157 //
158 
159 #ifndef EFIAPI                  // Forces EFI calling conventions reguardless of compiler options
160     #ifdef _MSC_EXTENSIONS
161         #define EFIAPI __cdecl  // Force C calling convention for Microsoft C compiler
162     #else
163         #define EFIAPI          // Substitute expresion to force C calling convention
164     #endif
165 #endif
166 
167 #define BOOTSERVICE
168 #define RUNTIMESERVICE
169 #define RUNTIMEFUNCTION
170 
171 #define RUNTIME_CODE(a)         alloc_text("rtcode", a)
172 #define BEGIN_RUNTIME_DATA()    data_seg("rtdata")
173 #define END_RUNTIME_DATA()      data_seg()
174 
175 #define VOLATILE    volatile
176 
177 //
178 // BugBug: Need to find out if this is portable across compilers.
179 //
180 void __mfa (void);
181 #define MEMORY_FENCE()    __mfa()
182 
183 #ifdef EFI_NO_INTERFACE_DECL
184   #define EFI_FORWARD_DECLARATION(x)
185   #define EFI_INTERFACE_DECL(x)
186 #else
187   #define EFI_FORWARD_DECLARATION(x) typedef struct _##x x
188   #define EFI_INTERFACE_DECL(x) typedef struct x
189 #endif
190 
191 //
192 // When build similar to FW, then link everything together as
193 // one big module.
194 //
195 
196 #define EFI_DRIVER_ENTRY_POINT(InitFunction)
197 
198 #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
199             (_if)->LoadInternal(type, name, entry)
200 //        entry(NULL, ST)
201 
202 #ifdef __FreeBSD__
203 #define INTERFACE_DECL(x) struct x
204 #else
205 //
206 // Some compilers don't support the forward reference construct:
207 //  typedef struct XXXXX
208 //
209 // The following macro provide a workaround for such cases.
210 //
211 #ifdef NO_INTERFACE_DECL
212 #define INTERFACE_DECL(x)
213 #else
214 #define INTERFACE_DECL(x) typedef struct x
215 #endif
216 #endif
217