;------------------------------------------------------------------------------ ;\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
RendezvousFunnelProcStart:\r
; At this point CS = 0x(vv00) and ip= 0x0.\r
; Save BIST information to ebp firstly\r
-BITS 16\r
\r
- mov eax, 1234h\r
- mov ebp, eax ; save BIST information\r
+BITS 16\r
+ mov ebp, eax ; Save BIST information\r
\r
mov ax, cs\r
mov ds, ax\r
mov si, BufferStartLocation\r
mov ebx, [si]\r
\r
- mov di, PmodeOffsetLocation\r
+ mov di, LmodeOffsetLocation\r
mov eax, [di]\r
+ mov di, CodeSegmentLocation\r
+ mov edx, [di]\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
- 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
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
- mov ds, ax\r
+ mov ds, ax ; Clear data segment\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
- 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 cr3, ecx\r
+ mov cr3, ecx ; Load CR3\r
\r
+ mov ecx, 0c0000080h ; EFER MSR number\r
+ rdmsr ; Read EFER\r
+ bts eax, 8 ; Set LME=1\r
+ wrmsr ; Write EFER\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 eax, cr0 ; Read CR0\r
+ bts eax, 31 ; Set PG=1\r
+ mov cr0, eax ; Write CR0\r
\r
- mov eax, cr0 ; Read CR0.\r
- bts eax, 31 ; Set PG=1.\r
- mov cr0, eax ; Write CR0.\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
- mov ax, LONG_MODE_DS\r
+ mov eax, edi\r
mov ds, ax\r
mov es, ax\r
mov ss, ax\r
sub rsp, 20h\r
call rax ; invoke C function\r
add rsp, 20h\r
+ jmp $\r
\r
RendezvousFunnelProcEnd:\r
\r
-global ASM_PFX(AsmCliHltLoop)\r
-ASM_PFX(AsmCliHltLoop):\r
- cli\r
- hlt\r
- jmp $-2\r
-\r
;-------------------------------------------------------------------------------------\r
; AsmGetAddressMap (&AddressMap);\r
;-------------------------------------------------------------------------------------\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
pop rax\r
\r
ret\r
-\r
-global ASM_PFX(AsmInitializeGdt)\r
-ASM_PFX(AsmInitializeGdt):\r
- push rbp\r
- mov rbp, rsp\r
-\r
- lgdt [rcx] ; update the GDTR\r
-\r
- sub rsp, 0x10\r
- mov rax, ASM_PFX(SetCodeSelectorFarJump)\r
- mov [rsp], rax\r
- mov rdx, LONG_MODE_CS\r
- mov [rsp + 4], dx ; get new CS\r
- jmp far dword [rsp] ; far jump with new CS\r
-ASM_PFX(SetCodeSelectorFarJump):\r
- add rsp, 0x10\r
-\r
- mov rax, LONG_MODE_DS ; get new DS\r
- mov ds, ax\r
- mov es, ax\r
- mov fs, ax\r
- mov gs, ax\r
- mov ss, ax\r
-\r
- pop rbp\r
-\r
- ret\r