;------------------------------------------------------------------------------ ;\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
; 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
- 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
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
- 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
- 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
-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
- 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
- db 0B9h\r
+ db 66h, 0B9h\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, 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 67h, 0EAh ; far jump\r
+ db 66h, 0EAh ; far jump\r
dd 0h ; 32-bit offset\r
- dw LONG_MODE_CS ; 16-bit selector\r
+ dw 0h ; 16-bit selector\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
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
ret\r
AsmExchangeRole ENDP\r
\r
-AsmInitializeGdt PROC\r
- push rbp\r
- mov rbp, rsp\r
-\r
- lgdt fword PTR [rcx] ; update the GDTR\r
-\r
- sub rsp, 0x10\r
- lea rax, SetCodeSelectorFarJump\r
- mov [rsp], rax\r
- mov rdx, LONG_MODE_CS\r
- mov [rsp + 4], dx ; get new CS\r
- jmp fword ptr [rsp]\r
-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
- ret\r
-AsmInitializeGdt ENDP\r
-\r
END\r