]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/BootScriptSaveOnS3SaveStateThunk/X64/DispatchExecute.c
Fix CYG GCC build fail on retf.
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / BootScriptSaveOnS3SaveStateThunk / X64 / DispatchExecute.c
1 /** @file
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
4 back to long mode.
5
6 Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16 #include "ScriptSave.h"
17
18 #pragma pack(1)
19 typedef union {
20 struct {
21 UINT32 LimitLow : 16;
22 UINT32 BaseLow : 16;
23 UINT32 BaseMid : 8;
24 UINT32 Type : 4;
25 UINT32 System : 1;
26 UINT32 Dpl : 2;
27 UINT32 Present : 1;
28 UINT32 LimitHigh : 4;
29 UINT32 Software : 1;
30 UINT32 Reserved : 1;
31 UINT32 DefaultSize : 1;
32 UINT32 Granularity : 1;
33 UINT32 BaseHigh : 8;
34 } Bits;
35 UINT64 Uint64;
36 } IA32_GDT;
37 #pragma pack()
38
39 //
40 // Global Descriptor Table (GDT)
41 //
42 GLOBAL_REMOVE_IF_UNREFERENCED IA32_GDT mGdtEntries[] = {
43 {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 0x0: reserve */
44 {{0xFFFF, 0, 0, 0xB, 1, 0, 1, 0xF, 0, 0, 1, 1, 0}}, /* 0x8: compatibility mode */
45 {{0xFFFF, 0, 0, 0xB, 1, 0, 1, 0xF, 0, 1, 0, 1, 0}}, /* 0x10: for long mode */
46 {{0xFFFF, 0, 0, 0x3, 1, 0, 1, 0xF, 0, 0, 1, 1, 0}}, /* 0x18: data */
47 {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 0x20: reserve */
48 };
49
50 //
51 // IA32 Gdt register
52 //
53 GLOBAL_REMOVE_IF_UNREFERENCED IA32_DESCRIPTOR mGdt = {
54 sizeof (mGdtEntries) - 1,
55 (UINTN) mGdtEntries
56 };
57 /**
58 Assembly function to transition from long mode to compatibility mode to execute 32-bit code and then transit back to
59 long mode.
60 @param Function The 32bit code entry to be executed.
61 @param Param1 The first parameter to pass to 32bit code
62 @param Param2 The second parameter to pass to 32bit code
63 @param InternalGdtr The GDT and GDT descriptor used by this library
64
65 @retval EFI_SUCCESS Execute 32bit code successfully.
66 @retval other Something wrong when execute the 32bit code
67 **/
68 EFI_STATUS
69 AsmExecute32BitCode (
70 IN UINT64 Function,
71 IN UINT64 Param1,
72 IN UINT64 Param2,
73 IN IA32_DESCRIPTOR *InternalGdtr
74 );
75
76 /**
77 Wrapper for a thunk to transition from long mode to compatibility mode to execute 32-bit code and then transit back to
78 long mode.
79
80 @param Function The 32bit code entry to be executed.
81 @param Param1 The first parameter to pass to 32bit code
82 @param Param2 The second parameter to pass to 32bit code
83 @retval EFI_SUCCESS Execute 32bit code successfully.
84 @retval other Something wrong when execute the 32bit code
85
86 **/
87 EFI_STATUS
88 Execute32BitCode (
89 IN UINT64 Function,
90 IN UINT64 Param1,
91 IN UINT64 Param2
92 )
93 {
94 EFI_STATUS Status;
95
96 ASSERT (Function != 0);
97
98 Status = AsmExecute32BitCode (
99 Function,
100 Param1,
101 Param2,
102 &mGdt
103 );
104 return Status;
105 }
106