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