]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
UefiCpuPkg/MpInitLib: increase NumApsExecuting only for ApInitConfig
[mirror_edk2.git] / UefiCpuPkg / Library / MpInitLib / Ia32 / MpFuncs.nasm
index 7ab136be4f5d55ed7188ed508dad0f17e2e62b06..b74046b76af32fc8a0a6e8518a9255cac7d832b5 100644 (file)
@@ -1,12 +1,6 @@
 ;------------------------------------------------------------------------------ ;\r
-; Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
-; This program and the accompanying materials\r
-; are licensed and made available under the terms and conditions of the BSD License\r
-; which accompanies this distribution.  The full text of the license may be found at\r
-; http://opensource.org/licenses/bsd-license.php.\r
-;\r
-; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+; Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.<BR>\r
+; SPDX-License-Identifier: BSD-2-Clause-Patent\r
 ;\r
 ; Module Name:\r
 ;\r
@@ -48,34 +42,35 @@ BITS 16
     mov        si,  BufferStartLocation\r
     mov        ebx, [si]\r
 \r
-    mov        si,  ModeOffsetLocation\r
-    mov        eax, [si]\r
-    mov        si,  CodeSegmentLocation\r
-    mov        edx, [si]\r
-    mov        di,  ax\r
-    sub        di,  02h\r
-    mov        [di], dx\r
-    sub        di,  04h\r
-    add        eax, ebx\r
-    mov        [di],eax\r
-\r
     mov        si,  DataSegmentLocation\r
     mov        edx, [si]\r
 \r
+    ;\r
+    ; Get start address of 32-bit code in low memory (<1MB)\r
+    ;\r
+    mov        edi, ModeTransitionMemoryLocation\r
+\r
     mov        si, GdtrLocation\r
 o32 lgdt       [cs:si]\r
 \r
     mov        si, IdtrLocation\r
 o32 lidt       [cs:si]\r
 \r
-    xor        ax,  ax\r
-    mov        ds,  ax\r
-\r
+    ;\r
+    ; Switch to protected mode\r
+    ;\r
     mov        eax, cr0                        ; Get control register 0\r
     or         eax, 000000003h                 ; Set PE bit (bit #0) & MP\r
     mov        cr0, eax\r
 \r
-    jmp        0:strict dword 0                ; far jump to protected mode\r
+    ; Switch to 32-bit code in executable memory (>1MB)\r
+o32 jmp far    [cs:di]\r
+\r
+;\r
+; Following code may be copied to memory with type of EfiBootServicesCode.\r
+; This is required at DXE phase if NX is enabled for EfiBootServicesCode of\r
+; memory.\r
+;\r
 BITS 32\r
 Flat32Start:                                   ; protected mode entry point\r
     mov        ds, dx\r
@@ -119,6 +114,12 @@ SkipEnableExecuteDisable:
     cmp        dword [edi], 1       ; 1 == ApInitConfig\r
     jnz        GetApicId\r
 \r
+    ; Increment the number of APs executing here as early as possible\r
+    ; This is decremented in C code when AP is finished executing\r
+    mov        edi, esi\r
+    add        edi, NumApsExecutingLocation\r
+    lock inc   dword [edi]\r
+\r
     ; AP init\r
     mov        edi, esi\r
     add        edi, LockLocation\r
@@ -130,7 +131,7 @@ TestLock:
     jz         TestLock\r
 \r
     mov        ecx, esi\r
-    add        ecx, NumApsExecutingLocation\r
+    add        ecx, ApIndexLocation\r
     inc        dword [ecx]\r
     mov        ebx, [ecx]\r
 \r
@@ -186,11 +187,11 @@ GetNextProcNumber:
     jz          ProgramStack\r
     add         edi, 20\r
     inc         ebx\r
-    jmp         GetNextProcNumber    \r
+    jmp         GetNextProcNumber\r
 \r
 ProgramStack:\r
     mov         esp, [edi + 12]\r
-   \r
+\r
 CProcedureInvoke:\r
     push       ebp               ; push BIST data at top of AP stack\r
     xor        ebp, ebp          ; clear ebp for call stack trace\r
@@ -200,7 +201,7 @@ CProcedureInvoke:
     mov        eax, ASM_PFX(InitializeFloatingPointUnits)\r
     call       eax               ; Call assembly function to initialize FPU per UEFI spec\r
 \r
-    push       ebx               ; Push NumApsExecuting\r
+    push       ebx               ; Push ApIndex\r
     mov        eax, esi\r
     add        eax, LockLocation\r
     push       eax               ; push address of exchange info data buffer\r
@@ -215,7 +216,7 @@ CProcedureInvoke:
 RendezvousFunnelProcEnd:\r
 \r
 ;-------------------------------------------------------------------------------------\r
-;  AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfApStack);\r
+;  AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfApStack, CountTofinish);\r
 ;-------------------------------------------------------------------------------------\r
 global ASM_PFX(AsmRelocateApLoop)\r
 ASM_PFX(AsmRelocateApLoop):\r
@@ -227,9 +228,12 @@ AsmRelocateApLoopStart:
     mov        ebp, esp\r
     mov        ebx, [eax + 8]      ; ApTargetCState\r
     mov        ecx, [eax + 4]      ; MwaitSupport\r
+    mov        eax, [eax + 20]     ; CountTofinish\r
+    lock dec   dword [eax]         ; (*CountTofinish)--\r
     cmp        cl,  1              ; Check mwait-monitor support\r
     jnz        HltLoop\r
 MwaitLoop:\r
+    cli\r
     mov        eax, esp\r
     xor        ecx, ecx\r
     xor        edx, edx\r
@@ -242,7 +246,6 @@ HltLoop:
     cli\r
     hlt\r
     jmp        HltLoop\r
-    ret\r
 AsmRelocateApLoopEnd:\r
 \r
 ;-------------------------------------------------------------------------------------\r
@@ -259,6 +262,7 @@ ASM_PFX(AsmGetAddressMap):
     mov        dword [ebx +  8h], RendezvousFunnelProcEnd - RendezvousFunnelProcStart\r
     mov        dword [ebx + 0Ch], AsmRelocateApLoopStart\r
     mov        dword [ebx + 10h], AsmRelocateApLoopEnd - AsmRelocateApLoopStart\r
+    mov        dword [ebx + 14h], Flat32Start - RendezvousFunnelProcStart\r
 \r
     popad\r
     ret\r