mirror of
				https://github.com/acidanthera/audk.git
				synced 2025-10-31 11:13:53 +01:00 
			
		
		
		
	UefiCpuPkg/CpuMpPei/X64: Use CodeSegment and DataSegment fields
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>
This commit is contained in:
		
							parent
							
								
									249ed12ea0
								
							
						
					
					
						commit
						d1471c0112
					
				| @ -1,5 +1,5 @@ | |||||||
| ;------------------------------------------------------------------------------ ; | ;------------------------------------------------------------------------------ ; | ||||||
| ; Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> | ; Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR> | ||||||
| ; This program and the accompanying materials | ; This program and the accompanying materials | ||||||
| ; are licensed and made available under the terms and conditions of the BSD License | ; are licensed and made available under the terms and conditions of the BSD License | ||||||
| ; which accompanies this distribution.  The full text of the license may be found at | ; which accompanies this distribution.  The full text of the license may be found at | ||||||
| @ -47,25 +47,18 @@ RendezvousFunnelProcStart:: | |||||||
|     dw BufferStartLocation            ; mov        si, BufferStartLocation |     dw BufferStartLocation            ; mov        si, BufferStartLocation | ||||||
|     db 66h,  8Bh, 1Ch                 ; mov        ebx, dword ptr [si] |     db 66h,  8Bh, 1Ch                 ; mov        ebx, dword ptr [si] | ||||||
| 
 | 
 | ||||||
|     db 0BFh                           ; opcode of mov di, mem16 |  | ||||||
|     dw PmodeOffsetLocation            ; mov        di, PmodeOffsetLocation |  | ||||||
|     db 66h,  8Bh, 05h                 ; mov        eax,dword ptr [di] |  | ||||||
|     db 8Bh,  0F8h                     ; mov        di, ax |  | ||||||
|     db 83h,  0EFh,06h                 ; sub        di, 06h |  | ||||||
|     db 66h,  03h, 0C3h                ; add        eax, ebx |  | ||||||
|     db 66h,  89h, 05h                 ; mov        dword ptr [di],eax |  | ||||||
| 
 |  | ||||||
|     db 0BFh                           ; opcode of mov di, mem16                          |     db 0BFh                           ; opcode of mov di, mem16                          | ||||||
|     dw LmodeOffsetLocation            ; mov        di,  LmodeOffsetLocation |     dw LmodeOffsetLocation            ; mov        di,  LmodeOffsetLocation | ||||||
|     db 66h,  8Bh, 05h                 ; mov        eax,dword ptr [di] |     db 66h, 8Bh, 05h                  ; mov        eax, [di] | ||||||
|     db 8Bh,  0F8h                     ; mov        di, ax |     db 0BFh                           ; opcode of mov di, mem16   | ||||||
|     db 83h,  0EFh,06h                 ; sub        di, 06h |     dw CodeSegmentLocation            ; mov        di,  CodeSegmentLocation | ||||||
|     db 66h,  03h, 0C3h                ; add        eax, ebx |     db 66h, 8Bh, 15h                  ; mov        edx, [di] | ||||||
|     db 66h,  89h, 05h                 ; mov        dword ptr [di],eax |     db 89h, 0C7h                      ; mov        di,  ax | ||||||
| 
 |     db 83h, 0EFh, 02h                 ; sub        di,  02h   | ||||||
|     db 0BEh |     db 89h, 15h                       ; mov        [di], dx        ; Patch long mode CS | ||||||
|     dw Cr3Location                    ; mov        si, Cr3Location |     db 83h, 0EFh, 04h                 ; sub        di,  04h | ||||||
|     db 66h,  8Bh, 0Ch                 ; mov        ecx,dword ptr [si]     ; ECX is keeping the value of CR3 |     db 66h, 01h, 0D8h                 ; add        eax, ebx | ||||||
|  |     db 66h, 89h, 05h                  ; mov        [di], eax       ; Patch address | ||||||
| 
 | 
 | ||||||
|     db 0BEh                           ; opcode of mov si, mem16 |     db 0BEh                           ; opcode of mov si, mem16 | ||||||
|     dw GdtrLocation                   ; mov        si, GdtrLocation |     dw GdtrLocation                   ; mov        si, GdtrLocation | ||||||
| @ -77,48 +70,44 @@ RendezvousFunnelProcStart:: | |||||||
|     db 66h                            ; db         66h |     db 66h                            ; db         66h | ||||||
|     db 2Eh,0Fh, 01h, 1Ch              ; lidt       fword ptr cs:[si] |     db 2Eh,0Fh, 01h, 1Ch              ; lidt       fword ptr cs:[si] | ||||||
| 
 | 
 | ||||||
