1 ;------------------------------------------------------------------------------ ;
2 ; Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
3 ; SPDX-License-Identifier: BSD-2-Clause-Patent
11 ; Functions for relocating SMBASE's for all processors
13 ;-------------------------------------------------------------------------------
15 %include "StuffRsbNasm.inc"
17 extern ASM_PFX(SmmInitHandler)
18 extern ASM_PFX(mRebasedFlag)
19 extern ASM_PFX(mSmmRelocationOriginalAddress)
21 global ASM_PFX(gPatchSmmCr3)
22 global ASM_PFX(gPatchSmmCr4)
23 global ASM_PFX(gPatchSmmCr0)
24 global ASM_PFX(gPatchSmmInitStack)
25 global ASM_PFX(gcSmiInitGdtr)
26 global ASM_PFX(gcSmmInitSize)
27 global ASM_PFX(gcSmmInitTemplate)
29 %define PROTECT_MODE_CS 0x8
30 %define PROTECT_MODE_DS 0x20
34 ASM_PFX(gcSmiInitGdtr):
38 global ASM_PFX(SmmStartup)
42 mov eax, 0x80000001 ; read capability
44 mov ebx, edx ; rdmsr will change edx. keep it in ebx.
45 and ebx, BIT20 ; extract NX capability bit
46 shr ebx, 9 ; shift bit to IA32_EFER.NXE[BIT11] position
47 mov eax, strict dword 0 ; source operand will be patched
48 ASM_PFX(gPatchSmmCr3):
50 o32 lgdt [cs:ebp + (ASM_PFX(gcSmiInitGdtr) - ASM_PFX(SmmStartup))]
51 mov eax, strict dword 0 ; source operand will be patched
52 ASM_PFX(gPatchSmmCr4):
54 mov ecx, 0xc0000080 ; IA32_EFER MSR
56 or eax, ebx ; set NXE bit if NX is available
58 mov eax, strict dword 0 ; source operand will be patched
59 ASM_PFX(gPatchSmmCr0):
60 mov di, PROTECT_MODE_DS
62 jmp PROTECT_MODE_CS : dword @32bit
71 mov esp, strict dword 0 ; source operand will be patched
72 ASM_PFX(gPatchSmmInitStack):
73 call ASM_PFX(SmmInitHandler)
78 ASM_PFX(gcSmmInitTemplate):
79 mov ebp, ASM_PFX(SmmStartup)
83 ASM_PFX(gcSmmInitSize): DW $ - ASM_PFX(gcSmmInitTemplate)
86 global ASM_PFX(SmmRelocationSemaphoreComplete)
87 ASM_PFX(SmmRelocationSemaphoreComplete):
89 mov eax, [ASM_PFX(mRebasedFlag)]
92 jmp [ASM_PFX(mSmmRelocationOriginalAddress)]
94 global ASM_PFX(PiSmmCpuSmmInitFixupAddress)
95 ASM_PFX(PiSmmCpuSmmInitFixupAddress):