]> git.proxmox.com Git - mirror_edk2.git/blob - EmulatorPkg/Win/Host/WinThunk.c
EmulatorPkg/Win: Add Windows host support
[mirror_edk2.git] / EmulatorPkg / Win / Host / WinThunk.c
1 /**@file
2
3 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 WinNtThunk.c
15
16 Abstract:
17
18 Since the SEC is the only windows program in our emulation we
19 must use a Tiano mechanism to export Win32 APIs to other modules.
20 This is the role of the EFI_WIN_NT_THUNK_PROTOCOL.
21
22 The mWinNtThunkTable exists so that a change to EFI_WIN_NT_THUNK_PROTOCOL
23 will cause an error in initializing the array if all the member functions
24 are not added. It looks like adding a element to end and not initializing
25 it may cause the table to be initaliized with the members at the end being
26 set to zero. This is bad as jumping to zero will case the NT32 to crash.
27
28 All the member functions in mWinNtThunkTable are Win32
29 API calls, so please reference Microsoft documentation.
30
31
32 gWinNt is a a public exported global that contains the initialized
33 data.
34
35 **/
36
37 #include "WinHost.h"
38
39 UINTN
40 SecWriteStdErr (
41 IN UINT8 *Buffer,
42 IN UINTN NumberOfBytes
43 )
44 {
45 return 0;
46 }
47
48
49 EFI_STATUS
50 SecConfigStdIn (
51 VOID
52 )
53 {
54 return EFI_SUCCESS;
55 }
56
57 UINTN
58 SecWriteStdOut (
59 IN UINT8 *Buffer,
60 IN UINTN NumberOfBytes
61 )
62 {
63 return 0;
64 }
65
66 BOOLEAN
67 SecPollStdIn (
68 VOID
69 )
70 {
71 return FALSE;
72 }
73
74 UINTN
75 SecReadStdIn (
76 IN UINT8 *Buffer,
77 IN UINTN NumberOfBytes
78 )
79 {
80 return 0;
81 }
82
83
84 VOID *
85 SecAlloc (
86 IN UINTN Size
87 )
88 {
89 return malloc ((size_t)Size);
90 }
91
92 BOOLEAN
93 SecFree (
94 IN VOID *Ptr
95 )
96 {
97 if (EfiSystemMemoryRange (Ptr)) {
98 // If an address range is in the EFI memory map it was alloced via EFI.
99 // So don't free those ranges and let the caller know.
100 return FALSE;
101 }
102
103 free (Ptr);
104 return TRUE;
105 }
106
107 VOID
108 SecSetTimer (
109 IN UINT64 TimerPeriod,
110 IN EMU_SET_TIMER_CALLBACK Callback
111 )
112 {
113 }
114
115 VOID
116 SecInitializeThunk (
117 VOID
118 )
119 {
120 }
121
122 VOID
123 SecEnableInterrupt (
124 VOID
125 )
126 {
127 }
128
129
130 VOID
131 SecDisableInterrupt (
132 VOID
133 )
134 {
135 }
136
137
138 UINT64
139 SecQueryPerformanceFrequency (
140 VOID
141 )
142 {
143 // Hard code to nanoseconds
144 return 1000000000ULL;
145 }
146
147 UINT64
148 SecQueryPerformanceCounter (
149 VOID
150 )
151 {
152 return 0;
153 }
154
155
156
157 VOID
158 SecSleep (
159 IN UINT64 Nanoseconds
160 )
161 {
162 Sleep ((DWORD)DivU64x32 (Nanoseconds, 1000000));
163 }
164
165
166 VOID
167 SecCpuSleep (
168 VOID
169 )
170 {
171 Sleep (1);
172 }
173
174
175 VOID
176 SecExit (
177 UINTN Status
178 )
179 {
180 exit ((int)Status);
181 }
182
183
184 VOID
185 SecGetTime (
186 OUT EFI_TIME *Time,
187 OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL
188 )
189 {
190 }
191
192 EFI_STATUS
193 SecSetTime (
194 IN EFI_TIME *Time
195 )
196 {
197 return EFI_SUCCESS;
198 }
199
200 EMU_THUNK_PROTOCOL gEmuThunkProtocol = {
201 SecWriteStdErr,
202 SecConfigStdIn,
203 SecWriteStdOut,
204 SecReadStdIn,
205 SecPollStdIn,
206 SecAlloc,
207 NULL,
208 SecFree,
209 SecPeCoffGetEntryPoint,
210 PeCoffLoaderRelocateImageExtraAction,
211 PeCoffLoaderUnloadImageExtraAction,
212 SecEnableInterrupt,
213 SecDisableInterrupt,
214 SecQueryPerformanceFrequency,
215 SecQueryPerformanceCounter,
216 SecSleep,
217 SecCpuSleep,
218 SecExit,
219 SecGetTime,
220 SecSetTime,
221 SecSetTimer,
222 GetNextThunkProtocol
223 };
224
225
226 #pragma warning(default : 4996)
227 #pragma warning(default : 4232)
228