]>
Commit | Line | Data |
---|---|---|
09119a00 | 1 | ;------------------------------------------------------------------------------ ;\r |
1c7a65eb | 2 | ; Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>\r |
09119a00 MK |
3 | ; This program and the accompanying materials\r |
4 | ; are licensed and made available under the terms and conditions of the BSD License\r | |
5 | ; which accompanies this distribution. The full text of the license may be found at\r | |
6 | ; http://opensource.org/licenses/bsd-license.php.\r | |
7 | ;\r | |
8 | ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
9 | ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
10 | ;\r | |
11 | ; Module Name:\r | |
12 | ;\r | |
13 | ; SmiException.nasm\r | |
14 | ;\r | |
15 | ; Abstract:\r | |
16 | ;\r | |
17 | ; Exception handlers used in SM mode\r | |
18 | ;\r | |
19 | ;-------------------------------------------------------------------------------\r | |
20 | \r | |
0df50560 HW |
21 | %include "StuffRsb.inc"\r |
22 | \r | |
09119a00 MK |
23 | global ASM_PFX(gcStmPsd)\r |
24 | \r | |
25 | extern ASM_PFX(SmmStmExceptionHandler)\r | |
26 | extern ASM_PFX(SmmStmSetup)\r | |
27 | extern ASM_PFX(SmmStmTeardown)\r | |
28 | extern ASM_PFX(gStmXdSupported)\r | |
29 | extern ASM_PFX(gStmSmiHandlerIdtr)\r | |
30 | \r | |
31 | %define MSR_IA32_MISC_ENABLE 0x1A0\r | |
32 | %define MSR_EFER 0xc0000080\r | |
33 | %define MSR_EFER_XD 0x800\r | |
34 | \r | |
35 | CODE_SEL equ 0x38\r | |
36 | DATA_SEL equ 0x20\r | |
37 | TR_SEL equ 0x40\r | |
38 | \r | |
39 | SECTION .data\r | |
40 | \r | |
41 | ;\r | |
42 | ; This structure serves as a template for all processors.\r | |
43 | ;\r | |
44 | ASM_PFX(gcStmPsd):\r | |
45 | DB 'TXTPSSIG'\r | |
46 | DW PSD_SIZE\r | |
47 | DW 1 ; Version\r | |
48 | DD 0 ; LocalApicId\r | |
49 | DB 0x0F ; Cr4Pse;Cr4Pae;Intel64Mode;ExecutionDisableOutsideSmrr\r | |
50 | DB 0 ; BIOS to STM\r | |
51 | DB 0 ; STM to BIOS\r | |
52 | DB 0\r | |
53 | DW CODE_SEL\r | |
54 | DW DATA_SEL\r | |
55 | DW DATA_SEL\r | |
56 | DW DATA_SEL\r | |
57 | DW TR_SEL\r | |
58 | DW 0\r | |
59 | DQ 0 ; SmmCr3\r | |
60 | DQ ASM_PFX(OnStmSetup)\r | |
61 | DQ ASM_PFX(OnStmTeardown)\r | |
62 | DQ 0 ; SmmSmiHandlerRip - SMM guest entrypoint\r | |
63 | DQ 0 ; SmmSmiHandlerRsp\r | |
64 | DQ 0\r | |
65 | DD 0\r | |
66 | DD 0x80010100 ; RequiredStmSmmRevId\r | |
67 | DQ ASM_PFX(OnException)\r | |
68 | DQ 0 ; ExceptionStack\r | |
69 | DW DATA_SEL\r | |
70 | DW 0x01F ; ExceptionFilter\r | |
71 | DD 0\r | |
72 | DQ 0\r | |
73 | DQ 0 ; BiosHwResourceRequirementsPtr\r | |
74 | DQ 0 ; AcpiRsdp\r | |
75 | DB 0 ; PhysicalAddressBits\r | |
76 | PSD_SIZE equ $ - ASM_PFX(gcStmPsd)\r | |
77 | \r | |
78 | DEFAULT REL\r | |
79 | SECTION .text\r | |
80 | ;------------------------------------------------------------------------------\r | |
81 | ; SMM Exception handlers\r | |
82 | ;------------------------------------------------------------------------------\r | |
83 | global ASM_PFX(OnException)\r | |
84 | ASM_PFX(OnException):\r | |
85 | mov rcx, rsp\r | |
86 | add rsp, -0x28\r | |
87 | call ASM_PFX(SmmStmExceptionHandler)\r | |
88 | add rsp, 0x28\r | |
89 | mov ebx, eax\r | |
90 | mov eax, 4\r | |
4c34a8ea | 91 | vmcall\r |
09119a00 MK |
92 | jmp $\r |
93 | \r | |
94 | global ASM_PFX(OnStmSetup)\r | |
95 | ASM_PFX(OnStmSetup):\r | |
96 | ;\r | |
97 | ; Check XD disable bit\r | |
98 | ;\r | |
99 | xor r8, r8\r | |
1c7a65eb | 100 | lea rax, [ASM_PFX(gStmXdSupported)]\r |
09119a00 MK |
101 | mov al, [rax]\r |
102 | cmp al, 0\r | |
103 | jz @StmXdDone1\r | |
104 | mov ecx, MSR_IA32_MISC_ENABLE\r | |
105 | rdmsr\r | |
106 | mov r8, rdx ; save MSR_IA32_MISC_ENABLE[63-32]\r | |
107 | test edx, BIT2 ; MSR_IA32_MISC_ENABLE[34]\r | |
108 | jz .01\r | |
109 | and dx, 0xFFFB ; clear XD Disable bit if it is set\r | |
110 | wrmsr\r | |
111 | .01:\r | |
112 | mov ecx, MSR_EFER\r | |
113 | rdmsr\r | |
114 | or ax, MSR_EFER_XD ; enable NXE\r | |
115 | wrmsr\r | |
116 | @StmXdDone1:\r | |
117 | push r8\r | |
118 | \r | |
119 | add rsp, -0x20\r | |
120 | call ASM_PFX(SmmStmSetup)\r | |
121 | add rsp, 0x20\r | |
122 | \r | |
1c7a65eb | 123 | lea rax, [ASM_PFX(gStmXdSupported)]\r |
09119a00 MK |
124 | mov al, [rax]\r |
125 | cmp al, 0\r | |
126 | jz .11\r | |
127 | pop rdx ; get saved MSR_IA32_MISC_ENABLE[63-32]\r | |
128 | test edx, BIT2\r | |
129 | jz .11\r | |
130 | mov ecx, MSR_IA32_MISC_ENABLE\r | |
131 | rdmsr\r | |
132 | or dx, BIT2 ; set XD Disable bit if it was set before entering into SMM\r | |
133 | wrmsr\r | |
134 | \r | |
135 | .11:\r | |
0df50560 HW |
136 | StuffRsb64\r |
137 | rsm\r | |
09119a00 MK |
138 | \r |
139 | global ASM_PFX(OnStmTeardown)\r | |
140 | ASM_PFX(OnStmTeardown):\r | |
141 | ;\r | |
142 | ; Check XD disable bit\r | |
143 | ;\r | |
144 | xor r8, r8\r | |
1c7a65eb | 145 | lea rax, [ASM_PFX(gStmXdSupported)]\r |
09119a00 MK |
146 | mov al, [rax]\r |
147 | cmp al, 0\r | |
148 | jz @StmXdDone2\r | |
149 | mov ecx, MSR_IA32_MISC_ENABLE\r | |
150 | rdmsr\r | |
151 | mov r8, rdx ; save MSR_IA32_MISC_ENABLE[63-32]\r | |
152 | test edx, BIT2 ; MSR_IA32_MISC_ENABLE[34]\r | |
153 | jz .02\r | |
154 | and dx, 0xFFFB ; clear XD Disable bit if it is set\r | |
155 | wrmsr\r | |
156 | .02:\r | |
157 | mov ecx, MSR_EFER\r | |
158 | rdmsr\r | |
159 | or ax, MSR_EFER_XD ; enable NXE\r | |
160 | wrmsr\r | |
161 | @StmXdDone2:\r | |
162 | push r8\r | |
163 | \r | |
164 | add rsp, -0x20\r | |
165 | call ASM_PFX(SmmStmTeardown)\r | |
166 | add rsp, 0x20\r | |
167 | \r | |
1c7a65eb | 168 | lea rax, [ASM_PFX(gStmXdSupported)]\r |
09119a00 MK |
169 | mov al, [rax]\r |
170 | cmp al, 0\r | |
171 | jz .12\r | |
172 | pop rdx ; get saved MSR_IA32_MISC_ENABLE[63-32]\r | |
173 | test edx, BIT2\r | |
174 | jz .12\r | |
175 | mov ecx, MSR_IA32_MISC_ENABLE\r | |
176 | rdmsr\r | |
177 | or dx, BIT2 ; set XD Disable bit if it was set before entering into SMM\r | |
178 | wrmsr\r | |
179 | \r | |
180 | .12:\r | |
0df50560 HW |
181 | StuffRsb64\r |
182 | rsm\r |