]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / UefiCpuPkg / Library / MpInitLib / Ia32 / MpFuncs.nasm
index 1d67f510e93e770833786abd625c77cd4938fad8..59db4081d62f4ac1ee829430313b2fb916426676 100644 (file)
@@ -1,5 +1,5 @@
 ;------------------------------------------------------------------------------ ;\r
-; Copyright (c) 2015 - 2022, Intel Corporation. All rights reserved.<BR>\r
+; Copyright (c) 2015 - 2023, Intel Corporation. All rights reserved.<BR>\r
 ; SPDX-License-Identifier: BSD-2-Clause-Patent\r
 ;\r
 ; Module Name:\r
@@ -179,6 +179,14 @@ ProgramStack:
     mov         esp, dword [edi + CPU_INFO_IN_HOB.ApTopOfStack]\r
 \r
 CProcedureInvoke:\r
+    ;\r
+    ; Reserve 4 bytes for CpuMpData.\r
+    ; When the AP wakes up again via INIT-SIPI-SIPI, push 0 will cause the existing CpuMpData to be overwritten with 0.\r
+    ; CpuMpData is filled in via InitializeApData() during the first time INIT-SIPI-SIPI,\r
+    ; while overwirrten may occurs when under ApInHltLoop but InitFlag is not set to ApInitConfig.\r
+    ; Therefore reservation is implemented by sub esp instead of push 0.\r
+    ;\r
+    sub        esp, 4\r
     push       ebp               ; push BIST data at top of AP stack\r
     xor        ebp, ebp          ; clear ebp for call stack trace\r
     push       ebp\r
@@ -211,24 +219,24 @@ SwitchToRealProcEnd:
 RendezvousFunnelProcEnd:\r
 \r
 ;-------------------------------------------------------------------------------------\r
-;  AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfApStack, CountTofinish, Pm16CodeSegment, SevEsAPJumpTable, WakeupBuffer);\r
+;  AsmRelocateApLoopGeneric (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfApStack, CountTofinish, Pm16CodeSegment, SevEsAPJumpTable, WakeupBuffer);\r
 ;\r
 ;  The last three parameters (Pm16CodeSegment, SevEsAPJumpTable and WakeupBuffer) are\r
 ;  specific to SEV-ES support and are not applicable on IA32.\r
 ;-------------------------------------------------------------------------------------\r
-AsmRelocateApLoopStart:\r
+AsmRelocateApLoopGenericStart:\r
     mov        eax, esp\r
-    mov        esp, [eax + 16]     ; TopOfApStack\r
+    mov        esp, [eax + 12]     ; TopOfApStack\r
     push       dword [eax]         ; push return address for stack trace\r
     push       ebp\r
     mov        ebp, esp\r
     mov        ebx, [eax + 8]      ; ApTargetCState\r
     mov        ecx, [eax + 4]      ; MwaitSupport\r
-    mov        eax, [eax + 20]     ; CountTofinish\r
+    mov        eax, [eax + 16]     ; CountTofinish\r
     lock dec   dword [eax]         ; (*CountTofinish)--\r
     cmp        cl,  1              ; Check mwait-monitor support\r
-    jnz        HltLoop\r
-MwaitLoop:\r
+    jnz        HltLoopGeneric\r
+MwaitLoopGeneric:\r
     cli\r
     mov        eax, esp\r
     xor        ecx, ecx\r
@@ -237,12 +245,12 @@ MwaitLoop:
     mov        eax, ebx            ; Mwait Cx, Target C-State per eax[7:4]\r
     shl        eax, 4\r
     mwait\r
-    jmp        MwaitLoop\r
-HltLoop:\r
+    jmp        MwaitLoopGeneric\r
+HltLoopGeneric:\r
     cli\r
     hlt\r
-    jmp        HltLoop\r
-AsmRelocateApLoopEnd:\r
+    jmp        HltLoopGeneric\r
+AsmRelocateApLoopGenericEnd:\r
 \r
 ;-------------------------------------------------------------------------------------\r
 ;  AsmGetAddressMap (&AddressMap);\r
@@ -256,8 +264,8 @@ ASM_PFX(AsmGetAddressMap):
     mov        dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.RendezvousFunnelAddress], RendezvousFunnelProcStart\r
     mov        dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.ModeEntryOffset], Flat32Start - RendezvousFunnelProcStart\r
     mov        dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.RendezvousFunnelSize], RendezvousFunnelProcEnd - RendezvousFunnelProcStart\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.RelocateApLoopFuncAddressGeneric], AsmRelocateApLoopGenericStart\r
+    mov        dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.RelocateApLoopFuncSizeGeneric], AsmRelocateApLoopGenericEnd - AsmRelocateApLoopGenericStart\r
     mov        dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.ModeTransitionOffset], Flat32Start - RendezvousFunnelProcStart\r
     mov        dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealNoNxOffset], SwitchToRealProcStart - Flat32Start\r
     mov        dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealPM16ModeOffset], 0\r