]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm
UefiCpuPkg/MpInitLib: Fix X64 XCODE5/NASM compatibility issues
[mirror_edk2.git] / UefiCpuPkg / Library / MpInitLib / X64 / MpFuncs.nasm
index 6a8794d83b5d37d3a0ba16629cc52aef9637014c..0b14a534668bb03557164ae90ec8b9e20d6bb758 100644 (file)
@@ -1,5 +1,5 @@
 ;------------------------------------------------------------------------------ ;\r
-; Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
+; Copyright (c) 2015 - 2017, 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
@@ -134,7 +134,7 @@ TestLock:
     cmp        rax, NotVacantFlag\r
     jz         TestLock\r
 \r
-    lea        ecx, [esi + InitFlagLocation]\r
+    lea        ecx, [esi + NumApsExecutingLocation]\r
     inc        dword [ecx]\r
     mov        ebx, [ecx]\r
 \r
@@ -158,21 +158,24 @@ GetApicId:
     mov        eax, 0\r
     cpuid\r
     cmp        eax, 0bh\r
-    jnb        X2Apic\r
+    jb         NoX2Apic             ; CPUID level below CPUID_EXTENDED_TOPOLOGY\r
+\r
+    mov        eax, 0bh\r
+    xor        ecx, ecx\r
+    cpuid\r
+    test       ebx, 0ffffh\r
+    jz         NoX2Apic             ; CPUID.0BH:EBX[15:0] is zero\r
+\r
+    ; Processor is x2APIC capable; 32-bit x2APIC ID is already in EDX\r
+    jmp        GetProcessorNumber\r
+\r
+NoX2Apic:\r
     ; Processor is not x2APIC capable, so get 8-bit APIC ID\r
     mov        eax, 1\r
     cpuid\r
     shr        ebx, 24\r
     mov        edx, ebx\r
-    jmp        GetProcessorNumber\r
 \r
-X2Apic:\r
-    ; Processor is x2APIC capable, so get 32-bit x2APIC ID\r
-    mov        eax, 0bh\r
-    xor        ecx, ecx\r
-    cpuid                   \r
-    ; edx save x2APIC ID\r
-    \r
 GetProcessorNumber:\r
     ;\r
     ; Get processor number for this AP\r
@@ -185,13 +188,12 @@ GetProcessorNumber:
 GetNextProcNumber:\r
     cmp         dword [edi], edx                      ; APIC ID match?\r
     jz          ProgramStack\r
-    add         edi, 16\r
+    add         edi, 20\r
     inc         ebx\r
     jmp         GetNextProcNumber    \r
 \r
 ProgramStack:\r
-    xor         rsp, rsp\r
-    mov         esp, dword [edi + 12]\r
+    mov         rsp, qword [edi + 12]\r
 \r
 CProcedureInvoke:\r
     push       rbp               ; Push BIST data at top of AP stack\r
@@ -199,7 +201,7 @@ CProcedureInvoke:
     push       rbp\r
     mov        rbp, rsp\r
 \r
-    mov        rax, ASM_PFX(InitializeFloatingPointUnits)\r
+    mov        rax, qword [esi + InitializeFloatingPointUnitsAddress]\r
     sub        rsp, 20h\r
     call       rax               ; Call assembly function to initialize FPU per UEFI spec\r
     add        rsp, 20h\r
@@ -220,11 +222,14 @@ CProcedureInvoke:
 RendezvousFunnelProcEnd:\r
 \r
 ;-------------------------------------------------------------------------------------\r
-;  AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment);\r
+;  AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfApStack, CountTofinish);\r
 ;-------------------------------------------------------------------------------------\r
 global ASM_PFX(AsmRelocateApLoop)\r
 ASM_PFX(AsmRelocateApLoop):\r
 AsmRelocateApLoopStart:\r
+    mov        rax, [rsp + 40]   ; CountTofinish\r
+    lock dec   dword [rax]       ; (*CountTofinish)--\r
+    mov        rsp, r9\r
     push       rcx\r
     push       rdx\r
 \r
@@ -261,15 +266,14 @@ MwaitLoop:
     xor        ecx, ecx           ; ecx = 0\r
     xor        edx, edx           ; edx = 0\r
     monitor\r
-    shl        ebx, 4\r
     mov        eax, ebx           ; Mwait Cx, Target C-State per eax[7:4]\r
+    shl        eax, 4\r
     mwait\r
     jmp        MwaitLoop\r
 HltLoop:\r
     cli\r
     hlt\r
     jmp        HltLoop\r
-    ret\r
 BITS 64\r
 AsmRelocateApLoopEnd:\r
 \r
@@ -278,11 +282,11 @@ AsmRelocateApLoopEnd:
 ;-------------------------------------------------------------------------------------\r
 global ASM_PFX(AsmGetAddressMap)\r
 ASM_PFX(AsmGetAddressMap):\r
-    mov        rax, ASM_PFX(RendezvousFunnelProc)\r
+    lea        rax, [ASM_PFX(RendezvousFunnelProc)]\r
     mov        qword [rcx], rax\r
     mov        qword [rcx +  8h], LongModeStart - RendezvousFunnelProcStart\r
     mov        qword [rcx + 10h], RendezvousFunnelProcEnd - RendezvousFunnelProcStart\r
-    mov        rax, ASM_PFX(AsmRelocateApLoop)\r
+    lea        rax, [ASM_PFX(AsmRelocateApLoop)]\r
     mov        qword [rcx + 18h], rax\r
     mov        qword [rcx + 20h], AsmRelocateApLoopEnd - AsmRelocateApLoopStart\r
     ret\r