TianoCore EDK2 master
Loading...
Searching...
No Matches
MmSaveStateCommon.c
Go to the documentation of this file.
1
11#include "MmSaveState.h"
12
13// Table used by MmSaveStateGetRegisterIndex() to convert an EFI_MM_SAVE_STATE_REGISTER
14// value to an index into a table of type CPU_MM_SAVE_STATE_LOOKUP_ENTRY
15CONST CPU_MM_SAVE_STATE_REGISTER_RANGE mCpuRegisterRanges[] = {
16 MM_REGISTER_RANGE (EFI_MM_SAVE_STATE_REGISTER_GDTBASE, EFI_MM_SAVE_STATE_REGISTER_LDTINFO),
17 MM_REGISTER_RANGE (EFI_MM_SAVE_STATE_REGISTER_ES, EFI_MM_SAVE_STATE_REGISTER_RIP),
18 MM_REGISTER_RANGE (EFI_MM_SAVE_STATE_REGISTER_RFLAGS, EFI_MM_SAVE_STATE_REGISTER_CR4),
20};
21
23
37 IN UINTN RegOffset
38 )
39{
40 UINTN Index;
41 UINTN Offset;
42
43 for (Index = 0, Offset = RegOffset; mCpuRegisterRanges[Index].Length != 0; Index++) {
44 if ((Register >= mCpuRegisterRanges[Index].Start) && (Register <= mCpuRegisterRanges[Index].End)) {
45 return Register - mCpuRegisterRanges[Index].Start + Offset;
46 }
47
48 Offset += mCpuRegisterRanges[Index].Length;
49 }
50
51 return 0;
52}
53
74 IN UINTN CpuIndex,
75 IN UINTN RegisterIndex,
76 IN UINTN Width,
77 OUT VOID *Buffer
78 )
79{
80 if (RegisterIndex == 0) {
81 return EFI_NOT_FOUND;
82 }
83
85 //
86 // If 32-bit mode width is zero, then the specified register can not be accessed
87 //
88 if (mCpuWidthOffset[RegisterIndex].Width32 == 0) {
89 return EFI_NOT_FOUND;
90 }
91
92 //
93 // If Width is bigger than the 32-bit mode width, then the specified register can not be accessed
94 //
95 if (Width > mCpuWidthOffset[RegisterIndex].Width32) {
96 return EFI_INVALID_PARAMETER;
97 }
98
99 //
100 // Write return buffer
101 //
102 ASSERT (gMmst->CpuSaveState[CpuIndex] != NULL);
103 CopyMem (Buffer, (UINT8 *)gMmst->CpuSaveState[CpuIndex] + mCpuWidthOffset[RegisterIndex].Offset32, Width);
104 } else {
105 //
106 // If 64-bit mode width is zero, then the specified register can not be accessed
107 //
108 if (mCpuWidthOffset[RegisterIndex].Width64 == 0) {
109 return EFI_NOT_FOUND;
110 }
111
112 //
113 // If Width is bigger than the 64-bit mode width, then the specified register can not be accessed
114 //
115 if (Width > mCpuWidthOffset[RegisterIndex].Width64) {
116 return EFI_INVALID_PARAMETER;
117 }
118
119 //
120 // Write lower 32-bits of return buffer
121 //
122 CopyMem (Buffer, (UINT8 *)gMmst->CpuSaveState[CpuIndex] + mCpuWidthOffset[RegisterIndex].Offset64Lo, MIN (4, Width));
123 if (Width > 4) {
124 //
125 // Write upper 32-bits of return buffer
126 //
127 CopyMem ((UINT8 *)Buffer + 4, (UINT8 *)gMmst->CpuSaveState[CpuIndex] + mCpuWidthOffset[RegisterIndex].Offset64Hi, Width - 4);
128 }
129 }
130
131 return EFI_SUCCESS;
132}
UINT64 UINTN
UINT8 MmSaveStateGetRegisterLma(VOID)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define MIN(a, b)
Definition: Base.h:1007
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define EFI_MM_SAVE_STATE_REGISTER_LMA_32BIT
Definition: MmCpu.h:113
EFI_MM_SAVE_STATE_REGISTER
Definition: MmCpu.h:25
@ EFI_MM_SAVE_STATE_REGISTER_GDTBASE
Definition: MmCpu.h:29
UINTN MmSaveStateGetRegisterIndex(IN EFI_MM_SAVE_STATE_REGISTER Register, IN UINTN RegOffset)
CONST CPU_MM_SAVE_STATE_LOOKUP_ENTRY mCpuWidthOffset[]
EFI_STATUS MmSaveStateReadRegisterByIndex(IN UINTN CpuIndex, IN UINTN RegisterIndex, IN UINTN Width, OUT VOID *Buffer)
EFI_STATUS EFIAPI Register(IN EFI_PEI_RSC_HANDLER_CALLBACK Callback)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
VOID ** CpuSaveState
Definition: PiMmCis.h:308