]>
git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/Thunk16/X86Thunk.c
76c93b28ae61c90e52b65b1fa5efc5f6338b7b61
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.
19 Real Mode Thunk Functions
23 #include "Thunk16Lib.h"
24 #include "EfiCommonLib.h"
26 extern CONST UINTN mCode16Size
;
32 IN OUT IA32_REGISTER_SET
*RegisterSet
,
47 IN CONST IA32_FX_BUFFER
*Buffer
53 OUT IA32_FX_BUFFER
*Buffer
62 IN THUNK_CONTEXT
*ThunkContext
,
63 IN OUT IA32_REGISTER_SET
*RegisterSet
,
70 Do the 16-bit thunk code.
72 NOTE: This function must be called on TPL_HIGH_LEVEL or with interrupts
73 disabled because of GDTR and IDTR manipulations.
74 This function must be placed in identity mapped pages.
78 ThunkContext - Thunk context to use.
79 RegisterSet - CPU registers would be set to the values contained in this
80 structure before making the far call. Then CPU registers are
81 copied back to this structure.
82 SS:ESP points to the real mode stack if THUNK_USER_STACK is
83 set on input, otherwise ignored.
84 EFlages is ignored on input.
85 On output, values of CS, EIP, SS and ESP should be ignored.
86 ThunkFlags - 2 flags have currently been defined, THUNK_SAVE_FP_STATE and
88 THUNK_SAVE_FP_STATE - FPU state would be saved/restored
89 before/after calling real mode code.
90 THUNK_USER_STACK - The stack specified by SS:ESP would be
91 used instead of the default stack.
95 RegisterSet is returned.
99 IA32_FX_BUFFER
*FpSavedState
;
100 UINT8 FpBuffer
[sizeof (*FpSavedState
) + 0x10];
102 FpSavedState
= (IA32_FX_BUFFER
*)(((UINTN
)FpBuffer
+ 0xf) & ~0xf);
104 if (!(ThunkFlags
& THUNK_USER_STACK
)) {
105 RegisterSet
->E
.ESP
= (UINT16
)ThunkContext
->DefaultStack
;
106 RegisterSet
->E
.SS
= (UINT16
)((ThunkContext
->DefaultStack
>> 4) & 0xf000);
109 if (ThunkFlags
& THUNK_SAVE_FP_STATE
) {
110 AsmFxSave (FpSavedState
);
113 EfiCommonLibCopyMem (
117 (UINT16
)(ThunkFlags
>> 16),
118 ThunkContext
->RealModeBuffer
>> 4
120 sizeof (*RegisterSet
)
123 if (ThunkFlags
& THUNK_SAVE_FP_STATE
) {
124 AsmFxRestore (FpSavedState
);
132 AsmThunk16GetProperties (
133 OUT UINTN
*MinimumStackSize
139 Returns the properties of this real mode thunk implementation. Currently
140 there are 2 properties has been defined, the minimum real mode buffer size
141 and the minimum stack size.
145 MinimumStackSize - The minimum size required for a 16-bit stack.
149 The minimum size of the real mode buffer needed by this thunk implementation
155 // This size should be large enough to hold the register set as well as saved
156 // CPU contexts including GDTR, CR0 and CR4
158 if (MinimumStackSize
) {
159 *MinimumStackSize
= sizeof (IA32_REGISTER_SET
) + 0x200;
167 AsmThunk16SetProperties (
168 OUT THUNK_CONTEXT
*ThunkContext
,
169 IN VOID
*RealModeBuffer
,
176 Tell this real mode thunk implementation the address and size of the real
181 ThunkContext - The thunk context whose properties to set.
182 RealModeBuffer - The address of the buffer allocated by caller. It should be
183 aligned on a 16-byte boundary.
184 This buffer must be in identity mapped pages.
185 BufferSize - The size of RealModeBuffer. Must be larger than the minimum
186 size required as returned by AsmThunk16GetProperties().
196 ThunkContext
->RealModeBuffer
= (UINT32
)(UINTN
)RealModeBuffer
;
197 ThunkContext
->DefaultStack
= (UINT32
)(ThunkContext
->RealModeBuffer
+ BufferSize
);
198 EfiCommonLibCopyMem (RealModeBuffer
, (VOID
*)(UINTN
)_Code16Addr
, mCode16Size
);
206 IN OUT THUNK_CONTEXT
*ThunkContext
212 Reset all internal states to their initial values. The caller should not
213 release the real mode buffer until after a call to this function.
217 ThunkContext - The thunk context to destroy.
225 ThunkContext
->RealModeBuffer
= 0;
230 AsmThunk16FarCall86 (
231 IN THUNK_CONTEXT
*ThunkContext
,
232 IN OUT IA32_REGISTER_SET
*RegisterSet
,
239 Make a far call to 16-bit code.
241 NOTE: This function must be called on TPL_HIGH_LEVEL or with interrupts
242 disabled because of GDTR and IDTR manipulations.
243 This function must be placed in identity mapped pages.
247 ThunkContext - Thunk context to use.
248 RegisterSet - CPU registers would be set to the values contained in this
249 structure before making the far call. Then CPU registers are
250 copied back to this structure.
251 CS:EIP points to the real mode code being called on input.
252 SS:ESP points to the real mode stack if THUNK_USER_STACK is
253 set on input, otherwise ignored.
254 EFlages is ignored on input.
255 On output, values of CS, EIP, SS and ESP should be ignored.
256 ThunkFlags - 2 flags have currently been defined, THUNK_SAVE_FP_STATE and
258 THUNK_SAVE_FP_STATE - FPU state would be saved/restored
259 before/after calling real mode code.
260 THUNK_USER_STACK - The stack specified by SS:ESP would be
261 used instead of the default stack.
265 RegisterSet is returned.
269 return AsmThunk16 (ThunkContext
, RegisterSet
, Flags
);
275 IN THUNK_CONTEXT
*ThunkContext
,
277 IN OUT IA32_REGISTER_SET
*RegisterSet
,
284 Invoke a 16-bit interrupt handler.
286 NOTE: This function must be called on TPL_HIGH_LEVEL or with interrupts
287 disabled because of GDTR and IDTR manipulations.
288 This function must be placed in identity mapped pages.
292 ThunkContext - Thunk context to use.
293 IntNumber - The ordinal of the interrupt handler ranging from 0 to 255.
294 RegisterSet - CPU registers would be set to the values contained in this
295 structure before making the far call. Then CPU registers are
296 copied back to this structure.
297 SS:ESP points to the real mode stack if THUNK_USER_STACK is
298 set on input, otherwise ignored.
299 EFlages is ignored on input.
300 On output, values of CS, EIP, SS and ESP should be ignored.
301 ThunkFlags - 2 flags have currently been defined, THUNK_SAVE_FP_STATE and
303 THUNK_SAVE_FP_STATE - FPU state would be saved/restored
304 before/after calling real mode code.
305 THUNK_USER_STACK - The stack specified by SS:ESP would be
306 used instead of the default stack.
310 RegisterSet is returned.
314 RegisterSet
->E
.EIP
= (UINT16
)((UINT32
*)NULL
)[IntNumber
];
315 RegisterSet
->E
.CS
= (UINT16
)(((UINT32
*)NULL
)[IntNumber
] >> 16);
317 return AsmThunk16 (ThunkContext
, RegisterSet
, Flags
| THUNK_INTERRUPT
);