From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.71]) by mx.groups.io with SMTP id smtpd.web11.252.1652114108412887790 for ; Mon, 09 May 2022 09:35:09 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=linkxyuj; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: 40.107.92.71, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=F1JDfjDWcFL1vZSKfmVObrKfP7r+CgoXpQr2r6pwbyOevgelC2jCrWSAtAkXzSpqA5tG89cB00xxv4W+APRE4l5Vy6QVeJdJt2jZ7ae5/CRi4pPRY4jpKnH0d1idvDuO1rd+7/7sgdF1Ip6yehqmzfwY1HQSplcy+ll+pRaomeXL9l1OGYLqYBiMyKHLRE6jPL227p/+7PeRwROL56Y7NvL2SrtsTgElyAn+E8iRJ5cr8m5fiatv22ECapqeIYQP1FpvqLsmnJnGFkrvk9V5ebW00QWJxV2zrxXuCAzeg09HgQRbMOwVaRgEdloGcNG/OEQL3R/3vJT7XnYFdHn0nQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=tE8lNh/lQRUkD0RSvaqYx/yo9D5qmeR/di5v9mBwrXI=; b=goNUzx1scgjmNjzBnMCYe5PWu2rP7j/mfuEgBIQDCdNKmGxKCgm9aGo29bqiBJ0+1ZBZFute5ohSUoDs+ZPlm62nmNSVssOKko1erM7AcW4J9Gf3NLBEvLZ3iXjNOa7EcIF7Oky1jEHnIdZam+W7/qKiBe/coRPnnyEdhuJEZG6X3zXTh3rw/byR4dPsLC+t+mV+IDymX+NW74KJWBbmMHCryLsp8wM26KlqtDeWSHDUPN9uCHcL36MwkO7z8KIA0QI5OtI3RN+P+CYi5XlI1jXlDn+7tMr9qsn/ObJ4EaVErR5GRvUFUSra0ZZ7g/3k2x5T2onctA9TYb7iF5vtcg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tE8lNh/lQRUkD0RSvaqYx/yo9D5qmeR/di5v9mBwrXI=; b=linkxyujKa0QDuQM7vbUvUSuH/9mNvQ8Sm5u27j1S4KMQkrO9OjgENm/MP7CUqsVVv1DjUx/ueZ6QAtOM9TQqUWXJgjcPV1m8lJ7G3AxJu0iV+iZklyPFsC6y8uV+F4I+33rgZvn1CBRUJVBmNZcpkcGv4KV5ZyuBmUIoOtJJc8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from DM4PR12MB5229.namprd12.prod.outlook.com (2603:10b6:5:398::12) by DM4PR12MB5940.namprd12.prod.outlook.com (2603:10b6:8:6b::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5227.23; Mon, 9 May 2022 16:35:06 +0000 Received: from DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::db8:5b23:acf0:6f9a]) by DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::db8:5b23:acf0:6f9a%4]) with mapi id 15.20.5227.023; Mon, 9 May 2022 16:35:05 +0000 Message-ID: Date: Mon, 9 May 2022 11:35:03 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [edk2-devel] [PATCH 3/4] MpInitLib: Put SEV logic in separate file To: "Ni, Ray" Cc: "Dong, Eric" , "Kumar, Rahul1" , Michael Roth , "devel@edk2.groups.io" , "Xu, Min M" , "Yao, Jiewen" , "Justen, Jordan L" , Ard Biesheuvel , "Aktas, Erdem" , Gerd Hoffmann , James Bottomley References: <20220507151313.115-1-ray.ni@intel.com> <16ECDB685492F55B.14104@groups.io> From: "Lendacky, Thomas" In-Reply-To: X-ClientProxiedBy: SN7PR18CA0024.namprd18.prod.outlook.com (2603:10b6:806:f3::33) To DM4PR12MB5229.namprd12.prod.outlook.com (2603:10b6:5:398::12) Return-Path: Thomas.Lendacky@amd.com MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: db0c2e3c-10aa-4521-b1bf-08da31d9dfbd X-MS-TrafficTypeDiagnostic: DM4PR12MB5940:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EIgdypXVBBn8ToI38Hh1d0qURYFhdymwCMVJ1WDrzxqR59z6yRcRASBhcFnUkIz+hKj9KO/+tM/5y012REXrf/vA1T4kXRFEQtr55qDNEv6QEyKkv0lmZkXEJ/T9skZq1kKLVQNvsHbVo0Qx/nWvXKa8KdUG9jGQGduZojpE9xfl5n7DTbeASdW8pOamhQM49fQtWHr5hoxX2kMWC5ijO7JGN1lQXtyYbjHVlDPX2t1Z8u9IIDr9Kohyw+VZlcJ+W8c5aCTlRuKe3+5RMmxT/PuCFmaFFrUnbQwrr/m0jFViyzmTBkpS8A5sVA/vd9WU3gTUMkaE8JX4ZqDogkLBeghC3CAIiPsGblwimnhBUVAITQIvqqzBPbjvjS/WlkMAgZjQ48YO+biXtucDQzeF2LZ9IYVC2pxCnXUjDyGOShm8oL/u4GTmt5NF2P/wiEcsBGt6ApmZpSVp94nB2o1yQfFxnIGHhYELJBrJ9mqGjJozSMmoMxHe2J7mw5JVb11B/97Dy1AFdTwcUVqiRF915ttzbGDkNR47EF2i2V1vtsl82ty6A8K0NAtbH0FdpfTXZrcMqYgXX9ghMuagU26LWqf+NfTISOWxhJMH6e3H8mwqoQu2El8CqMu2zCdiI+13t8QhDettPqdVQYno8A1HqmVa9ffWf1Z3sNrI6Ic0GLQysr1TommIkK6XWQ5aLPX2Cl758igieq51n8aroPhevjjIzxZRnwPBo7omWErqdVU3iE+2J7BseP+8xXSXhxjlSmYZa/+L8FZr0llGYqej3g++pLwnouG4lDgEQquW8gtVRvfyou1uY0nNnOphS0jBzCkgk31JA2+7XezWdSTvJQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM4PR12MB5229.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(6029001)(4636009)(366004)(8936002)(38100700002)(31696002)(966005)(86362001)(6486002)(5660300002)(7416002)(53546011)(6506007)(316002)(19627235002)(54906003)(66476007)(66556008)(6916009)(66946007)(4326008)(8676002)(31686004)(508600001)(83380400001)(186003)(36756003)(2616005)(2906002)(26005)(30864003)(6512007)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?WWRWNVQvS2RvU09Qcmxmc21CSmx1ci9JMUxZTmFyUDV6M2E4Z25scXIxS2lo?= =?utf-8?B?dEJYNnM1V29EVnkxL25rdm9tdjNuemo3RitLbE1TejhkNkdSVm05MnBLOU0v?= =?utf-8?B?TVgyNllmMUZDYkJSYW5ITzRpd2dhS05pb0dHTTRtZ2NBLzRPeVkwNDdYMmM5?= =?utf-8?B?dlp4NXN3TVI1YURwVnluM3JQZ3p2bVlwZWFkT3A3VkNYYlFIdlhvamhRR3lC?= =?utf-8?B?Vkk3SUNuVGxta0c4cmFtS21GRTlsTH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8?B?S3BMaVdPSTVvdlVaYmIwRW5ac3JpVmt6TW4rYm1JbnRXNGx0OXZmaDlyb3hU?= =?utf-8?B?SHFwY1FNU3E2VEFueEtucW9Qajc3NjRkS3FDVDdPMkN0b1hqc3d3bWQvdDNR?= =?utf-8?B?cGdVVXNxL2J3Nm9xU1BuSTExUVhVL0NDQlZZcE4vS2wzVXZ4QXRMQUJzcGd4?= =?utf-8?B?RDg5RWJTaXF0eEdvMGdyRlFRREEyQ1lUOE82L1Z4b25nbHQ1SC9RNlpkakkz?= =?utf-8?B?MjlnWm0vbCtaL1VPdW9HSUJwSlJOQnJGMFp2S3RkZ0xuYktWNVd6Zz09?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: db0c2e3c-10aa-4521-b1bf-08da31d9dfbd X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5229.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 May 2022 16:35:05.9012 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: V7rSpziHAlnpD+WUzoRdBtj/oTJ7VI0aafY2MdUHKhd84KFijcjKRlUO5ssYcOSCdZVIkUHp0Ykf3j7f1NtH9g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5940 Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 5/9/22 06:54, Ni, Ray wrote: > Tom, > Can you please review this change? Does it cause any regression to SEV feature? Hi Ray, I just got back from vacation today and I'm going through all my email. I'll take a look as soon as I can. Thanks, Tom > >> -----Original Message----- >> From: devel@edk2.groups.io On Behalf Of Ni, Ray >> Sent: Saturday, May 7, 2022 11:13 PM >> To: devel@edk2.groups.io >> Cc: Dong, Eric ; Kumar, Rahul1 ; Michael Roth ; >> James Bottomley ; Xu, Min M ; Yao, Jiewen ; Tom >> Lendacky ; Justen, Jordan L ; Ard Biesheuvel >> ; Aktas, Erdem ; Gerd Hoffmann >> Subject: [edk2-devel] [PATCH 3/4] MpInitLib: Put SEV logic in separate file >> >> Signed-off-by: Ray Ni >> Cc: Eric Dong >> Cc: Ray Ni >> Cc: Rahul Kumar >> Cc: Michael Roth >> Cc: James Bottomley >> Cc: Min Xu >> Cc: Jiewen Yao >> Cc: Tom Lendacky >> Cc: Jordan Justen >> Cc: Ard Biesheuvel >> Cc: Erdem Aktas >> Cc: Gerd Hoffmann >> --- >> .../Library/MpInitLib/Ia32/MpFuncs.nasm | 3 +- >> UefiCpuPkg/Library/MpInitLib/MpLib.c | 13 +- >> UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm | 148 +++++++++++++++++ >> UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 157 +----------------- >> 4 files changed, 159 insertions(+), 162 deletions(-) >> >> diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm >> index 8981c32722..67f9ed05cf 100644 >> --- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm >> +++ b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm >> @@ -199,7 +199,6 @@ CProcedureInvoke: >> call eax ; Invoke C function >> >> >> >> jmp $ ; Never reach here >> >> -RendezvousFunnelProcEnd: >> >> >> >> ;------------------------------------------------------------------------------------- >> >> ;SwitchToRealProc procedure follows. >> >> @@ -209,6 +208,8 @@ SwitchToRealProcStart: >> jmp $ ; Never reach here >> >> SwitchToRealProcEnd: >> >> >> >> +RendezvousFunnelProcEnd: >> >> + >> >> ;------------------------------------------------------------------------------------- >> >> ; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfApStack, CountTofinish, Pm16CodeSegment, >> SevEsAPJumpTable, WakeupBuffer); >> >> ; >> >> diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c >> index 3dc1b9f872..722ff3fd42 100644 >> --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c >> +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c >> @@ -938,8 +938,7 @@ FillExchangeInfoData ( >> // EfiBootServicesCode to avoid page fault if NX memory protection is enabled. >> >> // >> >> if (CpuMpData->WakeupBufferHigh != 0) { >> >> - Size = CpuMpData->AddressMap.RendezvousFunnelSize + >> >> - CpuMpData->AddressMap.SwitchToRealSize - >> >> + Size = CpuMpData->AddressMap.RendezvousFunnelSize - >> >> CpuMpData->AddressMap.ModeTransitionOffset; >> >> CopyMem ( >> >> (VOID *)CpuMpData->WakeupBufferHigh, >> >> @@ -993,8 +992,7 @@ BackupAndPrepareWakeupBuffer ( >> CopyMem ( >> >> (VOID *)CpuMpData->WakeupBuffer, >> >> (VOID *)CpuMpData->AddressMap.RendezvousFunnelAddress, >> >> - CpuMpData->AddressMap.RendezvousFunnelSize + >> >> - CpuMpData->AddressMap.SwitchToRealSize >> >> + CpuMpData->AddressMap.RendezvousFunnelSize >> >> ); >> >> } >> >> >> >> @@ -1031,7 +1029,6 @@ GetApResetVectorSize ( >> UINTN Size; >> >> >> >> Size = AddressMap->RendezvousFunnelSize + >> >> - AddressMap->SwitchToRealSize + >> >> sizeof (MP_CPU_EXCHANGE_INFO); >> >> >> >> return Size; >> >> @@ -1056,11 +1053,9 @@ AllocateResetVector ( >> CpuMpData->WakeupBuffer = GetWakeupBuffer (ApResetVectorSize); >> >> CpuMpData->MpCpuExchangeInfo = (MP_CPU_EXCHANGE_INFO *)(UINTN) >> >> (CpuMpData->WakeupBuffer + >> >> - CpuMpData->AddressMap.RendezvousFunnelSize + >> >> - CpuMpData->AddressMap.SwitchToRealSize); >> >> + CpuMpData->AddressMap.RendezvousFunnelSize); >> >> CpuMpData->WakeupBufferHigh = AllocateCodeBuffer ( >> >> - CpuMpData->AddressMap.RendezvousFunnelSize + >> >> - CpuMpData->AddressMap.SwitchToRealSize - >> >> + CpuMpData->AddressMap.RendezvousFunnelSize - >> >> CpuMpData->AddressMap.ModeTransitionOffset >> >> ); >> >> // >> >> diff --git a/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm b/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm >> index 8bb1161fa0..7c2469f9c5 100644 >> --- a/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm >> +++ b/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm >> @@ -198,3 +198,151 @@ RestoreGhcb: >> >> >> SevEsGetApicIdExit: >> >> OneTimeCallRet SevEsGetApicId >> >> + >> >> + >> >> +;------------------------------------------------------------------------------------- >> >> +;SwitchToRealProc procedure follows. >> >> +;ALSO THIS PROCEDURE IS EXECUTED BY APs TRANSITIONING TO 16 BIT MODE. HENCE THIS PROC >> >> +;IS IN MACHINE CODE. >> >> +; SwitchToRealProc (UINTN BufferStart, UINT16 Code16, UINT16 Code32, UINTN StackStart) >> >> +; rcx - Buffer Start >> >> +; rdx - Code16 Selector Offset >> >> +; r8 - Code32 Selector Offset >> >> +; r9 - Stack Start >> >> +;------------------------------------------------------------------------------------- >> >> +SwitchToRealProcStart: >> >> +BITS 64 >> >> + cli >> >> + >> >> + ; >> >> + ; Get RDX reset value before changing stacks since the >> >> + ; new stack won't be able to accomodate a #VC exception. >> >> + ; >> >> + push rax >> >> + push rbx >> >> + push rcx >> >> + push rdx >> >> + >> >> + mov rax, 1 >> >> + cpuid >> >> + mov rsi, rax ; Save off the reset value for RDX >> >> + >> >> + pop rdx >> >> + pop rcx >> >> + pop rbx >> >> + pop rax >> >> + >> >> + ; >> >> + ; Establish stack below 1MB >> >> + ; >> >> + mov rsp, r9 >> >> + >> >> + ; >> >> + ; Push ultimate Reset Vector onto the stack >> >> + ; >> >> + mov rax, rcx >> >> + shr rax, 4 >> >> + push word 0x0002 ; RFLAGS >> >> + push ax ; CS >> >> + push word 0x0000 ; RIP >> >> + push word 0x0000 ; For alignment, will be discarded >> >> + >> >> + ; >> >> + ; Get address of "16-bit operand size" label >> >> + ; >> >> + lea rbx, [PM16Mode] >> >> + >> >> + ; >> >> + ; Push addresses used to change to compatibility mode >> >> + ; >> >> + lea rax, [CompatMode] >> >> + push r8 >> >> + push rax >> >> + >> >> + ; >> >> + ; Clear R8 - R15, for reset, before going into 32-bit mode >> >> + ; >> >> + xor r8, r8 >> >> + xor r9, r9 >> >> + xor r10, r10 >> >> + xor r11, r11 >> >> + xor r12, r12 >> >> + xor r13, r13 >> >> + xor r14, r14 >> >> + xor r15, r15 >> >> + >> >> + ; >> >> + ; Far return into 32-bit mode >> >> + ; >> >> + retfq >> >> + >> >> +BITS 32 >> >> +CompatMode: >> >> + ; >> >> + ; Set up stack to prepare for exiting protected mode >> >> + ; >> >> + push edx ; Code16 CS >> >> + push ebx ; PM16Mode label address >> >> + >> >> + ; >> >> + ; Disable paging >> >> + ; >> >> + mov eax, cr0 ; Read CR0 >> >> + btr eax, 31 ; Set PG=0 >> >> + mov cr0, eax ; Write CR0 >> >> + >> >> + ; >> >> + ; Disable long mode >> >> + ; >> >> + mov ecx, 0c0000080h ; EFER MSR number >> >> + rdmsr ; Read EFER >> >> + btr eax, 8 ; Set LME=0 >> >> + wrmsr ; Write EFER >> >> + >> >> + ; >> >> + ; Disable PAE >> >> + ; >> >> + mov eax, cr4 ; Read CR4 >> >> + btr eax, 5 ; Set PAE=0 >> >> + mov cr4, eax ; Write CR4 >> >> + >> >> + mov edx, esi ; Restore RDX reset value >> >> + >> >> + ; >> >> + ; Switch to 16-bit operand size >> >> + ; >> >> + retf >> >> + >> >> +BITS 16 >> >> + ; >> >> + ; At entry to this label >> >> + ; - RDX will have its reset value >> >> + ; - On the top of the stack >> >> + ; - Alignment data (two bytes) to be discarded >> >> + ; - IP for Real Mode (two bytes) >> >> + ; - CS for Real Mode (two bytes) >> >> + ; >> >> + ; This label is also used with AsmRelocateApLoop. During MP finalization, >> >> + ; the code from PM16Mode to SwitchToRealProcEnd is copied to the start of >> >> + ; the WakeupBuffer, allowing a parked AP to be booted by an OS. >> >> + ; >> >> +PM16Mode: >> >> + mov eax, cr0 ; Read CR0 >> >> + btr eax, 0 ; Set PE=0 >> >> + mov cr0, eax ; Write CR0 >> >> + >> >> + pop ax ; Discard alignment data >> >> + >> >> + ; >> >> + ; Clear registers (except RDX and RSP) before going into 16-bit mode >> >> + ; >> >> + xor eax, eax >> >> + xor ebx, ebx >> >> + xor ecx, ecx >> >> + xor esi, esi >> >> + xor edi, edi >> >> + xor ebp, ebp >> >> + >> >> + iret >> >> + >> >> +SwitchToRealProcEnd: >> >> diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm >> index d7e0e1fabd..53df478661 100644 >> --- a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm >> +++ b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm >> @@ -152,11 +152,6 @@ SkipEnable5LevelPaging: >> >> >> BITS 64 >> >> >> >> -; >> >> -; Required for the AMD SEV helper functions >> >> -; >> >> -%include "AmdSev.nasm" >> >> - >> >> LongModeStart: >> >> mov esi, ebx >> >> lea edi, [esi + MP_CPU_EXCHANGE_INFO_FIELD (InitFlag)] >> >> @@ -265,154 +260,12 @@ CProcedureInvoke: >> add rsp, 20h >> >> jmp $ ; Should never reach here >> >> >> >> -RendezvousFunnelProcEnd: >> >> - >> >> -;------------------------------------------------------------------------------------- >> >> -;SwitchToRealProc procedure follows. >> >> -;ALSO THIS PROCEDURE IS EXECUTED BY APs TRANSITIONING TO 16 BIT MODE. HENCE THIS PROC >> >> -;IS IN MACHINE CODE. >> >> -; SwitchToRealProc (UINTN BufferStart, UINT16 Code16, UINT16 Code32, UINTN StackStart) >> >> -; rcx - Buffer Start >> >> -; rdx - Code16 Selector Offset >> >> -; r8 - Code32 Selector Offset >> >> -; r9 - Stack Start >> >> -;------------------------------------------------------------------------------------- >> >> -SwitchToRealProcStart: >> >> -BITS 64 >> >> - cli >> >> - >> >> - ; >> >> - ; Get RDX reset value before changing stacks since the >> >> - ; new stack won't be able to accomodate a #VC exception. >> >> - ; >> >> - push rax >> >> - push rbx >> >> - push rcx >> >> - push rdx >> >> - >> >> - mov rax, 1 >> >> - cpuid >> >> - mov rsi, rax ; Save off the reset value for RDX >> >> - >> >> - pop rdx >> >> - pop rcx >> >> - pop rbx >> >> - pop rax >> >> - >> >> - ; >> >> - ; Establish stack below 1MB >> >> - ; >> >> - mov rsp, r9 >> >> - >> >> - ; >> >> - ; Push ultimate Reset Vector onto the stack >> >> - ; >> >> - mov rax, rcx >> >> - shr rax, 4 >> >> - push word 0x0002 ; RFLAGS >> >> - push ax ; CS >> >> - push word 0x0000 ; RIP >> >> - push word 0x0000 ; For alignment, will be discarded >> >> - >> >> - ; >> >> - ; Get address of "16-bit operand size" label >> >> - ; >> >> - lea rbx, [PM16Mode] >> >> - >> >> - ; >> >> - ; Push addresses used to change to compatibility mode >> >> - ; >> >> - lea rax, [CompatMode] >> >> - push r8 >> >> - push rax >> >> - >> >> - ; >> >> - ; Clear R8 - R15, for reset, before going into 32-bit mode >> >> - ; >> >> - xor r8, r8 >> >> - xor r9, r9 >> >> - xor r10, r10 >> >> - xor r11, r11 >> >> - xor r12, r12 >> >> - xor r13, r13 >> >> - xor r14, r14 >> >> - xor r15, r15 >> >> - >> >> - ; >> >> - ; Far return into 32-bit mode >> >> - ; >> >> - retfq >> >> - >> >> -BITS 32 >> >> -CompatMode: >> >> - ; >> >> - ; Set up stack to prepare for exiting protected mode >> >> - ; >> >> - push edx ; Code16 CS >> >> - push ebx ; PM16Mode label address >> >> - >> >> - ; >> >> - ; Disable paging >> >> - ; >> >> - mov eax, cr0 ; Read CR0 >> >> - btr eax, 31 ; Set PG=0 >> >> - mov cr0, eax ; Write CR0 >> >> - >> >> - ; >> >> - ; Disable long mode >> >> - ; >> >> - mov ecx, 0c0000080h ; EFER MSR number >> >> - rdmsr ; Read EFER >> >> - btr eax, 8 ; Set LME=0 >> >> - wrmsr ; Write EFER >> >> - >> >> - ; >> >> - ; Disable PAE >> >> - ; >> >> - mov eax, cr4 ; Read CR4 >> >> - btr eax, 5 ; Set PAE=0 >> >> - mov cr4, eax ; Write CR4 >> >> - >> >> - mov edx, esi ; Restore RDX reset value >> >> - >> >> - ; >> >> - ; Switch to 16-bit operand size >> >> - ; >> >> - retf >> >> - >> >> -BITS 16 >> >> - ; >> >> - ; At entry to this label >> >> - ; - RDX will have its reset value >> >> - ; - On the top of the stack >> >> - ; - Alignment data (two bytes) to be discarded >> >> - ; - IP for Real Mode (two bytes) >> >> - ; - CS for Real Mode (two bytes) >> >> - ; >> >> - ; This label is also used with AsmRelocateApLoop. During MP finalization, >> >> - ; the code from PM16Mode to SwitchToRealProcEnd is copied to the start of >> >> - ; the WakeupBuffer, allowing a parked AP to be booted by an OS. >> >> - ; >> >> -PM16Mode: >> >> - mov eax, cr0 ; Read CR0 >> >> - btr eax, 0 ; Set PE=0 >> >> - mov cr0, eax ; Write CR0 >> >> - >> >> - pop ax ; Discard alignment data >> >> - >> >> - ; >> >> - ; Clear registers (except RDX and RSP) before going into 16-bit mode >> >> - ; >> >> - xor eax, eax >> >> - xor ebx, ebx >> >> - xor ecx, ecx >> >> - xor esi, esi >> >> - xor edi, edi >> >> - xor ebp, ebp >> >> - >> >> - iret >> >> +; >> >> +; Required for the AMD SEV helper functions >> >> +; >> >> +%include "AmdSev.nasm" >> >> >> >> -SwitchToRealProcEnd: >> >> +RendezvousFunnelProcEnd: >> >> >> >> ;------------------------------------------------------------------------------------- >> >> ; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfApStack, CountTofinish, Pm16CodeSegment, >> SevEsAPJumpTable, WakeupBuffer); >> >> -- >> 2.32.0.windows.1 >> >> >> >> -=-=-=-=-=-= >> Groups.io Links: You receive all messages sent to this group. >> View/Reply Online (#89578): https://edk2.groups.io/g/devel/message/89578 >> Mute This Topic: https://groups.io/mt/90954628/1712937 >> Group Owner: devel+owner@edk2.groups.io >> Unsubscribe: https://edk2.groups.io/g/devel/unsub >> -=-=-=-=-=-= >> >