call eax ; Invoke C function\r
\r
jmp $ ; Never reach here\r
-RendezvousFunnelProcEnd:\r
\r
;-------------------------------------------------------------------------------------\r
;SwitchToRealProc procedure follows.\r
jmp $ ; Never reach here\r
SwitchToRealProcEnd:\r
\r
+RendezvousFunnelProcEnd:\r
+\r
;-------------------------------------------------------------------------------------\r
; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfApStack, CountTofinish, Pm16CodeSegment, SevEsAPJumpTable, WakeupBuffer);\r
;\r
mov dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.RelocateApLoopFuncAddress], AsmRelocateApLoopStart\r
mov dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.RelocateApLoopFuncSize], AsmRelocateApLoopEnd - AsmRelocateApLoopStart\r
mov dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.ModeTransitionOffset], Flat32Start - RendezvousFunnelProcStart\r
- mov dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealSize], SwitchToRealProcEnd - SwitchToRealProcStart\r
- mov dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealOffset], SwitchToRealProcStart - RendezvousFunnelProcStart\r
mov dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealNoNxOffset], SwitchToRealProcStart - Flat32Start\r
mov dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealPM16ModeOffset], 0\r
mov dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealPM16ModeSize], 0\r
;------------------------------------------------------------------------------ ;\r
-; Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.<BR>\r
+; Copyright (c) 2015 - 2022, Intel Corporation. All rights reserved.<BR>\r
; SPDX-License-Identifier: BSD-2-Clause-Patent\r
;\r
; Module Name:\r
.RelocateApLoopFuncAddress CTYPE_UINTN 1\r
.RelocateApLoopFuncSize CTYPE_UINTN 1\r
.ModeTransitionOffset CTYPE_UINTN 1\r
- .SwitchToRealSize CTYPE_UINTN 1\r
- .SwitchToRealOffset CTYPE_UINTN 1\r
.SwitchToRealNoNxOffset CTYPE_UINTN 1\r
.SwitchToRealPM16ModeOffset CTYPE_UINTN 1\r
.SwitchToRealPM16ModeSize CTYPE_UINTN 1\r
// EfiBootServicesCode to avoid page fault if NX memory protection is enabled.\r
//\r
if (CpuMpData->WakeupBufferHigh != 0) {\r
- Size = CpuMpData->AddressMap.RendezvousFunnelSize +\r
- CpuMpData->AddressMap.SwitchToRealSize -\r
+ Size = CpuMpData->AddressMap.RendezvousFunnelSize -\r
CpuMpData->AddressMap.ModeTransitionOffset;\r
CopyMem (\r
(VOID *)CpuMpData->WakeupBufferHigh,\r
CopyMem (\r
(VOID *)CpuMpData->WakeupBuffer,\r
(VOID *)CpuMpData->AddressMap.RendezvousFunnelAddress,\r
- CpuMpData->AddressMap.RendezvousFunnelSize +\r
- CpuMpData->AddressMap.SwitchToRealSize\r
+ CpuMpData->AddressMap.RendezvousFunnelSize\r
);\r
}\r
\r
UINTN Size;\r
\r
Size = AddressMap->RendezvousFunnelSize +\r
- AddressMap->SwitchToRealSize +\r
sizeof (MP_CPU_EXCHANGE_INFO);\r
\r
return Size;\r
CpuMpData->WakeupBuffer = GetWakeupBuffer (ApResetVectorSize);\r
CpuMpData->MpCpuExchangeInfo = (MP_CPU_EXCHANGE_INFO *)(UINTN)\r
(CpuMpData->WakeupBuffer +\r
- CpuMpData->AddressMap.RendezvousFunnelSize +\r
- CpuMpData->AddressMap.SwitchToRealSize);\r
+ CpuMpData->AddressMap.RendezvousFunnelSize);\r
CpuMpData->WakeupBufferHigh = AllocateCodeBuffer (\r
- CpuMpData->AddressMap.RendezvousFunnelSize +\r
- CpuMpData->AddressMap.SwitchToRealSize -\r
+ CpuMpData->AddressMap.RendezvousFunnelSize -\r
CpuMpData->AddressMap.ModeTransitionOffset\r
);\r
//\r
/** @file\r
Common header file for MP Initialize Library.\r
\r
- Copyright (c) 2016 - 2021, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2016 - 2022, Intel Corporation. All rights reserved.<BR>\r
Copyright (c) 2020, AMD Inc. All rights reserved.<BR>\r
\r
SPDX-License-Identifier: BSD-2-Clause-Patent\r
UINT8 *RelocateApLoopFuncAddress;\r
UINTN RelocateApLoopFuncSize;\r
UINTN ModeTransitionOffset;\r
- UINTN SwitchToRealSize;\r
- UINTN SwitchToRealOffset;\r
UINTN SwitchToRealNoNxOffset;\r
UINTN SwitchToRealPM16ModeOffset;\r
UINTN SwitchToRealPM16ModeSize;\r
\r
SevEsGetApicIdExit:\r
OneTimeCallRet SevEsGetApicId\r
+\r
+\r
+;-------------------------------------------------------------------------------------\r
+;SwitchToRealProc procedure follows.\r
+;ALSO THIS PROCEDURE IS EXECUTED BY APs TRANSITIONING TO 16 BIT MODE. HENCE THIS PROC\r
+;IS IN MACHINE CODE.\r
+; SwitchToRealProc (UINTN BufferStart, UINT16 Code16, UINT16 Code32, UINTN StackStart)\r
+; rcx - Buffer Start\r
+; rdx - Code16 Selector Offset\r
+; r8 - Code32 Selector Offset\r
+; r9 - Stack Start\r
+;-------------------------------------------------------------------------------------\r
+SwitchToRealProcStart:\r
+BITS 64\r
+ cli\r
+\r
+ ;\r
+ ; Get RDX reset value before changing stacks since the\r
+ ; new stack won't be able to accomodate a #VC exception.\r
+ ;\r
+ push rax\r
+ push rbx\r
+ push rcx\r
+ push rdx\r
+\r
+ mov rax, 1\r
+ cpuid\r
+ mov rsi, rax ; Save off the reset value for RDX\r
+\r
+ pop rdx\r
+ pop rcx\r
+ pop rbx\r
+ pop rax\r
+\r
+ ;\r
+ ; Establish stack below 1MB\r
+ ;\r
+ mov rsp, r9\r
+\r
+ ;\r
+ ; Push ultimate Reset Vector onto the stack\r
+ ;\r
+ mov rax, rcx\r
+ shr rax, 4\r
+ push word 0x0002 ; RFLAGS\r
+ push ax ; CS\r
+ push word 0x0000 ; RIP\r
+ push word 0x0000 ; For alignment, will be discarded\r
+\r
+ ;\r
+ ; Get address of "16-bit operand size" label\r
+ ;\r
+ lea rbx, [PM16Mode]\r
+\r
+ ;\r
+ ; Push addresses used to change to compatibility mode\r
+ ;\r
+ lea rax, [CompatMode]\r
+ push r8\r
+ push rax\r
+\r
+ ;\r
+ ; Clear R8 - R15, for reset, before going into 32-bit mode\r
+ ;\r
+ xor r8, r8\r
+ xor r9, r9\r
+ xor r10, r10\r
+ xor r11, r11\r
+ xor r12, r12\r
+ xor r13, r13\r
+ xor r14, r14\r
+ xor r15, r15\r
+\r
+ ;\r
+ ; Far return into 32-bit mode\r
+ ;\r
+ retfq\r
+\r
+BITS 32\r
+CompatMode:\r
+ ;\r
+ ; Set up stack to prepare for exiting protected mode\r
+ ;\r
+ push edx ; Code16 CS\r
+ push ebx ; PM16Mode label address\r
+\r
+ ;\r
+ ; Disable paging\r
+ ;\r
+ mov eax, cr0 ; Read CR0\r
+ btr eax, 31 ; Set PG=0\r
+ mov cr0, eax ; Write CR0\r
+\r
+ ;\r
+ ; Disable long mode\r
+ ;\r
+ mov ecx, 0c0000080h ; EFER MSR number\r
+ rdmsr ; Read EFER\r
+ btr eax, 8 ; Set LME=0\r
+ wrmsr ; Write EFER\r
+\r
+ ;\r
+ ; Disable PAE\r
+ ;\r
+ mov eax, cr4 ; Read CR4\r
+ btr eax, 5 ; Set PAE=0\r
+ mov cr4, eax ; Write CR4\r
+\r
+ mov edx, esi ; Restore RDX reset value\r
+\r
+ ;\r
+ ; Switch to 16-bit operand size\r
+ ;\r
+ retf\r
+\r
+BITS 16\r
+ ;\r
+ ; At entry to this label\r
+ ; - RDX will have its reset value\r
+ ; - On the top of the stack\r
+ ; - Alignment data (two bytes) to be discarded\r
+ ; - IP for Real Mode (two bytes)\r
+ ; - CS for Real Mode (two bytes)\r
+ ;\r
+ ; This label is also used with AsmRelocateApLoop. During MP finalization,\r
+ ; the code from PM16Mode to SwitchToRealProcEnd is copied to the start of\r
+ ; the WakeupBuffer, allowing a parked AP to be booted by an OS.\r
+ ;\r
+PM16Mode:\r
+ mov eax, cr0 ; Read CR0\r
+ btr eax, 0 ; Set PE=0\r
+ mov cr0, eax ; Write CR0\r
+\r
+ pop ax ; Discard alignment data\r
+\r
+ ;\r
+ ; Clear registers (except RDX and RSP) before going into 16-bit mode\r
+ ;\r
+ xor eax, eax\r
+ xor ebx, ebx\r
+ xor ecx, ecx\r
+ xor esi, esi\r
+ xor edi, edi\r
+ xor ebp, ebp\r
+\r
+ iret\r
+\r
+SwitchToRealProcEnd:\r
\r
BITS 64\r
\r
-;\r
-; Required for the AMD SEV helper functions\r
-;\r
-%include "AmdSev.nasm"\r
-\r
LongModeStart:\r
mov esi, ebx\r
lea edi, [esi + MP_CPU_EXCHANGE_INFO_FIELD (InitFlag)]\r
add rsp, 20h\r
jmp $ ; Should never reach here\r
\r
-RendezvousFunnelProcEnd:\r
-\r
-;-------------------------------------------------------------------------------------\r
-;SwitchToRealProc procedure follows.\r
-;ALSO THIS PROCEDURE IS EXECUTED BY APs TRANSITIONING TO 16 BIT MODE. HENCE THIS PROC\r
-;IS IN MACHINE CODE.\r
-; SwitchToRealProc (UINTN BufferStart, UINT16 Code16, UINT16 Code32, UINTN StackStart)\r
-; rcx - Buffer Start\r
-; rdx - Code16 Selector Offset\r
-; r8 - Code32 Selector Offset\r
-; r9 - Stack Start\r
-;-------------------------------------------------------------------------------------\r
-SwitchToRealProcStart:\r
-BITS 64\r
- cli\r
-\r
- ;\r
- ; Get RDX reset value before changing stacks since the\r
- ; new stack won't be able to accomodate a #VC exception.\r
- ;\r
- push rax\r
- push rbx\r
- push rcx\r
- push rdx\r
-\r
- mov rax, 1\r
- cpuid\r
- mov rsi, rax ; Save off the reset value for RDX\r
-\r
- pop rdx\r
- pop rcx\r
- pop rbx\r
- pop rax\r
-\r
- ;\r
- ; Establish stack below 1MB\r
- ;\r
- mov rsp, r9\r
-\r
- ;\r
- ; Push ultimate Reset Vector onto the stack\r
- ;\r
- mov rax, rcx\r
- shr rax, 4\r
- push word 0x0002 ; RFLAGS\r
- push ax ; CS\r
- push word 0x0000 ; RIP\r
- push word 0x0000 ; For alignment, will be discarded\r
-\r
- ;\r
- ; Get address of "16-bit operand size" label\r
- ;\r
- lea rbx, [PM16Mode]\r
-\r
- ;\r
- ; Push addresses used to change to compatibility mode\r
- ;\r
- lea rax, [CompatMode]\r
- push r8\r
- push rax\r
-\r
- ;\r
- ; Clear R8 - R15, for reset, before going into 32-bit mode\r
- ;\r
- xor r8, r8\r
- xor r9, r9\r
- xor r10, r10\r
- xor r11, r11\r
- xor r12, r12\r
- xor r13, r13\r
- xor r14, r14\r
- xor r15, r15\r
-\r
- ;\r
- ; Far return into 32-bit mode\r
- ;\r
- retfq\r
-\r
-BITS 32\r
-CompatMode:\r
- ;\r
- ; Set up stack to prepare for exiting protected mode\r
- ;\r
- push edx ; Code16 CS\r
- push ebx ; PM16Mode label address\r
-\r
- ;\r
- ; Disable paging\r
- ;\r
- mov eax, cr0 ; Read CR0\r
- btr eax, 31 ; Set PG=0\r
- mov cr0, eax ; Write CR0\r
-\r
- ;\r
- ; Disable long mode\r
- ;\r
- mov ecx, 0c0000080h ; EFER MSR number\r
- rdmsr ; Read EFER\r
- btr eax, 8 ; Set LME=0\r
- wrmsr ; Write EFER\r
-\r
- ;\r
- ; Disable PAE\r
- ;\r
- mov eax, cr4 ; Read CR4\r
- btr eax, 5 ; Set PAE=0\r
- mov cr4, eax ; Write CR4\r
-\r
- mov edx, esi ; Restore RDX reset value\r
-\r
- ;\r
- ; Switch to 16-bit operand size\r
- ;\r
- retf\r
-\r
-BITS 16\r
- ;\r
- ; At entry to this label\r
- ; - RDX will have its reset value\r
- ; - On the top of the stack\r
- ; - Alignment data (two bytes) to be discarded\r
- ; - IP for Real Mode (two bytes)\r
- ; - CS for Real Mode (two bytes)\r
- ;\r
- ; This label is also used with AsmRelocateApLoop. During MP finalization,\r
- ; the code from PM16Mode to SwitchToRealProcEnd is copied to the start of\r
- ; the WakeupBuffer, allowing a parked AP to be booted by an OS.\r
- ;\r
-PM16Mode:\r
- mov eax, cr0 ; Read CR0\r
- btr eax, 0 ; Set PE=0\r
- mov cr0, eax ; Write CR0\r
-\r
- pop ax ; Discard alignment data\r
-\r
- ;\r
- ; Clear registers (except RDX and RSP) before going into 16-bit mode\r
- ;\r
- xor eax, eax\r
- xor ebx, ebx\r
- xor ecx, ecx\r
- xor esi, esi\r
- xor edi, edi\r
- xor ebp, ebp\r
-\r
- iret\r
+;\r
+; Required for the AMD SEV helper functions\r
+;\r
+%include "AmdSev.nasm"\r
\r
-SwitchToRealProcEnd:\r
+RendezvousFunnelProcEnd:\r
\r
;-------------------------------------------------------------------------------------\r
; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfApStack, CountTofinish, Pm16CodeSegment, SevEsAPJumpTable, WakeupBuffer);\r
mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.RelocateApLoopFuncAddress], rax\r
mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.RelocateApLoopFuncSize], AsmRelocateApLoopEnd - AsmRelocateApLoopStart\r
mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.ModeTransitionOffset], Flat32Start - RendezvousFunnelProcStart\r
- mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealSize], SwitchToRealProcEnd - SwitchToRealProcStart\r
- mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealOffset], SwitchToRealProcStart - RendezvousFunnelProcStart\r
mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealNoNxOffset], SwitchToRealProcStart - Flat32Start\r
mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealPM16ModeOffset], PM16Mode - RendezvousFunnelProcStart\r
mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealPM16ModeSize], SwitchToRealProcEnd - PM16Mode\r