1 ;------------------------------------------------------------------------------ ;
2 ; Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
3 ; SPDX-License-Identifier: BSD-2-Clause-Patent
11 ; Exception handlers used in SM mode
13 ;-------------------------------------------------------------------------------
15 %include "StuffRsbNasm.inc"
17 global ASM_PFX(gcStmPsd)
19 extern ASM_PFX(SmmStmExceptionHandler)
20 extern ASM_PFX(SmmStmSetup)
21 extern ASM_PFX(SmmStmTeardown)
22 extern ASM_PFX(gStmXdSupported)
23 extern ASM_PFX(gStmSmiHandlerIdtr)
25 %define MSR_IA32_MISC_ENABLE 0x1A0
26 %define MSR_EFER 0xc0000080
27 %define MSR_EFER_XD 0x800
36 ; This structure serves as a template for all processors.
43 DB 0x0F ; Cr4Pse;Cr4Pae;Intel64Mode;ExecutionDisableOutsideSmrr
54 DQ ASM_PFX(OnStmSetup)
55 DQ ASM_PFX(OnStmTeardown)
56 DQ 0 ; SmmSmiHandlerRip - SMM guest entrypoint
57 DQ 0 ; SmmSmiHandlerRsp
60 DD 0x80010100 ; RequiredStmSmmRevId
61 DQ ASM_PFX(OnException)
64 DW 0x01F ; ExceptionFilter
67 DQ 0 ; BiosHwResourceRequirementsPtr
69 DB 0 ; PhysicalAddressBits
70 PSD_SIZE equ $ - ASM_PFX(gcStmPsd)
74 ;------------------------------------------------------------------------------
75 ; SMM Exception handlers
76 ;------------------------------------------------------------------------------
77 global ASM_PFX(OnException)
81 call ASM_PFX(SmmStmExceptionHandler)
88 global ASM_PFX(OnStmSetup)
91 ; Check XD disable bit
94 lea rax, [ASM_PFX(gStmXdSupported)]
98 mov ecx, MSR_IA32_MISC_ENABLE
100 mov r8, rdx ; save MSR_IA32_MISC_ENABLE[63-32]
101 test edx, BIT2 ; MSR_IA32_MISC_ENABLE[34]
103 and dx, 0xFFFB ; clear XD Disable bit if it is set
108 or ax, MSR_EFER_XD ; enable NXE
114 call ASM_PFX(SmmStmSetup)
117 lea rax, [ASM_PFX(gStmXdSupported)]
121 pop rdx ; get saved MSR_IA32_MISC_ENABLE[63-32]
124 mov ecx, MSR_IA32_MISC_ENABLE
126 or dx, BIT2 ; set XD Disable bit if it was set before entering into SMM
133 global ASM_PFX(OnStmTeardown)
134 ASM_PFX(OnStmTeardown):
136 ; Check XD disable bit
139 lea rax, [ASM_PFX(gStmXdSupported)]
143 mov ecx, MSR_IA32_MISC_ENABLE
145 mov r8, rdx ; save MSR_IA32_MISC_ENABLE[63-32]
146 test edx, BIT2 ; MSR_IA32_MISC_ENABLE[34]
148 and dx, 0xFFFB ; clear XD Disable bit if it is set
153 or ax, MSR_EFER_XD ; enable NXE
159 call ASM_PFX(SmmStmTeardown)
162 lea rax, [ASM_PFX(gStmXdSupported)]
166 pop rdx ; get saved MSR_IA32_MISC_ENABLE[63-32]
169 mov ecx, MSR_IA32_MISC_ENABLE
171 or dx, BIT2 ; set XD Disable bit if it was set before entering into SMM