]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm
UefiCpuPkg/MpInitLib: Add AsmRelocateApLoop() assembly code
[mirror_edk2.git] / UefiCpuPkg / Library / MpInitLib / X64 / MpFuncs.nasm
index 3c55ffaafecc53b37ba96417b9ea9e43a0000885..d5d7efe2921cb30d20fec3be8fc6864a026fa940 100644 (file)
@@ -176,6 +176,60 @@ CProcedureInvoke:
 \r
 RendezvousFunnelProcEnd:\r
 \r
+;-------------------------------------------------------------------------------------\r
+;  AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment);\r
+;-------------------------------------------------------------------------------------\r
+global ASM_PFX(AsmRelocateApLoop)\r
+ASM_PFX(AsmRelocateApLoop):\r
+AsmRelocateApLoopStart:\r
+    push       rcx\r
+    push       rdx\r
+\r
+    lea        rsi, [PmEntry]    ; rsi <- The start address of transition code\r
+\r
+    push       r8\r
+    push       rsi\r
+    DB         0x48\r
+    retf\r
+BITS 32\r
+PmEntry:\r
+    mov        eax, cr0\r
+    btr        eax, 31           ; Clear CR0.PG\r
+    mov        cr0, eax          ; Disable paging and caches\r
+\r
+    mov        ebx, edx          ; Save EntryPoint to rbx, for rdmsr will overwrite rdx\r
+    mov        ecx, 0xc0000080\r
+    rdmsr\r
+    and        ah, ~ 1           ; Clear LME\r
+    wrmsr\r
+    mov        eax, cr4\r
+    and        al, ~ (1 << 5)    ; Clear PAE\r
+    mov        cr4, eax\r
+\r
+    pop        edx\r
+    add        esp, 4\r
+    pop        ecx,\r
+    add        esp, 4\r
+    cmp        cl, 1              ; Check mwait-monitor support\r
+    jnz        HltLoop\r
+    mov        ebx, edx           ; Save C-State to ebx\r
+MwaitLoop:\r
+    mov        eax, esp           ; Set Monitor Address\r
+    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
+    mwait\r
+    jmp        MwaitLoop\r
+HltLoop:\r
+    cli\r
+    hlt\r
+    jmp        HltLoop\r
+    ret\r
+BITS 64\r
+AsmRelocateApLoopEnd:\r
+\r
 ;-------------------------------------------------------------------------------------\r
 ;  AsmGetAddressMap (&AddressMap);\r
 ;-------------------------------------------------------------------------------------\r