Bug Summary

File:home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/Core/Runtime/PeLoadVm.c
Warning:line 823, column 2
Value stored to 'Rflags' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name PeLoadVm.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -fno-jump-tables -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -ffreestanding -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/build/StmPkg/Core/Runtime -resource-dir /opt/xgcc/lib/clang/17 -include PcdData.h -D COREBOOT32 -D RELEASE -I /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/Core -I /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/EDKII/BaseTools/Source/C/Include/X64 -I /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/EdkII/MdePkg/Include -I /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/EdkII/MdePkg/Include/X64 -I /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/Include -I /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/Include/x64 -I /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/Core/Runtime -I /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/Core/Runtime/../Init -I /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/Core/Runtime/. -internal-isystem /opt/xgcc/lib/clang/17/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -source-date-epoch 1714465709 -Os -fdebug-compilation-dir=/home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/build/StmPkg/Core/Runtime -ferror-limit 19 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-max-loop 10 -analyzer-output=plist-html -faddrsig -o /cb-build/coreboot_scanbuild.0/PURISM_LIBREM15_V4_STM-scanbuildtmp/2024-05-02-081243-2232343-1/report-RDcDTZ.plist -x c /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/Core/Runtime/PeLoadVm.c
1/** @file
2
3VM/PE setup, load and VM breakdown functions
4
5This program and the accompanying materials
6are licensed and made available under the terms and conditions of the BSD License
7which accompanies this distribution. The full text of the license may be found at
8http://opensource.org/licenses/bsd-license.php.
9
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13**/
14
15#define VMCALL_C1 1
16
17#include "StmRuntime.h"
18#include "PeStm.h"
19#include "PeLoadVm.h"
20#include "StmApi.h"
21#include "CpuDef.h"
22
23extern VOIDvoid InitCpuReadySync();
24extern VOIDvoid CpuReadySync(UINT32 Index);
25extern UINT32 GetVmcsSize (VOIDvoid);
26extern VOIDvoid AsmHostEntrypointSmmPe (VOIDvoid);
27extern RETURN_STATUS RegisterExceptionHandler(IN EFI_EXCEPTION_TYPE ExceptionType,
28 IN EFI_EXCEPTION_CALLBACK ExceptionCallback);
29extern void AsmSendInt2(); // setup NMI
30extern void PeEptFree(IN UINT64 EptPointer);
31extern UINT32 GetVmcsOffset( UINT32 field_encoding);
32extern UINT32 GetMPState;
33
34static int CpuGetState = 0;
35
36void SetEndOfSmi(void);
37void StartTimer(void);
38void StopTimer(void);
39void ClearTimerSTS(void);
40void SetMaxSwTimerInt(void);
41void SetMinSwTimerInt(void);
42void SetTimerRate(UINT16 value);
43
44extern void MapVmcs();
45void LaunchPeVm(UINT32 PeType, UINT32 CpuIndex);
46void AckTimer(void);
47UINT16 get_pmbase(void);
48
49UINT32 save_Inter_PeVm(UINT32 CpuIndex);
50
51UINT32 PeSmiHandler(UINT32 CpuIndex);
52
53#define PER_SMI_SEL(1<<0) (1<<0) // selects timinf for periodic SMI - in GEN_PMCON_1 (offset A0-A1h)
54
55// Periodic SMI rates
56
57#define PeriodicSmi64Sec0 0
58#define PeriodicSmi32Sec1 1
59#define PeriodicSmi16Sec2 2
60#define PeriodicSmi8Sec3 3
61
62// need to add or modify
63
64void enable_nmi(); // turn on NMI
65VOIDvoid EFIAPI NullExceptionHandler(IN EFI_EXCEPTION_TYPE InterruptType, IN EFI_SYSTEM_CONTEXT SystemContext);
66
67UINT32 SetupProtExecVm(UINT32 CpuIndex, UINT32 VM_Configuration, UINT32 mode, UINT32 PeType);
68//static UINT32 FreePE_PageTables(UINT32 PeType);
69static void apic_wrmsr(UINT32 reg, UINT64 msr_content);
70void print_region_list(UINT32 PeType, UINT32 CpuIndex);
71
72extern int GetMultiProcessorState(UINT32 CpuIndex);
73
74void InitPe();
75
76typedef struct
77{
78 UINT64 Reserved1:8;
79 UINT64 MaxNonTurboRatio:8;
80 UINT64 Reserved2:12;
81 UINT64 ProgRatioLimitTM:1;
82 UINT64 ProgTDPLimitTM:1;
83 UINT64 Reserved3:10;
84 UINT64 MaxEffRatio:8;
85 UINT64 Reserved4:16;
86}MSR_PLATFORM_INFO_BITS;
87
88typedef union
89{
90 MSR_PLATFORM_INFO_BITS Bits;
91 UINT64 Uint64;
92} MSR_PLATFORM_INFO_DATA;
93
94extern PE_SMI_CONTROL PeSmiControl;
95PE_VM_DATA PeVmData[4]; // right now support a max of 3 PE VM (VM 0 is the SMI_HANDLER)
96static UINT64 StartPeTimeStamp = 0;
97UINT64 EndTimeStamp = 0;
98
99static unsigned int VmPeReady = 0;
100static unsigned int NMIReceived = 0;
101
102// This function launches the VM/PE for each "run"
103
104void LaunchPeVm(UINT32 PeType, UINT32 CpuIndex)
105{
106 UINTN Rflags;
107 UINTN InitStackPointer = 0; // Initial Stack pointer
108 // load the shared page and region list addresses into the register save area
109 // so that the PE module will access to those addresses
110
111 mGuestContextCommonSmm[PeType].GuestContextPerCpu[0].Register.Rbx =
112 (UINT64)PeVmData[PeType].UserModule.SharedPage & 0xFFFFFFFF;
113 mGuestContextCommonSmm[PeType].GuestContextPerCpu[0].Register.Rcx =
114 (UINT64)PeVmData[PeType].UserModule.SharedPage >> 32;
115 mGuestContextCommonSmm[PeType].GuestContextPerCpu[0].Register.Rdx =
116 (UINT32) PeVmData[PeType].UserModule.SharedStmPage;
117
118 // check and make aure that the heap is cleared as requested
119
120 if((PeVmData[PeType].UserModule.VmConfig & PERM_VM_CLEAR_MEMORY(1<<23)) == PERM_VM_CLEAR_MEMORY(1<<23))
121 {
122
123 // addess and size calculations from setupModulepages
124 UINTN StartEndBlock = PeVmData[PeType].UserModule.DataRegionSmmLoc;
125 UINTN EndSize = PeVmData[PeType].UserModule.DataRegionSize;
126
127 StartEndBlock += PeVmData[PeType].UserModule.DoNotClearSize;
128 EndSize -= PeVmData[PeType].UserModule.DoNotClearSize;
129
130 if(0 >= EndSize)
131 {
132 DEBUG((EFI_D_ERROR,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVM - VM/PE heap space not cleared because of DoNotClearSize too large\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
133 "%ld LaunchPeVM - VM/PE heap space not cleared because of DoNotClearSize too large\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVM - VM/PE heap space not cleared because of DoNotClearSize too large\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
134 CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVM - VM/PE heap space not cleared because of DoNotClearSize too large\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
135 }
136 else
137 {
138 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm - Clearing VM/PE heap space: 0x%016llx:0x%016llx\n"
, CpuIndex, StartEndBlock, EndSize ); } } while (((BOOLEAN)(0
==1)))
139 "%ld LaunchPeVm - Clearing VM/PE heap space: 0x%016llx:0x%016llx\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm - Clearing VM/PE heap space: 0x%016llx:0x%016llx\n"
, CpuIndex, StartEndBlock, EndSize ); } } while (((BOOLEAN)(0
==1)))
140 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm - Clearing VM/PE heap space: 0x%016llx:0x%016llx\n"
, CpuIndex, StartEndBlock, EndSize ); } } while (((BOOLEAN)(0
==1)))
141 StartEndBlock,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm - Clearing VM/PE heap space: 0x%016llx:0x%016llx\n"
, CpuIndex, StartEndBlock, EndSize ); } } while (((BOOLEAN)(0
==1)))
142 EndSize ))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm - Clearing VM/PE heap space: 0x%016llx:0x%016llx\n"
, CpuIndex, StartEndBlock, EndSize ); } } while (((BOOLEAN)(0
==1)))
;
143
144 ZeroMem ((VOIDvoid *)(UINTN)StartEndBlock, EndSize);
145 }
146 }
147
148 // setup the variables that are used in case an SMI is taken
149 // while the PE VM is running
150
151 // this needs to be fixed if more than one PE/VM is running
152
153 // when 1, a NMI has been sent to break the thread in PE_APIC_id
154 PeSmiControl.PeNmiBreak = 1;
155
156 // APIC id of the thread that is executing the PE V<
157 PeSmiControl.PeApicId = ReadLocalApicId ();
158 PeSmiControl.PeCpuIndex = CpuIndex;
159 PeSmiControl.PeExec = 0; // when 1 PE_APIC_ID is executing a
160 VmPeReady = 0; // set the ready gate
161
162 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm - before check PeSmiState: %ld\n"
, CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0
==1)))
163 "%ld LaunchPeVm - before check PeSmiState: %ld\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm - before check PeSmiState: %ld\n"
, CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0
==1)))
164 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm - before check PeSmiState: %ld\n"
, CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0
==1)))
165 PeSmiControl.PeSmiState))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm - before check PeSmiState: %ld\n"
, CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0
==1)))
;
166
167 if(InterlockedCompareExchange32(&PeSmiControl.PeSmiState, PESMIHSMI2, PESMIHSMI2) ==
168 PESMIHSMI2) // try to set the NMI
169 {
170 // if we know that the SMI handler is already active, then don't continue
171 // save the state, process the SMI, then start the VM/PE afterwards
172
173 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVM - SMI being processed - faking NMI - PeSmiState: %ld\n"
, CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0
==1)))
174 "%ld LaunchPeVM - SMI being processed - faking NMI - PeSmiState: %ld\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVM - SMI being processed - faking NMI - PeSmiState: %ld\n"
, CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0
==1)))
175 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVM - SMI being processed - faking NMI - PeSmiState: %ld\n"
, CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0
==1)))
176 PeSmiControl.PeSmiState))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVM - SMI being processed - faking NMI - PeSmiState: %ld\n"
, CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0
==1)))
;
177 }
178 else
179 {
180 PeSmiControl.PeNmiBreak = 0;
181 PeSmiControl.PeExec = 1;
182 enable_nmi(); // turn on NMI
183 // make sure we setup the NMI first
184 }
185
186 // Set InitialStack pointer to the top of User memory...
187
188 InitStackPointer = (UINTN) PeVmData[PeType].UserModule.AddressSpaceStart +
189 (UINTN) PeVmData[PeType].UserModule.AddressSpaceSize - (UINTN) 16;
190 VmWriteN (VMCS_N_GUEST_RSP_INDEX0x681C, InitStackPointer);
191
192 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm- IntialStackPointer: 0x%llx\n"
, CpuIndex, InitStackPointer); } } while (((BOOLEAN)(0==1)))
193 "%ld LaunchPeVm- IntialStackPointer: 0x%llx\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm- IntialStackPointer: 0x%llx\n"
, CpuIndex, InitStackPointer); } } while (((BOOLEAN)(0==1)))
194 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm- IntialStackPointer: 0x%llx\n"
, CpuIndex, InitStackPointer); } } while (((BOOLEAN)(0==1)))
195 InitStackPointer))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm- IntialStackPointer: 0x%llx\n"
, CpuIndex, InitStackPointer); } } while (((BOOLEAN)(0==1)))
;
196 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm- VMCS_N_GUEST_RFLAGS_INDEX: %08llx\n"
, CpuIndex, VmReadN(0x6820)); } } while (((BOOLEAN)(0==1)))
197 "%ld LaunchPeVm- VMCS_N_GUEST_RFLAGS_INDEX: %08llx\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm- VMCS_N_GUEST_RFLAGS_INDEX: %08llx\n"
, CpuIndex, VmReadN(0x6820)); } } while (((BOOLEAN)(0==1)))
198 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm- VMCS_N_GUEST_RFLAGS_INDEX: %08llx\n"
, CpuIndex, VmReadN(0x6820)); } } while (((BOOLEAN)(0==1)))
199 VmReadN(VMCS_N_GUEST_RFLAGS_INDEX)))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm- VMCS_N_GUEST_RFLAGS_INDEX: %08llx\n"
, CpuIndex, VmReadN(0x6820)); } } while (((BOOLEAN)(0==1)))
;
200 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm- IA32_EFER_MSR: 0x%llx\n"
, CpuIndex, AsmReadMsr64 (0xC0000080)); } } while (((BOOLEAN)
(0==1)))
201 "%ld LaunchPeVm- IA32_EFER_MSR: 0x%llx\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm- IA32_EFER_MSR: 0x%llx\n"
, CpuIndex, AsmReadMsr64 (0xC0000080)); } } while (((BOOLEAN)
(0==1)))
202 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm- IA32_EFER_MSR: 0x%llx\n"
, CpuIndex, AsmReadMsr64 (0xC0000080)); } } while (((BOOLEAN)
(0==1)))
203 AsmReadMsr64 (IA32_EFER_MSR_INDEX)))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm- IA32_EFER_MSR: 0x%llx\n"
, CpuIndex, AsmReadMsr64 (0xC0000080)); } } while (((BOOLEAN)
(0==1)))
;
204 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm- VMCS_32_CONTROL_PIN_BASED_VM_EXECUTION_INDEX: 0x%llx\n"
, CpuIndex, VmRead32(0x4000)); } } while (((BOOLEAN)(0==1)))
205 "%ld LaunchPeVm- VMCS_32_CONTROL_PIN_BASED_VM_EXECUTION_INDEX: 0x%llx\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm- VMCS_32_CONTROL_PIN_BASED_VM_EXECUTION_INDEX: 0x%llx\n"
, CpuIndex, VmRead32(0x4000)); } } while (((BOOLEAN)(0==1)))
206 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm- VMCS_32_CONTROL_PIN_BASED_VM_EXECUTION_INDEX: 0x%llx\n"
, CpuIndex, VmRead32(0x4000)); } } while (((BOOLEAN)(0==1)))
207 VmRead32(VMCS_32_CONTROL_PIN_BASED_VM_EXECUTION_INDEX)))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm- VMCS_32_CONTROL_PIN_BASED_VM_EXECUTION_INDEX: 0x%llx\n"
, CpuIndex, VmRead32(0x4000)); } } while (((BOOLEAN)(0==1)))
;
208
209 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm- guest parameter regs:\n RBX: %p (shared page - low)\n RCX: %p (shared page - high)\n RDX: %p (shared STM)\n"
, CpuIndex, mGuestContextCommonSmm[PeType].GuestContextPerCpu
[0].Register.Rbx, mGuestContextCommonSmm[PeType].GuestContextPerCpu
[0].Register.Rcx, mGuestContextCommonSmm[PeType].GuestContextPerCpu
[0].Register.Rdx); } } while (((BOOLEAN)(0==1)))
210 "%ld LaunchPeVm- guest parameter regs:\n RBX: %p (shared page - low)\n RCX: %p (shared page - high)\n RDX: %p (shared STM)\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm- guest parameter regs:\n RBX: %p (shared page - low)\n RCX: %p (shared page - high)\n RDX: %p (shared STM)\n"
, CpuIndex, mGuestContextCommonSmm[PeType].GuestContextPerCpu
[0].Register.Rbx, mGuestContextCommonSmm[PeType].GuestContextPerCpu
[0].Register.Rcx, mGuestContextCommonSmm[PeType].GuestContextPerCpu
[0].Register.Rdx); } } while (((BOOLEAN)(0==1)))
211 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm- guest parameter regs:\n RBX: %p (shared page - low)\n RCX: %p (shared page - high)\n RDX: %p (shared STM)\n"
, CpuIndex, mGuestContextCommonSmm[PeType].GuestContextPerCpu
[0].Register.Rbx, mGuestContextCommonSmm[PeType].GuestContextPerCpu
[0].Register.Rcx, mGuestContextCommonSmm[PeType].GuestContextPerCpu
[0].Register.Rdx); } } while (((BOOLEAN)(0==1)))
212 mGuestContextCommonSmm[PeType].GuestContextPerCpu[0].Register.Rbx,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm- guest parameter regs:\n RBX: %p (shared page - low)\n RCX: %p (shared page - high)\n RDX: %p (shared STM)\n"
, CpuIndex, mGuestContextCommonSmm[PeType].GuestContextPerCpu
[0].Register.Rbx, mGuestContextCommonSmm[PeType].GuestContextPerCpu
[0].Register.Rcx, mGuestContextCommonSmm[PeType].GuestContextPerCpu
[0].Register.Rdx); } } while (((BOOLEAN)(0==1)))
213 mGuestContextCommonSmm[PeType].GuestContextPerCpu[0].Register.Rcx,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm- guest parameter regs:\n RBX: %p (shared page - low)\n RCX: %p (shared page - high)\n RDX: %p (shared STM)\n"
, CpuIndex, mGuestContextCommonSmm[PeType].GuestContextPerCpu
[0].Register.Rbx, mGuestContextCommonSmm[PeType].GuestContextPerCpu
[0].Register.Rcx, mGuestContextCommonSmm[PeType].GuestContextPerCpu
[0].Register.Rdx); } } while (((BOOLEAN)(0==1)))
214 mGuestContextCommonSmm[PeType].GuestContextPerCpu[0].Register.Rdx))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm- guest parameter regs:\n RBX: %p (shared page - low)\n RCX: %p (shared page - high)\n RDX: %p (shared STM)\n"
, CpuIndex, mGuestContextCommonSmm[PeType].GuestContextPerCpu
[0].Register.Rbx, mGuestContextCommonSmm[PeType].GuestContextPerCpu
[0].Register.Rcx, mGuestContextCommonSmm[PeType].GuestContextPerCpu
[0].Register.Rdx); } } while (((BOOLEAN)(0==1)))
;
215
216 PeVmData[PeType].UserModule.RunCount++;
217 // set the runcount into the STM shared page
218
219 *((UINT64 *)(PeVmData[PeType].SharedPageStm + sizeof(UINT64))) =
220 PeVmData[PeType].UserModule.RunCount;
221
222 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVM - Initiating PE/VM run number: %d\n"
, CpuIndex, PeVmData[PeType].UserModule.RunCount); } } while (
((BOOLEAN)(0==1)))
223 "%ld LaunchPeVM - Initiating PE/VM run number: %d\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVM - Initiating PE/VM run number: %d\n"
, CpuIndex, PeVmData[PeType].UserModule.RunCount); } } while (
((BOOLEAN)(0==1)))
224 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVM - Initiating PE/VM run number: %d\n"
, CpuIndex, PeVmData[PeType].UserModule.RunCount); } } while (
((BOOLEAN)(0==1)))
225 PeVmData[PeType].UserModule.RunCount))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVM - Initiating PE/VM run number: %d\n"
, CpuIndex, PeVmData[PeType].UserModule.RunCount); } } while (
((BOOLEAN)(0==1)))
;
226
227 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVM - SharedPageStm 0x%016llx 0x%016llx\n"
, CpuIndex, *((UINT64 *)(PeVmData[PeType].SharedPageStm)), *(
(UINT64 *)(PeVmData[PeType].SharedPageStm + sizeof(UINT64))))
; } } while (((BOOLEAN)(0==1)))
228 "%ld LaunchPeVM - SharedPageStm 0x%016llx 0x%016llx\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVM - SharedPageStm 0x%016llx 0x%016llx\n"
, CpuIndex, *((UINT64 *)(PeVmData[PeType].SharedPageStm)), *(
(UINT64 *)(PeVmData[PeType].SharedPageStm + sizeof(UINT64))))
; } } while (((BOOLEAN)(0==1)))
229 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVM - SharedPageStm 0x%016llx 0x%016llx\n"
, CpuIndex, *((UINT64 *)(PeVmData[PeType].SharedPageStm)), *(
(UINT64 *)(PeVmData[PeType].SharedPageStm + sizeof(UINT64))))
; } } while (((BOOLEAN)(0==1)))
230 *((UINT64 *)(PeVmData[PeType].SharedPageStm)),do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVM - SharedPageStm 0x%016llx 0x%016llx\n"
, CpuIndex, *((UINT64 *)(PeVmData[PeType].SharedPageStm)), *(
(UINT64 *)(PeVmData[PeType].SharedPageStm + sizeof(UINT64))))
; } } while (((BOOLEAN)(0==1)))
231 *((UINT64 *)(PeVmData[PeType].SharedPageStm + sizeof(UINT64)))))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVM - SharedPageStm 0x%016llx 0x%016llx\n"
, CpuIndex, *((UINT64 *)(PeVmData[PeType].SharedPageStm)), *(
(UINT64 *)(PeVmData[PeType].SharedPageStm + sizeof(UINT64))))
; } } while (((BOOLEAN)(0==1)))
;
232
233 // Make sure we take the correct path upon RSM
234 mHostContextCommon.HostContextPerCpu[CpuIndex].GuestVmType = PeType;
235
236 StartPeTimeStamp = AsmReadTsc(); // set start time
237
238 AsmWbinvd ();
239
240 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm - VmPE ready for launch PeType %d registers-address: 0x%016llx\n"
, CpuIndex, PeType, &mGuestContextCommonSmm[PeType].GuestContextPerCpu
[0].Register ); } } while (((BOOLEAN)(0==1)))
241 "%ld LaunchPeVm - VmPE ready for launch PeType %d registers-address: 0x%016llx\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm - VmPE ready for launch PeType %d registers-address: 0x%016llx\n"
, CpuIndex, PeType, &mGuestContextCommonSmm[PeType].GuestContextPerCpu
[0].Register ); } } while (((BOOLEAN)(0==1)))
242 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm - VmPE ready for launch PeType %d registers-address: 0x%016llx\n"
, CpuIndex, PeType, &mGuestContextCommonSmm[PeType].GuestContextPerCpu
[0].Register ); } } while (((BOOLEAN)(0==1)))
243 PeType,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm - VmPE ready for launch PeType %d registers-address: 0x%016llx\n"
, CpuIndex, PeType, &mGuestContextCommonSmm[PeType].GuestContextPerCpu
[0].Register ); } } while (((BOOLEAN)(0==1)))
244 &mGuestContextCommonSmm[PeType].GuestContextPerCpu[0].Register ))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVm - VmPE ready for launch PeType %d registers-address: 0x%016llx\n"
, CpuIndex, PeType, &mGuestContextCommonSmm[PeType].GuestContextPerCpu
[0].Register ); } } while (((BOOLEAN)(0==1)))
;
245
246 // need to check to see if an SMI happend during this period
247 // first incidcate that the VM/PE is ready for launch
248
249 // this will cause the interrupt handler to save the VM/PE and
250 // launch the VM/PE once the SMI is handled
251 VmPeReady = 1;
252
253 if(InterlockedCompareExchange32(&PeSmiControl.PeSmiState, PESMIPNMI3, PESMIHSMI2) == PESMIHSMI2)
254 {
255 // if we are here, then an SMI has come in and the system is processing it
256 // we need to get out and let the system process the SMI and then restart
257
258 // PeSmiState = PESIMHSMI (2) means that the other processors are waitng for us to sync up
259 // so synch and then save up the state for when the processors come out of the SMI
260
261 // This will cause the current PE/VM state to be saved and fake a return to the MLE
262 // which will cause the SMI for this processor to be fired
263
264 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVM - SMI detected during build - delaying launch to handle SMI\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
265 "%ld LaunchPeVM - SMI detected during build - delaying launch to handle SMI\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVM - SMI detected during build - delaying launch to handle SMI\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
266 CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVM - SMI detected during build - delaying launch to handle SMI\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
267 save_Inter_PeVm(CpuIndex);
268 DEBUG((EFI_D_ERROR,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVM - Warning: Return from non-returnable function\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
269 "%ld LaunchPeVM - Warning: Return from non-returnable function\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVM - Warning: Return from non-returnable function\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
270 CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVM - Warning: Return from non-returnable function\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
271 }
272
273 // check to see if we received an NMI during the build proceess -
274 // if so, handle the SMI then launch
275 if(NMIReceived > 1)
276 {
277 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVM - NMI detected during build - delaying launch to handle SMI\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
278 "%ld LaunchPeVM - NMI detected during build - delaying launch to handle SMI\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVM - NMI detected during build - delaying launch to handle SMI\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
279 CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVM - NMI detected during build - delaying launch to handle SMI\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
280
281 // This will cause the current PE/VM state to be saved and fake a return to the MLE
282 // which will cause the SMI for this processor to be fired. Since the NMI has been fired from one of
283 // the other processors, they are waiting this processor to join up.
284
285 save_Inter_PeVm(CpuIndex);
286 DEBUG((EFI_D_ERROR,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVM - Warning: Return from non-returnable function\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
287 "%ld LaunchPeVM - Warning: Return from non-returnable function\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVM - Warning: Return from non-returnable function\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
288 CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVM - Warning: Return from non-returnable function\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
289 // this function should not return
290 }
291
292 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVM - Launching PE/VM - NMIReceived: %d\n"
, CpuIndex, NMIReceived); } } while (((BOOLEAN)(0==1)))
293 "%ld LaunchPeVM - Launching PE/VM - NMIReceived: %d\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVM - Launching PE/VM - NMIReceived: %d\n"
, CpuIndex, NMIReceived); } } while (((BOOLEAN)(0==1)))
294 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVM - Launching PE/VM - NMIReceived: %d\n"
, CpuIndex, NMIReceived); } } while (((BOOLEAN)(0==1)))
295 NMIReceived))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld LaunchPeVM - Launching PE/VM - NMIReceived: %d\n"
, CpuIndex, NMIReceived); } } while (((BOOLEAN)(0==1)))
;
296
297 Rflags = AsmVmLaunch (&mGuestContextCommonSmm[PeType].GuestContextPerCpu[0].Register);
298 DEBUG ((EFI_D_ERROR, "%ld LaunchPeVm - (STM):o(\n", (UINTN)CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVm - (STM):o(\n"
, (UINTN)CpuIndex); } } while (((BOOLEAN)(0==1)))
;
299 DEBUG ((EFI_D_ERROR,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVm - !!!LaunchGuestSmm fail for PeVm!!!\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
300 "%ld LaunchPeVm - !!!LaunchGuestSmm fail for PeVm!!!\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVm - !!!LaunchGuestSmm fail for PeVm!!!\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
301 CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVm - !!!LaunchGuestSmm fail for PeVm!!!\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
302 DEBUG ((EFI_D_ERROR,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVm - Rflags: (UINTN)CpuIndex, %08llx\n"
, CpuIndex, Rflags); } } while (((BOOLEAN)(0==1)))
303 "%ld LaunchPeVm - Rflags: (UINTN)CpuIndex, %08llx\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVm - Rflags: (UINTN)CpuIndex, %08llx\n"
, CpuIndex, Rflags); } } while (((BOOLEAN)(0==1)))
304 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVm - Rflags: (UINTN)CpuIndex, %08llx\n"
, CpuIndex, Rflags); } } while (((BOOLEAN)(0==1)))
305 Rflags))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVm - Rflags: (UINTN)CpuIndex, %08llx\n"
, CpuIndex, Rflags); } } while (((BOOLEAN)(0==1)))
;
306 DEBUG ((EFI_D_ERROR, "%ld LaunchPeVm - VMCS_32_RO_VM_INSTRUCTION_ERROR: %08x\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVm - VMCS_32_RO_VM_INSTRUCTION_ERROR: %08x\n"
, (UINTN)CpuIndex, (UINTN)VmRead32 (0x4400)); } } while (((BOOLEAN
)(0==1)))
307 (UINTN)CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVm - VMCS_32_RO_VM_INSTRUCTION_ERROR: %08x\n"
, (UINTN)CpuIndex, (UINTN)VmRead32 (0x4400)); } } while (((BOOLEAN
)(0==1)))
308 (UINTN)VmRead32 (VMCS_32_RO_VM_INSTRUCTION_ERROR_INDEX)))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVm - VMCS_32_RO_VM_INSTRUCTION_ERROR: %08x\n"
, (UINTN)CpuIndex, (UINTN)VmRead32 (0x4400)); } } while (((BOOLEAN
)(0==1)))
;
309 Rflags = AsmVmResume (&mGuestContextCommonSmm[PeType].GuestContextPerCpu[0].Register);
310
311 // returing here means that the launch has failed...
312
313 PeSmiControl.PeExec = 0; // not any more
314
315 AcquireSpinLock (&mHostContextCommon.DebugLock);
316
317 DEBUG ((EFI_D_ERROR,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVm - !!!ResumeGuestSmm fail for PeVm!!! - %d\n"
, (UINTN)CpuIndex); } } while (((BOOLEAN)(0==1)))
318 "%ld LaunchPeVm - !!!ResumeGuestSmm fail for PeVm!!! - %d\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVm - !!!ResumeGuestSmm fail for PeVm!!! - %d\n"
, (UINTN)CpuIndex); } } while (((BOOLEAN)(0==1)))
319 (UINTN)CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVm - !!!ResumeGuestSmm fail for PeVm!!! - %d\n"
, (UINTN)CpuIndex); } } while (((BOOLEAN)(0==1)))
;
320 DEBUG ((EFI_D_ERROR,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVm - Rflags: %08llx\n"
, (UINTN) CpuIndex, Rflags); } } while (((BOOLEAN)(0==1)))
321 "%ld LaunchPeVm - Rflags: %08llx\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVm - Rflags: %08llx\n"
, (UINTN) CpuIndex, Rflags); } } while (((BOOLEAN)(0==1)))
322 (UINTN) CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVm - Rflags: %08llx\n"
, (UINTN) CpuIndex, Rflags); } } while (((BOOLEAN)(0==1)))
323 Rflags))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVm - Rflags: %08llx\n"
, (UINTN) CpuIndex, Rflags); } } while (((BOOLEAN)(0==1)))
;
324 DEBUG ((EFI_D_ERROR,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVm - VMCS_32_RO_VM_INSTRUCTION_ERROR: %08x\n"
, (UINTN) CpuIndex, (UINTN)VmRead32 (0x4400)); } } while (((BOOLEAN
)(0==1)))
325 "%ld LaunchPeVm - VMCS_32_RO_VM_INSTRUCTION_ERROR: %08x\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVm - VMCS_32_RO_VM_INSTRUCTION_ERROR: %08x\n"
, (UINTN) CpuIndex, (UINTN)VmRead32 (0x4400)); } } while (((BOOLEAN
)(0==1)))
326 (UINTN) CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVm - VMCS_32_RO_VM_INSTRUCTION_ERROR: %08x\n"
, (UINTN) CpuIndex, (UINTN)VmRead32 (0x4400)); } } while (((BOOLEAN
)(0==1)))
327 (UINTN)VmRead32 (VMCS_32_RO_VM_INSTRUCTION_ERROR_INDEX)))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld LaunchPeVm - VMCS_32_RO_VM_INSTRUCTION_ERROR: %08x\n"
, (UINTN) CpuIndex, (UINTN)VmRead32 (0x4400)); } } while (((BOOLEAN
)(0==1)))
;
328 DumpVmcsAllField (CpuIndex);
329 DumpRegContext (&mGuestContextCommonSmm[PeType].GuestContextPerCpu[0].Register,
330 CpuIndex);
331 ReleaseSpinLock (&mHostContextCommon.DebugLock);
332}
333
334// this function restarts a perm PE/VM
335// we always start with the same "state" as the first launch
336
337STM_STATUS RunPermVM(UINT32 CpuIndex)
338{
339 UINT32 rc;
340 UINT32 PeType = PE_PERM1; // can only restart perm vms...
341
342 // (for now) start the VM...
343
344 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld RunPermVM entered\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
345 "%ld RunPermVM entered\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld RunPermVM entered\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
346 CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld RunPermVM entered\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
347
348 if((PeVmData[PeType].PeVmState != PE_VM_IDLE2) &&
349 (PeVmData[PeType].PeVmState != PE_VM_WAIT_START8))
350 {
351 DEBUG((EFI_D_ERROR,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld RunPermVM - Can not run a Perm PE/VM\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
352 "%ld RunPermVM - Can not run a Perm PE/VM\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld RunPermVM - Can not run a Perm PE/VM\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
353 CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld RunPermVM - Can not run a Perm PE/VM\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
354 if((PeVmData[PeType].PeVmState == PE_VM_ACTIVE1) ||
355 (PeVmData[PeType].PeVmState == PE_VM_SUSPEND5))
356 {
357 rc = PE_VM_EXECUTING0X8004001C;
358 DEBUG((EFI_D_ERROR,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld RunPermVM - Attempting to execute an already running Perm PE/VM\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
359 "%ld RunPermVM - Attempting to execute an already running Perm PE/VM\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld RunPermVM - Attempting to execute an already running Perm PE/VM\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
360 CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld RunPermVM - Attempting to execute an already running Perm PE/VM\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
361 }
362 else
363 {
364 rc = PE_VM_NO_PERM_VM0x8004001B;
365 DEBUG((EFI_D_ERROR,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld RunPermVM - Attempt to execute a non-existant PE/VM state: %d\n"
, CpuIndex, PeVmData[PeType].PeVmState); } } while (((BOOLEAN
)(0==1)))
366 "%ld RunPermVM - Attempt to execute a non-existant PE/VM state: %d\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld RunPermVM - Attempt to execute a non-existant PE/VM state: %d\n"
, CpuIndex, PeVmData[PeType].PeVmState); } } while (((BOOLEAN
)(0==1)))
367 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld RunPermVM - Attempt to execute a non-existant PE/VM state: %d\n"
, CpuIndex, PeVmData[PeType].PeVmState); } } while (((BOOLEAN
)(0==1)))
368 PeVmData[PeType].PeVmState))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld RunPermVM - Attempt to execute a non-existant PE/VM state: %d\n"
, CpuIndex, PeVmData[PeType].PeVmState); } } while (((BOOLEAN
)(0==1)))
;
369 }
370 return rc;
371 }
372
373 PeVmData[PeType].PeVmState = PE_VM_ACTIVE1;
374
375 if(PeVmData[PeType].StartMode == PEVM_PRESTART_SMI3)
376 {
377 PeVmData[PeType].StartMode = PEVM_START_SMI2;
378 }
379 else
380 {
381 PeVmData[PeType].StartMode = PEVM_START_VMCALL1;
382 }
383
384 // setup the return
385
386 rc = SetupProtExecVm(CpuIndex,
387 PeVmData[PE_PERM1].UserModule.VmConfig,
388 RESTART_VM2,
389 PeType); // can only restart PERM_VM
390
391 if(rc != PE_SUCCESS0) // did we have a problem
392 {
393 DEBUG((EFI_D_ERROR,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld - Error in configuring PE VM\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
394 "%ld - Error in configuring PE VM\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld - Error in configuring PE VM\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
395 CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld - Error in configuring PE VM\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
396 PeVmData[PeType].PeVmState = PE_VM_AVAIL0;
397 return(rc);
398 }
399
400 LaunchPeVm(PeType, CpuIndex); // Launch the PE/VM
401
402 PeVmData[PE_PERM1].PeVmState = PE_VM_AVAIL0; // not there anymore
403 mHostContextCommon.HostContextPerCpu[CpuIndex].GuestVmType = SMI_HANDLER0;
404 return rc;
405}
406
407// used to cleanup a VM when we are done
408// PRESERVE_VM - ensures that the structures needed for the perminate PE VM are retained
409// SUSPEND_VM - VM has been interrupted by an SMI
410// RELEASE_VM - used to release the resources associated with a PE VM
411// used in cases of temp PE VM's and VM's that encounter errors
412
413#define MSR_HSW_PLATFORM_INFO0xCE 0xCE // not in cpudef.h
414
415UINT32 PostPeVmProc(UINT32 rc, UINT32 CpuIndex, UINT32 mode)
416{
417 UINTN Rflags;
418 X86_REGISTER *Reg;
419 //UINT64 EndTimeStamp = AsmReadTsc();
420 UINT64 TotalPeTime = EndTimeStamp - StartPeTimeStamp;
421 UINT32 PeType = mHostContextCommon.HostContextPerCpu[CpuIndex].GuestVmType;
422 UINT64 Scale;
423 UINT64 TotalScaleTime;
424 MSR_PLATFORM_INFO_DATA PlatformData;
425
426 PlatformData.Uint64 = AsmReadMsr64(MSR_HSW_PLATFORM_INFO0xCE);
427
428 Scale = MultU64x32(PlatformData.Bits.MaxNonTurboRatio, 100000);
429
430 TotalScaleTime = DivU64x32(TotalPeTime, (UINT32) Scale);
431 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - Platform Data - Max Ratio: %d\n"
, CpuIndex, PlatformData.Bits.MaxNonTurboRatio); } } while ((
(BOOLEAN)(0==1)))
432 "%ld PostPeVmProc - Platform Data - Max Ratio: %d\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - Platform Data - Max Ratio: %d\n"
, CpuIndex, PlatformData.Bits.MaxNonTurboRatio); } } while ((
(BOOLEAN)(0==1)))
433 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - Platform Data - Max Ratio: %d\n"
, CpuIndex, PlatformData.Bits.MaxNonTurboRatio); } } while ((
(BOOLEAN)(0==1)))
434 PlatformData.Bits.MaxNonTurboRatio))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - Platform Data - Max Ratio: %d\n"
, CpuIndex, PlatformData.Bits.MaxNonTurboRatio); } } while ((
(BOOLEAN)(0==1)))
;
435 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - TSC Info - StartPeTimeStamp: %ld EndTimeStamp: %ld\n"
, CpuIndex, StartPeTimeStamp, EndTimeStamp); } } while (((BOOLEAN
)(0==1)))
436 "%ld PostPeVmProc - TSC Info - StartPeTimeStamp: %ld EndTimeStamp: %ld\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - TSC Info - StartPeTimeStamp: %ld EndTimeStamp: %ld\n"
, CpuIndex, StartPeTimeStamp, EndTimeStamp); } } while (((BOOLEAN
)(0==1)))
437 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - TSC Info - StartPeTimeStamp: %ld EndTimeStamp: %ld\n"
, CpuIndex, StartPeTimeStamp, EndTimeStamp); } } while (((BOOLEAN
)(0==1)))
438 StartPeTimeStamp,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - TSC Info - StartPeTimeStamp: %ld EndTimeStamp: %ld\n"
, CpuIndex, StartPeTimeStamp, EndTimeStamp); } } while (((BOOLEAN
)(0==1)))
439 EndTimeStamp))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - TSC Info - StartPeTimeStamp: %ld EndTimeStamp: %ld\n"
, CpuIndex, StartPeTimeStamp, EndTimeStamp); } } while (((BOOLEAN
)(0==1)))
;
440 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - PeType: %d mode: %d PE clocktime: %ld runtime(scaled): %ldms\n"
, CpuIndex, PeType, mode, TotalPeTime, TotalScaleTime); } } while
(((BOOLEAN)(0==1)))
441 "%ld PostPeVmProc - PeType: %d mode: %d PE clocktime: %ld runtime(scaled): %ldms\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - PeType: %d mode: %d PE clocktime: %ld runtime(scaled): %ldms\n"
, CpuIndex, PeType, mode, TotalPeTime, TotalScaleTime); } } while
(((BOOLEAN)(0==1)))
442 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - PeType: %d mode: %d PE clocktime: %ld runtime(scaled): %ldms\n"
, CpuIndex, PeType, mode, TotalPeTime, TotalScaleTime); } } while
(((BOOLEAN)(0==1)))
443 PeType,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - PeType: %d mode: %d PE clocktime: %ld runtime(scaled): %ldms\n"
, CpuIndex, PeType, mode, TotalPeTime, TotalScaleTime); } } while
(((BOOLEAN)(0==1)))
444 mode,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - PeType: %d mode: %d PE clocktime: %ld runtime(scaled): %ldms\n"
, CpuIndex, PeType, mode, TotalPeTime, TotalScaleTime); } } while
(((BOOLEAN)(0==1)))
445 TotalPeTime,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - PeType: %d mode: %d PE clocktime: %ld runtime(scaled): %ldms\n"
, CpuIndex, PeType, mode, TotalPeTime, TotalScaleTime); } } while
(((BOOLEAN)(0==1)))
446 TotalScaleTime))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - PeType: %d mode: %d PE clocktime: %ld runtime(scaled): %ldms\n"
, CpuIndex, PeType, mode, TotalPeTime, TotalScaleTime); } } while
(((BOOLEAN)(0==1)))
;
447
448 switch (rc)
449 {
450 case PE_VM_ATTEMPTED_VMCALL0x80040011:
451 case PE_VMLAUNCH_ERROR0x8004000B:
452 case PE_VM_PAGE_FAULT0x80040010:
453 case PE_VM_GP_FAULT0x80040024:
454 case PE_VM_NMI0x80040012:
455 case PE_VM_CPUID0x80040013:
456 case PE_VM_IO0x80040014:
457 case PE_VM_READ_MSR0x80040016:
458 case PE_VM_WRITE_MSR0x80040017:
459 case PE_VM_BAD_ACCESS0x8004000C:
460 case PE_VM_TRIPLE_FAULT0x8004000F:
461 case PE_VM_EXCEPTION0x80040020:
462 DumpVmcsAllField(CpuIndex); // temp debug
463 DumpVmxCapabillityMsr(CpuIndex);
464 DumpRegContext(&mGuestContextCommonSmm[PeType].GuestContextPerCpu[0].Register,
465 CpuIndex);
466 print_region_list(PeType, CpuIndex);
467
468 if((PERM_VM_CRASH_BREAKDOWN(1<<21) & PeVmData[PeType].UserModule.VmConfig) ==
469 PERM_VM_CRASH_BREAKDOWN(1<<21))
470 {
471 // user wants perm vm released after crash
472 mode = RELEASE_VM2;
473 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - Perm VM configured to be released after crash\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
474 "%ld PostPeVmProc - Perm VM configured to be released after crash\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - Perm VM configured to be released after crash\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
475 CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - Perm VM configured to be released after crash\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
476 }
477 else
478 {
479 mode = PRESERVE_VM1;
480 }
481 break;
482 default:
483 // print out vm state during debug
484 {
485#if EFI_D_ERROR0x80000000 == 1
486 DumpVmcsAllField();
487 print_region_list(PeType, CpuIndex);
488#endif
489 }
490 }
491 // indicate that we are not running
492
493 PeSmiControl.PeExec = 0;
494 // bug - think about this one....
495 PeSmiControl.PeSmiState = PESMINULL0; // indicate that we are out of it
496
497 if(mode == PRESERVE_VM1)
498 {
499 if((PERM_VM_RUN_ONCE(1<<20) & PeVmData[PeType].UserModule.VmConfig) ==
500 PERM_VM_RUN_ONCE(1<<20))
501 {
502 // user wants perm vm released after crash
503 mode = RELEASE_VM2;
504 DEBUG ((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - Perm VM configured to run only once\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
505 "%ld PostPeVmProc - Perm VM configured to run only once\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - Perm VM configured to run only once\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
506 CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - Perm VM configured to run only once\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
507
508 // indicate none functioning at this momemnet
509 PeSmiControl.PeCpuIndex = -1;
510 }
511 else
512 {
513 if((PERM_VM_RUN_PERIODIC(1<<22) & PeVmData[PeType].UserModule.VmConfig) ==
514 PERM_VM_RUN_PERIODIC(1<<22))
515 {
516 // the PE/VM is running in periodic mode
517 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - Perm VM being setup for Timer interrupt\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
518 "%ld PostPeVmProc - Perm VM being setup for Timer interrupt\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - Perm VM being setup for Timer interrupt\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
519 CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - Perm VM being setup for Timer interrupt\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
520 PeSmiControl.PeCpuIndex = CpuIndex;
521 //
522 PeSmiControl.PeWaitTimer = 1;
523 PeVmData[PeType].PeVmState = PE_VM_IDLE2;
524
525 // turn on the timer
526
527 SetTimerRate(PeriodicSmi16Sec2);
528 StartTimer();
529
530 AckTimer();
531 }
532 }
533 }
534
535 // Suspend the PE/VM and start the SMI Handler.
536 if(mode == SUSPEND_VM3)
537 {
538 // suspending PE/VM so that SMI handler can run
539
540 PeVmData[PeType].PeVmState = PE_VM_SUSPEND5;
541 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - PE/VM suspended - PeType: %ld\n"
, CpuIndex, PeType); } } while (((BOOLEAN)(0==1)))
542 "%ld PostPeVmProc - PE/VM suspended - PeType: %ld\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - PE/VM suspended - PeType: %ld\n"
, CpuIndex, PeType); } } while (((BOOLEAN)(0==1)))
543 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - PE/VM suspended - PeType: %ld\n"
, CpuIndex, PeType); } } while (((BOOLEAN)(0==1)))
544 PeType))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - PE/VM suspended - PeType: %ld\n"
, CpuIndex, PeType); } } while (((BOOLEAN)(0==1)))
;
545
546 // we will fake a return to the MLE -
547 // that will cause the pending SMI to fire allowing
548 // the smiEvent handler to process it and release all
549 // he processor threads
550 // to handle the SMI
551
552 AsmVmPtrLoad(&mGuestContextCommonSmi.GuestContextPerCpu[CpuIndex].Vmcs);
553
554 /// at this point we should return to the MLE as per the Intel method...
555
556 AsmVmClear(&mGuestContextCommonSmm[PeType].GuestContextPerCpu[0].Vmcs);
557
558 DEBUG ((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - !!exiting to allow SMI to fire to Enter SmiHandler\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
559 "%ld PostPeVmProc - !!exiting to allow SMI to fire to Enter SmiHandler\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - !!exiting to allow SMI to fire to Enter SmiHandler\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
560 CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - !!exiting to allow SMI to fire to Enter SmiHandler\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
561
562 mHostContextCommon.HostContextPerCpu[CpuIndex].GuestVmType = SMI_HANDLER0;
563 if (mGuestContextCommonSmi.GuestContextPerCpu[CpuIndex].Launched) {
564 Rflags = AsmVmResume (&mGuestContextCommonSmi.GuestContextPerCpu[CpuIndex].Register);
565 // BUGBUG: - AsmVmLaunch if AsmVmResume fail
566 if (VmRead32 (VMCS_32_RO_VM_INSTRUCTION_ERROR_INDEX0x4400) ==
567 VmxFailErrorVmResumeWithNonLaunchedVmcs) {
568 DEBUG ((EFI_D_ERROR, "%ld :-(\n", (UINTN)CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld :-(\n"
, (UINTN)CpuIndex); } } while (((BOOLEAN)(0==1)))
;
569 Rflags = AsmVmLaunch (&mGuestContextCommonSmi.GuestContextPerCpu[CpuIndex].Register);
570 }
571 } else {
572 mGuestContextCommonSmi.GuestContextPerCpu[CpuIndex].Launched = TRUE((BOOLEAN)(1==1));
573 Rflags = AsmVmLaunch (&mGuestContextCommonSmi.GuestContextPerCpu[CpuIndex].Register);
574 DEBUG ((EFI_D_ERROR, "PostPeVmProc - somehow we did not launch\n"))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "PostPeVmProc - somehow we did not launch\n"
); } } while (((BOOLEAN)(0==1)))
;
575 mGuestContextCommonSmi.GuestContextPerCpu[CpuIndex].Launched = FALSE((BOOLEAN)(0==1));
576 }
577 DEBUG ((EFI_D_ERROR, "%ld PostPeVmProc - Problem in SMI during VM/PE\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld PostPeVmProc - Problem in SMI during VM/PE\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
578 }
579 else
580 {
581 // set the MLE VMCS into place
582
583 AsmVmPtrLoad(&mGuestContextCommonSmi.GuestContextPerCpu[CpuIndex].Vmcs);
584
585 /// at this point we should return to the MLE as per the Intel method...
586
587 AsmVmClear(&mGuestContextCommonSmm[PeType].GuestContextPerCpu[0].Vmcs);
588
589 if(PeVmData[PeType].StartMode == PEVM_START_VMCALL1)
590 {
591 // fixup return address
592
593 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - PE/VM guest return address bumped\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
594 "%ld PostPeVmProc - PE/VM guest return address bumped\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - PE/VM guest return address bumped\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
595 CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - PE/VM guest return address bumped\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
596 VmWriteN (VMCS_N_GUEST_RIP_INDEX0x681E,
597 VmReadN (VMCS_N_GUEST_RIP_INDEX0x681E) +
598 VmRead32 (VMCS_32_RO_VMEXIT_INSTRUCTION_LENGTH_INDEX0x440C));
599 }
600 }
601 // clear out the page table list
602 if(mode == RELEASE_VM2)
603 {
604 FreePE_DataStructures(PeType);
605 // need to add code here in the instance a perm PE VM has crashed
606 // so that in production someone cannot take advantange of this case
607 PeVmData[PeType].PeVmState = PE_VM_AVAIL0; // not there anymore
608 PeSmiControl.PeCpuIndex = -1; // indicate none functioning at this momemnet
609 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - PE/VM Free (AVAIL) - PeType: %ld\n"
, CpuIndex, PeType); } } while (((BOOLEAN)(0==1)))
610 "%ld PostPeVmProc - PE/VM Free (AVAIL) - PeType: %ld\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - PE/VM Free (AVAIL) - PeType: %ld\n"
, CpuIndex, PeType); } } while (((BOOLEAN)(0==1)))
611 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - PE/VM Free (AVAIL) - PeType: %ld\n"
, CpuIndex, PeType); } } while (((BOOLEAN)(0==1)))
612 PeType))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - PE/VM Free (AVAIL) - PeType: %ld\n"
, CpuIndex, PeType); } } while (((BOOLEAN)(0==1)))
;
613 }
614 else
615 {
616 // mark this VM as idle
617
618 PeVmData[PeType].PeVmState = PE_VM_IDLE2; // Waiting for more action
619 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - PE/VM Idle - PeType: %ld\n"
, CpuIndex, PeType); } } while (((BOOLEAN)(0==1)))
620 "%ld PostPeVmProc - PE/VM Idle - PeType: %ld\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - PE/VM Idle - PeType: %ld\n"
, CpuIndex, PeType); } } while (((BOOLEAN)(0==1)))
621 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - PE/VM Idle - PeType: %ld\n"
, CpuIndex, PeType); } } while (((BOOLEAN)(0==1)))
622 PeType))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - PE/VM Idle - PeType: %ld\n"
, CpuIndex, PeType); } } while (((BOOLEAN)(0==1)))
;
623 }
624
625 if(PeVmData[PeType].StartMode == PEVM_START_VMCALL1)
626 {
627 // setup the return codes
628
629 Reg = &mGuestContextCommonSmi.GuestContextPerCpu[CpuIndex].Register;
630
631 WriteUnaligned32 ((UINT32 *)&Reg->Rax, rc);
632 if (rc == PE_SUCCESS0)
633 {
634 VmWriteN (VMCS_N_GUEST_RFLAGS_INDEX0x6820,
635 VmReadN(VMCS_N_GUEST_RFLAGS_INDEX0x6820) & ~RFLAGS_CF1u);
636 }
637 else
638 {
639 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - Unsucessful return noted in RFLAGS_CF\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
640 "%ld PostPeVmProc - Unsucessful return noted in RFLAGS_CF\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - Unsucessful return noted in RFLAGS_CF\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
641 CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - Unsucessful return noted in RFLAGS_CF\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
642 VmWriteN (VMCS_N_GUEST_RFLAGS_INDEX0x6820,
643 VmReadN(VMCS_N_GUEST_RFLAGS_INDEX0x6820) | RFLAGS_CF1u);
644 }
645 }
646
647 mHostContextCommon.HostContextPerCpu[CpuIndex].GuestVmType = SMI_HANDLER0;
648 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - sucessfully completed - RC: 0x%x\n"
, CpuIndex, rc); } } while (((BOOLEAN)(0==1)))
649 "%ld PostPeVmProc - sucessfully completed - RC: 0x%x\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - sucessfully completed - RC: 0x%x\n"
, CpuIndex, rc); } } while (((BOOLEAN)(0==1)))
650 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - sucessfully completed - RC: 0x%x\n"
, CpuIndex, rc); } } while (((BOOLEAN)(0==1)))
651 rc))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PostPeVmProc - sucessfully completed - RC: 0x%x\n"
, CpuIndex, rc); } } while (((BOOLEAN)(0==1)))
;
652 CheckPendingMtf (CpuIndex);
653
654 //
655 // Launch back
656 //
657 Rflags = AsmVmResume (&mGuestContextCommonSmi.GuestContextPerCpu[CpuIndex].Register);
658 // BUGBUG: - AsmVmLaunch if AsmVmResume fail
659 if (VmRead32 (VMCS_32_RO_VM_INSTRUCTION_ERROR_INDEX0x4400) ==
660 VmxFailErrorVmResumeWithNonLaunchedVmcs) {
661 DEBUG ((EFI_D_ERROR,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld PostPeVmProc - Rflags: %08x\n"
, CpuIndex, Rflags); } } while (((BOOLEAN)(0==1)))
662 "%ld PostPeVmProc - Rflags: %08x\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld PostPeVmProc - Rflags: %08x\n"
, CpuIndex, Rflags); } } while (((BOOLEAN)(0==1)))
663 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld PostPeVmProc - Rflags: %08x\n"
, CpuIndex, Rflags); } } while (((BOOLEAN)(0==1)))
664 Rflags))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld PostPeVmProc - Rflags: %08x\n"
, CpuIndex, Rflags); } } while (((BOOLEAN)(0==1)))
;
665 DEBUG ((EFI_D_ERROR,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld PostPeVmProc - VMCS_32_RO_VM_INSTRUCTION_ERROR: %08x\n"
, CpuIndex, (UINTN)VmRead32 (0x4400)); } } while (((BOOLEAN)(
0==1)))
666 "%ld PostPeVmProc - VMCS_32_RO_VM_INSTRUCTION_ERROR: %08x\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld PostPeVmProc - VMCS_32_RO_VM_INSTRUCTION_ERROR: %08x\n"
, CpuIndex, (UINTN)VmRead32 (0x4400)); } } while (((BOOLEAN)(
0==1)))
667 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld PostPeVmProc - VMCS_32_RO_VM_INSTRUCTION_ERROR: %08x\n"
, CpuIndex, (UINTN)VmRead32 (0x4400)); } } while (((BOOLEAN)(
0==1)))
668 (UINTN)VmRead32 (VMCS_32_RO_VM_INSTRUCTION_ERROR_INDEX)))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld PostPeVmProc - VMCS_32_RO_VM_INSTRUCTION_ERROR: %08x\n"
, CpuIndex, (UINTN)VmRead32 (0x4400)); } } while (((BOOLEAN)(
0==1)))
;
669 DEBUG ((EFI_D_ERROR,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld PostPeVmProc - (STM):o(\n"
, (UINTN)CpuIndex); } } while (((BOOLEAN)(0==1)))
670 "%ld PostPeVmProc - (STM):o(\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld PostPeVmProc - (STM):o(\n"
, (UINTN)CpuIndex); } } while (((BOOLEAN)(0==1)))
671 (UINTN)CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld PostPeVmProc - (STM):o(\n"
, (UINTN)CpuIndex); } } while (((BOOLEAN)(0==1)))
;
672 Rflags = AsmVmLaunch (&mGuestContextCommonSmi.GuestContextPerCpu[CpuIndex].Register);
673 }
674
675 AcquireSpinLock (&mHostContextCommon.DebugLock);
676 DEBUG ((EFI_D_ERROR,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld PostPeVmProc - !!!PePostVmProcessing FAIL!!!\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
677 "%ld PostPeVmProc - !!!PePostVmProcessing FAIL!!!\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld PostPeVmProc - !!!PePostVmProcessing FAIL!!!\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
678 CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld PostPeVmProc - !!!PePostVmProcessing FAIL!!!\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
679 DEBUG ((EFI_D_ERROR,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld PostPeVmProc - Rflags: %08x\n"
, CpuIndex, Rflags); } } while (((BOOLEAN)(0==1)))
680 "%ld PostPeVmProc - Rflags: %08x\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld PostPeVmProc - Rflags: %08x\n"
, CpuIndex, Rflags); } } while (((BOOLEAN)(0==1)))
681 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld PostPeVmProc - Rflags: %08x\n"
, CpuIndex, Rflags); } } while (((BOOLEAN)(0==1)))
682 Rflags))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld PostPeVmProc - Rflags: %08x\n"
, CpuIndex, Rflags); } } while (((BOOLEAN)(0==1)))
;
683 DEBUG ((EFI_D_ERROR,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld PostPeVmProc - VMCS_32_RO_VM_INSTRUCTION_ERROR: %08x\n"
, CpuIndex, (UINTN)VmRead32 (0x4400)); } } while (((BOOLEAN)(
0==1)))
684 "%ld PostPeVmProc - VMCS_32_RO_VM_INSTRUCTION_ERROR: %08x\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld PostPeVmProc - VMCS_32_RO_VM_INSTRUCTION_ERROR: %08x\n"
, CpuIndex, (UINTN)VmRead32 (0x4400)); } } while (((BOOLEAN)(
0==1)))
685 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld PostPeVmProc - VMCS_32_RO_VM_INSTRUCTION_ERROR: %08x\n"
, CpuIndex, (UINTN)VmRead32 (0x4400)); } } while (((BOOLEAN)(
0==1)))
686 (UINTN)VmRead32 (VMCS_32_RO_VM_INSTRUCTION_ERROR_INDEX)))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld PostPeVmProc - VMCS_32_RO_VM_INSTRUCTION_ERROR: %08x\n"
, CpuIndex, (UINTN)VmRead32 (0x4400)); } } while (((BOOLEAN)(
0==1)))
;
687
688 DumpVmcsAllField (CpuIndex);
689 DumpRegContext (&mGuestContextCommonSmi.GuestContextPerCpu[CpuIndex].Register,
690 CpuIndex);
691 ReleaseSpinLock (&mHostContextCommon.DebugLock);
692 DEBUG((EFI_D_ERROR, "%ld PostPeVmProc - CpuDeadLoop\n"))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld PostPeVmProc - CpuDeadLoop\n"
); } } while (((BOOLEAN)(0==1)))
;
693 CpuDeadLoop (); // crash here because we cannot get back to the MLE...
694
695 // check to see if there is a path through the intel code
696 // for going back to the MLE
697
698 return rc; // always succeed
699}
700// standard function used to free the memory, etc associated with a PE VM
701
702UINT32 FreePE_DataStructures(UINT32 PeType)
703{
704 // first clear out the pages
705
706 if(PeVmData[PeType].SmmBuffer != NULL((void *) 0))
707 {
708 FreePages(PeVmData[PeType].SmmBuffer, PeVmData[PeType].SmmBufferSize);
709 PeVmData[PeType].SmmBuffer = 0;
710 PeVmData[PeType].SmmBufferSize = 0;
711 }
712 if(mGuestContextCommonSmm[PeType].EptPointer.Uint64 != 0)
713 {
714 PeEptFree(mGuestContextCommonSmm[PeType].EptPointer.Uint64);
715 mGuestContextCommonSmm[PeType].EptPointer.Uint64 = 0;
716 }
717
718 if(PeVmData[PeType].SharedPageStm != NULL((void *) 0))
719 {
720 FreePages(PeVmData[PeType].SharedPageStm, 1);
721 PeVmData[PeType].SharedPageStm = 0;
722 }
723
724 return STM_SUCCESS0x00000000;
725}
726
727//setup the guest physical address space assigned for the module to be RWX
728// the remainder of guest physical addrss space will be setup as RW.
729
730UINT32 save_Inter_PeVm(UINT32 CpuIndex)
731{
732 // come here when the VM has been interrupted by an SMI
733 // setup for the call to PostPeVmProc
734
735 // which PT are we using
736 UINT32 PeType = mHostContextCommon.HostContextPerCpu[CpuIndex].GuestVmType;
737
738 // let the STM know that we are waiting to come back
739 mHostContextCommon.HostContextPerCpu[CpuIndex].NonSmiHandler = PeType;
740
741 EndTimeStamp = AsmReadTsc();
742
743 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld save_Inter_PeVm - sucessfully completed\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
744 "%ld save_Inter_PeVm - sucessfully completed\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld save_Inter_PeVm - sucessfully completed\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
745 CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld save_Inter_PeVm - sucessfully completed\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
746
747 PostPeVmProc(PE_SUCCESS0, CpuIndex, SUSPEND_VM3);
748
749 return STM_SUCCESS0x00000000; // always succeed
750}
751
752UINT32 RestoreInterPeVm(UINT32 CpuIndex, UINT32 PeType)
753{
754 UINT32 rc = STM_SUCCESS0x00000000;
755 UINTN Rflags;
756
757 // restores a VM after an SMI
758
759 if(GetMPState == 1)
760 {
761 // should only happen when the PEV/VM is initially loaded, otherwise
762 // this informaition should be normally grabbed upon a smi timer interrupt
763 // bug -
764 // need to consider the case of debug loading of a module for testing
765
766 if(GetMultiProcessorState(CpuIndex) == -1)
767 {
768 // Indicate that we still need to get the processor state
769 GetMPState = 1;
770
771 // in this case there is an SMI in process and
772 // we need to let it be processed.
773
774 return 1;
775 }
776 else
777 {
778 //Success - got the processor state
779 GetMPState = 0;
780 }
781 }
782
783 if(InterlockedCompareExchange32(&PeSmiControl.PeSmiState,
784 PESMIHSMI2, PESMIHSMI2) == PESMIHSMI2)
785 {
786 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld RestoreInterPeVm - SMI in progress - aborting PE/VM restart\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
787 "%ld RestoreInterPeVm - SMI in progress - aborting PE/VM restart\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld RestoreInterPeVm - SMI in progress - aborting PE/VM restart\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
788 CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld RestoreInterPeVm - SMI in progress - aborting PE/VM restart\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
789 return 1;
790 }
791
792 // need to think about locking here in case there are two smi's in a row...
793 PeVmData[PeType].PeVmState = PE_VM_ACTIVE1;
794
795 // when 1, a NMI has been sent to break the thread in PE_APIC_id
796 PeSmiControl.PeNmiBreak = 1;
797
798 // APIC id of the thread that is executing the PE V<
799 PeSmiControl.PeApicId = ReadLocalApicId ();
800
801 PeSmiControl.PeCpuIndex = CpuIndex;
802
803 // think about break code (BUG)
804
805 // set the ready gate (for here do not get out
806 // (BUG - Review this!!! for SMI in this interval)
807 VmPeReady = 0;
808 enable_nmi(); // turn on NMI
809
810 // when 1, a NMI has been sent to break the thread in PE_APIC_id
811 PeSmiControl.PeNmiBreak = 0;
812 PeSmiControl.PeExec = 1; // when 1 PE_APIC_ID is executing a
813 // setup the return
814
815 AsmVmPtrLoad(&mGuestContextCommonSmm[PeType].GuestContextPerCpu[0].Vmcs);
816 mHostContextCommon.HostContextPerCpu[CpuIndex].GuestVmType = PeType;
817
818 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld RestoreInterPeVm - setup done, launching PE/VM\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
819 "%ld RestoreInterPeVm - setup done, launching PE/VM\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld RestoreInterPeVm - setup done, launching PE/VM\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
820 CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld RestoreInterPeVm - setup done, launching PE/VM\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
821 // Launch back
822 //
823 Rflags = AsmVmResume (&mGuestContextCommonSmm[PeType].GuestContextPerCpu[0].Register);
Value stored to 'Rflags' is never read
824 // BUGBUG: - AsmVmLaunch if AsmVmResume fail
825 if (VmRead32 (VMCS_32_RO_VM_INSTRUCTION_ERROR_INDEX0x4400) ==
826 VmxFailErrorVmResumeWithNonLaunchedVmcs) {
827 // DEBUG ((EFI_D_ERROR, "(STM):o(\n", (UINTN)Index));
828 Rflags = AsmVmLaunch (&mGuestContextCommonSmm[PeType].GuestContextPerCpu[0].Register);
829 }
830
831 return rc;
832}
833
834void print_region_list(UINT32 PeType, UINT32 CpuIndex)
835{
836 int counter;
837 PE_REGION_LIST * rlist;
838 UINT64 EndAddress;
839 //UINT32 CpuIndex = (UINT32) GetCpuNumFromAcpi();
840
841 rlist = PeVmData[PeType].UserModule.Segment; // start the list
842
843 if(rlist == NULL((void *) 0))
844 {
845 DEBUG((EFI_D_INFO, "%ld - No region list\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld - No region list\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
846 return;
847 }
848
849 DEBUG((EFI_D_INFO, "%ld --- Region List --- \n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld --- Region List --- \n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
850
851 for(counter = 0; counter < (4096/sizeof(PE_REGION_LIST)); counter++)
852 {
853 if(rlist[counter].Address == (UINT64) 0)
854 {
855 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld Finish scanning Region List - %d elements found\n"
, CpuIndex, counter); } } while (((BOOLEAN)(0==1)))
856 "%ld Finish scanning Region List - %d elements found\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld Finish scanning Region List - %d elements found\n"
, CpuIndex, counter); } } while (((BOOLEAN)(0==1)))
857 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld Finish scanning Region List - %d elements found\n"
, CpuIndex, counter); } } while (((BOOLEAN)(0==1)))
858 counter))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld Finish scanning Region List - %d elements found\n"
, CpuIndex, counter); } } while (((BOOLEAN)(0==1)))
;
859 break; // done at end of list
860 }
861
862 EndAddress = rlist[counter].Address + rlist[counter].Size;
863 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld region set at 0x%016llx:%016llx - size 0x%016lx\n"
, CpuIndex, rlist[counter].Address, EndAddress, rlist[counter
].Size); } } while (((BOOLEAN)(0==1)))
864 "%ld region set at 0x%016llx:%016llx - size 0x%016lx\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld region set at 0x%016llx:%016llx - size 0x%016lx\n"
, CpuIndex, rlist[counter].Address, EndAddress, rlist[counter
].Size); } } while (((BOOLEAN)(0==1)))
865 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld region set at 0x%016llx:%016llx - size 0x%016lx\n"
, CpuIndex, rlist[counter].Address, EndAddress, rlist[counter
].Size); } } while (((BOOLEAN)(0==1)))
866 rlist[counter].Address,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld region set at 0x%016llx:%016llx - size 0x%016lx\n"
, CpuIndex, rlist[counter].Address, EndAddress, rlist[counter
].Size); } } while (((BOOLEAN)(0==1)))
867 EndAddress,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld region set at 0x%016llx:%016llx - size 0x%016lx\n"
, CpuIndex, rlist[counter].Address, EndAddress, rlist[counter
].Size); } } while (((BOOLEAN)(0==1)))
868 rlist[counter].Size))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld region set at 0x%016llx:%016llx - size 0x%016lx\n"
, CpuIndex, rlist[counter].Address, EndAddress, rlist[counter
].Size); } } while (((BOOLEAN)(0==1)))
;
869 }
870}
871
872void enable_nmi()
873{
874 UINT32 Index = 2; // need to
875 RegisterExceptionHandler (Index, NullExceptionHandler);
876 NMIReceived = 0;
877 AsmSendInt2(); // setup NMI
878 // reset because we received an NMI because of the previous instruction
879 // BUG - might have to review this to ensure that NMIReceived is set to zero after
880 // the interrupt is fired
881
882 while(NMIReceived == 0) {} // wait for NMI interrupt
883 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "NMI handler active\n"
); } } while (((BOOLEAN)(0==1)))
884 "NMI handler active\n"))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "NMI handler active\n"
); } } while (((BOOLEAN)(0==1)))
;
885}
886
887VOIDvoid
888 EFIAPI
889 NullExceptionHandler (
890 IN EFI_EXCEPTION_TYPE InterruptType,
891 IN EFI_SYSTEM_CONTEXT SystemContext
892 )
893{
894 NMIReceived = NMIReceived + 1; // increment
895 //DEBUG((EFI_D_INFO, "***NMI***Happened****\n"));
896
897 if(VmPeReady == 1)
898 {
899
900 UINT32 CpuIndex = ApicToIndex (ReadLocalApicId ());
901 // in this instance, the VmPe is ready for launch,
902 // but an SMI has appeared after the NMI has
903 // been enabled, but during the iterval between
904 // VM/PE setup complete and its launch
905 // so we will hold the launch, service the SMI and
906 // then launch the VM/PE once the
907 // SMI is handled
908
909 save_Inter_PeVm(CpuIndex);
910 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld enable_nmi - Return from non-returnable function\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
911 "%ld enable_nmi - Return from non-returnable function\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld enable_nmi - Return from non-returnable function\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
912 CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld enable_nmi - Return from non-returnable function\n"
, CpuIndex); } } while (((BOOLEAN)(0==1)))
;
913
914 // this function should not return...
915 }
916 return; // basically we are ignoring NMI, but setting a flag that it occurred
917}
918
919// Initialization code goes here - ran everytime that StmInit is run
920
921static STM_GUEST_CONTEXT_PER_CPU GuestContext[3];
922extern void PeInitStmHandlerSmm ();
923
924void InitPe()
925{
926 unsigned int i;
927 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "InitPe - Starting PE initiaization\n"
); } } while (((BOOLEAN)(0==1)))
928 "InitPe - Starting PE initiaization\n"))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "InitPe - Starting PE initiaization\n"
); } } while (((BOOLEAN)(0==1)))
;
929 mGuestContextCommonSmm[1].GuestContextPerCpu = &GuestContext[0];
930 mGuestContextCommonSmm[2].GuestContextPerCpu = &GuestContext[1];
931 mGuestContextCommonSmm[3].GuestContextPerCpu = &GuestContext[2];
932
933 // initialize the VM/PE memory pointer to null
934
935 for(i = 0; i < 4; i++)
936 {
937 PeVmData[i].SharedPageStm = 0;
938 PeVmData[i].SmmBuffer = 0;
939 PeVmData[i].SmmBufferSize = 0;
940 PeVmData[i].PeVmState = PE_VM_AVAIL0;
941 }
942
943 PeSmiControl.PeExec = 0;
944 PeSmiControl.PeNmiBreak = 0;
945 PeSmiControl.PeCpuIndex = -1;
946 PeSmiControl.PeSmiState = 0;
947 PeSmiControl.PeWaitTimer = 0; // non-zero reflect timer length and active
948
949 PeInitStmHandlerSmm ();
950
951 InitializeSpinLock (&PeSmiControl.PeSmiControlLock);
952
953 DEBUG((EFI_D_INFO, "InitPe - PE initialization complete\n"))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "InitPe - PE initialization complete\n"
); } } while (((BOOLEAN)(0==1)))
;
954}