2 Execute 32-bit code in Long Mode.
3 Provide a thunk function to transition from long mode to compatibility mode to execute 32-bit code and then transit
6 Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #include <Library/BaseLib.h>
28 UINT32 DefaultSize
: 1;
29 UINT32 Granularity
: 1;
36 GLOBAL_REMOVE_IF_UNREFERENCED IA32_GDT mGdtEntries
[] = {
37 {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 0x0: reserve */
38 {{0xFFFF, 0, 0, 0xB, 1, 0, 1, 0xF, 0, 0, 1, 1, 0}}, /* 0x8: compatibility mode */
39 {{0xFFFF, 0, 0, 0xB, 1, 0, 1, 0xF, 0, 1, 0, 1, 0}}, /* 0x10: for long mode */
40 {{0xFFFF, 0, 0, 0x3, 1, 0, 1, 0xF, 0, 0, 1, 1, 0}}, /* 0x18: data */
41 {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 0x20: reserve */
47 GLOBAL_REMOVE_IF_UNREFERENCED IA32_DESCRIPTOR mGdt
= {
48 sizeof (mGdtEntries
) - 1,
53 Assembly function to transition from long mode to compatibility mode to execute 32-bit code and then transit back to
56 @param[in] Function The 32bit code entry to be executed.
57 @param[in] Param1 The first parameter to pass to 32bit code
58 @param[in] Param2 The second parameter to pass to 32bit code
59 @param[in] InternalGdtr The GDT and GDT descriptor used by this library
68 IN IA32_DESCRIPTOR
*InternalGdtr
72 Wrapper for a thunk to transition from long mode to compatibility mode to execute 32-bit code and then transit back to
75 @param[in] Function The 32bit code entry to be executed.
76 @param[in] Param1 The first parameter to pass to 32bit code.
90 // Idtr might be changed inside of FSP. 32bit FSP only knows the <4G address.
91 // If IDTR.Base is >4G, FSP can not handle. So we need save/restore IDTR here for X64 only.
92 // Interrupt is already disabled here, so it is safety to update IDTR.
95 Status
= AsmExecute32BitCode (Function
, Param1
, 0, &mGdt
);