]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/CpuMpPei/X64: Use CodeSegment and DataSegment fields
authorJeff Fan <jeff.fan@intel.com>
Mon, 11 Jul 2016 11:40:05 +0000 (19:40 +0800)
committerJeff Fan <jeff.fan@intel.com>
Thu, 14 Jul 2016 01:43:36 +0000 (09:43 +0800)
Using CodeSegment and DataSegment fields in ExchangeInfo instead of the hardcode
MACROs for x64 arch. Switch AP from real mode to long mode directly, so needn't
the CS/DS of protected mode.

Cc: Feng Tian <feng.tian@intel.com>
Cc: Michael Kinney <michael.d.kinney@intel.com>
Cc: Giri Mudusuru <giri.p.mudusuru@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <jeff.fan@intel.com>
Reviewed-by: Giri P Mudusuru <giri.p.mudusuru@intel.com>
UefiCpuPkg/CpuMpPei/X64/MpFuncs.asm
UefiCpuPkg/CpuMpPei/X64/MpFuncs.nasm

index 1bb3b6d6b6680b191af53b15b32a340e5698bf6a..f018c3bb09a01a1ac171a4ccac68a2d6eb1024c0 100644 (file)
@@ -1,5 +1,5 @@
 ;------------------------------------------------------------------------------ ;\r
 ;------------------------------------------------------------------------------ ;\r
-; Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\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
 ; 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
@@ -35,37 +35,30 @@ RendezvousFunnelProcStart::
 ; Save BIST information to ebp firstly\r
     db 66h,  08bh, 0e8h               ; mov        ebp, eax    ; save BIST information\r
 \r
 ; Save BIST information to ebp firstly\r
     db 66h,  08bh, 0e8h               ; mov        ebp, eax    ; save BIST information\r
 \r
-    db 8ch,0c8h                       ; mov        ax,cs\r
-    db 8eh,0d8h                       ; mov        ds,ax\r
-    db 8eh,0c0h                       ; mov        es,ax\r
-    db 8eh,0d0h                       ; mov        ss,ax\r
-    db 33h,0c0h                       ; xor        ax,ax\r
-    db 8eh,0e0h                       ; mov        fs,ax\r
-    db 8eh,0e8h                       ; mov        gs,ax\r
+    db 8ch,0c8h                       ; mov        ax, cs\r
+    db 8eh,0d8h                       ; mov        ds, ax\r
+    db 8eh,0c0h                       ; mov        es, ax\r
+    db 8eh,0d0h                       ; mov        ss, ax\r
+    db 33h,0c0h                       ; xor        ax, ax\r
+    db 8eh,0e0h                       ; mov        fs, ax\r
+    db 8eh,0e8h                       ; mov        gs, ax\r
 \r
     db 0BEh                           ; opcode of mov si, mem16\r
     dw BufferStartLocation            ; mov        si, BufferStartLocation\r
 \r
     db 0BEh                           ; opcode of mov si, mem16\r
     dw BufferStartLocation            ; mov        si, BufferStartLocation\r
-    db 66h,  8Bh, 1Ch                 ; mov        ebx,dword ptr [si]\r
-\r
-    db 0BFh                           ; opcode of mov di, mem16\r
-    dw PmodeOffsetLocation            ; mov        di, PmodeOffsetLocation\r
-    db 66h,  8Bh, 05h                 ; mov        eax,dword ptr [di]\r
-    db 8Bh,  0F8h                     ; mov        di, ax\r
-    db 83h,  0EFh,06h                 ; sub        di, 06h\r
-    db 66h,  03h, 0C3h                ; add        eax, ebx\r
-    db 66h,  89h, 05h                 ; mov        dword ptr [di],eax\r
-\r
-    db 0BFh                           ; opcode of mov di, mem16\r
-    dw LmodeOffsetLocation            ; mov        di, LmodeOffsetLocation\r
-    db 66h,  8Bh, 05h                 ; mov        eax,dword ptr [di]\r
-    db 8Bh,  0F8h                     ; mov        di, ax\r
-    db 83h,  0EFh,06h                 ; sub        di, 06h\r
-    db 66h,  03h, 0C3h                ; add        eax, ebx\r
-    db 66h,  89h, 05h                 ; mov        dword ptr [di],eax\r
-\r
-    db 0BEh\r
-    dw Cr3Location                    ; mov        si, Cr3Location\r
-    db 66h,  8Bh, 0Ch                 ; mov        ecx,dword ptr [si]     ; ECX is keeping the value of CR3\r
+    db 66h,  8Bh, 1Ch                 ; mov        ebx, dword ptr [si]\r
+\r
+    db 0BFh                           ; opcode of mov di, mem16                         \r
+    dw LmodeOffsetLocation            ; mov        di,  LmodeOffsetLocation\r
+    db 66h, 8Bh, 05h                  ; mov        eax, [di]\r
+    db 0BFh                           ; opcode of mov di, mem16  \r
+    dw CodeSegmentLocation            ; mov        di,  CodeSegmentLocation\r
+    db 66h, 8Bh, 15h                  ; mov        edx, [di]\r
+    db 89h, 0C7h                      ; mov        di,  ax\r
+    db 83h, 0EFh, 02h                 ; sub        di,  02h  \r
+    db 89h, 15h                       ; mov        [di], dx        ; Patch long mode CS\r
+    db 83h, 0EFh, 04h                 ; sub        di,  04h\r
+    db 66h, 01h, 0D8h                 ; add        eax, ebx\r
+    db 66h, 89h, 05h                  ; mov        [di], eax       ; Patch address\r
 \r
     db 0BEh                           ; opcode of mov si, mem16\r
     dw GdtrLocation                   ; mov        si, GdtrLocation\r
 \r
     db 0BEh                           ; opcode of mov si, mem16\r
     dw GdtrLocation                   ; mov        si, GdtrLocation\r
