]>
Commit | Line | Data |
---|---|---|
949f388f | 1 | /** @file\r |
2 | Emulator Thunk to abstract OS services from pure EFI code\r | |
3 | \r | |
4 | Copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>\r | |
d18d8a1d | 5 | \r |
e3ba31da | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
949f388f | 7 | \r |
8 | **/\r | |
9 | \r | |
10 | #ifndef __EMU_THUNK_PROTOCOL_H__\r | |
11 | #define __EMU_THUNK_PROTOCOL_H__\r | |
12 | \r | |
13 | #define EMU_THUNK_PROTOCOL_GUID \\r | |
7e284acb | 14 | { 0x5CF32E0B, 0x8EDF, 0x2E44, { 0x9C, 0xDA, 0x93, 0x20, 0x5E, 0x99, 0xEC, 0x1C } }\r |
949f388f | 15 | \r |
16 | // neded for things like EFI_TIME_CAPABILITIES\r | |
17 | #include <Uefi.h>\r | |
18 | \r | |
19 | #include <Library/PeCoffExtraActionLib.h>\r | |
20 | \r | |
21 | #include <Protocol/EmuIoThunk.h>\r | |
22 | #include <Protocol/DevicePath.h>\r | |
23 | \r | |
949f388f | 24 | typedef struct {\r |
a550d468 MK |
25 | VENDOR_DEVICE_PATH VendorDevicePath;\r |
26 | UINT32 Instance;\r | |
949f388f | 27 | } EMU_VENDOR_DEVICE_PATH_NODE;\r |
28 | \r | |
29 | typedef struct {\r | |
a550d468 MK |
30 | EMU_VENDOR_DEVICE_PATH_NODE Vendor;\r |
31 | EFI_DEVICE_PATH_PROTOCOL EndDevicePath;\r | |
949f388f | 32 | } EMU_THUNK_DEVICE_PATH;\r |
33 | \r | |
a550d468 | 34 | typedef struct _EMU_THUNK_PROTOCOL EMU_THUNK_PROTOCOL;\r |
949f388f | 35 | \r |
d18d8a1d | 36 | typedef\r |
7e284acb | 37 | UINTN\r |
a550d468 | 38 | (EFIAPI *EMU_WRITE_STD_ERROR)(\r |
7e284acb | 39 | IN UINT8 *Buffer,\r |
40 | IN UINTN NumberOfBytes\r | |
d18d8a1d | 41 | );\r |
42 | \r | |
43 | typedef\r | |
7e284acb | 44 | EFI_STATUS\r |
a550d468 | 45 | (EFIAPI *EMU_CONFIG_STD_IN)(\r |
7e284acb | 46 | VOID\r |
47 | );\r | |
d18d8a1d | 48 | \r |
49 | typedef\r | |
7e284acb | 50 | UINTN\r |
a550d468 | 51 | (EFIAPI *EMU_WRITE_STD_OUT)(\r |
949f388f | 52 | IN UINT8 *Buffer,\r |
53 | IN UINTN NumberOfBytes\r | |
54 | );\r | |
d18d8a1d | 55 | \r |
56 | typedef\r | |
7e284acb | 57 | UINTN\r |
a550d468 | 58 | (EFIAPI *EMU_READ_STD_IN)(\r |
7e284acb | 59 | OUT UINT8 *Buffer,\r |
60 | IN UINTN NumberOfBytes\r | |
61 | );\r | |
62 | \r | |
d18d8a1d | 63 | typedef\r |
7e284acb | 64 | BOOLEAN\r |
a550d468 | 65 | (EFIAPI *EMU_POLL_STD_IN)(\r |
7e284acb | 66 | VOID\r |
67 | );\r | |
68 | \r | |
c2175068 | 69 | typedef\r |
70 | VOID *\r | |
a550d468 | 71 | (EFIAPI *EMU_OS_MALLOC)(\r |
c2175068 | 72 | IN UINTN Size\r |
73 | );\r | |
1d7ac5a6 | 74 | \r |
75 | typedef\r | |
76 | VOID *\r | |
a550d468 | 77 | (EFIAPI *EMU_OS_VMALLOC)(\r |
1d7ac5a6 | 78 | IN UINTN Size\r |
79 | );\r | |
d18d8a1d | 80 | \r |
81 | typedef\r | |
1d7ac5a6 | 82 | BOOLEAN\r |
a550d468 | 83 | (EFIAPI *EMU_OS_FREE)(\r |
c2175068 | 84 | IN VOID *Ptr\r |
85 | );\r | |
86 | \r | |
d18d8a1d | 87 | typedef\r |
949f388f | 88 | EFI_STATUS\r |
a550d468 | 89 | (EFIAPI *EMU_PE_COFF_GET_ENTRY_POINT)(\r |
949f388f | 90 | IN VOID *Pe32Data,\r |
91 | IN OUT VOID **EntryPoint\r | |
92 | );\r | |
93 | \r | |
d18d8a1d | 94 | typedef\r |
949f388f | 95 | VOID\r |
a550d468 | 96 | (EFIAPI *EMU_PE_COFF_RELOCATE_EXTRA_ACTION)(\r |
949f388f | 97 | IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r |
98 | );\r | |
99 | \r | |
d18d8a1d | 100 | typedef\r |
949f388f | 101 | VOID\r |
a550d468 | 102 | (EFIAPI *EMU_PE_COFF_UNLOAD_EXTRA_ACTION)(\r |
949f388f | 103 | IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r |
104 | );\r | |
105 | \r | |
106 | typedef\r | |
107 | VOID\r | |
a550d468 | 108 | (EFIAPI *EMU_ENABLE_INERRUPTS)(\r |
949f388f | 109 | VOID\r |
110 | );\r | |
d18d8a1d | 111 | \r |
949f388f | 112 | typedef\r |
113 | VOID\r | |
a550d468 | 114 | (EFIAPI *EMU_DISABLE_INERRUPTS)(\r |
949f388f | 115 | VOID\r |
116 | );\r | |
117 | \r | |
118 | typedef\r | |
119 | UINT64\r | |
a550d468 | 120 | (EFIAPI *EMU_QUERY_PERFORMANCE_FREQENCY)(\r |
949f388f | 121 | VOID\r |
122 | );\r | |
123 | \r | |
124 | typedef\r | |
125 | UINT64\r | |
a550d468 | 126 | (EFIAPI *EMU_QUERY_PERFORMANCE_COUNTER)(\r |
949f388f | 127 | VOID\r |
128 | );\r | |
129 | \r | |
130 | typedef\r | |
131 | VOID\r | |
a550d468 | 132 | (EFIAPI *EMU_SLEEP)(\r |
f6ce1a5c | 133 | IN UINT64 Nanoseconds\r |
949f388f | 134 | );\r |
135 | \r | |
57c7d70f | 136 | typedef\r |
137 | VOID\r | |
a550d468 | 138 | (EFIAPI *EMU_CPU_SLEEP)(\r |
57c7d70f | 139 | VOID\r |
140 | );\r | |
141 | \r | |
949f388f | 142 | typedef\r |
143 | VOID\r | |
a550d468 | 144 | (EFIAPI *EMU_EXIT)(\r |
949f388f | 145 | IN UINTN Status\r |
146 | );\r | |
d18d8a1d | 147 | \r |
949f388f | 148 | typedef\r |
149 | VOID\r | |
a550d468 | 150 | (EFIAPI *EMU_GET_TIME)(\r |
949f388f | 151 | OUT EFI_TIME *Time,\r |
152 | OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL\r | |
153 | );\r | |
d18d8a1d | 154 | \r |
949f388f | 155 | typedef\r |
156 | VOID\r | |
a550d468 | 157 | (EFIAPI *EMU_SET_TIME)(\r |
949f388f | 158 | IN EFI_TIME *Time\r |
159 | );\r | |
160 | \r | |
949f388f | 161 | typedef\r |
162 | VOID\r | |
a550d468 | 163 | (EFIAPI EMU_SET_TIMER_CALLBACK)(\r |
949f388f | 164 | IN UINT64 DeltaMs\r |
165 | );\r | |
166 | \r | |
167 | typedef\r | |
168 | VOID\r | |
a550d468 | 169 | (EFIAPI *EMU_SET_TIMER)(\r |
949f388f | 170 | IN UINT64 PeriodMs,\r |
171 | IN EMU_SET_TIMER_CALLBACK CallBack\r | |
172 | );\r | |
d18d8a1d | 173 | \r |
949f388f | 174 | /**\r |
175 | Enumerates the current set of protocol instances that abstract OS services from EFI.\r | |
d18d8a1d | 176 | \r |
949f388f | 177 | A given protocol can have multiple instances. Usually a protocol is configured via a\r |
d18d8a1d | 178 | single PCD string. The data associated for each instance is seperated via a ! in the string.\r |
949f388f | 179 | EMU_IO_THUNK_PROTOCOL_CLOSE.ConfigString will contain the information in the PCD string up to the next !.\r |
d18d8a1d | 180 | Thus each instance has a unique ConfigString.\r |
949f388f | 181 | \r |
182 | @param EmuBusDriver TRUE means only return protocol instances that need to be produced\r | |
183 | by the EmuBusDriver. FALSE means return all possible protocols\r | |
d18d8a1d | 184 | @param Instance On input the protocol to search for, or NULL to start a search\r |
185 | of all the supported protocol instances.\r | |
186 | @param NextProtocol On output it represents the next value to be passed into Protocol.\r | |
187 | @param Interface A pointer to the EMU_IO_THUNK_PROTOCOL_CLOSE interface.\r | |
949f388f | 188 | \r |
189 | @retval EFI_SUCCESS The function completed successfully.\r | |
190 | @retval EFI_NOT_FOUND The next protocol instance was not found.\r | |
191 | @retval EFI_INVALID_PARAMETER Instance is NULL.\r | |
192 | \r | |
193 | **/\r | |
194 | typedef\r | |
195 | EFI_STATUS\r | |
a550d468 | 196 | (EFIAPI *EMU_GET_NEXT_PROTOCOL)(\r |
949f388f | 197 | IN BOOLEAN EmuBusDriver,\r |
198 | OUT EMU_IO_THUNK_PROTOCOL **Instance OPTIONAL\r | |
199 | );\r | |
d18d8a1d | 200 | \r |
949f388f | 201 | struct _EMU_THUNK_PROTOCOL {\r |
202 | // Used for early debug printing\r | |
a550d468 MK |
203 | EMU_WRITE_STD_ERROR WriteStdErr;\r |
204 | EMU_CONFIG_STD_IN ConfigStdIn;\r | |
205 | EMU_WRITE_STD_OUT WriteStdOut;\r | |
206 | EMU_READ_STD_IN ReadStdIn;\r | |
207 | EMU_POLL_STD_IN PollStdIn;\r | |
d18d8a1d | 208 | \r |
c2175068 | 209 | //\r |
210 | // Map OS malloc/free so we can use OS based guard malloc\r | |
211 | //\r | |
a550d468 MK |
212 | EMU_OS_MALLOC Malloc;\r |
213 | EMU_OS_VMALLOC Valloc;\r | |
214 | EMU_OS_FREE Free;\r | |
d18d8a1d | 215 | \r |
949f388f | 216 | ///\r |
217 | /// PE/COFF loader hooks to get symbols loaded\r | |
218 | ///\r | |
a550d468 MK |
219 | EMU_PE_COFF_GET_ENTRY_POINT PeCoffGetEntryPoint;\r |
220 | EMU_PE_COFF_RELOCATE_EXTRA_ACTION PeCoffRelocateImageExtraAction;\r | |
221 | EMU_PE_COFF_UNLOAD_EXTRA_ACTION PeCoffUnloadImageExtraAction;\r | |
d18d8a1d | 222 | \r |
949f388f | 223 | ///\r |
224 | /// DXE Architecture Protocol Services\r | |
225 | ///\r | |
a550d468 MK |
226 | EMU_ENABLE_INERRUPTS EnableInterrupt;\r |
227 | EMU_DISABLE_INERRUPTS DisableInterrupt;\r | |
228 | EMU_QUERY_PERFORMANCE_FREQENCY QueryPerformanceFrequency;\r | |
229 | EMU_QUERY_PERFORMANCE_COUNTER QueryPerformanceCounter;\r | |
230 | \r | |
231 | EMU_SLEEP Sleep;\r | |
232 | EMU_CPU_SLEEP CpuSleep;\r | |
233 | EMU_EXIT Exit;\r | |
234 | EMU_GET_TIME GetTime;\r | |
235 | EMU_SET_TIME SetTime;\r | |
236 | EMU_SET_TIMER SetTimer;\r | |
d18d8a1d | 237 | \r |
949f388f | 238 | ///\r |
239 | /// Generic System Services\r | |
240 | ///\r | |
a550d468 | 241 | EMU_GET_NEXT_PROTOCOL GetNextProtocol;\r |
949f388f | 242 | };\r |
243 | \r | |
a550d468 | 244 | extern EFI_GUID gEmuThunkProtocolGuid;\r |
949f388f | 245 | \r |
246 | #endif\r |