/*++\r
\r
-Copyright (c) 2006, Intel Corporation \r
-All rights reserved. This program and the accompanying materials \r
+Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
+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
UINTN mTimerVector = 0;\r
volatile EFI_CPU_INTERRUPT_HANDLER mTimerHandler = NULL;\r
EFI_LEGACY_8259_PROTOCOL *gLegacy8259 = NULL;\r
+THUNK_CONTEXT mThunkContext;\r
+#define EFI_CPU_EFLAGS_IF 0x200\r
\r
+VOID\r
+InitializeBiosIntCaller (\r
+ VOID\r
+ );\r
+ \r
+BOOLEAN\r
+EFIAPI\r
+LegacyBiosInt86 (\r
+ IN UINT8 BiosInt,\r
+ IN EFI_IA32_REGISTER_SET *Regs\r
+ );\r
+ \r
//\r
// The Cpu Architectural Protocol that this Driver produces\r
//\r
\r
ErrorCodeFlag = 0x00027d00;\r
\r
-#ifdef EFI32\r
+#ifdef MDE_CPU_IA32\r
DEBUG ((\r
EFI_D_ERROR,\r
"!!!! IA32 Exception Type - %08x !!!!\n",\r
}\r
#endif\r
\r
-UINTN\r
-SPrint (\r
- IN OUT CHAR16 *Buffer,\r
- IN CONST CHAR16 *Format,\r
- ...\r
- )\r
-{\r
- VA_LIST Marker;\r
- UINTN Index;\r
- UINTN Flags;\r
- UINTN Width;\r
- UINT64 Value;\r
-\r
- VA_START (Marker, Format);\r
-\r
- //\r
- // Process the format string. Stop if Buffer is over run.\r
- //\r
-\r
- for (Index = 0; *Format != 0; Format++) {\r
- if (*Format != L'%') {\r
- Buffer[Index++] = *Format;\r
- } else {\r
- \r
- //\r
- // Now it's time to parse what follows after %\r
- // Support: % [ 0 width ] [ l ] x\r
- // width - fill 0, to ensure the width of x will be "width"\r
- // l - UINT64 instead of UINT32\r
- //\r
- Width = 0;\r
- Flags = 0;\r
- Format ++;\r
-\r
- if (*Format == L'0') {\r
- Flags |= PREFIX_ZERO;\r
- do {\r
- Width += Width * 10 + (*Format - L'0');\r
- Format ++;\r
- } while (*Format >= L'1' && *Format <= L'9');\r
- }\r
-\r
- if (*Format == L'l') {\r
- Flags |= LONG_TYPE;\r
- Format ++;\r
- }\r
-\r
- \r
- switch (*Format) {\r
- case 'X':\r
- Flags |= PREFIX_ZERO;\r
- Width = sizeof (UINT64) * 2;\r
- //\r
- // break skiped on purpose\r
- //\r
- case 'x':\r
- if ((Flags & LONG_TYPE) == LONG_TYPE) {\r
- Value = VA_ARG (Marker, UINT64);\r
- } else {\r
- Value = VA_ARG (Marker, UINTN);\r
- }\r
-\r
- UnicodeValueToString (Buffer+Index, Flags, Value, Width);\r
- \r
- for ( ; Buffer[Index] != L'\0'; Index ++) {\r
- }\r
-\r
- break;\r
-\r
- default:\r
- //\r
- // if the type is unknown print it to the screen\r
- //\r
- Buffer[Index++] = *Format;\r
- }\r
- } \r
- }\r
- Buffer[Index++] = '\0'; \r
- \r
- VA_END (Marker);\r
- return Index;\r
-}\r
\r
VOID\r
DumpExceptionDataVgaOut (\r
VideoBufferBase = (CHAR16 *) (UINTN) 0xb8000;\r
VideoBuffer = (CHAR16 *) (UINTN) 0xb8000;\r
\r
-#ifdef EFI32\r
- SPrint (\r
- VideoBuffer, \r
- L"!!!! IA32 Exception Type - %08x !!!!",\r
+#ifdef MDE_CPU_IA32\r
+ UnicodeSPrintAsciiFormat (\r
+ VideoBuffer,\r
+ COLUMN_MAX * sizeof (CHAR16),\r
+ "!!!! IA32 Exception Type - %08x !!!!",\r
InterruptType\r
);\r
VideoBuffer += COLUMN_MAX;\r
- SPrint (\r
- VideoBuffer, \r
- L"EIP - %08x, CS - %08x, EFLAGS - %08x",\r
+ UnicodeSPrintAsciiFormat (\r
+ VideoBuffer,\r
+ COLUMN_MAX * sizeof (CHAR16),\r
+ "EIP - %08x, CS - %08x, EFLAGS - %08x",\r
SystemContext.SystemContextIa32->Eip,\r
SystemContext.SystemContextIa32->Cs,\r
SystemContext.SystemContextIa32->Eflags\r
);\r
VideoBuffer += COLUMN_MAX;\r
if (ErrorCodeFlag & (1 << InterruptType)) {\r
- SPrint (\r
+ UnicodeSPrintAsciiFormat (\r
VideoBuffer,\r
- L"ExceptionData - %08x",\r
+ COLUMN_MAX * sizeof (CHAR16),\r
+ "ExceptionData - %08x",\r
SystemContext.SystemContextIa32->ExceptionData\r
);\r
VideoBuffer += COLUMN_MAX;\r
}\r
- SPrint (\r
+ UnicodeSPrintAsciiFormat (\r
VideoBuffer,\r
- L"EAX - %08x, ECX - %08x, EDX - %08x, EBX - %08x",\r
+ COLUMN_MAX * sizeof (CHAR16),\r
+ "EAX - %08x, ECX - %08x, EDX - %08x, EBX - %08x",\r
SystemContext.SystemContextIa32->Eax,\r
SystemContext.SystemContextIa32->Ecx,\r
SystemContext.SystemContextIa32->Edx,\r
);\r
VideoBuffer += COLUMN_MAX;\r
\r
- SPrint (\r
+ UnicodeSPrintAsciiFormat (\r
VideoBuffer,\r
- L"ESP - %08x, EBP - %08x, ESI - %08x, EDI - %08x",\r
+ COLUMN_MAX * sizeof (CHAR16),\r
+ "ESP - %08x, EBP - %08x, ESI - %08x, EDI - %08x",\r
SystemContext.SystemContextIa32->Esp,\r
SystemContext.SystemContextIa32->Ebp,\r
SystemContext.SystemContextIa32->Esi,\r
);\r
VideoBuffer += COLUMN_MAX;\r
\r
- SPrint (\r
+ UnicodeSPrintAsciiFormat (\r
VideoBuffer,\r
- L"DS - %08x, ES - %08x, FS - %08x, GS - %08x, SS - %08x",\r
+ COLUMN_MAX * sizeof (CHAR16),\r
+ "DS - %08x, ES - %08x, FS - %08x, GS - %08x, SS - %08x",\r
SystemContext.SystemContextIa32->Ds,\r
SystemContext.SystemContextIa32->Es,\r
SystemContext.SystemContextIa32->Fs,\r
);\r
VideoBuffer += COLUMN_MAX;\r
\r
- SPrint (\r
+ UnicodeSPrintAsciiFormat (\r
VideoBuffer,\r
- L"GDTR - %08x %08x, IDTR - %08x %08x",\r
+ COLUMN_MAX * sizeof (CHAR16),\r
+ "GDTR - %08x %08x, IDTR - %08x %08x",\r
SystemContext.SystemContextIa32->Gdtr[0],\r
SystemContext.SystemContextIa32->Gdtr[1],\r
SystemContext.SystemContextIa32->Idtr[0],\r
);\r
VideoBuffer += COLUMN_MAX;\r
\r
- SPrint (\r
+ UnicodeSPrintAsciiFormat (\r
VideoBuffer,\r
- L"LDTR - %08x, TR - %08x",\r
+ COLUMN_MAX * sizeof (CHAR16),\r
+ "LDTR - %08x, TR - %08x",\r
SystemContext.SystemContextIa32->Ldtr,\r
SystemContext.SystemContextIa32->Tr\r
);\r
VideoBuffer += COLUMN_MAX;\r
\r
- SPrint (\r
+ UnicodeSPrintAsciiFormat (\r
VideoBuffer,\r
- L"CR0 - %08x, CR2 - %08x, CR3 - %08x, CR4 - %08x",\r
+ COLUMN_MAX * sizeof (CHAR16),\r
+ "CR0 - %08x, CR2 - %08x, CR3 - %08x, CR4 - %08x",\r
SystemContext.SystemContextIa32->Cr0,\r
SystemContext.SystemContextIa32->Cr2,\r
SystemContext.SystemContextIa32->Cr3,\r
);\r
VideoBuffer += COLUMN_MAX;\r
\r
- SPrint (\r
+ UnicodeSPrintAsciiFormat (\r
VideoBuffer,\r
- L"DR0 - %08x, DR1 - %08x, DR2 - %08x, DR3 - %08x",\r
+ COLUMN_MAX * sizeof (CHAR16),\r
+ "DR0 - %08x, DR1 - %08x, DR2 - %08x, DR3 - %08x",\r
SystemContext.SystemContextIa32->Dr0,\r
SystemContext.SystemContextIa32->Dr1,\r
SystemContext.SystemContextIa32->Dr2,\r
);\r
VideoBuffer += COLUMN_MAX;\r
\r
- SPrint (\r
+ UnicodeSPrintAsciiFormat (\r
VideoBuffer,\r
- L"DR6 - %08x, DR7 - %08x",\r
+ COLUMN_MAX * sizeof (CHAR16),\r
+ "DR6 - %08x, DR7 - %08x",\r
SystemContext.SystemContextIa32->Dr6,\r
SystemContext.SystemContextIa32->Dr7\r
);\r
VideoBuffer += COLUMN_MAX;\r
#else\r
- SPrint (\r
+ UnicodeSPrintAsciiFormat (\r
VideoBuffer,\r
- L"!!!! X64 Exception Type - %016lx !!!!",\r
+ COLUMN_MAX * sizeof (CHAR16),\r
+ "!!!! X64 Exception Type - %016lx !!!!",\r
(UINT64)InterruptType\r
);\r
VideoBuffer += COLUMN_MAX;\r
\r
- SPrint (\r
+ UnicodeSPrintAsciiFormat (\r
VideoBuffer,\r
- L"RIP - %016lx, CS - %016lx, RFLAGS - %016lx",\r
+ COLUMN_MAX * sizeof (CHAR16),\r
+ "RIP - %016lx, CS - %016lx, RFLAGS - %016lx",\r
SystemContext.SystemContextX64->Rip,\r
SystemContext.SystemContextX64->Cs,\r
SystemContext.SystemContextX64->Rflags\r
VideoBuffer += COLUMN_MAX;\r
\r
if (ErrorCodeFlag & (1 << InterruptType)) {\r
- SPrint (\r
+ UnicodeSPrintAsciiFormat (\r
VideoBuffer,\r
- L"ExceptionData - %016lx",\r
+ COLUMN_MAX * sizeof (CHAR16),\r
+ "ExceptionData - %016lx",\r
SystemContext.SystemContextX64->ExceptionData\r
);\r
VideoBuffer += COLUMN_MAX;\r
}\r
\r
- SPrint (\r
+ UnicodeSPrintAsciiFormat (\r
VideoBuffer,\r
- L"RAX - %016lx, RCX - %016lx, RDX - %016lx",\r
+ COLUMN_MAX * sizeof (CHAR16),\r
+ "RAX - %016lx, RCX - %016lx, RDX - %016lx",\r
SystemContext.SystemContextX64->Rax,\r
SystemContext.SystemContextX64->Rcx,\r
SystemContext.SystemContextX64->Rdx\r
);\r
VideoBuffer += COLUMN_MAX;\r
\r
- SPrint (\r
+ UnicodeSPrintAsciiFormat (\r
VideoBuffer,\r
- L"RBX - %016lx, RSP - %016lx, RBP - %016lx",\r
+ COLUMN_MAX * sizeof (CHAR16),\r
+ "RBX - %016lx, RSP - %016lx, RBP - %016lx",\r
SystemContext.SystemContextX64->Rbx,\r
SystemContext.SystemContextX64->Rsp,\r
SystemContext.SystemContextX64->Rbp\r
);\r
VideoBuffer += COLUMN_MAX;\r
\r
- SPrint (\r
+ UnicodeSPrintAsciiFormat (\r
VideoBuffer,\r
- L"RSI - %016lx, RDI - %016lx",\r
+ COLUMN_MAX * sizeof (CHAR16),\r
+ "RSI - %016lx, RDI - %016lx",\r
SystemContext.SystemContextX64->Rsi,\r
SystemContext.SystemContextX64->Rdi\r
);\r
VideoBuffer += COLUMN_MAX;\r
\r
- SPrint (\r
+ UnicodeSPrintAsciiFormat (\r
VideoBuffer,\r
- L"R8 - %016lx, R9 - %016lx, R10 - %016lx",\r
+ COLUMN_MAX * sizeof (CHAR16),\r
+ "R8 - %016lx, R9 - %016lx, R10 - %016lx",\r
SystemContext.SystemContextX64->R8,\r
SystemContext.SystemContextX64->R9,\r
SystemContext.SystemContextX64->R10\r
);\r
VideoBuffer += COLUMN_MAX;\r
\r
- SPrint (\r
+ UnicodeSPrintAsciiFormat (\r
VideoBuffer,\r
- L"R11 - %016lx, R12 - %016lx, R13 - %016lx",\r
+ COLUMN_MAX * sizeof (CHAR16),\r
+ "R11 - %016lx, R12 - %016lx, R13 - %016lx",\r
SystemContext.SystemContextX64->R11,\r
SystemContext.SystemContextX64->R12,\r
SystemContext.SystemContextX64->R13\r
);\r
VideoBuffer += COLUMN_MAX;\r
\r
- SPrint (\r
+ UnicodeSPrintAsciiFormat (\r
VideoBuffer,\r
- L"R14 - %016lx, R15 - %016lx",\r
+ COLUMN_MAX * sizeof (CHAR16),\r
+ "R14 - %016lx, R15 - %016lx",\r
SystemContext.SystemContextX64->R14,\r
SystemContext.SystemContextX64->R15\r
);\r
VideoBuffer += COLUMN_MAX;\r
\r
- SPrint (\r
+ UnicodeSPrintAsciiFormat (\r
VideoBuffer,\r
- L"DS - %016lx, ES - %016lx, FS - %016lx",\r
+ COLUMN_MAX * sizeof (CHAR16),\r
+ "DS - %016lx, ES - %016lx, FS - %016lx",\r
SystemContext.SystemContextX64->Ds,\r
SystemContext.SystemContextX64->Es,\r
SystemContext.SystemContextX64->Fs\r
);\r
VideoBuffer += COLUMN_MAX;\r
\r
- SPrint (\r
+ UnicodeSPrintAsciiFormat (\r
VideoBuffer,\r
- L"GS - %016lx, SS - %016lx",\r
+ COLUMN_MAX * sizeof (CHAR16),\r
+ "GS - %016lx, SS - %016lx",\r
SystemContext.SystemContextX64->Gs,\r
SystemContext.SystemContextX64->Ss\r
);\r
VideoBuffer += COLUMN_MAX;\r
\r
- SPrint (\r
+ UnicodeSPrintAsciiFormat (\r
VideoBuffer,\r
- L"GDTR - %016lx %016lx, LDTR - %016lx",\r
+ COLUMN_MAX * sizeof (CHAR16),\r
+ "GDTR - %016lx %016lx, LDTR - %016lx",\r
SystemContext.SystemContextX64->Gdtr[0],\r
SystemContext.SystemContextX64->Gdtr[1],\r
SystemContext.SystemContextX64->Ldtr\r
);\r
VideoBuffer += COLUMN_MAX;\r
\r
- SPrint (\r
+ UnicodeSPrintAsciiFormat (\r
VideoBuffer,\r
- L"IDTR - %016lx %016lx, TR - %016lx",\r
+ COLUMN_MAX * sizeof (CHAR16),\r
+ "IDTR - %016lx %016lx, TR - %016lx",\r
SystemContext.SystemContextX64->Idtr[0],\r
SystemContext.SystemContextX64->Idtr[1],\r
SystemContext.SystemContextX64->Tr\r
);\r
VideoBuffer += COLUMN_MAX;\r
\r
- SPrint (\r
+ UnicodeSPrintAsciiFormat (\r
VideoBuffer,\r
- L"CR0 - %016lx, CR2 - %016lx, CR3 - %016lx",\r
+ COLUMN_MAX * sizeof (CHAR16),\r
+ "CR0 - %016lx, CR2 - %016lx, CR3 - %016lx",\r
SystemContext.SystemContextX64->Cr0,\r
SystemContext.SystemContextX64->Cr2,\r
SystemContext.SystemContextX64->Cr3\r
);\r
VideoBuffer += COLUMN_MAX;\r
\r
- SPrint (\r
+ UnicodeSPrintAsciiFormat (\r
VideoBuffer,\r
- L"CR4 - %016lx, CR8 - %016lx",\r
+ COLUMN_MAX * sizeof (CHAR16),\r
+ "CR4 - %016lx, CR8 - %016lx",\r
SystemContext.SystemContextX64->Cr4,\r
SystemContext.SystemContextX64->Cr8\r
);\r
VideoBuffer += COLUMN_MAX;\r
\r
- SPrint (\r
+ UnicodeSPrintAsciiFormat (\r
VideoBuffer,\r
- L"DR0 - %016lx, DR1 - %016lx, DR2 - %016lx",\r
+ COLUMN_MAX * sizeof (CHAR16),\r
+ "DR0 - %016lx, DR1 - %016lx, DR2 - %016lx",\r
SystemContext.SystemContextX64->Dr0,\r
SystemContext.SystemContextX64->Dr1,\r
SystemContext.SystemContextX64->Dr2\r
);\r
VideoBuffer += COLUMN_MAX;\r
\r
- SPrint (\r
+ UnicodeSPrintAsciiFormat (\r
VideoBuffer,\r
- L"DR3 - %016lx, DR6 - %016lx, DR7 - %016lx",\r
+ COLUMN_MAX * sizeof (CHAR16),\r
+ "DR3 - %016lx, DR6 - %016lx, DR7 - %016lx",\r
SystemContext.SystemContextX64->Dr3,\r
SystemContext.SystemContextX64->Dr6,\r
SystemContext.SystemContextX64->Dr7\r
EFI_IA32_REGISTER_SET Regs;\r
UINT16 OriginalVideoMode = (UINT16) -1;\r
\r
- //\r
- // See if the Legacy BIOS Protocol is available\r
- //\r
- Status = gBS->LocateProtocol (&gEfiLegacyBiosThunkProtocolGuid, NULL, (VOID **) &LegacyBios);\r
- if (EFI_ERROR (Status)) {\r
- return OriginalVideoMode;\r
- }\r
\r
//\r
// VESA SuperVGA BIOS - GET CURRENT VIDEO MODE\r
//\r
gBS->SetMem (&Regs, sizeof (Regs), 0);\r
Regs.X.AX = 0x4F03;\r
- LegacyBios->Int86 (LegacyBios, 0x10, &Regs);\r
+ LegacyBiosInt86 (0x10, &Regs);\r
if (Regs.X.AX == 0x004F) {\r
OriginalVideoMode = Regs.X.BX;\r
} else {\r
//\r
gBS->SetMem (&Regs, sizeof (Regs), 0);\r
Regs.H.AH = 0x0F;\r
- LegacyBios->Int86 (LegacyBios, 0x10, &Regs);\r
+ LegacyBiosInt86 (0x10, &Regs);\r
OriginalVideoMode = Regs.H.AL;\r
}\r
\r
gBS->SetMem (&Regs, sizeof (Regs), 0);\r
Regs.H.AH = 0x00;\r
Regs.H.AL = (UINT8) NewVideoMode;\r
- LegacyBios->Int86 (LegacyBios, 0x10, &Regs);\r
+ LegacyBiosInt86 (0x10, &Regs);\r
\r
//\r
// VIDEO - TEXT-MODE CHARGEN - LOAD ROM 8x16 CHARACTER SET (VGA)\r
Regs.H.AH = 0x11;\r
Regs.H.AL = 0x14;\r
Regs.H.BL = 0;\r
- LegacyBios->Int86 (LegacyBios, 0x10, &Regs);\r
+ LegacyBiosInt86 (0x10, &Regs);\r
} else {\r
//\r
// VESA SuperVGA BIOS - SET SuperVGA VIDEO MODE\r
gBS->SetMem (&Regs, sizeof (Regs), 0);\r
Regs.X.AX = 0x4F02;\r
Regs.X.BX = NewVideoMode;\r
- LegacyBios->Int86 (LegacyBios, 0x10, &Regs);\r
+ LegacyBiosInt86 (0x10, &Regs);\r
if (Regs.X.AX != 0x004F) {\r
DEBUG ((EFI_D_ERROR, "SORRY: Cannot set to video mode: 0x%04X!\n", NewVideoMode));\r
return (UINT16) -1;\r
InstallInterruptHandler (InterruptVector, SystemTimerHandler);\r
}\r
\r
+ InitializeBiosIntCaller();\r
+ \r
//\r
// Install CPU Architectural Protocol and the thunk protocol\r
//\r
return EFI_SUCCESS;\r
}\r
\r
+VOID\r
+InitializeBiosIntCaller (\r
+ VOID\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ UINT32 RealModeBufferSize;\r
+ UINT32 ExtraStackSize;\r
+ EFI_PHYSICAL_ADDRESS LegacyRegionBase;\r
+ \r
+ //\r
+ // Get LegacyRegion\r
+ //\r
+ AsmGetThunk16Properties (&RealModeBufferSize, &ExtraStackSize);\r
+\r
+ LegacyRegionBase = 0x100000;\r
+ Status = gBS->AllocatePages (\r
+ AllocateMaxAddress,\r
+ EfiACPIMemoryNVS,\r
+ EFI_SIZE_TO_PAGES(RealModeBufferSize + ExtraStackSize + 200),\r
+ &LegacyRegionBase\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
+ \r
+}\r
+\r
+BOOLEAN\r
+EFIAPI\r
+LegacyBiosInt86 (\r
+ IN UINT8 BiosInt,\r
+ IN EFI_IA32_REGISTER_SET *Regs\r
+ )\r
+{\r
+ UINTN Status;\r
+ UINTN Eflags;\r
+ IA32_REGISTER_SET ThunkRegSet;\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.EDI = Regs->E.EDI;\r
+ ThunkRegSet.E.ESI = Regs->E.ESI;\r
+ ThunkRegSet.E.EBP = Regs->E.EBP;\r
+ ThunkRegSet.E.EBX = Regs->E.EBX;\r
+ ThunkRegSet.E.EDX = Regs->E.EDX;\r
+ ThunkRegSet.E.ECX = Regs->E.ECX;\r
+ ThunkRegSet.E.EAX = Regs->E.EAX;\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
+ Eflags = AsmReadEflags ();\r
+ if ((Eflags | EFI_CPU_EFLAGS_IF) != 0) {\r
+ DisableInterrupts ();\r
+ }\r
+\r
+ //\r
+ // Set Legacy16 state. 0x08, 0x70 is legacy 8259 vector bases.\r
+ //\r
+ Status = gLegacy8259->SetMode (gLegacy8259, 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
+\r
+ ThunkRegSet.E.SS = (UINT16) (((UINTN) Stack16 >> 16) << 12);\r
+ ThunkRegSet.E.ESP = (UINT16) (UINTN) Stack16;\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
+ //\r
+ // Restore protected mode interrupt state\r
+ //\r
+ Status = gLegacy8259->SetMode (gLegacy8259, Efi8259ProtectedMode, NULL, NULL);\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ //\r
+ // End critical section\r
+ //\r
+ if ((Eflags | EFI_CPU_EFLAGS_IF) != 0) {\r
+ EnableInterrupts ();\r
+ }\r
+\r
+ Regs->E.EDI = ThunkRegSet.E.EDI; \r
+ Regs->E.ESI = ThunkRegSet.E.ESI; \r
+ Regs->E.EBP = ThunkRegSet.E.EBP; \r
+ Regs->E.EBX = ThunkRegSet.E.EBX; \r
+ Regs->E.EDX = ThunkRegSet.E.EDX; \r
+ Regs->E.ECX = ThunkRegSet.E.ECX; \r
+ Regs->E.EAX = ThunkRegSet.E.EAX;\r
+ Regs->E.SS = ThunkRegSet.E.SS;\r
+ Regs->E.CS = ThunkRegSet.E.CS; \r
+ Regs->E.DS = ThunkRegSet.E.DS; \r
+ Regs->E.ES = ThunkRegSet.E.ES;\r
+\r
+ CopyMem (&(Regs->E.EFlags), &(ThunkRegSet.E.EFLAGS), sizeof (UINT32));\r
+\r
+ Ret = (BOOLEAN) (Regs->E.EFlags.CF == 1);\r
+\r
+ return Ret;\r
+}\r