+/** @file\r
+ Provide legacy thunk interface for accessing Bios Video Rom.\r
+ \r
+Copyright (c) 2006 - 2007, Intel Corporation \r
+All rights reserved. This program and the accompanying materials \r
+are licensed and made available under the terms and conditions of the BSD License \r
+which accompanies this distribution. The full text of the license may be found at \r
+http://opensource.org/licenses/bsd-license.php \r
+ \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
+\r
+**/\r
\r
#include "BiosVideo.h"\r
\r
#define EFI_CPU_EFLAGS_IF 0x200\r
\r
-THUNK_CONTEXT mThunkContext;\r
-\r
+/**\r
+ Initialize legacy environment for BIOS INI caller.\r
+ \r
+ @param ThunkContext the instance pointer of THUNK_CONTEXT\r
+**/\r
VOID\r
InitializeBiosIntCaller (\r
- IN BIOS_VIDEO_DEV *BiosDev\r
+ THUNK_CONTEXT *ThunkContext\r
)\r
{\r
EFI_STATUS Status;\r
);\r
ASSERT_EFI_ERROR (Status);\r
\r
- mThunkContext.RealModeBuffer = (VOID*)(UINTN)LegacyRegionBase;\r
- mThunkContext.RealModeBufferSize = EFI_PAGES_TO_SIZE (RealModeBufferSize);\r
- mThunkContext.ThunkAttributes = 3;\r
- AsmPrepareThunk16(&mThunkContext);\r
+ ThunkContext->RealModeBuffer = (VOID*)(UINTN)LegacyRegionBase;\r
+ ThunkContext->RealModeBufferSize = EFI_PAGES_TO_SIZE (RealModeBufferSize);\r
+ ThunkContext->ThunkAttributes = 3;\r
+ AsmPrepareThunk16(ThunkContext);\r
\r
}\r
\r
+/**\r
+ Initialize interrupt redirection code and entries, because\r
+ IDT Vectors 0x68-0x6f must be redirected to IDT Vectors 0x08-0x0f.\r
+ Or the interrupt will lost when we do thunk.\r
+ NOTE: We do not reset 8259 vector base, because it will cause pending\r
+ interrupt lost.\r
+ \r
+ @param Legacy8259 Instance pointer for EFI_LEGACY_8259_PROTOCOL.\r
+ \r
+**/\r
VOID\r
InitializeInterruptRedirection (\r
- IN BIOS_VIDEO_DEV *BiosDev\r
+ IN EFI_LEGACY_8259_PROTOCOL *Legacy8259\r
)\r
-/*++\r
-\r
- Routine Description:\r
- Initialize interrupt redirection code and entries, because\r
- IDT Vectors 0x68-0x6f must be redirected to IDT Vectors 0x08-0x0f.\r
- Or the interrupt will lost when we do thunk.\r
- NOTE: We do not reset 8259 vector base, because it will cause pending\r
- interrupt lost.\r
-\r
- Arguments:\r
- NONE\r
-\r
- Returns:\r
- NONE\r
---*/\r
{\r
EFI_STATUS Status;\r
EFI_PHYSICAL_ADDRESS LegacyRegionBase;\r
//\r
// Get VectorBase, it should be 0x68\r
//\r
- Status = BiosDev->Legacy8259->GetVector (BiosDev->Legacy8259, Efi8259Irq0, &ProtectedModeBaseVector);\r
+ Status = Legacy8259->GetVector (Legacy8259, Efi8259Irq0, &ProtectedModeBaseVector);\r
ASSERT_EFI_ERROR (Status);\r
\r
//\r
return ;\r
}\r
\r
+/**\r
+ Thunk to 16-bit real mode and execute a software interrupt with a vector \r
+ of BiosInt. Regs will contain the 16-bit register context on entry and \r
+ exit.\r
+ \r
+ @param This Protocol instance pointer.\r
+ @param BiosInt Processor interrupt vector to invoke\r
+ @param Reg Register contexted passed into (and returned) from thunk to 16-bit mode\r
+ \r
+ @retval TRUE Thunk completed, and there were no BIOS errors in the target code.\r
+ See Regs for status.\r
+ @retval FALSE There was a BIOS erro in the target code. \r
+**/\r
BOOLEAN\r
EFIAPI\r
LegacyBiosInt86 (\r
IN UINT8 BiosInt,\r
IN EFI_IA32_REGISTER_SET *Regs\r
)\r
-/*++\r
-\r
- Routine Description:\r
- Thunk to 16-bit real mode and execute a software interrupt with a vector \r
- of BiosInt. Regs will contain the 16-bit register context on entry and \r
- exit.\r
-\r
- Arguments:\r
- This - Protocol instance pointer.\r
- BiosInt - Processor interrupt vector to invoke\r
- Reg - Register contexted passed into (and returned) from thunk to \r
- 16-bit mode\r
-\r
- Returns:\r
- FALSE - Thunk completed, and there were no BIOS errors in the target code.\r
- See Regs for status.\r
- TRUE - There was a BIOS erro in the target code.\r
-\r
---*/\r
{\r
UINTN Status;\r
UINTN Eflags;\r
BOOLEAN Ret;\r
UINT16 *Stack16;\r
\r
- Regs->X.Flags.Reserved1 = 1;\r
- Regs->X.Flags.Reserved2 = 0;\r
- Regs->X.Flags.Reserved3 = 0;\r
- Regs->X.Flags.Reserved4 = 0;\r
- Regs->X.Flags.IOPL = 3;\r
- Regs->X.Flags.NT = 0;\r
- Regs->X.Flags.IF = 1;\r
- Regs->X.Flags.TF = 0;\r
- Regs->X.Flags.CF = 0;\r
-\r
ZeroMem (&ThunkRegSet, sizeof (ThunkRegSet));\r
+ ThunkRegSet.E.EFLAGS.Bits.Reserved_0 = 1;\r
+ ThunkRegSet.E.EFLAGS.Bits.Reserved_1 = 0;\r
+ ThunkRegSet.E.EFLAGS.Bits.Reserved_2 = 0;\r
+ ThunkRegSet.E.EFLAGS.Bits.Reserved_3 = 0;\r
+ ThunkRegSet.E.EFLAGS.Bits.IOPL = 3;\r
+ ThunkRegSet.E.EFLAGS.Bits.NT = 0;\r
+ ThunkRegSet.E.EFLAGS.Bits.IF = 1;\r
+ ThunkRegSet.E.EFLAGS.Bits.TF = 0;\r
+ ThunkRegSet.E.EFLAGS.Bits.CF = 0;\r
+ \r
ThunkRegSet.E.EDI = Regs->E.EDI;\r
ThunkRegSet.E.ESI = Regs->E.ESI;\r
ThunkRegSet.E.EBP = Regs->E.EBP;\r
ThunkRegSet.E.DS = Regs->E.DS;\r
ThunkRegSet.E.ES = Regs->E.ES;\r
\r
- CopyMem (&(ThunkRegSet.E.EFLAGS), &(Regs->E.EFlags), sizeof (UINT32));\r
- \r
//\r
// The call to Legacy16 is a critical section to EFI\r
//\r
Status = BiosDev->Legacy8259->SetMode (BiosDev->Legacy8259, Efi8259LegacyMode, NULL, NULL);\r
ASSERT_EFI_ERROR (Status);\r
\r
- Stack16 = (UINT16 *)((UINT8 *) mThunkContext.RealModeBuffer + mThunkContext.RealModeBufferSize - sizeof (UINT16));\r
- Stack16 -= sizeof (ThunkRegSet.E.EFLAGS) / sizeof (UINT16);\r
- CopyMem (Stack16, &ThunkRegSet.E.EFLAGS, sizeof (ThunkRegSet.E.EFLAGS));\r
+ Stack16 = (UINT16 *)((UINT8 *) BiosDev->ThunkContext->RealModeBuffer + BiosDev->ThunkContext->RealModeBufferSize - sizeof (UINT16));\r
\r
ThunkRegSet.E.SS = (UINT16) (((UINTN) Stack16 >> 16) << 12);\r
ThunkRegSet.E.ESP = (UINT16) (UINTN) Stack16;\r
+\r
ThunkRegSet.E.Eip = (UINT16)((UINT32 *)NULL)[BiosInt];\r
ThunkRegSet.E.CS = (UINT16)(((UINT32 *)NULL)[BiosInt] >> 16);\r
- mThunkContext.RealModeState = &ThunkRegSet;\r
- AsmThunk16 (&mThunkContext);\r
-\r
+ BiosDev->ThunkContext->RealModeState = &ThunkRegSet;\r
+ AsmThunk16 (BiosDev->ThunkContext);\r
+ \r
//\r
// Restore protected mode interrupt state\r
//\r