]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.S
UefiCpuPkg/PiSmmCpuDxeSmm: Remove MTRRs from PSD structure
[mirror_edk2.git] / UefiCpuPkg / PiSmmCpuDxeSmm / Ia32 / SmiEntry.S
CommitLineData
7947da3c
MK
1#------------------------------------------------------------------------------\r
2#\r
717fb604 3# Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
7947da3c
MK
4# This program and the accompanying materials\r
5# are licensed and made available under the terms and conditions of the BSD License\r
6# which accompanies this distribution. The full text of the license may be found at\r
7# http://opensource.org/licenses/bsd-license.php.\r
8#\r
9# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11#\r
12# Module Name:\r
13#\r
14# SmiEntry.S\r
15#\r
16# Abstract:\r
17#\r
18# Code template of the SMI handler for a particular processor\r
19#\r
20#------------------------------------------------------------------------------\r
21\r
22ASM_GLOBAL ASM_PFX(gcSmiHandlerTemplate)\r
23ASM_GLOBAL ASM_PFX(gcSmiHandlerSize)\r
24ASM_GLOBAL ASM_PFX(gSmiCr3)\r
25ASM_GLOBAL ASM_PFX(gSmiStack)\r
26ASM_GLOBAL ASM_PFX(gSmbase)\r
717fb604 27ASM_GLOBAL ASM_PFX(mXdSupported)\r
7947da3c
MK
28ASM_GLOBAL ASM_PFX(FeaturePcdGet (PcdCpuSmmStackGuard))\r
29ASM_GLOBAL ASM_PFX(gSmiHandlerIdtr)\r
30\r
717fb604
JY
31.equ MSR_EFER, 0xc0000080\r
32.equ MSR_EFER_XD, 0x800\r
33\r
7947da3c
MK
34.equ DSC_OFFSET, 0xfb00\r
35.equ DSC_GDTPTR, 0x30\r
36.equ DSC_GDTSIZ, 0x38\r
37.equ DSC_CS, 14\r
38.equ DSC_DS, 16\r
39.equ DSC_SS, 18\r
40.equ DSC_OTHERSEG, 20\r
41\r
42.equ PROTECT_MODE_CS, 0x08\r
43.equ PROTECT_MODE_DS, 0x20\r
44.equ TSS_SEGMENT, 0x40\r
45\r
46 .text\r
47\r
48ASM_PFX(gcSmiHandlerTemplate):\r
49\r
50_SmiEntryPoint:\r
51 .byte 0xbb # mov bx, imm16\r
52 .word _GdtDesc - _SmiEntryPoint + 0x8000\r
53 .byte 0x2e,0xa1 # mov ax, cs:[offset16]\r
54 .word DSC_OFFSET + DSC_GDTSIZ\r
55 decl %eax\r
56 movl %eax, %cs:(%edi) # mov cs:[bx], ax\r
57 .byte 0x66,0x2e,0xa1 # mov eax, cs:[offset16]\r
58 .word DSC_OFFSET + DSC_GDTPTR\r
59 movw %ax, %cs:2(%edi)\r
60 movw %ax, %bp # ebp = GDT base\r
61 .byte 0x66\r
62 lgdt %cs:(%edi)\r
63# Patch ProtectedMode Segment\r
64 .byte 0xb8 # mov ax, imm16\r
65 .word PROTECT_MODE_CS # set AX for segment directly\r
66 movl %eax, %cs:-2(%edi) # mov cs:[bx - 2], ax\r
67# Patch ProtectedMode entry\r
68 .byte 0x66, 0xbf # mov edi, SMBASE\r
69ASM_PFX(gSmbase): .space 4\r
70 .byte 0x67\r
71 lea ((Start32bit - _SmiEntryPoint) + 0x8000)(%edi), %ax\r
72 movw %ax, %cs:-6(%edi)\r
73 movl %cr0, %ebx\r
74 .byte 0x66\r
75 andl $0x9ffafff3, %ebx\r
76 .byte 0x66\r
77 orl $0x23, %ebx\r
78 movl %ebx, %cr0\r
79 .byte 0x66,0xea\r
80 .space 4\r
81 .space 2\r
82_GdtDesc: .space 4\r
83 .space 2\r
84\r
85Start32bit:\r
86 movw $PROTECT_MODE_DS, %ax\r
87 movl %eax,%ds\r
88 movl %eax,%es\r
89 movl %eax,%fs\r
90 movl %eax,%gs\r
91 movl %eax,%ss\r
92 .byte 0xbc # mov esp, imm32\r
93ASM_PFX(gSmiStack): .space 4\r
94 movl $ASM_PFX(gSmiHandlerIdtr), %eax\r
95 lidt (%eax)\r
96 jmp ProtFlatMode\r
97\r
98ProtFlatMode:\r
99 .byte 0xb8 # mov eax, imm32\r
100ASM_PFX(gSmiCr3): .space 4\r
101 movl %eax, %cr3\r
102#\r
103# Need to test for CR4 specific bit support\r
104#\r
105 movl $1, %eax\r
106 cpuid # use CPUID to determine if specific CR4 bits are supported\r
107 xorl %eax, %eax # Clear EAX\r
108 testl $BIT2, %edx # Check for DE capabilities\r
109 jz L8\r
110 orl $BIT3, %eax\r
111L8:\r
112 testl $BIT6, %edx # Check for PAE capabilities\r
113 jz L9\r
114 orl $BIT5, %eax\r
115L9:\r
116 testl $BIT7, %edx # Check for MCE capabilities\r
117 jz L10\r
118 orl $BIT6, %eax\r
119L10:\r
120 testl $BIT24, %edx # Check for FXSR capabilities\r
121 jz L11\r
122 orl $BIT9, %eax\r
123L11:\r
124 testl $BIT25, %edx # Check for SSE capabilities\r
125 jz L12\r
126 orl $BIT10, %eax\r
127L12: # as cr4.PGE is not set here, refresh cr3\r
128 movl %eax, %cr4 # in PreModifyMtrrs() to flush TLB.\r
717fb604
JY
129\r
130 cmpb $0, ASM_PFX(FeaturePcdGet (PcdCpuSmmStackGuard))\r
131 jz L5\r
132# Load TSS\r
133 movb $0x89, (TSS_SEGMENT + 5)(%ebp) # clear busy flag\r
134 movl $TSS_SEGMENT, %eax\r
135 ltrw %ax\r
136L5:\r
137\r
138# enable NXE if supported\r
139 .byte 0xb0 # mov al, imm8\r
140ASM_PFX(mXdSupported): .byte 1\r
141 cmpb $0, %al\r
142 jz SkipNxe\r
143#\r
144# Check XD disable bit\r
145#\r
146 movl $MSR_IA32_MISC_ENABLE, %ecx\r
147 rdmsr\r
148 pushl %edx # save MSR_IA32_MISC_ENABLE[63-32]\r
149 testl $BIT2, %edx # MSR_IA32_MISC_ENABLE[34]\r
150 jz L13\r
151 andw $0x0FFFB, %dx # clear XD Disable bit if it is set\r
152 wrmsr\r
153L13:\r
154 movl $MSR_EFER, %ecx\r
155 rdmsr\r
156 orw $MSR_EFER_XD,%ax # enable NXE\r
157 wrmsr\r
158SkipNxe:\r
159 subl $4, %esp\r
160NxeDone:\r
161\r
7947da3c 162 movl %cr0, %ebx\r
717fb604 163 orl $0x080010023, %ebx # enable paging + WP + NE + MP + PE\r
7947da3c
MK
164 movl %ebx, %cr0\r
165 leal DSC_OFFSET(%edi),%ebx\r
166 movw DSC_DS(%ebx),%ax\r
167 movl %eax, %ds\r
168 movw DSC_OTHERSEG(%ebx),%ax\r
169 movl %eax, %es\r
170 movl %eax, %fs\r
171 movl %eax, %gs\r
172 movw DSC_SS(%ebx),%ax\r
173 movl %eax, %ss\r
174\r
7947da3c
MK
175# jmp _SmiHandler # instruction is not needed\r
176\r
177_SmiHandler:\r
717fb604 178 movl 4(%esp), %ebx\r
7947da3c 179\r
f45f2d4a
JY
180 pushl %ebx\r
181 movl $ASM_PFX(CpuSmmDebugEntry), %eax\r
182 call *%eax\r
717fb604
JY
183 addl $4, %esp\r
184\r
f45f2d4a 185 pushl %ebx\r
7947da3c
MK
186 movl $ASM_PFX(SmiRendezvous), %eax\r
187 call *%eax\r
717fb604 188 addl $4, %esp\r
7947da3c 189\r
f45f2d4a
JY
190 pushl %ebx\r
191 movl $ASM_PFX(CpuSmmDebugExit), %eax\r
192 call *%eax\r
717fb604
JY
193 addl $4, %esp\r
194\r
195 movl $ASM_PFX(mXdSupported), %eax\r
196 movb (%eax), %al\r
197 cmpb $0, %al\r
198 jz L16\r
199 popl %edx # get saved MSR_IA32_MISC_ENABLE[63-32]\r
200 testl $BIT2, %edx\r
201 jz L16\r
202 movl $MSR_IA32_MISC_ENABLE, %ecx\r
203 rdmsr\r
204 orw $BIT2, %dx # set XD Disable bit if it was set before entering into SMM\r
205 wrmsr\r
206\r
207L16:\r
7947da3c
MK
208 rsm\r
209\r
210ASM_PFX(gcSmiHandlerSize): .word . - _SmiEntryPoint\r