From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.65]) by mx.groups.io with SMTP id smtpd.web11.4599.1652364785575238600 for ; Thu, 12 May 2022 07:13:05 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=05OzM2Rq; 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.223.65, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Cgt/SxjI3fbipn0oC3s6zFUB1YIIp2dZb1WeTmhe6r0Kqii83+EuZOEgEFz+Dp6wJnJBjJehhzLVq5BM7gO8OigkixU1Z0hFYwzGLS2rcRpnsJYvP0JuXoj0HknD7vUPy7U/et2UwYD/Opi4sGwXlfudGsgVvGoUiTT+wpN3ZeOFFIC7onMx9FYWZ/ZmPDm/ozv5hzYMhmZUaSZLn2uj/rHLTMDbCP6fb/AzifH3hWBf7EJ8wpBaoppoKezGRuQNKNiuL2UoJ+9c0ZYBq5Y1OezTrq6DLjhJEwaoRnpxNEpc0B1vC8SAiRi8dT76Ahw1fxfTfOMorsWEvizX2mpLjw== 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=ijY6TTSAr5NmHh2kHcIvJmhLicetPtqOpJZhlL1ni/Y=; b=W9gC0PYQ+CK9rPTxWr41y3iCdUDv9brupaKBAQsvnrWKcWY1K7NmlLSvsUiuonwe3fxiSkXyJAj8I6ObTiX9zt9itJsO7V9CkPXt3giIXq0AXesrvJ1964kHqme01EStD2fEyAYOh5lGOXEowiilmxezmeL8NSI8EnjrhSNvH/rbNd4y7HQQl3gRdc8MDOS5yvmxX/n/nUMg8PaDWY34HPv03wKeB5ddi42884cSbO2zYyIJRI7Kia1RInGjW75ojUOHYB7498KUtEnKJJgp5YGZF1P7kGhM6RsQnCbyMjInjxRnfNYwTNroo6KHASN+zH6rE7sBJLokpMKR6pnaiQ== 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=ijY6TTSAr5NmHh2kHcIvJmhLicetPtqOpJZhlL1ni/Y=; b=05OzM2Rqb7f99xSRfncP/OLHKvB3QK7xfZcndw1wLiKWuhwAFWwt/8mmByxUIHbY71GBqsOqH8oYQ/hi7jImghEHIh9kakfm91/BLCnsXq8rGmvXSMESNkahd31N7BUHe4jD/IN3HpLaJWZfBhDVCP5zaxQiMaNZXgdLajyA9F8= 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 BL1PR12MB5948.namprd12.prod.outlook.com (2603:10b6:208:39b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5227.23; Thu, 12 May 2022 14:13:03 +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.5250.014; Thu, 12 May 2022 14:13:03 +0000 Message-ID: <6951d2ae-2531-3cc5-bda6-73640c61de92@amd.com> Date: Thu, 12 May 2022 09:13:00 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: Re: [PATCH 3/4] MpInitLib: Put SEV logic in separate file To: Ray Ni , devel@edk2.groups.io Cc: Eric Dong , Rahul Kumar , Michael Roth , James Bottomley , Min Xu , Jiewen Yao , Jordan Justen , Ard Biesheuvel , Erdem Aktas , Gerd Hoffmann References: <20220507151313.115-1-ray.ni@intel.com> <20220507151313.115-4-ray.ni@intel.com> From: "Lendacky, Thomas" In-Reply-To: <20220507151313.115-4-ray.ni@intel.com> X-ClientProxiedBy: BL1P221CA0013.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:2c5::11) 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: e7b08afb-83dd-43ba-ae45-08da34218712 X-MS-TrafficTypeDiagnostic: BL1PR12MB5948: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: RNZVbGawIe3+E9Y83CS7bBcUhHk6GZZ9gwu9g9539CcGPJBH3pSDfsye/70hcOI13NUxH+S8iN/zaVpw/J5ReftC+JhOlMV+OtPo8vvNgdBSrEqn+Av6Z1V8q2HqVnYd2xi4HsbbJ+JyIYmPzo37H+8X/KBTozCHH8mhnnO0DIa1GuFFASdBDp6CElGMfMTzByjou3wBR8IPqV8vi0FFcntX3n9Twud573Ougb1V/KFkJIqHfuHjj530TAjWie9eKW5KMZE8MxI7CmYEvmzhEYTe6atUzLYcYF9Fx6JTa8Mnpd/gVdYC7kAk7+glN3pPbZyme6Yk9cygNOwN24OfRUT+EVnuXUeVkl0tu2yajOjnNX0WROVlyuiitJEZie3pQXb19SwsVUP8LFk7IqUaSyfKwCUKMRD5tVpvEKsusBu6oJbkqAlMkMX18M/eZIhrPZxWchKKQLeRh27yc41CGZAHqs15tQETEs4ARjF3Ye6nmKjwXGO5GcaiJHuVfv7TaYgwjJERGm+5nJVnVAzQh0hTh9hcJzuqx9t7/VIh6/NJKKJC4yaJldu+qEq+UuFioxYV4qUGEtZupcSDC3uuc/US9CwOtB3XQbchT33VA6mCXGFzH7T3HnzlNpmOBfEp1b0KeXrji/Yh22yY7A0wLgACdV5ZYop5qgYgnX5hOJdmMjj/oitbR2FQeqLbJbXJ9Y81uqELKFsvLh3dBIEjGHicswruhfskMPNnDq2y1k4Q//tZpaZjWmtWAhYfVmSP 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)(83380400001)(186003)(31686004)(6512007)(2906002)(2616005)(30864003)(26005)(36756003)(6486002)(86362001)(7416002)(8936002)(5660300002)(38100700002)(508600001)(31696002)(54906003)(66476007)(66556008)(66946007)(8676002)(4326008)(19627235002)(6506007)(53546011)(316002)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?U2FkTjVIN2FDc0x6anNlNk1pazdmZ3MxQkwwTUtEMEpOdGlpYXA2aXFvNUo3?= =?utf-8?B?bU9LVzZHZXVleThYZUMvT2ZocHJCSnF0cEhBV1FzaDVvQlJoWTQ0SHpzbExN?= =?utf-8?B?U3VwWHh5R1lnMGFFT0Q0VW5WU3A1SzRQdEZGRmsxdEJPUUhoeTB5VFdGbEJR?= =?utf-8?B?bnFNaFVDOVFKdTdsbExmMzhlOGxpMVhicWpwcmM0TmkvUWlIZmxOeHJtZlJD?= =?utf-8?B?NzQreGNyOFVBZlFjaWh1T0hTVWFtUitSYXhROU8rT3BuTE14RjFNaUQ4U0Rt?= =?utf-8?B?TVpsaFMwV05IR21oNTA4a0IvczFoTTA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yYkx3d3VKWFZDdUVEcmZLMlNKUkU4R003NmZZc2hXYXZEaDBXMEpZNE54?= =?utf-8?B?dWU1YTFuelErRzdWVTQyVnBMVG8zTUJBa21aZUJZVWhJZi9rUkhwK0IvWGZt?= =?utf-8?B?RUFpazY2VUIvRUszc2dwVWtxVE4wcWxJNUVmTDM5ellITG51Q1FQRkNkWGk0?= =?utf-8?B?OUNITDZqNDNvbFVPamFSSG9SUTZVeWFXSGV1M0hydVBpQ2xmWHJ5QT09?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e7b08afb-83dd-43ba-ae45-08da34218712 X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5229.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 May 2022 14:13:03.3090 (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: FG9Lg3bbTJnKGHATSQqm08x7C+6hAGEEzGI/wIazzNhFPs5T0NbOVtev8kEpgtsE2LLyb1uk2yzRBkG01hfIwQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5948 Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 5/7/22 10:13, Ray Ni wrote: Probably should have a commit message here explaining the reason for the changes. Overall, this works, but it does seem strange to have the SwitchToRealProc procedure in the middle of the RendezvousFunnelProc procedure. Not sure if it would be worth just creating a second SEV nasm file (and maybe renaming the first one): AmdSevRendevous.nasm AmdSevSwitchToReal.nasm and then including the two in different locations. Then you wouldn't have to change any of the size calculations either. If you want to keep the function within the function and eliminate the use of SwitchToRealSize, you should probably update the struct in MpLib.h to remove SwitchToRealSize and then update the Ia32 and X64 AsmGetAddressMap function to no longer set SwitchToRealSize (or just reserve the field so that none of the other offsets change and just remove the set in AsmGetAddressMap). Thanks, Tom > 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);