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