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