3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. 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
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.
18 Real Mode Thunk Header file
22 #ifndef __THUNK_16_LIB_H__
23 #define __THUNK_16_LIB_H__
29 #define THUNK_SAVE_FP_STATE 0x1
30 #define THUNK_USER_STACK 0x2
31 #define THUNK_INTERRUPT 0x10000
34 // Byte packed structure for 16-bit Real Mode FLAGS
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
58 // Byte packed structure for EFLAGS
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
92 // Byte packed structure for an FP/SSE/SSE2 context
99 // Structures for the 16-bit real mode thunks
161 IA32_EFLAGS32 EFLAGS
;
174 // Byte packed structure for an 16-bit real mode thunks
177 UINT32 RealModeBuffer
;
182 // 16-bit thunking services
187 AsmThunk16GetProperties (
188 OUT UINTN
*MinimumStackSize OPTIONAL
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.
200 MinimumStackSize - The minimum size required for a 16-bit stack.
204 The minimum size of the real mode buffer needed by this thunk implementation
212 AsmThunk16SetProperties (
213 OUT THUNK_CONTEXT
*ThunkContext
,
214 IN VOID
*RealModeBuffer
,
221 Tell this real mode thunk implementation the address and size of the real
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().
243 IN OUT THUNK_CONTEXT
*ThunkContext
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.
254 ThunkContext - The thunk context to destroy.
265 AsmThunk16FarCall86 (
266 IN THUNK_CONTEXT
*ThunkContext
,
267 IN OUT IA32_REGISTER_SET
*RegisterSet
,
274 Make a far call to 16-bit code.
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.
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
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.
300 RegisterSet is returned.
308 IN THUNK_CONTEXT
*ThunkContext
,
310 IN OUT IA32_REGISTER_SET
*RegisterSet
,
317 Invoke a 16-bit interrupt handler.
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.
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
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.
343 RegisterSet is returned.