TianoCore EDK2 master
Loading...
Searching...
No Matches
AmdSmramSaveStateConfig.c
Go to the documentation of this file.
1
11
19UINT8
21 VOID
22 )
23{
24 UINT8 SmmSaveStateRegisterLma;
26
27 Msr.Uint64 = AsmReadMsr64 (MSR_IA32_EFER);
28
29 SmmSaveStateRegisterLma = (UINT8)EFI_MM_SAVE_STATE_REGISTER_LMA_32BIT;
30
31 if (Msr.Bits.LMA) {
32 SmmSaveStateRegisterLma = (UINT8)EFI_MM_SAVE_STATE_REGISTER_LMA_64BIT;
33 }
34
35 return SmmSaveStateRegisterLma;
36}
37
44VOID
45EFIAPI
47 IN UINT64 SmBase
48 )
49{
50 AMD_SMRAM_SAVE_STATE_MAP *AmdCpuState;
51
53
54 AmdCpuState->x64.SMBASE = (UINT32)SmBase;
55}
56
83UINT64
84EFIAPI
86 IN OUT SMRAM_SAVE_STATE_MAP *CpuState,
87 IN UINT64 NewInstructionPointer32,
88 IN UINT64 NewInstructionPointer
89 )
90{
91 UINT64 OriginalInstructionPointer;
92 AMD_SMRAM_SAVE_STATE_MAP *AmdCpuState;
94
95 AmdCpuState = (AMD_SMRAM_SAVE_STATE_MAP *)CpuState;
96
97 OriginalInstructionPointer = AmdCpuState->x64._RIP;
98 Msr.Uint64 = AmdCpuState->x64.EFER;
99
100 if (!Msr.Bits.LMA) {
101 AmdCpuState->x64._RIP = NewInstructionPointer32;
102 } else {
103 AmdCpuState->x64._RIP = NewInstructionPointer;
104 }
105
106 //
107 // Clear the auto HALT restart flag so the RSM instruction returns
108 // program control to the instruction following the HLT instruction.
109 //
110 if ((AmdCpuState->x64.AutoHALTRestart & BIT0) != 0) {
111 AmdCpuState->x64.AutoHALTRestart &= ~BIT0;
112 }
113
114 return OriginalInstructionPointer;
115}
UINT64 UINTN
UINT64 EFIAPI HookReturnFromSmm(IN OUT SMRAM_SAVE_STATE_MAP *CpuState, IN UINT64 NewInstructionPointer32, IN UINT64 NewInstructionPointer)
VOID EFIAPI ConfigureSmBase(IN UINT64 SmBase)
UINT8 GetMmSaveStateRegisterLma(VOID)
UINT64 EFIAPI AsmReadMsr64(IN UINT32 Index)
Definition: GccInlinePriv.c:60
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define SMM_DEFAULT_SMBASE
#define MSR_IA32_EFER
#define SMRAM_SAVE_STATE_MAP_OFFSET
#define EFI_MM_SAVE_STATE_REGISTER_LMA_32BIT
Definition: MmCpu.h:113