TianoCore EDK2 master
Loading...
Searching...
No Matches
CcExitLib.c
Go to the documentation of this file.
1
10#include <Base.h>
11#include <Uefi.h>
13#include <Library/CcExitLib.h>
14#include <Register/Amd/Msr.h>
15
30UINT64
32 IN GHCB *Ghcb
33 )
34{
36 GHCB_EXIT_INFO ExitInfo;
37 UINT64 Status;
38
39 ExitInfo.Uint64 = Ghcb->SaveArea.SwExitInfo1;
40 ASSERT (
41 (ExitInfo.Elements.Lower32Bits == 0) ||
42 (ExitInfo.Elements.Lower32Bits == 1)
43 );
44
45 Status = 0;
46 if (ExitInfo.Elements.Lower32Bits == 0) {
47 return Status;
48 }
49
50 if (ExitInfo.Elements.Lower32Bits == 1) {
51 ASSERT (Ghcb->SaveArea.SwExitInfo2 != 0);
52
53 //
54 // Check that the return event is valid
55 //
56 Event.Uint64 = Ghcb->SaveArea.SwExitInfo2;
57 if (Event.Elements.Valid &&
58 (Event.Elements.Type == GHCB_EVENT_INJECTION_TYPE_EXCEPTION))
59 {
60 switch (Event.Elements.Vector) {
61 case GP_EXCEPTION:
62 case UD_EXCEPTION:
63 //
64 // Use returned event as return code
65 //
66 Status = Event.Uint64;
67 }
68 }
69 }
70
71 if (Status == 0) {
73
74 GpEvent.Uint64 = 0;
75 GpEvent.Elements.Vector = GP_EXCEPTION;
76 GpEvent.Elements.Type = GHCB_EVENT_INJECTION_TYPE_EXCEPTION;
77 GpEvent.Elements.Valid = 1;
78
79 Status = GpEvent.Uint64;
80 }
81
82 return Status;
83}
84
104UINT64
105EFIAPI
107 IN OUT GHCB *Ghcb,
108 IN UINT64 ExitCode,
109 IN UINT64 ExitInfo1,
110 IN UINT64 ExitInfo2
111 )
112{
113 Ghcb->SaveArea.SwExitCode = ExitCode;
114 Ghcb->SaveArea.SwExitInfo1 = ExitInfo1;
115 Ghcb->SaveArea.SwExitInfo2 = ExitInfo2;
116
117 CcExitVmgSetOffsetValid (Ghcb, GhcbSwExitCode);
118 CcExitVmgSetOffsetValid (Ghcb, GhcbSwExitInfo1);
119 CcExitVmgSetOffsetValid (Ghcb, GhcbSwExitInfo2);
120
121 //
122 // Guest memory is used for the guest-hypervisor communication, so fence
123 // the invocation of the VMGEXIT instruction to ensure GHCB accesses are
124 // synchronized properly.
125 //
126 MemoryFence ();
127 AsmVmgExit ();
128 MemoryFence ();
129
130 return VmgExitErrorCheck (Ghcb);
131}
132
144VOID
145EFIAPI
147 IN OUT GHCB *Ghcb,
148 IN OUT BOOLEAN *InterruptState
149 )
150{
151 //
152 // Be sure that an interrupt can't cause a #VC while the GHCB is
153 // being used.
154 //
155 *InterruptState = GetInterruptState ();
156 if (*InterruptState) {
158 }
159
160 SetMem (&Ghcb->SaveArea, sizeof (Ghcb->SaveArea), 0);
161}
162
174VOID
175EFIAPI
177 IN OUT GHCB *Ghcb,
178 IN BOOLEAN InterruptState
179 )
180{
181 if (InterruptState) {
183 }
184}
185
196VOID
197EFIAPI
199 IN OUT GHCB *Ghcb,
200 IN GHCB_REGISTER Offset
201 )
202{
203 UINT32 OffsetIndex;
204 UINT32 OffsetBit;
205
206 OffsetIndex = Offset / 8;
207 OffsetBit = Offset % 8;
208
209 Ghcb->SaveArea.ValidBitmap[OffsetIndex] |= (1 << OffsetBit);
210}
211
225BOOLEAN
226EFIAPI
228 IN GHCB *Ghcb,
229 IN GHCB_REGISTER Offset
230 )
231{
232 UINT32 OffsetIndex;
233 UINT32 OffsetBit;
234
235 OffsetIndex = Offset / 8;
236 OffsetBit = Offset % 8;
237
238 return ((Ghcb->SaveArea.ValidBitmap[OffsetIndex] & (1 << OffsetBit)) != 0);
239}
#define STATIC
Definition: Base.h:264
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
BOOLEAN EFIAPI GetInterruptState(VOID)
Definition: CpuBreakpoint.c:86
VOID EFIAPI MemoryFence(VOID)
Definition: CpuBreakpoint.c:42
VOID EFIAPI EnableInterrupts(VOID)
Definition: CpuBreakpoint.c:67
VOID EFIAPI DisableInterrupts(VOID)
Definition: CpuBreakpoint.c:54
VOID *EFIAPI SetMem(OUT VOID *Buffer, IN UINTN Length, IN UINT8 Value)
Definition: SetMemWrapper.c:38
UINT64 EFIAPI CcExitVmgExit(IN OUT GHCB *Ghcb, IN UINT64 ExitCode, IN UINT64 ExitInfo1, IN UINT64 ExitInfo2)
Definition: CcExitLib.c:106
BOOLEAN EFIAPI CcExitVmgIsOffsetValid(IN GHCB *Ghcb, IN GHCB_REGISTER Offset)
Definition: CcExitLib.c:227
VOID EFIAPI CcExitVmgSetOffsetValid(IN OUT GHCB *Ghcb, IN GHCB_REGISTER Offset)
Definition: CcExitLib.c:198
VOID EFIAPI CcExitVmgInit(IN OUT GHCB *Ghcb, IN OUT BOOLEAN *InterruptState)
Definition: CcExitLib.c:146
VOID EFIAPI CcExitVmgDone(IN OUT GHCB *Ghcb, IN BOOLEAN InterruptState)
Definition: CcExitLib.c:176
STATIC UINT64 VmgExitErrorCheck(IN GHCB *Ghcb)
Definition: CcExitLib.c:31