+; If SEV-ES is enabled then initialize and make the GHCB page shared\r
+SevClearPageEncMaskForGhcbPage:\r
+ ; Check if SEV is enabled\r
+ cmp byte[WORK_AREA_GUEST_TYPE], 1\r
+ jnz SevClearPageEncMaskForGhcbPageExit\r
+\r
+ ; Check if SEV-ES is enabled\r
+ cmp byte[SEV_ES_WORK_AREA], 1\r
+ jnz SevClearPageEncMaskForGhcbPageExit\r
+\r
+ ;\r
+ ; The initial GHCB will live at GHCB_BASE and needs to be un-encrypted.\r
+ ; This requires the 2MB page for this range be broken down into 512 4KB\r
+ ; pages. All will be marked encrypted, except for the GHCB.\r
+ ;\r
+ mov ecx, (GHCB_BASE >> 21)\r
+ mov eax, GHCB_PT_ADDR + PAGE_PDP_ATTR\r
+ mov [ecx * 8 + PT_ADDR (0x2000)], eax\r
+\r
+ ;\r
+ ; Page Table Entries (512 * 4KB entries => 2MB)\r
+ ;\r
+ mov ecx, 512\r
+pageTableEntries4kLoop:\r
+ mov eax, ecx\r
+ dec eax\r
+ shl eax, 12\r
+ add eax, GHCB_BASE & 0xFFE0_0000\r
+ add eax, PAGE_4K_PDE_ATTR\r
+ mov [ecx * 8 + GHCB_PT_ADDR - 8], eax\r
+ mov [(ecx * 8 + GHCB_PT_ADDR - 8) + 4], edx\r
+ loop pageTableEntries4kLoop\r
+\r
+ ;\r
+ ; Clear the encryption bit from the GHCB entry\r
+ ;\r
+ mov ecx, (GHCB_BASE & 0x1F_FFFF) >> 12\r
+ mov [ecx * 8 + GHCB_PT_ADDR + 4], strict dword 0\r
+\r
+ mov ecx, GHCB_SIZE / 4\r
+ xor eax, eax\r
+clearGhcbMemoryLoop:\r
+ mov dword[ecx * 4 + GHCB_BASE - 4], eax\r
+ loop clearGhcbMemoryLoop\r
+\r
+SevClearPageEncMaskForGhcbPageExit:\r
+ OneTimeCallRet SevClearPageEncMaskForGhcbPage\r
+\r
+; Check if SEV is enabled, and get the C-bit mask above 31.\r
+; Modified: EDX\r
+;\r
+; The value is returned in the EDX\r
+GetSevCBitMaskAbove31:\r
+ xor edx, edx\r
+\r
+ ; Check if SEV is enabled\r
+ cmp byte[WORK_AREA_GUEST_TYPE], 1\r
+ jnz GetSevCBitMaskAbove31Exit\r
+\r
+ mov edx, dword[SEV_ES_WORK_AREA_ENC_MASK + 4]\r
+\r
+GetSevCBitMaskAbove31Exit:\r
+ OneTimeCallRet GetSevCBitMaskAbove31\r
+\r