2 X64 #VC Exception Handler functon.
4 Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/BaseMemoryLib.h>
12 #include <Library/VmgExitLib.h>
13 #include <Register/Amd/Msr.h>
16 Handle a #VC exception.
18 Performs the necessary processing to handle a #VC exception.
20 @param[in, out] ExceptionType Pointer to an EFI_EXCEPTION_TYPE to be set
21 as value to use on error.
22 @param[in, out] SystemContext Pointer to EFI_SYSTEM_CONTEXT
24 @retval EFI_SUCCESS Exception handled
25 @retval EFI_UNSUPPORTED #VC not supported, (new) exception value to
27 @retval EFI_PROTOCOL_ERROR #VC handling failed, (new) exception value to
34 IN OUT EFI_EXCEPTION_TYPE
*ExceptionType
,
35 IN OUT EFI_SYSTEM_CONTEXT SystemContext
38 MSR_SEV_ES_GHCB_REGISTER Msr
;
39 EFI_SYSTEM_CONTEXT_X64
*Regs
;
41 UINT64 ExitCode
, Status
;
46 Msr
.GhcbPhysicalAddress
= AsmReadMsr64 (MSR_SEV_ES_GHCB
);
47 ASSERT (Msr
.GhcbInfo
.Function
== 0);
48 ASSERT (Msr
.Ghcb
!= 0);
50 Regs
= SystemContext
.SystemContextX64
;
55 ExitCode
= Regs
->ExceptionData
;
58 Status
= VmgExit (Ghcb
, SVM_EXIT_UNSUPPORTED
, ExitCode
, 0);
60 Regs
->ExceptionData
= 0;
61 *ExceptionType
= GP_EXCEPTION
;
63 GHCB_EVENT_INJECTION Event
;
65 Event
.Uint64
= Status
;
66 if (Event
.Elements
.ErrorCodeValid
!= 0) {
67 Regs
->ExceptionData
= Event
.Elements
.ErrorCode
;
69 Regs
->ExceptionData
= 0;
72 *ExceptionType
= Event
.Elements
.Vector
;
75 VcRet
= EFI_PROTOCOL_ERROR
;