1 ;------------------------------------------------------------------------------ ;
2 ; Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
3 ; This program and the accompanying materials
4 ; are licensed and made available under the terms and conditions of the BSD License
5 ; which accompanies this distribution. The full text of the license may be found at
6 ; http://opensource.org/licenses/bsd-license.php.
8 ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 ; Exception handlers used in SM mode
19 ;-------------------------------------------------------------------------------
21 %include "StuffRsbNasm.inc"
23 global ASM_PFX(gcStmPsd)
25 extern ASM_PFX(SmmStmExceptionHandler)
26 extern ASM_PFX(SmmStmSetup)
27 extern ASM_PFX(SmmStmTeardown)
28 extern ASM_PFX(gStmXdSupported)
29 extern ASM_PFX(gStmSmiHandlerIdtr)
31 %define MSR_IA32_MISC_ENABLE 0x1A0
32 %define MSR_EFER 0xc0000080
33 %define MSR_EFER_XD 0x800
42 ; This structure serves as a template for all processors.
49 DB 0x0F ; Cr4Pse;Cr4Pae;Intel64Mode;ExecutionDisableOutsideSmrr
60 DQ ASM_PFX(OnStmSetup)
61 DQ ASM_PFX(OnStmTeardown)
62 DQ 0 ; SmmSmiHandlerRip - SMM guest entrypoint
63 DQ 0 ; SmmSmiHandlerRsp
66 DD 0x80010100 ; RequiredStmSmmRevId
67 DQ ASM_PFX(OnException)
70 DW 0x01F ; ExceptionFilter
73 DQ 0 ; BiosHwResourceRequirementsPtr
75 DB 0 ; PhysicalAddressBits
76 PSD_SIZE equ $ - ASM_PFX(gcStmPsd)
80 ;------------------------------------------------------------------------------
81 ; SMM Exception handlers
82 ;------------------------------------------------------------------------------
83 global ASM_PFX(OnException)
87 call ASM_PFX(SmmStmExceptionHandler)
94 global ASM_PFX(OnStmSetup)
97 ; Check XD disable bit
100 lea rax, [ASM_PFX(gStmXdSupported)]
104 mov ecx, MSR_IA32_MISC_ENABLE
106 mov r8, rdx ; save MSR_IA32_MISC_ENABLE[63-32]
107 test edx, BIT2 ; MSR_IA32_MISC_ENABLE[34]
109 and dx, 0xFFFB ; clear XD Disable bit if it is set
114 or ax, MSR_EFER_XD ; enable NXE
120 call ASM_PFX(SmmStmSetup)
123 lea rax, [ASM_PFX(gStmXdSupported)]
127 pop rdx ; get saved MSR_IA32_MISC_ENABLE[63-32]
130 mov ecx, MSR_IA32_MISC_ENABLE
132 or dx, BIT2 ; set XD Disable bit if it was set before entering into SMM
139 global ASM_PFX(OnStmTeardown)
140 ASM_PFX(OnStmTeardown):
142 ; Check XD disable bit
145 lea rax, [ASM_PFX(gStmXdSupported)]
149 mov ecx, MSR_IA32_MISC_ENABLE
151 mov r8, rdx ; save MSR_IA32_MISC_ENABLE[63-32]
152 test edx, BIT2 ; MSR_IA32_MISC_ENABLE[34]
154 and dx, 0xFFFB ; clear XD Disable bit if it is set
159 or ax, MSR_EFER_XD ; enable NXE
165 call ASM_PFX(SmmStmTeardown)
168 lea rax, [ASM_PFX(gStmXdSupported)]
172 pop rdx ; get saved MSR_IA32_MISC_ENABLE[63-32]
175 mov ecx, MSR_IA32_MISC_ENABLE
177 or dx, BIT2 ; set XD Disable bit if it was set before entering into SMM