;\r
;-------------------------------------------------------------------------------\r
\r
+%include "StuffRsb.inc"\r
+\r
;\r
; Variables referrenced by C code\r
;\r
extern ASM_PFX(CpuSmmDebugEntry)\r
extern ASM_PFX(CpuSmmDebugExit)\r
\r
-global ASM_PFX(gSmbase)\r
-global ASM_PFX(mXdSupported)\r
-global ASM_PFX(gSmiStack)\r
-global ASM_PFX(gSmiCr3)\r
+global ASM_PFX(gPatchSmbase)\r
+extern ASM_PFX(mXdSupported)\r
+global ASM_PFX(gPatchXdSupported)\r
+global ASM_PFX(gPatchSmiStack)\r
+global ASM_PFX(gPatchSmiCr3)\r
global ASM_PFX(gcSmiHandlerTemplate)\r
global ASM_PFX(gcSmiHandlerSize)\r
\r
o32 lgdt [cs:bx] ; lgdt fword ptr cs:[bx]\r
mov ax, PROTECT_MODE_CS\r
mov [cs:bx-0x2],ax\r
- DB 0x66, 0xbf ; mov edi, SMBASE\r
-ASM_PFX(gSmbase): DD 0\r
+ mov edi, strict dword 0 ; source operand will be patched\r
+ASM_PFX(gPatchSmbase):\r
lea eax, [edi + (@ProtectedMode - _SmiEntryPoint) + 0x8000]\r
mov [cs:bx-0x6],eax\r
mov ebx, cr0\r
o16 mov fs, ax\r
o16 mov gs, ax\r
o16 mov ss, ax\r
- DB 0xbc ; mov esp, imm32\r
-ASM_PFX(gSmiStack): DD 0\r
+ mov esp, strict dword 0 ; source operand will be patched\r
+ASM_PFX(gPatchSmiStack):\r
jmp ProtFlatMode\r
\r
BITS 64\r
ProtFlatMode:\r
- DB 0xb8 ; mov eax, offset gSmiCr3\r
-ASM_PFX(gSmiCr3): DD 0\r
+ mov eax, strict dword 0 ; source operand will be patched\r
+ASM_PFX(gPatchSmiCr3):\r
mov cr3, rax\r
mov eax, 0x668 ; as cr4.PGE is not set here, refresh cr3\r
mov cr4, rax ; in PreModifyMtrrs() to flush TLB.\r
ltr ax\r
\r
; enable NXE if supported\r
- DB 0xb0 ; mov al, imm8\r
-ASM_PFX(mXdSupported): DB 1\r
+ mov al, strict byte 1 ; source operand may be patched\r
+ASM_PFX(gPatchXdSupported):\r
cmp al, 0\r
jz @SkipXd\r
;\r
mov gs, eax\r
mov ax, [rbx + DSC_SS]\r
mov ss, eax\r
- mov rax, strict qword 0 ; mov rax, _SmiHandler\r
-_SmiHandlerAbsAddr:\r
- jmp rax\r
\r
_SmiHandler:\r
mov rbx, [rsp + 0x8] ; rcx <- CpuIndex\r
; Save FP registers\r
;\r
sub rsp, 0x200\r
- DB 0x48 ; FXSAVE64\r
- fxsave [rsp]\r
+ fxsave64 [rsp]\r
\r
add rsp, -0x20\r
\r
mov rcx, rbx\r
- call ASM_PFX(CpuSmmDebugEntry)\r
+ mov rax, strict qword 0 ; call ASM_PFX(CpuSmmDebugEntry)\r
+CpuSmmDebugEntryAbsAddr:\r
+ call rax\r
\r
mov rcx, rbx\r
- call ASM_PFX(SmiRendezvous)\r
+ mov rax, strict qword 0 ; call ASM_PFX(SmiRendezvous)\r
+SmiRendezvousAbsAddr:\r
+ call rax\r
\r
mov rcx, rbx\r
- call ASM_PFX(CpuSmmDebugExit)\r
+ mov rax, strict qword 0 ; call ASM_PFX(CpuSmmDebugExit)\r
+CpuSmmDebugExitAbsAddr:\r
+ call rax\r
\r
add rsp, 0x20\r
\r
;\r
; Restore FP registers\r
;\r
- DB 0x48 ; FXRSTOR64\r
- fxrstor [rsp]\r
+ fxrstor64 [rsp]\r
\r
add rsp, 0x200\r
\r
- lea rax, [ASM_PFX(mXdSupported)]\r
+ mov rax, strict qword 0 ; lea rax, [ASM_PFX(mXdSupported)]\r
+mXdSupportedAbsAddr:\r
mov al, [rax]\r
cmp al, 0\r
jz .1\r
wrmsr\r
\r
.1:\r
+ StuffRsb64\r
rsm\r
\r
ASM_PFX(gcSmiHandlerSize) DW $ - _SmiEntryPoint\r
\r
+;\r
+; Retrieve the address and fill it into mov opcode.\r
+;\r
+; It is called in the driver entry point first.\r
+; It is used to fix up the real address in mov opcode.\r
+; Then, after the code logic is copied to the different location,\r
+; the code can also run.\r
+;\r
global ASM_PFX(PiSmmCpuSmiEntryFixupAddress)\r
ASM_PFX(PiSmmCpuSmiEntryFixupAddress):\r
lea rax, [ASM_PFX(gSmiHandlerIdtr)]\r
lea rcx, [SmiHandlerIdtrAbsAddr]\r
mov qword [rcx - 8], rax\r
\r
- lea rax, [_SmiHandler]\r
- lea rcx, [_SmiHandlerAbsAddr]\r
+ lea rax, [ASM_PFX(CpuSmmDebugEntry)]\r
+ lea rcx, [CpuSmmDebugEntryAbsAddr]\r
+ mov qword [rcx - 8], rax\r
+\r
+ lea rax, [ASM_PFX(SmiRendezvous)]\r
+ lea rcx, [SmiRendezvousAbsAddr]\r
+ mov qword [rcx - 8], rax\r
+\r
+ lea rax, [ASM_PFX(CpuSmmDebugExit)]\r
+ lea rcx, [CpuSmmDebugExitAbsAddr]\r
+ mov qword [rcx - 8], rax\r
+\r
+ lea rax, [ASM_PFX(mXdSupported)]\r
+ lea rcx, [mXdSupportedAbsAddr]\r
mov qword [rcx - 8], rax\r
ret\r