@@ -77,48 +70,44 @@ RendezvousFunnelProcStart::
     db 66h                            ; db         66h\r
     db 2Eh,0Fh, 01h, 1Ch              ; lidt       fword ptr cs:[si]\r
 \r
     db 66h                            ; db         66h\r
     db 2Eh,0Fh, 01h, 1Ch              ; lidt       fword ptr cs:[si]\r
 \r
-    db 33h,  0C0h                     ; xor        ax,  ax\r
-    db 8Eh,  0D8h                     ; mov        ds,  ax\r
+    db 0BFh                           ; opcode of mov di, mem16  \r
+    dw DataSegmentLocation            ; mov        di,  DataSegmentLocation\r
+    db 66h, 8Bh, 3Dh                  ; mov        edi, [di]           ; Save long mode DS in edi\r
 \r
 \r
-    db 0Fh,  20h, 0C0h                ; mov        eax, cr0               ;Get control register 0\r
-    db 66h,  83h, 0C8h, 03h           ; or         eax, 000000003h        ;Set PE bit (bit #0) & MP\r
-    db 0Fh,  22h, 0C0h                ; mov        cr0, eax\r
+    db 0BEh\r
+    dw Cr3Location                    ; mov        si, Cr3Location\r
+    db 66h,  8Bh, 0Ch                 ; mov        ecx, dword ptr [si]  ; ECX is keeping the value of CR3\r
 \r
 \r
-    db 66h,  67h, 0EAh                ; far jump\r
-    dd 0h                             ; 32-bit offset\r
-    dw PROTECT_MODE_CS                ; 16-bit selector\r
+    db 31h, 0C0h                      ; xor        ax,  ax\r
+    db 8Eh, 0D8h                      ; mov        ds,  ax             ; Clear data segment\r
 \r
 \r
-Flat32Start::                         ; protected mode entry point\r
-    mov        ax, PROTECT_MODE_DS\r
-    mov        ds, ax\r
-    mov        es, ax\r
-    mov        fs, ax\r
-    mov        gs, ax\r
-    mov        ss, ax\r
+    db 0Fh, 20h, 0C0h                 ; mov        eax, cr0            ; Get control register 0\r
+    db 66h, 83h, 0C8h, 03h            ; or         eax, 000000003h     ; Set PE bit (bit #0) & MP\r
+    db 0Fh, 22h, 0C0h                 ; mov        cr0, eax\r
 \r
 \r
-    db 0Fh,  20h,  0E0h           ; mov        eax, cr4\r
-    db 0Fh,  0BAh, 0E8h, 05h      ; bts        eax, 5\r
-    db 0Fh,  22h,  0E0h           ; mov        cr4, eax\r
+    db 0Fh, 20h, 0E0h             ; mov        eax, cr4\r
+    db 66h, 0Fh, 0BAh, 0E8h, 05h  ; bts        eax, 5\r
+    db 0Fh, 22h, 0E0h             ; mov        cr4, eax\r
 \r
     db 0Fh,  22h,  0D9h           ; mov        cr3, ecx\r
 \r
 \r
     db 0Fh,  22h,  0D9h           ; mov        cr3, ecx\r
 \r
-    db 0B9h\r
+    db 66h,  0B9h\r
     dd 0C0000080h                 ; mov        ecx, 0c0000080h     ; EFER MSR number.\r
     db 0Fh,  32h                  ; rdmsr                          ; Read EFER.\r
     dd 0C0000080h                 ; mov        ecx, 0c0000080h     ; EFER MSR number.\r
     db 0Fh,  32h                  ; rdmsr                          ; Read EFER.\r
-    db 0Fh,  0BAh, 0E8h, 08h      ; bts        eax, 8              ; Set LME=1.\r
+    db 66h,  0Fh,  0BAh, 0E8h, 08h; bts        eax, 8              ; Set LME=1.\r
     db 0Fh,  30h                  ; wrmsr                          ; Write EFER.\r
 \r
     db 0Fh,  20h,  0C0h           ; mov        eax, cr0            ; Read CR0.\r
     db 0Fh,  30h                  ; wrmsr                          ; Write EFER.\r
 \r
     db 0Fh,  20h,  0C0h           ; mov        eax, cr0            ; Read CR0.\r
-    db 0Fh,  0BAh, 0E8h, 1Fh      ; bts        eax, 31             ; Set PG=1.\r
+    db 66h,  0Fh,  0BAh, 0E8h, 1Fh; bts        eax, 31             ; Set PG=1.\r
     db 0Fh,  22h,  0C0h           ; mov        cr0, eax            ; Write CR0.\r
 \r
 LONG_JUMP:\r
     db 0Fh,  22h,  0C0h           ; mov        cr0, eax            ; Write CR0.\r
 \r
 LONG_JUMP:\r
-    db 67h,  0EAh                 ; far jump\r
+    db 66h,  0EAh                 ; far jump\r
     dd 0h                         ; 32-bit offset\r
     dd 0h                         ; 32-bit offset\r
-    dw LONG_MODE_CS               ; 16-bit selector\r
+    dw 0h                         ; 16-bit selector\r
 \r
 LongModeStart::\r
 \r
 LongModeStart::\r
-    mov        ax,  LONG_MODE_DS\r
+    mov        eax, edi\r
     mov        ds,  ax\r
     mov        es,  ax\r
     mov        ss,  ax\r
     mov        ds,  ax\r
     mov        es,  ax\r
     mov        ss,  ax\r
@@ -187,7 +176,7 @@ RendezvousFunnelProcEnd::
 AsmGetAddressMap   PROC\r
     mov        rax, offset RendezvousFunnelProcStart\r
     mov        qword ptr [rcx], rax\r
 AsmGetAddressMap   PROC\r
     mov        rax, offset RendezvousFunnelProcStart\r
     mov        qword ptr [rcx], rax\r
-    mov        qword ptr [rcx +  8h], Flat32Start - RendezvousFunnelProcStart\r
+    mov        qword ptr [rcx +  8h], 0\r
     mov        qword ptr [rcx + 10h], LongModeStart - RendezvousFunnelProcStart\r
     mov        qword ptr [rcx + 18h], RendezvousFunnelProcEnd - RendezvousFunnelProcStart\r
     ret\r
     mov        qword ptr [rcx + 10h], LongModeStart - RendezvousFunnelProcStart\r
     mov        qword ptr [rcx + 18h], RendezvousFunnelProcEnd - RendezvousFunnelProcStart\r
     ret\r
index 7e7f405b2efaf7336ad540e6a5f00ec9d737f911..99cbee296b7d969564070169468e1b387ba10051 100644 (file)
@@ -52,23 +52,16 @@ BITS 16
     mov        si,  BufferStartLocation\r
     mov        ebx, [si]\r
 \r
     mov        si,  BufferStartLocation\r
     mov        ebx, [si]\r
 \r
-    mov        di,  PmodeOffsetLocation\r
+    mov        di,  LmodeOffsetLocation\r
     mov        eax, [di]\r
     mov        eax, [di]\r
+    mov        di,  CodeSegmentLocation\r
+    mov        edx, [di]\r
     mov        di,  ax\r
     mov        di,  ax\r
-    sub        di,  06h\r
+    sub        di,  02h  \r
+    mov        [di],dx                         ; Patch long mode CS\r
+    sub        di,  04h\r
     add        eax, ebx\r
     add        eax, ebx\r
-    mov        [di],eax\r
-\r
-    mov        di, LmodeOffsetLocation\r
-    mov        eax, [di]\r
-    mov        di,  ax\r
-    sub        di,  06h\r
-    add        eax, ebx\r
-    mov        [di],eax\r
-\r
-\r
-    mov        si, Cr3Location\r
-    mov        ecx,[si]                        ; ECX is keeping the value of CR3\r
+    mov        [di],eax                        ; Patch address\r
 \r
     mov        si, GdtrLocation\r
 o32 lgdt       [cs:si]\r
 \r
     mov        si, GdtrLocation\r
 o32 lgdt       [cs:si]\r
@@ -77,43 +70,38 @@ o32 lgdt       [cs:si]
 o32 lidt       [cs:si]\r
 \r
 \r
 o32 lidt       [cs:si]\r
 \r
 \r
+    mov        di,  DataSegmentLocation\r
+    mov        edi, [di]                   ; Save long mode DS in edi\r
+\r
+    mov        si, Cr3Location             ; Save CR3 in ecx\r
+    mov        ecx, [si]\r
+\r
     xor        ax,  ax\r
     xor        ax,  ax\r
-    mov        ds,  ax\r
+    mov        ds,  ax                     ; Clear data segment\r
 \r
 \r
-    mov        eax, cr0                        ;Get control register 0\r
-    or         eax, 000000003h                 ;Set PE bit (bit #0) & MP\r
+    mov        eax, cr0                    Get control register 0\r
+    or         eax, 000000003h             Set PE bit (bit #0) & MP\r
     mov        cr0, eax\r
 \r
     mov        cr0, eax\r
 \r
-    jmp        PROTECT_MODE_CS:strict dword 0  ; far jump to protected mode\r
-BITS 32\r
-Flat32Start:                                   ; protected mode entry point\r
-    mov        ax, PROTECT_MODE_DS\r
-    mov        ds, ax\r
-    mov        es, ax\r
-    mov        fs, ax\r
-    mov        gs, ax\r
-    mov        ss, ax\r
-\r
     mov        eax, cr4\r
     bts        eax, 5\r
     mov        cr4, eax\r
 \r
     mov        eax, cr4\r
     bts        eax, 5\r
     mov        cr4, eax\r
 \r
-    mov        cr3, ecx\r
-\r
+    mov        cr3, ecx                    ; Load CR3\r
 \r
 \r
-    mov        ecx, 0c0000080h             ; EFER MSR number.\r
-    rdmsr                                  ; Read EFER.\r
-    bts        eax, 8                      ; Set LME=1.\r
-    wrmsr                                  ; Write EFER.\r
+    mov        ecx, 0c0000080h             ; EFER MSR number\r
+    rdmsr                                  ; Read EFER\r
+    bts        eax, 8                      ; Set LME=1\r
+    wrmsr                                  ; Write EFER\r
 \r
 \r
-    mov        eax, cr0                    ; Read CR0.\r
-    bts        eax, 31                     ; Set PG=1.\r
-    mov        cr0, eax                    ; Write CR0.\r
+    mov        eax, cr0                    ; Read CR0\r
+    bts        eax, 31                     ; Set PG=1\r
+    mov        cr0, eax                    ; Write CR0\r
 \r
 \r
-    jmp        LONG_MODE_CS:strict dword 0 ; far jump to long mode\r
+    jmp        0:strict dword 0  ; far jump to long mode\r
 BITS 64\r
 LongModeStart:\r
 BITS 64\r
 LongModeStart:\r
-    mov        ax,  LONG_MODE_DS\r
+    mov        eax, edi\r
     mov        ds,  ax\r
     mov        es,  ax\r
     mov        ss,  ax\r
     mov        ds,  ax\r
     mov        es,  ax\r
     mov        ss,  ax\r
@@ -171,6 +159,7 @@ CProcedureInvoke:
     sub        rsp, 20h\r
     call       rax               ; invoke C function\r
     add        rsp, 20h\r
     sub        rsp, 20h\r
     call       rax               ; invoke C function\r
     add        rsp, 20h\r
+    jmp        $\r
 \r
 RendezvousFunnelProcEnd:\r
 \r
 \r
 RendezvousFunnelProcEnd:\r
 \r
@@ -181,7 +170,7 @@ global ASM_PFX(AsmGetAddressMap)
 ASM_PFX(AsmGetAddressMap):\r
     mov        rax, ASM_PFX(RendezvousFunnelProc)\r
     mov        qword [rcx], rax\r
 ASM_PFX(AsmGetAddressMap):\r
     mov        rax, ASM_PFX(RendezvousFunnelProc)\r
     mov        qword [rcx], rax\r
-    mov        qword [rcx +  8h], Flat32Start - RendezvousFunnelProcStart\r
+    mov        qword [rcx +  8h], 0\r
     mov        qword [rcx + 10h], LongModeStart - RendezvousFunnelProcStart\r
     mov        qword [rcx + 18h], RendezvousFunnelProcEnd - RendezvousFunnelProcStart\r
     ret\r
     mov        qword [rcx + 10h], LongModeStart - RendezvousFunnelProcStart\r
     mov        qword [rcx + 18h], RendezvousFunnelProcEnd - RendezvousFunnelProcStart\r
     ret\r