]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
UefiCpuPkg: Clean up source files
[mirror_edk2.git] / UefiCpuPkg / Library / MpInitLib / Ia32 / MpFuncs.nasm
index 64e51d87ae2462155ec4e34a2c4d69bb37345381..2f60c478d72d751643d2a224ae2d6e098fff4b5d 100644 (file)
@@ -1,5 +1,5 @@
 ;------------------------------------------------------------------------------ ;\r
-; Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
+; Copyright (c) 2015 - 2018, 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
@@ -48,34 +48,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
@@ -86,6 +87,12 @@ Flat32Start:                                   ; protected mode entry point
 \r
     mov        esi, ebx\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
     mov         edi, esi\r
     add         edi, EnableExecuteDisableLocation\r
     cmp         byte [edi], 0\r
@@ -130,7 +137,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
@@ -154,21 +161,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
@@ -183,11 +193,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
@@ -197,7 +207,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
@@ -212,19 +222,29 @@ 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
-    cmp        byte [esp + 4], 1\r
+    mov        eax, esp\r
+    mov        esp, [eax + 16]     ; 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
+    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
     monitor\r
-    mov        eax, [esp + 8]    ; Mwait Cx, Target C-State per eax[7:4]\r
+    mov        eax, ebx            ; Mwait Cx, Target C-State per eax[7:4]\r
     shl        eax, 4\r
     mwait\r
     jmp        MwaitLoop\r
@@ -232,7 +252,6 @@ HltLoop:
     cli\r
     hlt\r
     jmp        HltLoop\r
-    ret\r
 AsmRelocateApLoopEnd:\r
 \r
 ;-------------------------------------------------------------------------------------\r
@@ -249,6 +268,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