29} SEV_ES_INSTRUCTION_MODE;
39} SEV_ES_INSTRUCTION_SIZE;
51} SEV_ES_INSTRUCTION_SEGMENT;
60} SEV_ES_INSTRUCTION_REP;
92 SEV_ES_INSTRUCTION_MODE Mode;
93 SEV_ES_INSTRUCTION_SIZE DataSize;
94 SEV_ES_INSTRUCTION_SIZE AddrSize;
95 BOOLEAN SegmentSpecified;
96 SEV_ES_INSTRUCTION_SEGMENT Segment;
97 SEV_ES_INSTRUCTION_REP RepMode;
109 BOOLEAN ModRmPresent;
117 UINTN DisplacementSize;
137typedef PACKED
struct {
147} SEV_SNP_CPUID_FUNCTION;
152typedef PACKED
struct {
156 SEV_SNP_CPUID_FUNCTION function[0];
252 InstructionData->DisplacementSize = Size;
253 InstructionData->Immediate += Size;
254 InstructionData->End += Size;
277 Ext = &InstructionData->Ext;
279 return ((InstructionData->Mode == LongMode64Bit) &&
280 (Ext->ModRm.Mod == 0) &&
281 (Ext->ModRm.Rm == 5) &&
282 (InstructionData->SibPresent ==
FALSE));
305 UINT64 EffectiveAddress;
307 Ext = &InstructionData->Ext;
308 EffectiveAddress = 0;
316 RipRelative = *(INT32 *)InstructionData->Displacement;
323 return Regs->Rip + (UINT64)RipRelative;
326 switch (Ext->ModRm.Mod) {
329 EffectiveAddress += (UINT64)(*(INT8 *)(InstructionData->Displacement));
332 switch (InstructionData->AddrSize) {
335 EffectiveAddress += (UINT64)(*(INT16 *)(InstructionData->Displacement));
339 EffectiveAddress += (UINT64)(*(INT32 *)(InstructionData->Displacement));
346 if (InstructionData->SibPresent) {
349 if (Ext->Sib.Index != 4) {
353 sizeof (Displacement)
355 Displacement *= (INT64)(1 << Ext->Sib.Scale);
360 EffectiveAddress += (UINT64)Displacement;
363 if ((Ext->Sib.Base != 5) || Ext->ModRm.Mod) {
367 EffectiveAddress += (UINT64)(*(INT32 *)(InstructionData->Displacement));
373 return EffectiveAddress;
398 RexPrefix = &InstructionData->RexPrefix;
399 Ext = &InstructionData->Ext;
400 ModRm = &InstructionData->ModRm;
401 Sib = &InstructionData->Sib;
403 InstructionData->ModRmPresent =
TRUE;
404 ModRm->Uint8 = *(InstructionData->End);
406 InstructionData->Displacement++;
407 InstructionData->Immediate++;
408 InstructionData->End++;
410 Ext->ModRm.Mod = ModRm->Bits.Mod;
411 Ext->ModRm.Reg = (RexPrefix->Bits.BitR << 3) | ModRm->Bits.Reg;
412 Ext->ModRm.Rm = (RexPrefix->Bits.BitB << 3) | ModRm->Bits.Rm;
416 if (Ext->ModRm.Mod == 3) {
419 if (ModRm->Bits.Rm == 4) {
420 InstructionData->SibPresent =
TRUE;
421 Sib->Uint8 = *(InstructionData->End);
423 InstructionData->Displacement++;
424 InstructionData->Immediate++;
425 InstructionData->End++;
427 Ext->Sib.Scale = Sib->Bits.Scale;
428 Ext->Sib.Index = (RexPrefix->Bits.BitX << 3) | Sib->Bits.Index;
429 Ext->Sib.Base = (RexPrefix->Bits.BitB << 3) | Sib->Bits.Base;
453 SEV_ES_INSTRUCTION_MODE Mode;
454 SEV_ES_INSTRUCTION_SIZE ModeDataSize;
455 SEV_ES_INSTRUCTION_SIZE ModeAddrSize;
461 Mode = LongMode64Bit;
462 ModeDataSize = Size32Bits;
463 ModeAddrSize = Size64Bits;
465 InstructionData->Mode = Mode;
466 InstructionData->DataSize = ModeDataSize;
467 InstructionData->AddrSize = ModeAddrSize;
469 InstructionData->Prefixes = InstructionData->Begin;
471 Byte = InstructionData->Prefixes;
472 for ( ; ; Byte++, InstructionData->PrefixSize++) {
478 if ((*Byte >= REX_PREFIX_START) && (*Byte <= REX_PREFIX_STOP)) {
479 InstructionData->RexPrefix.Uint8 = *Byte;
480 if ((*Byte & REX_64BIT_OPERAND_SIZE_MASK) != 0) {
481 InstructionData->DataSize = Size64Bits;
488 case OVERRIDE_SEGMENT_CS:
489 case OVERRIDE_SEGMENT_DS:
490 case OVERRIDE_SEGMENT_ES:
491 case OVERRIDE_SEGMENT_SS:
492 if (Mode != LongMode64Bit) {
493 InstructionData->SegmentSpecified =
TRUE;
494 InstructionData->Segment = (*Byte >> 3) & 3;
499 case OVERRIDE_SEGMENT_FS:
500 case OVERRIDE_SEGMENT_GS:
501 InstructionData->SegmentSpecified =
TRUE;
502 InstructionData->Segment = *Byte & 7;
505 case OVERRIDE_OPERAND_SIZE:
506 if (InstructionData->RexPrefix.Uint8 == 0) {
507 InstructionData->DataSize =
508 (Mode == LongMode64Bit) ? Size16Bits :
509 (Mode == LongModeCompat32Bit) ? Size16Bits :
510 (Mode == LongModeCompat16Bit) ? Size32Bits : 0;
515 case OVERRIDE_ADDRESS_SIZE:
516 InstructionData->AddrSize =
517 (Mode == LongMode64Bit) ? Size32Bits :
518 (Mode == LongModeCompat32Bit) ? Size16Bits :
519 (Mode == LongModeCompat16Bit) ? Size32Bits : 0;
526 InstructionData->RepMode = RepZ;
530 InstructionData->RepMode = RepNZ;
534 InstructionData->OpCodes = Byte;
535 InstructionData->OpCodeSize = (*Byte == TWO_BYTE_OPCODE_ESCAPE) ? 2 : 1;
537 InstructionData->End = Byte + InstructionData->OpCodeSize;
538 InstructionData->Displacement = InstructionData->End;
539 InstructionData->Immediate = InstructionData->End;
561 return (UINT64)(InstructionData->End - InstructionData->Begin);
584 SetMem (InstructionData,
sizeof (*InstructionData), 0);
585 InstructionData->Ghcb = Ghcb;
586 InstructionData->Begin = (UINT8 *)Regs->Rip;
587 InstructionData->End = (UINT8 *)Regs->Rip;
615 Status =
VmgExit (Ghcb, SVM_EXIT_UNSUPPORTED, Regs->ExceptionData, 0);
620 Event.Elements.Vector = GP_EXCEPTION;
621 Event.Elements.Type = GHCB_EVENT_INJECTION_TYPE_EXCEPTION;
622 Event.Elements.Valid = 1;
624 Status = Event.Uint64;
652 MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE State;
660 Address = MemoryAddress & ~(SIZE_4KB - 1);
670 if (State == MemEncryptSevAddressRangeUnencrypted) {
679 "MMIO using encrypted memory: %lx\n",
680 (UINT64)MemoryAddress
683 GpEvent.Elements.Vector = GP_EXCEPTION;
684 GpEvent.Elements.Type = GHCB_EVENT_INJECTION_TYPE_EXCEPTION;
685 GpEvent.Elements.Valid = 1;
687 return GpEvent.Uint64;
712 UINT64 ExitInfo1, ExitInfo2, Status;
715 UINT8 OpCode, SignByte;
720 OpCode = *(InstructionData->OpCodes);
721 if (OpCode == TWO_BYTE_OPCODE_ESCAPE) {
722 OpCode = *(InstructionData->OpCodes + 1);
736 Bytes = ((Bytes != 0) ? Bytes :
737 (InstructionData->DataSize == Size16Bits) ? 2 :
738 (InstructionData->DataSize == Size32Bits) ? 4 :
739 (InstructionData->DataSize == Size64Bits) ? 8 :
742 if (InstructionData->Ext.ModRm.Mod == 3) {
754 ExitInfo1 = InstructionData->Ext.RmData;
756 CopyMem (Ghcb->SharedBuffer, &InstructionData->Ext.RegData, Bytes);
758 Ghcb->SaveArea.SwScratch = (UINT64)Ghcb->SharedBuffer;
760 Status =
VmgExit (Ghcb, SVM_EXIT_MMIO_WRITE, ExitInfo1, ExitInfo2);
776 Bytes = ((Bytes != 0) ? Bytes :
777 (InstructionData->DataSize == Size16Bits) ? 2 :
778 (InstructionData->DataSize == Size32Bits) ? 4 :
779 (InstructionData->DataSize == Size64Bits) ? 8 :
782 InstructionData->ImmediateSize = (
UINTN)(1 << InstructionData->AddrSize);
783 InstructionData->End += InstructionData->ImmediateSize;
790 sizeof (
UINTN) ==
sizeof (UINT64),
791 "sizeof (UINTN) != sizeof (UINT64), this file must be built as X64"
797 InstructionData->Immediate,
798 InstructionData->ImmediateSize
808 CopyMem (Ghcb->SharedBuffer, &Regs->Rax, Bytes);
810 Ghcb->SaveArea.SwScratch = (UINT64)Ghcb->SharedBuffer;
812 Status =
VmgExit (Ghcb, SVM_EXIT_MMIO_WRITE, ExitInfo1, ExitInfo2);
829 Bytes = ((Bytes != 0) ? Bytes :
830 (InstructionData->DataSize == Size16Bits) ? 2 :
831 (InstructionData->DataSize == Size32Bits) ? 4 :
834 InstructionData->ImmediateSize = Bytes;
835 InstructionData->End += Bytes;
842 ExitInfo1 = InstructionData->Ext.RmData;
844 CopyMem (Ghcb->SharedBuffer, InstructionData->Immediate, Bytes);
846 Ghcb->SaveArea.SwScratch = (UINT64)Ghcb->SharedBuffer;
848 Status =
VmgExit (Ghcb, SVM_EXIT_MMIO_WRITE, ExitInfo1, ExitInfo2);
865 Bytes = ((Bytes != 0) ? Bytes :
866 (InstructionData->DataSize == Size16Bits) ? 2 :
867 (InstructionData->DataSize == Size32Bits) ? 4 :
868 (InstructionData->DataSize == Size64Bits) ? 8 :
870 if (InstructionData->Ext.ModRm.Mod == 3) {
882 ExitInfo1 = InstructionData->Ext.RmData;
885 Ghcb->SaveArea.SwScratch = (UINT64)Ghcb->SharedBuffer;
887 Status =
VmgExit (Ghcb, SVM_EXIT_MMIO_READ, ExitInfo1, ExitInfo2);
912 Bytes = ((Bytes != 0) ? Bytes :
913 (InstructionData->DataSize == Size16Bits) ? 2 :
914 (InstructionData->DataSize == Size32Bits) ? 4 :
915 (InstructionData->DataSize == Size64Bits) ? 8 :
918 InstructionData->ImmediateSize = (
UINTN)(1 << InstructionData->AddrSize);
919 InstructionData->End += InstructionData->ImmediateSize;
926 sizeof (
UINTN) ==
sizeof (UINT64),
927 "sizeof (UINTN) != sizeof (UINT64), this file must be built as X64"
933 InstructionData->Immediate,
934 InstructionData->ImmediateSize
945 Ghcb->SaveArea.SwScratch = (UINT64)Ghcb->SharedBuffer;
947 Status =
VmgExit (Ghcb, SVM_EXIT_MMIO_READ, ExitInfo1, ExitInfo2);
959 CopyMem (&Regs->Rax, Ghcb->SharedBuffer, Bytes);
972 Bytes = (Bytes != 0) ? Bytes : 2;
979 ExitInfo1 = InstructionData->Ext.RmData;
982 Ghcb->SaveArea.SwScratch = (UINT64)Ghcb->SharedBuffer;
984 Status =
VmgExit (Ghcb, SVM_EXIT_MMIO_READ, ExitInfo1, ExitInfo2);
1004 Bytes = (Bytes != 0) ? Bytes : 2;
1011 ExitInfo1 = InstructionData->Ext.RmData;
1014 Ghcb->SaveArea.SwScratch = (UINT64)Ghcb->SharedBuffer;
1016 Status =
VmgExit (Ghcb, SVM_EXIT_MMIO_READ, ExitInfo1, ExitInfo2);
1024 Data = (UINT8 *)Ghcb->SharedBuffer;
1025 SignByte = ((*Data & BIT7) != 0) ? 0xFF : 0x00;
1029 Data = (UINT16 *)Ghcb->SharedBuffer;
1030 SignByte = ((*Data & BIT15) != 0) ? 0xFF : 0x00;
1039 DEBUG ((DEBUG_ERROR,
"Invalid MMIO opcode (%x)\n", OpCode));
1040 Status = GP_EXCEPTION;
1071 Ghcb->SaveArea.Rax = Regs->Rax;
1073 Ghcb->SaveArea.Rcx = Regs->Rcx;
1076 return VmgExit (Ghcb, SVM_EXIT_MWAIT, 0, 0);
1103 Ghcb->SaveArea.Rax = Regs->Rax;
1105 Ghcb->SaveArea.Rcx = Regs->Rcx;
1107 Ghcb->SaveArea.Rdx = Regs->Rdx;
1110 return VmgExit (Ghcb, SVM_EXIT_MONITOR, 0, 0);
1135 return VmgExit (Ghcb, SVM_EXIT_WBINVD, 0, 0);
1164 Status =
VmgExit (Ghcb, SVM_EXIT_RDTSCP, 0, 0);
1176 Regs->Rax = Ghcb->SaveArea.Rax;
1177 Regs->Rcx = Ghcb->SaveArea.Rcx;
1178 Regs->Rdx = Ghcb->SaveArea.Rdx;
1209 Ghcb->SaveArea.Rax = Regs->Rax;
1211 Ghcb->SaveArea.Cpl = (UINT8)(Regs->Cs & 0x3);
1214 Status =
VmgExit (Ghcb, SVM_EXIT_VMMCALL, 0, 0);
1223 Regs->Rax = Ghcb->SaveArea.Rax;
1250 UINT64 ExitInfo1, Status;
1254 switch (*(InstructionData->OpCodes + 1)) {
1257 Ghcb->SaveArea.Rax = Regs->Rax;
1259 Ghcb->SaveArea.Rdx = Regs->Rdx;
1265 Ghcb->SaveArea.Rcx = Regs->Rcx;
1272 Status =
VmgExit (Ghcb, SVM_EXIT_MSR, ExitInfo1, 0);
1277 if (ExitInfo1 == 0) {
1284 Regs->Rax = Ghcb->SaveArea.Rax;
1285 Regs->Rdx = Ghcb->SaveArea.Rdx;
1314 switch (*(InstructionData->OpCodes)) {
1320 ExitInfo |= IOIO_TYPE_INS;
1321 ExitInfo |= IOIO_SEG_ES;
1322 ExitInfo |= ((Regs->Rdx & 0xffff) << 16);
1330 ExitInfo |= IOIO_TYPE_OUTS;
1331 ExitInfo |= IOIO_SEG_DS;
1332 ExitInfo |= ((Regs->Rdx & 0xffff) << 16);
1340 InstructionData->ImmediateSize = 1;
1341 InstructionData->End++;
1342 ExitInfo |= IOIO_TYPE_IN;
1343 ExitInfo |= ((*(InstructionData->OpCodes + 1)) << 16);
1351 InstructionData->ImmediateSize = 1;
1352 InstructionData->End++;
1353 ExitInfo |= IOIO_TYPE_OUT;
1354 ExitInfo |= ((*(InstructionData->OpCodes + 1)) << 16) | IOIO_TYPE_OUT;
1362 ExitInfo |= IOIO_TYPE_IN;
1363 ExitInfo |= ((Regs->Rdx & 0xffff) << 16);
1371 ExitInfo |= IOIO_TYPE_OUT;
1372 ExitInfo |= ((Regs->Rdx & 0xffff) << 16);
1379 switch (*(InstructionData->OpCodes)) {
1389 ExitInfo |= IOIO_DATA_8;
1396 ExitInfo |= (InstructionData->DataSize == Size16Bits) ? IOIO_DATA_16
1400 switch (InstructionData->AddrSize) {
1402 ExitInfo |= IOIO_ADDR_16;
1406 ExitInfo |= IOIO_ADDR_32;
1410 ExitInfo |= IOIO_ADDR_64;
1417 if (InstructionData->RepMode != 0) {
1418 ExitInfo |= IOIO_REP;
1446 UINT64 ExitInfo1, ExitInfo2, Status;
1450 if (ExitInfo1 == 0) {
1454 IsString = ((ExitInfo1 & IOIO_TYPE_STR) != 0) ?
TRUE :
FALSE;
1456 UINTN IoBytes, VmgExitBytes;
1457 UINTN GhcbCount, OpCount;
1461 IoBytes = IOIO_DATA_BYTES (ExitInfo1);
1462 GhcbCount =
sizeof (Ghcb->SharedBuffer) / IoBytes;
1464 OpCount = ((ExitInfo1 & IOIO_REP) != 0) ? Regs->Rcx : 1;
1465 while (OpCount != 0) {
1466 ExitInfo2 =
MIN (OpCount, GhcbCount);
1467 VmgExitBytes = ExitInfo2 * IoBytes;
1469 if ((ExitInfo1 & IOIO_TYPE_IN) == 0) {
1470 CopyMem (Ghcb->SharedBuffer, (VOID *)Regs->Rsi, VmgExitBytes);
1471 Regs->Rsi += VmgExitBytes;
1474 Ghcb->SaveArea.SwScratch = (UINT64)Ghcb->SharedBuffer;
1476 Status =
VmgExit (Ghcb, SVM_EXIT_IOIO_PROT, ExitInfo1, ExitInfo2);
1481 if ((ExitInfo1 & IOIO_TYPE_IN) != 0) {
1482 CopyMem ((VOID *)Regs->Rdi, Ghcb->SharedBuffer, VmgExitBytes);
1483 Regs->Rdi += VmgExitBytes;
1486 if ((ExitInfo1 & IOIO_REP) != 0) {
1487 Regs->Rcx -= ExitInfo2;
1490 OpCount -= ExitInfo2;
1493 if ((ExitInfo1 & IOIO_TYPE_IN) != 0) {
1494 Ghcb->SaveArea.Rax = 0;
1496 CopyMem (&Ghcb->SaveArea.Rax, &Regs->Rax, IOIO_DATA_BYTES (ExitInfo1));
1501 Status =
VmgExit (Ghcb, SVM_EXIT_IOIO_PROT, ExitInfo1, 0);
1506 if ((ExitInfo1 & IOIO_TYPE_IN) != 0) {
1511 CopyMem (&Regs->Rax, &Ghcb->SaveArea.Rax, IOIO_DATA_BYTES (ExitInfo1));
1540 return VmgExit (Ghcb, SVM_EXIT_INVD, 0, 0);
1579 IN OUT UINT64 *Status,
1584 Ghcb->SaveArea.Rax = EaxIn;
1586 Ghcb->SaveArea.Rcx = EcxIn;
1589 Ghcb->SaveArea.XCr0 = XCr0;
1593 *Status =
VmgExit (Ghcb, SVM_EXIT_CPUID, 0, 0);
1608 *Eax = (UINT32)(
UINTN)Ghcb->SaveArea.Rax;
1612 *Ebx = (UINT32)(
UINTN)Ghcb->SaveArea.Rbx;
1616 *Ecx = (UINT32)(
UINTN)Ghcb->SaveArea.Rcx;
1620 *Edx = (UINT32)(
UINTN)Ghcb->SaveArea.Rdx;
1643 return !!Msr.Bits.SevSnpBit;
1666 IN UINT64 XFeaturesEnabled,
1667 IN UINT32 XSaveBaseSize,
1668 IN OUT UINT32 *XSaveSize,
1669 IN BOOLEAN Compacted
1672 SEV_SNP_CPUID_INFO *CpuidInfo;
1673 UINT64 XFeaturesFound = 0;
1676 *XSaveSize = XSaveBaseSize;
1677 CpuidInfo = (SEV_SNP_CPUID_INFO *)(UINT64)
PcdGet32 (PcdOvmfCpuidBase);
1679 for (Idx = 0; Idx < CpuidInfo->Count; Idx++) {
1680 SEV_SNP_CPUID_FUNCTION *CpuidFn = &CpuidInfo->function[Idx];
1682 if (!((CpuidFn->EaxIn == 0xD) &&
1683 ((CpuidFn->EcxIn == 0) || (CpuidFn->EcxIn == 1))))
1688 if (XFeaturesFound & (1ULL << CpuidFn->EcxIn) ||
1689 !(XFeaturesEnabled & (1ULL << CpuidFn->EcxIn)))
1694 XFeaturesFound |= (1ULL << CpuidFn->EcxIn);
1696 *XSaveSize += CpuidFn->Eax;
1698 *XSaveSize =
MAX (*XSaveSize, CpuidFn->Eax + CpuidFn->Ebx);
1706 if (XFeaturesFound != (XFeaturesEnabled & ~3UL)) {
1782 IN OUT UINT64 *Status,
1783 IN OUT BOOLEAN *Unsupported
1786 SEV_SNP_CPUID_INFO *CpuidInfo;
1790 CpuidInfo = (SEV_SNP_CPUID_INFO *)(UINT64)
PcdGet32 (PcdOvmfCpuidBase);
1793 for (Idx = 0; Idx < CpuidInfo->Count; Idx++) {
1794 SEV_SNP_CPUID_FUNCTION *CpuidFn = &CpuidInfo->function[Idx];
1796 if (CpuidFn->EaxIn != EaxIn) {
1804 *Eax = CpuidFn->Eax;
1805 *Ebx = CpuidFn->Ebx;
1806 *Ecx = CpuidFn->Ecx;
1807 *Edx = CpuidFn->Edx;
1814 *Eax = *Ebx = *Ecx = *Edx = 0;
1840 *Ebx = (*Ebx & 0x00FFFFFF) | (Ebx2 & 0xFF000000);
1842 *Edx = (*Edx & ~BIT9) | (Edx2 & BIT9);
1845 *Ecx = (Cr4.Bits.OSXSAVE) ? (*Ecx & ~BIT27) | (*Ecx & BIT27)
1852 *Ecx = (Cr4.Bits.PKE) ? (*Ecx | BIT4) : (*Ecx & ~BIT4);
1883 if (!(*Eax & (BIT3 | BIT1))) {
1903 }
else if (EaxIn == 0x8000001E) {
1925 *Ebx = (*Ebx & 0xFFFFFF00) | (Ebx2 & 0x000000FF);
1927 *Ecx = (*Ecx & 0xFFFFFF00) | (Ecx2 & 0x000000FF);
1932 *Unsupported =
FALSE;
1958 BOOLEAN Unsupported;
1968 EaxIn = (UINT32)(
UINTN)Regs->Rax;
1969 EcxIn = (UINT32)(
UINTN)Regs->Rcx;
1975 Ghcb->SaveArea.XCr0 = (Cr4.Bits.OSXSAVE == 1) ? AsmXGetBv (0) : 1;
1976 XCr0 = (Cr4.Bits.OSXSAVE == 1) ? AsmXGetBv (0) : 1;
2052 Ghcb->SaveArea.Rcx = Regs->Rcx;
2055 Status =
VmgExit (Ghcb, SVM_EXIT_RDPMC, 0, 0);
2066 Regs->Rax = Ghcb->SaveArea.Rax;
2067 Regs->Rdx = Ghcb->SaveArea.Rdx;
2096 Status =
VmgExit (Ghcb, SVM_EXIT_RDTSC, 0, 0);
2107 Regs->Rax = Ghcb->SaveArea.Rax;
2108 Regs->Rdx = Ghcb->SaveArea.Rdx;
2140 Ext = &InstructionData->Ext;
2156 Status =
VmgExit (Ghcb, SVM_EXIT_DR7_WRITE, 0, 0);
2162 SevEsData->Dr7Cached = 1;
2192 Ext = &InstructionData->Ext;
2206 *
Register = (SevEsData->Dr7Cached == 1) ? SevEsData->Dr7 : 0x400;
2239 UINT64 ExitCode, Status;
2241 BOOLEAN InterruptState;
2245 Regs = SystemContext.SystemContextX64;
2247 VmgInit (Ghcb, &InterruptState);
2249 ExitCode = Regs->ExceptionData;
2251 case SVM_EXIT_DR7_READ:
2255 case SVM_EXIT_DR7_WRITE:
2259 case SVM_EXIT_RDTSC:
2263 case SVM_EXIT_RDPMC:
2267 case SVM_EXIT_CPUID:
2275 case SVM_EXIT_IOIO_PROT:
2283 case SVM_EXIT_VMMCALL:
2287 case SVM_EXIT_RDTSCP:
2291 case SVM_EXIT_WBINVD:
2295 case SVM_EXIT_MONITOR:
2299 case SVM_EXIT_MWAIT:
2313 Status = NaeExit (Ghcb, Regs, &InstructionData);
2319 Event.Uint64 = Status;
2320 if (Event.Elements.ErrorCodeValid != 0) {
2321 Regs->ExceptionData = Event.Elements.ErrorCode;
2323 Regs->ExceptionData = 0;
2326 *ExceptionType = Event.Elements.Vector;
2328 VcRet = EFI_PROTOCOL_ERROR;
2331 VmgDone (Ghcb, InterruptState);
2352 SevEsData->VcCount = 0;
VOID EFIAPI CpuDeadLoop(VOID)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI SetMem(OUT VOID *Buffer, IN UINTN Length, IN UINT8 Value)
#define DEBUG(Expression)
#define ASSERT(Expression)
UINT64 EFIAPI AsmReadMsr64(IN UINT32 Index)
UINTN EFIAPI AsmReadCr4(VOID)
UINTN EFIAPI GetLocalApicBaseAddress(VOID)
#define CPUID_INTEL_PROCESSOR_TRACE
#define CPUID_DETERMINISTIC_ADDRESS_TRANSLATION_PARAMETERS
#define CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS
#define CPUID_CACHE_PARAMS
#define CPUID_INTEL_RDT_MONITORING
#define CPUID_VERSION_INFO
#define CPUID_EXTENDED_STATE
#define CPUID_EXTENDED_TOPOLOGY
#define CPUID_V2_EXTENDED_TOPOLOGY
#define CPUID_INTEL_RDT_ALLOCATION
MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE EFIAPI MemEncryptSevGetAddressRangeState(IN PHYSICAL_ADDRESS Cr3BaseAddress, IN PHYSICAL_ADDRESS BaseAddress, IN UINTN Length)
#define PcdGet32(TokenName)
EFI_STATUS EFIAPI Register(IN EFI_PEI_RSC_HANDLER_CALLBACK Callback)
VOID EFIAPI VmgSetOffsetValid(IN OUT GHCB *Ghcb, IN GHCB_REGISTER Offset)
BOOLEAN EFIAPI VmgIsOffsetValid(IN GHCB *Ghcb, IN GHCB_REGISTER Offset)
UINT64 EFIAPI VmgExit(IN OUT GHCB *Ghcb, IN UINT64 ExitCode, IN UINT64 ExitInfo1, IN UINT64 ExitInfo2)
VOID EFIAPI VmgInit(IN OUT GHCB *Ghcb, IN OUT BOOLEAN *InterruptState)
VOID EFIAPI VmgDone(IN OUT GHCB *Ghcb, IN BOOLEAN InterruptState)
STATIC UINT64 ValidateMmioMemory(IN GHCB *Ghcb, IN UINTN MemoryAddress, IN UINTN MemoryLength)
STATIC BOOLEAN SnpEnabled(VOID)
STATIC UINT64 RdtscpExit(IN OUT GHCB *Ghcb, IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, IN SEV_ES_INSTRUCTION_DATA *InstructionData)
STATIC UINT64 Dr7WriteExit(IN OUT GHCB *Ghcb, IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, IN SEV_ES_INSTRUCTION_DATA *InstructionData)
STATIC UINT64 MsrExit(IN OUT GHCB *Ghcb, IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, IN SEV_ES_INSTRUCTION_DATA *InstructionData)
STATIC UINT64 MwaitExit(IN OUT GHCB *Ghcb, IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, IN SEV_ES_INSTRUCTION_DATA *InstructionData)
STATIC UINT64 UnsupportedExit(IN GHCB *Ghcb, IN EFI_SYSTEM_CONTEXT_X64 *Regs, IN SEV_ES_INSTRUCTION_DATA *InstructionData)
STATIC UINT64 VmmCallExit(IN OUT GHCB *Ghcb, IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, IN SEV_ES_INSTRUCTION_DATA *InstructionData)
STATIC BOOLEAN GetCpuidXSaveSize(IN UINT64 XFeaturesEnabled, IN UINT32 XSaveBaseSize, IN OUT UINT32 *XSaveSize, IN BOOLEAN Compacted)
STATIC UINT64 * GetRegisterPointer(IN EFI_SYSTEM_CONTEXT_X64 *Regs, IN UINT8 Register)
STATIC UINT64 MonitorExit(IN OUT GHCB *Ghcb, IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, IN SEV_ES_INSTRUCTION_DATA *InstructionData)
STATIC UINT64 Dr7ReadExit(IN OUT GHCB *Ghcb, IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, IN SEV_ES_INSTRUCTION_DATA *InstructionData)
STATIC BOOLEAN GetCpuidHyp(IN OUT GHCB *Ghcb, IN UINT32 EaxIn, IN UINT32 EcxIn, IN UINT64 XCr0, IN OUT UINT32 *Eax, IN OUT UINT32 *Ebx, IN OUT UINT32 *Ecx, IN OUT UINT32 *Edx, IN OUT UINT64 *Status, IN OUT BOOLEAN *UnsupportedExit)
STATIC UINT64 CpuidExit(IN OUT GHCB *Ghcb, IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, IN SEV_ES_INSTRUCTION_DATA *InstructionData)
STATIC VOID DecodePrefixes(IN EFI_SYSTEM_CONTEXT_X64 *Regs, IN OUT SEV_ES_INSTRUCTION_DATA *InstructionData)
STATIC UINT64 InvdExit(IN OUT GHCB *Ghcb, IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, IN SEV_ES_INSTRUCTION_DATA *InstructionData)
STATIC UINT64 GetEffectiveMemoryAddress(IN EFI_SYSTEM_CONTEXT_X64 *Regs, IN SEV_ES_INSTRUCTION_DATA *InstructionData)
STATIC UINT64 RdpmcExit(IN OUT GHCB *Ghcb, IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, IN SEV_ES_INSTRUCTION_DATA *InstructionData)
STATIC VOID UpdateForDisplacement(IN OUT SEV_ES_INSTRUCTION_DATA *InstructionData, IN UINTN Size)
STATIC VOID InitInstructionData(IN OUT SEV_ES_INSTRUCTION_DATA *InstructionData, IN GHCB *Ghcb, IN EFI_SYSTEM_CONTEXT_X64 *Regs)
EFI_STATUS EFIAPI InternalVmgExitHandleVc(IN OUT GHCB *Ghcb, IN OUT EFI_EXCEPTION_TYPE *ExceptionType, IN OUT EFI_SYSTEM_CONTEXT SystemContext)
STATIC BOOLEAN IsRipRelative(IN SEV_ES_INSTRUCTION_DATA *InstructionData)
VOID EFIAPI VmgExitIssueAssert(IN OUT SEV_ES_PER_CPU_DATA *SevEsData)
STATIC BOOLEAN IsFunctionIndexed(IN UINT32 EaxIn)
STATIC UINT64 MmioExit(IN OUT GHCB *Ghcb, IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, IN OUT SEV_ES_INSTRUCTION_DATA *InstructionData)
STATIC BOOLEAN GetCpuidFw(IN OUT GHCB *Ghcb, IN UINT32 EaxIn, IN UINT32 EcxIn, IN UINT64 XCr0, IN OUT UINT32 *Eax, IN OUT UINT32 *Ebx, IN OUT UINT32 *Ecx, IN OUT UINT32 *Edx, IN OUT UINT64 *Status, IN OUT BOOLEAN *Unsupported)
STATIC UINT64 IoioExit(IN OUT GHCB *Ghcb, IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, IN SEV_ES_INSTRUCTION_DATA *InstructionData)
STATIC UINT64 RdtscExit(IN OUT GHCB *Ghcb, IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, IN SEV_ES_INSTRUCTION_DATA *InstructionData)
STATIC UINT64 WbinvdExit(IN OUT GHCB *Ghcb, IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, IN SEV_ES_INSTRUCTION_DATA *InstructionData)
STATIC UINT64 IoioExitInfo(IN EFI_SYSTEM_CONTEXT_X64 *Regs, IN OUT SEV_ES_INSTRUCTION_DATA *InstructionData)
STATIC VOID DecodeModRm(IN EFI_SYSTEM_CONTEXT_X64 *Regs, IN OUT SEV_ES_INSTRUCTION_DATA *InstructionData)
STATIC UINT64 InstructionLength(IN SEV_ES_INSTRUCTION_DATA *InstructionData)
UINT32 EFIAPI AsmReadMsr32(IN UINT32 Index)