|     db 33h,  0C0h                     ; xor        ax,  ax |     db 0BFh                           ; opcode of mov di, mem16   | ||||||
|     db 8Eh,  0D8h                     ; mov        ds,  ax |     dw DataSegmentLocation            ; mov        di,  DataSegmentLocation | ||||||
|  |     db 66h, 8Bh, 3Dh                  ; mov        edi, [di]           ; Save long mode DS in edi | ||||||
|  | 
 | ||||||
|  |     db 0BEh | ||||||
|  |     dw Cr3Location                    ; mov        si, Cr3Location | ||||||
|  |     db 66h,  8Bh, 0Ch                 ; mov        ecx, dword ptr [si]  ; ECX is keeping the value of CR3 | ||||||
|  | 
 | ||||||
|  |     db 31h, 0C0h                      ; xor        ax,  ax | ||||||
|  |     db 8Eh, 0D8h                      ; mov        ds,  ax             ; Clear data segment | ||||||
| 
 | 
 | ||||||
|     db 0Fh, 20h, 0C0h                 ; mov        eax, cr0            ; Get control register 0 |     db 0Fh, 20h, 0C0h                 ; mov        eax, cr0            ; Get control register 0 | ||||||
|     db 66h, 83h, 0C8h, 03h            ; or         eax, 000000003h     ; Set PE bit (bit #0) & MP |     db 66h, 83h, 0C8h, 03h            ; or         eax, 000000003h     ; Set PE bit (bit #0) & MP | ||||||
|     db 0Fh, 22h, 0C0h                 ; mov        cr0, eax |     db 0Fh, 22h, 0C0h                 ; mov        cr0, eax | ||||||
| 
 | 
 | ||||||
|     db 66h,  67h, 0EAh                ; far jump |  | ||||||
|     dd 0h                             ; 32-bit offset |  | ||||||
|     dw PROTECT_MODE_CS                ; 16-bit selector |  | ||||||
| 
 |  | ||||||
| Flat32Start::                         ; protected mode entry point |  | ||||||
|     mov        ax, PROTECT_MODE_DS |  | ||||||
|     mov        ds, ax |  | ||||||
|     mov        es, ax |  | ||||||
|     mov        fs, ax |  | ||||||
|     mov        gs, ax |  | ||||||
|     mov        ss, ax |  | ||||||
| 
 |  | ||||||
|     db 0Fh, 20h, 0E0h             ; mov        eax, cr4 |     db 0Fh, 20h, 0E0h             ; mov        eax, cr4 | ||||||
|     db 0Fh,  0BAh, 0E8h, 05h      ; bts        eax, 5 |     db 66h, 0Fh, 0BAh, 0E8h, 05h  ; bts        eax, 5 | ||||||
|     db 0Fh, 22h, 0E0h             ; mov        cr4, eax |     db 0Fh, 22h, 0E0h             ; mov        cr4, eax | ||||||
| 
 | 
 | ||||||
|     db 0Fh,  22h,  0D9h           ; mov        cr3, ecx |     db 0Fh,  22h,  0D9h           ; mov        cr3, ecx | ||||||
| 
 | 
 | ||||||
|     db 0B9h |     db 66h,  0B9h | ||||||
|     dd 0C0000080h                 ; mov        ecx, 0c0000080h     ; EFER MSR number. |     dd 0C0000080h                 ; mov        ecx, 0c0000080h     ; EFER MSR number. | ||||||
|     db 0Fh,  32h                  ; rdmsr                          ; Read EFER. |     db 0Fh,  32h                  ; rdmsr                          ; Read EFER. | ||||||
|     db 0Fh,  0BAh, 0E8h, 08h      ; bts        eax, 8              ; Set LME=1. |     db 66h,  0Fh,  0BAh, 0E8h, 08h; bts        eax, 8              ; Set LME=1. | ||||||
|     db 0Fh,  30h                  ; wrmsr                          ; Write EFER. |     db 0Fh,  30h                  ; wrmsr                          ; Write EFER. | ||||||
| 
 | 
 | ||||||
|     db 0Fh,  20h,  0C0h           ; mov        eax, cr0            ; Read CR0. |     db 0Fh,  20h,  0C0h           ; mov        eax, cr0            ; Read CR0. | ||||||
|     db 0Fh,  0BAh, 0E8h, 1Fh      ; bts        eax, 31             ; Set PG=1. |     db 66h,  0Fh,  0BAh, 0E8h, 1Fh; bts        eax, 31             ; Set PG=1. | ||||||
|     db 0Fh,  22h,  0C0h           ; mov        cr0, eax            ; Write CR0. |     db 0Fh,  22h,  0C0h           ; mov        cr0, eax            ; Write CR0. | ||||||
| 
 | 
 | ||||||
| LONG_JUMP: | LONG_JUMP: | ||||||
|     db 67h,  0EAh                 ; far jump |     db 66h,  0EAh                 ; far jump | ||||||
|     dd 0h                         ; 32-bit offset |     dd 0h                         ; 32-bit offset | ||||||
|     dw LONG_MODE_CS               ; 16-bit selector |     dw 0h                         ; 16-bit selector | ||||||
| 
 | 
 | ||||||
| LongModeStart:: | LongModeStart:: | ||||||
|     mov        ax,  LONG_MODE_DS |     mov        eax, edi | ||||||
|     mov        ds,  ax |     mov        ds,  ax | ||||||
|     mov        es,  ax |     mov        es,  ax | ||||||
|     mov        ss,  ax |     mov        ss,  ax | ||||||
| @ -187,7 +176,7 @@ RendezvousFunnelProcEnd:: | |||||||
| AsmGetAddressMap   PROC | AsmGetAddressMap   PROC | ||||||
|     mov        rax, offset RendezvousFunnelProcStart |     mov        rax, offset RendezvousFunnelProcStart | ||||||
|     mov        qword ptr [rcx], rax |     mov        qword ptr [rcx], rax | ||||||
|     mov        qword ptr [rcx +  8h], Flat32Start - RendezvousFunnelProcStart |     mov        qword ptr [rcx +  8h], 0 | ||||||
|     mov        qword ptr [rcx + 10h], LongModeStart - RendezvousFunnelProcStart |     mov        qword ptr [rcx + 10h], LongModeStart - RendezvousFunnelProcStart | ||||||
|     mov        qword ptr [rcx + 18h], RendezvousFunnelProcEnd - RendezvousFunnelProcStart |     mov        qword ptr [rcx + 18h], RendezvousFunnelProcEnd - RendezvousFunnelProcStart | ||||||
|     ret |     ret | ||||||
|  | |||||||
| @ -52,23 +52,16 @@ BITS 16 | |||||||
|     mov        si,  BufferStartLocation |     mov        si,  BufferStartLocation | ||||||
|     mov        ebx, [si] |     mov        ebx, [si] | ||||||
| 
 | 
 | ||||||
|     mov        di,  PmodeOffsetLocation |  | ||||||
|     mov        eax, [di] |  | ||||||
|     mov        di,  ax |  | ||||||
|     sub        di,  06h |  | ||||||
|     add        eax, ebx |  | ||||||
|     mov        [di],eax |  | ||||||
| 
 |  | ||||||
|     mov        di,  LmodeOffsetLocation |     mov        di,  LmodeOffsetLocation | ||||||
|     mov        eax, [di] |     mov        eax, [di] | ||||||
|  |     mov        di,  CodeSegmentLocation | ||||||
|  |     mov        edx, [di] | ||||||
|     mov        di,  ax |     mov        di,  ax | ||||||
|     sub        di,  06h |     sub        di,  02h   | ||||||
|  |     mov        [di],dx                         ; Patch long mode CS | ||||||
|  |     sub        di,  04h | ||||||
|     add        eax, ebx |     add        eax, ebx | ||||||
|     mov        [di],eax |     mov        [di],eax                        ; Patch address | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|     mov        si, Cr3Location |  | ||||||
|     mov        ecx,[si]                        ; ECX is keeping the value of CR3 |  | ||||||
| 
 | 
 | ||||||
|     mov        si, GdtrLocation |     mov        si, GdtrLocation | ||||||
| o32 lgdt       [cs:si] | o32 lgdt       [cs:si] | ||||||
| @ -77,43 +70,38 @@ o32 lgdt       [cs:si] | |||||||
| o32 lidt       [cs:si] | o32 lidt       [cs:si] | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |     mov        di,  DataSegmentLocation | ||||||
|  |     mov        edi, [di]                   ; Save long mode DS in edi | ||||||
|  | 
 | ||||||
|  |     mov        si, Cr3Location             ; Save CR3 in ecx | ||||||
|  |     mov        ecx, [si] | ||||||
|  | 
 | ||||||
|     xor        ax,  ax |     xor        ax,  ax | ||||||
|     mov        ds,  ax |     mov        ds,  ax                     ; Clear data segment | ||||||
| 
 | 
 | ||||||
|     mov        eax, cr0                    ; Get control register 0 |     mov        eax, cr0                    ; Get control register 0 | ||||||
|     or         eax, 000000003h             ; Set PE bit (bit #0) & MP |     or         eax, 000000003h             ; Set PE bit (bit #0) & MP | ||||||
|     mov        cr0, eax |     mov        cr0, eax | ||||||
| 
 | 
 | ||||||
|     jmp        PROTECT_MODE_CS:strict dword 0  ; far jump to protected mode |  | ||||||
| BITS 32 |  | ||||||
| Flat32Start:                                   ; protected mode entry point |  | ||||||
|     mov        ax, PROTECT_MODE_DS |  | ||||||
|     mov        ds, ax |  | ||||||
|     mov        es, ax |  | ||||||
|     mov        fs, ax |  | ||||||
|     mov        gs, ax |  | ||||||
|     mov        ss, ax |  | ||||||
| 
 |  | ||||||
|     mov        eax, cr4 |     mov        eax, cr4 | ||||||
|     bts        eax, 5 |     bts        eax, 5 | ||||||
|     mov        cr4, eax |     mov        cr4, eax | ||||||
| 
 | 
 | ||||||
|     mov        cr3, ecx |     mov        cr3, ecx                    ; Load CR3 | ||||||
| 
 | 
 | ||||||
|  |     mov        ecx, 0c0000080h             ; EFER MSR number | ||||||
|  |     rdmsr                                  ; Read EFER | ||||||
|  |     bts        eax, 8                      ; Set LME=1 | ||||||
|  |     wrmsr                                  ; Write EFER | ||||||
| 
 | 
 | ||||||
|     mov        ecx, 0c0000080h             ; EFER MSR number. |     mov        eax, cr0                    ; Read CR0 | ||||||
|     rdmsr                                  ; Read EFER. |     bts        eax, 31                     ; Set PG=1 | ||||||
|     bts        eax, 8                      ; Set LME=1. |     mov        cr0, eax                    ; Write CR0 | ||||||
|     wrmsr                                  ; Write EFER. |  | ||||||
| 
 | 
 | ||||||
|     mov        eax, cr0                    ; Read CR0. |     jmp        0:strict dword 0  ; far jump to long mode | ||||||
|     bts        eax, 31                     ; Set PG=1. |  | ||||||
|     mov        cr0, eax                    ; Write CR0. |  | ||||||
| 
 |  | ||||||
|     jmp        LONG_MODE_CS:strict dword 0 ; far jump to long mode |  | ||||||
| BITS 64 | BITS 64 | ||||||
| LongModeStart: | LongModeStart: | ||||||
|     mov        ax,  LONG_MODE_DS |     mov        eax, edi | ||||||
|     mov        ds,  ax |     mov        ds,  ax | ||||||
|     mov        es,  ax |     mov        es,  ax | ||||||
|     mov        ss,  ax |     mov        ss,  ax | ||||||
| @ -171,6 +159,7 @@ CProcedureInvoke: | |||||||
|     sub        rsp, 20h |     sub        rsp, 20h | ||||||
|     call       rax               ; invoke C function |     call       rax               ; invoke C function | ||||||
|     add        rsp, 20h |     add        rsp, 20h | ||||||
|  |     jmp        $ | ||||||
| 
 | 
 | ||||||
| RendezvousFunnelProcEnd: | RendezvousFunnelProcEnd: | ||||||
| 
 | 
 | ||||||
| @ -181,7 +170,7 @@ global ASM_PFX(AsmGetAddressMap) | |||||||
| ASM_PFX(AsmGetAddressMap): | ASM_PFX(AsmGetAddressMap): | ||||||
|     mov        rax, ASM_PFX(RendezvousFunnelProc) |     mov        rax, ASM_PFX(RendezvousFunnelProc) | ||||||
|     mov        qword [rcx], rax |     mov        qword [rcx], rax | ||||||
|     mov        qword [rcx +  8h], Flat32Start - RendezvousFunnelProcStart |     mov        qword [rcx +  8h], 0 | ||||||
|     mov        qword [rcx + 10h], LongModeStart - RendezvousFunnelProcStart |     mov        qword [rcx + 10h], LongModeStart - RendezvousFunnelProcStart | ||||||
|     mov        qword [rcx + 18h], RendezvousFunnelProcEnd - RendezvousFunnelProcStart |     mov        qword [rcx + 18h], RendezvousFunnelProcEnd - RendezvousFunnelProcStart | ||||||
|     ret |     ret | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user