]>
Commit | Line | Data |
---|---|---|
3eb9473e | 1 | /*++\r |
2 | \r | |
3 | Copyright (c) 2006, Intel Corporation \r | |
4 | All rights reserved. This program and the accompanying materials \r | |
5 | are licensed and made available under the terms and conditions of the BSD License \r | |
6 | which accompanies this distribution. The full text of the license may be found at \r | |
7 | http://opensource.org/licenses/bsd-license.php \r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
11 | \r | |
12 | Module Name:\r | |
13 | \r | |
14 | Thunk16Lib.h\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | Real Mode Thunk Header file\r | |
19 | \r | |
20 | --*/\r | |
21 | \r | |
22 | #ifndef __THUNK_16_LIB_H__\r | |
23 | #define __THUNK_16_LIB_H__\r | |
24 | #include "Tiano.h"\r | |
25 | \r | |
26 | //\r | |
27 | // Thunk Flags\r | |
28 | //\r | |
29 | #define THUNK_SAVE_FP_STATE 0x1\r | |
30 | #define THUNK_USER_STACK 0x2\r | |
31 | #define THUNK_INTERRUPT 0x10000\r | |
32 | \r | |
33 | //\r | |
34 | // Byte packed structure for 16-bit Real Mode FLAGS\r | |
35 | //\r | |
36 | typedef union {\r | |
37 | struct {\r | |
38 | UINT32 CF:1; // Carry Flag\r | |
39 | UINT32 Reserved_0:1; // Reserved\r | |
40 | UINT32 PF:1; // Parity Flag\r | |
41 | UINT32 Reserved_1:1; // Reserved\r | |
42 | UINT32 AF:1; // Auxiliary Carry Flag\r | |
43 | UINT32 Reserved_2:1; // Reserved\r | |
44 | UINT32 ZF:1; // Zero Flag\r | |
45 | UINT32 SF:1; // Sign Flag\r | |
46 | UINT32 TF:1; // Trap Flag\r | |
47 | UINT32 IF:1; // Interrupt Enable Flag\r | |
48 | UINT32 DF:1; // Direction Flag\r | |
49 | UINT32 OF:1; // Overflow Flag\r | |
50 | UINT32 IOPL:2; // I/O Privilege Level\r | |
51 | UINT32 NT:1; // Nested Task\r | |
52 | UINT32 Reserved_3:1; // Reserved\r | |
53 | } Bits;\r | |
54 | UINTN UintN;\r | |
55 | } IA32_FLAGS16;\r | |
56 | \r | |
57 | //\r | |
58 | // Byte packed structure for EFLAGS\r | |
59 | // 32-bits on IA32\r | |
60 | // 64-bits on X64\r | |
61 | //\r | |
62 | \r | |
63 | typedef union {\r | |
64 | struct {\r | |
65 | UINT32 CF:1; // Carry Flag\r | |
66 | UINT32 Reserved_0:1; // Reserved\r | |
67 | UINT32 PF:1; // Parity Flag\r | |
68 | UINT32 Reserved_1:1; // Reserved\r | |
69 | UINT32 AF:1; // Auxiliary Carry Flag\r | |
70 | UINT32 Reserved_2:1; // Reserved\r | |
71 | UINT32 ZF:1; // Zero Flag\r | |
72 | UINT32 SF:1; // Sign Flag\r | |
73 | UINT32 TF:1; // Trap Flag\r | |
74 | UINT32 IF:1; // Interrupt Enable Flag\r | |
75 | UINT32 DF:1; // Direction Flag\r | |
76 | UINT32 OF:1; // Overflow Flag\r | |
77 | UINT32 IOPL:2; // I/O Privilege Level\r | |
78 | UINT32 NT:1; // Nested Task\r | |
79 | UINT32 Reserved_3:1; // Reserved\r | |
80 | UINT32 RF:1; // Resume Flag\r | |
81 | UINT32 VM:1; // Virtual 8086 Mode\r | |
82 | UINT32 AC:1; // Alignment Check\r | |
83 | UINT32 VIF:1; // Virtual Interrupt Flag\r | |
84 | UINT32 VIP:1; // Virtual Interrupt Pending\r | |
85 | UINT32 ID:1; // ID Flag\r | |
86 | UINT32 Reserved_4:10; // Reserved\r | |
87 | } Bits;\r | |
88 | UINTN UintN;\r | |
89 | } IA32_EFLAGS32;\r | |
90 | \r | |
91 | //\r | |
92 | // Byte packed structure for an FP/SSE/SSE2 context\r | |
93 | //\r | |
94 | typedef struct {\r | |
95 | UINT8 Buffer[512];\r | |
96 | } IA32_FX_BUFFER;\r | |
97 | \r | |
98 | //\r | |
99 | // Structures for the 16-bit real mode thunks\r | |
100 | //\r | |
101 | typedef struct {\r | |
102 | UINT32 Reserved1;\r | |
103 | UINT32 Reserved2;\r | |
104 | UINT32 Reserved3;\r | |
105 | UINT32 Reserved4;\r | |
106 | UINT8 BL;\r | |
107 | UINT8 BH;\r | |
108 | UINT16 Reserved5;\r | |
109 | UINT8 DL;\r | |
110 | UINT8 DH;\r | |
111 | UINT16 Reserved6;\r | |
112 | UINT8 CL;\r | |
113 | UINT8 CH;\r | |
114 | UINT16 Reserved7;\r | |
115 | UINT8 AL;\r | |
116 | UINT8 AH;\r | |
117 | UINT16 Reserved8;\r | |
118 | } IA32_BYTE_REGS;\r | |
119 | \r | |
120 | typedef struct {\r | |
121 | UINT16 DI;\r | |
122 | UINT16 Reserved1;\r | |
123 | UINT16 SI;\r | |
124 | UINT16 Reserved2;\r | |
125 | UINT16 BP;\r | |
126 | UINT16 Reserved3;\r | |
127 | UINT16 SP;\r | |
128 | UINT16 Reserved4;\r | |
129 | UINT16 BX;\r | |
130 | UINT16 Reserved5;\r | |
131 | UINT16 DX;\r | |
132 | UINT16 Reserved6;\r | |
133 | UINT16 CX;\r | |
134 | UINT16 Reserved7;\r | |
135 | UINT16 AX;\r | |
136 | UINT16 Reserved8;\r | |
137 | UINT16 DS;\r | |
138 | UINT16 ES;\r | |
139 | UINT16 FS;\r | |
140 | UINT16 GS;\r | |
141 | IA32_FLAGS16 Flags;\r | |
142 | UINT16 IP;\r | |
143 | UINT16 Reserved10;\r | |
144 | UINT16 CS;\r | |
145 | UINT16 SS;\r | |
146 | } IA32_WORD_REGS;\r | |
147 | \r | |
148 | typedef struct {\r | |
149 | UINT32 EDI;\r | |
150 | UINT32 ESI;\r | |
151 | UINT32 EBP;\r | |
152 | UINT32 ESP;\r | |
153 | UINT32 EBX;\r | |
154 | UINT32 EDX;\r | |
155 | UINT32 ECX;\r | |
156 | UINT32 EAX;\r | |
157 | UINT16 DS;\r | |
158 | UINT16 ES;\r | |
159 | UINT16 FS;\r | |
160 | UINT16 GS;\r | |
161 | IA32_EFLAGS32 EFLAGS;\r | |
162 | UINT32 EIP;\r | |
163 | UINT16 CS;\r | |
164 | UINT16 SS;\r | |
165 | } IA32_DWORD_REGS;\r | |
166 | \r | |
167 | typedef union {\r | |
168 | IA32_DWORD_REGS E;\r | |
169 | IA32_WORD_REGS X;\r | |
170 | IA32_BYTE_REGS H;\r | |
171 | } IA32_REGISTER_SET;\r | |
172 | \r | |
173 | //\r | |
174 | // Byte packed structure for an 16-bit real mode thunks\r | |
175 | //\r | |
176 | typedef struct {\r | |
177 | UINT32 RealModeBuffer;\r | |
178 | UINT32 DefaultStack;\r | |
179 | } THUNK_CONTEXT;\r | |
180 | \r | |
181 | //\r | |
182 | // 16-bit thunking services\r | |
183 | //\r | |
184 | \r | |
185 | UINTN\r | |
186 | EFIAPI\r | |
187 | AsmThunk16GetProperties (\r | |
188 | OUT UINTN *MinimumStackSize OPTIONAL\r | |
189 | )\r | |
190 | /*++\r | |
191 | \r | |
192 | Routine Description:\r | |
193 | \r | |
194 | Returns the properties of this real mode thunk implementation. Currently\r | |
195 | there are 2 properties has been defined, the minimum real mode buffer size\r | |
196 | and the minimum stack size.\r | |
197 | \r | |
198 | Arguments:\r | |
199 | \r | |
200 | MinimumStackSize - The minimum size required for a 16-bit stack.\r | |
201 | \r | |
202 | Returns:\r | |
203 | \r | |
204 | The minimum size of the real mode buffer needed by this thunk implementation\r | |
205 | is returned.\r | |
206 | \r | |
207 | --*/\r | |
208 | ;\r | |
209 | \r | |
210 | THUNK_CONTEXT *\r | |
211 | EFIAPI\r | |
212 | AsmThunk16SetProperties (\r | |
213 | OUT THUNK_CONTEXT *ThunkContext,\r | |
214 | IN VOID *RealModeBuffer,\r | |
215 | IN UINTN BufferSize\r | |
216 | )\r | |
217 | /*++\r | |
218 | \r | |
219 | Routine Description:\r | |
220 | \r | |
221 | Tell this real mode thunk implementation the address and size of the real\r | |
222 | mode buffer needed.\r | |
223 | \r | |
224 | Arguments:\r | |
225 | \r | |
226 | ThunkContext - The thunk context whose properties to set.\r | |
227 | RealModeBuffer - The address of the buffer allocated by caller. It should be\r | |
228 | aligned on a 16-byte boundary.\r | |
229 | This buffer must be in identity mapped pages.\r | |
230 | BufferSize - The size of RealModeBuffer. Must be larger than the minimum\r | |
231 | size required as returned by AsmThunk16GetProperties().\r | |
232 | \r | |
233 | Returns:\r | |
234 | \r | |
235 | None\r | |
236 | \r | |
237 | --*/\r | |
238 | ;\r | |
239 | \r | |
240 | VOID\r | |
241 | EFIAPI\r | |
242 | AsmThunk16Destroy (\r | |
243 | IN OUT THUNK_CONTEXT *ThunkContext\r | |
244 | )\r | |
245 | /*++\r | |
246 | \r | |
247 | Routine Description:\r | |
248 | \r | |
249 | Reset all internal states to their initial values. The caller should not\r | |
250 | release the real mode buffer until after a call to this function.\r | |
251 | \r | |
252 | Arguments:\r | |
253 | \r | |
254 | ThunkContext - The thunk context to destroy.\r | |
255 | \r | |
256 | Returns:\r | |
257 | \r | |
258 | None\r | |
259 | \r | |
260 | --*/\r | |
261 | ;\r | |
262 | \r | |
263 | IA32_REGISTER_SET *\r | |
264 | EFIAPI\r | |
265 | AsmThunk16FarCall86 (\r | |
266 | IN THUNK_CONTEXT *ThunkContext,\r | |
267 | IN OUT IA32_REGISTER_SET *RegisterSet,\r | |
268 | IN UINT32 ThunkFlags\r | |
269 | )\r | |
270 | /*++\r | |
271 | \r | |
272 | Routine Description:\r | |
273 | \r | |
274 | Make a far call to 16-bit code.\r | |
275 | \r | |
276 | NOTE: This function must be called on TPL_HIGH_LEVEL or with interrupts\r | |
277 | disabled because of GDTR and IDTR manipulations.\r | |
278 | This function must be placed in identity mapped pages.\r | |
279 | \r | |
280 | Arguments:\r | |
281 | \r | |
282 | ThunkContext - Thunk context to use.\r | |
283 | RegisterSet - CPU registers would be set to the values contained in this\r | |
284 | structure before making the far call. Then CPU registers are\r | |
285 | copied back to this structure.\r | |
286 | CS:EIP points to the real mode code being called on input.\r | |
287 | SS:ESP points to the real mode stack if THUNK_USER_STACK is\r | |
288 | set on input, otherwise ignored.\r | |
289 | EFlages is ignored on input.\r | |
290 | On output, values of CS, EIP, SS and ESP should be ignored.\r | |
291 | ThunkFlags - 2 flags have currently been defined, THUNK_SAVE_FP_STATE and\r | |
292 | THUNK_USER_STACK.\r | |
293 | THUNK_SAVE_FP_STATE - FPU state would be saved/restored\r | |
294 | before/after calling real mode code.\r | |
295 | THUNK_USER_STACK - The stack specified by SS:ESP would be\r | |
296 | used instead of the default stack.\r | |
297 | \r | |
298 | Returns:\r | |
299 | \r | |
300 | RegisterSet is returned.\r | |
301 | \r | |
302 | --*/\r | |
303 | ;\r | |
304 | \r | |
305 | IA32_REGISTER_SET *\r | |
306 | EFIAPI\r | |
307 | AsmThunk16Int86 (\r | |
308 | IN THUNK_CONTEXT *ThunkContext,\r | |
309 | IN UINT8 IntNumber,\r | |
310 | IN OUT IA32_REGISTER_SET *RegisterSet,\r | |
311 | IN UINT32 ThunkFlags\r | |
312 | )\r | |
313 | /*++\r | |
314 | \r | |
315 | Routine Description:\r | |
316 | \r | |
317 | Invoke a 16-bit interrupt handler.\r | |
318 | \r | |
319 | NOTE: This function must be called on TPL_HIGH_LEVEL or with interrupts\r | |
320 | disabled because of GDTR and IDTR manipulations.\r | |
321 | This function must be placed in identity mapped pages.\r | |
322 | \r | |
323 | Arguments:\r | |
324 | \r | |
325 | ThunkContext - Thunk context to use.\r | |
326 | IntNumber - The ordinal of the interrupt handler ranging from 0 to 255.\r | |
327 | RegisterSet - CPU registers would be set to the values contained in this\r | |
328 | structure before making the far call. Then CPU registers are\r | |
329 | copied back to this structure.\r | |
330 | SS:ESP points to the real mode stack if THUNK_USER_STACK is\r | |
331 | set on input, otherwise ignored.\r | |
332 | EFlages is ignored on input.\r | |
333 | On output, values of CS, EIP, SS and ESP should be ignored.\r | |
334 | ThunkFlags - 2 flags have currently been defined, THUNK_SAVE_FP_STATE and\r | |
335 | THUNK_USER_STACK.\r | |
336 | THUNK_SAVE_FP_STATE - FPU state would be saved/restored\r | |
337 | before/after calling real mode code.\r | |
338 | THUNK_USER_STACK - The stack specified by SS:ESP would be\r | |
339 | used instead of the default stack.\r | |
340 | \r | |
341 | Returns:\r | |
342 | \r | |
343 | RegisterSet is returned.\r | |
344 | \r | |
345 | --*/\r | |
346 | ;\r | |
347 | \r | |
348 | #endif\r |