]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.asm
Install LoadedImage protocol for PiSmmCore.
[mirror_edk2.git] / UefiCpuPkg / PiSmmCpuDxeSmm / Ia32 / SmiEntry.asm
CommitLineData
7947da3c
MK
1;------------------------------------------------------------------------------ ;\r
2; Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
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; SmiEntry.asm\r
14;\r
15; Abstract:\r
16;\r
17; Code template of the SMI handler for a particular processor\r
18;\r
19;-------------------------------------------------------------------------------\r
20\r
21 .686p\r
22 .model flat,C\r
23 .xmm\r
24\r
25DSC_OFFSET EQU 0fb00h\r
26DSC_GDTPTR EQU 30h\r
27DSC_GDTSIZ EQU 38h\r
28DSC_CS EQU 14\r
29DSC_DS EQU 16\r
30DSC_SS EQU 18\r
31DSC_OTHERSEG EQU 20\r
32\r
33PROTECT_MODE_CS EQU 08h\r
34PROTECT_MODE_DS EQU 20h\r
35TSS_SEGMENT EQU 40h\r
36\r
37SmiRendezvous PROTO C\r
38\r
39EXTERNDEF gcSmiHandlerTemplate:BYTE\r
40EXTERNDEF gcSmiHandlerSize:WORD\r
41EXTERNDEF gSmiCr3:DWORD\r
42EXTERNDEF gSmiStack:DWORD\r
43EXTERNDEF gSmbase:DWORD\r
44EXTERNDEF FeaturePcdGet (PcdCpuSmmDebug):BYTE\r
45EXTERNDEF FeaturePcdGet (PcdCpuSmmStackGuard):BYTE\r
46EXTERNDEF gSmiHandlerIdtr:FWORD\r
47\r
48 .code\r
49\r
50gcSmiHandlerTemplate LABEL BYTE\r
51\r
52_SmiEntryPoint:\r
53 DB 0bbh ; mov bx, imm16\r
54 DW offset _GdtDesc - _SmiEntryPoint + 8000h\r
55 DB 2eh, 0a1h ; mov ax, cs:[offset16]\r
56 DW DSC_OFFSET + DSC_GDTSIZ\r
57 dec eax\r
58 mov cs:[edi], eax ; mov cs:[bx], ax\r
59 DB 66h, 2eh, 0a1h ; mov eax, cs:[offset16]\r
60 DW DSC_OFFSET + DSC_GDTPTR\r
61 mov cs:[edi + 2], ax ; mov cs:[bx + 2], eax\r
62 mov bp, ax ; ebp = GDT base\r
63 DB 66h\r
64 lgdt fword ptr cs:[edi] ; lgdt fword ptr cs:[bx]\r
65; Patch ProtectedMode Segment\r
66 DB 0b8h ; mov ax, imm16\r
67 DW PROTECT_MODE_CS ; set AX for segment directly\r
68 mov cs:[edi - 2], eax ; mov cs:[bx - 2], ax\r
69; Patch ProtectedMode entry\r
70 DB 66h, 0bfh ; mov edi, SMBASE\r
71gSmbase DD ?\r
72 DB 67h\r
73 lea ax, [edi + (@32bit - _SmiEntryPoint) + 8000h]\r
74 mov cs:[edi - 6], ax ; mov cs:[bx - 6], eax\r
75 mov ebx, cr0\r
76 DB 66h\r
77 and ebx, 9ffafff3h\r
78 DB 66h\r
79 or ebx, 23h\r
80 mov cr0, ebx\r
81 DB 66h, 0eah\r
82 DD ?\r
83 DW ?\r
84_GdtDesc FWORD ?\r
85\r
86@32bit:\r
87 mov ax, PROTECT_MODE_DS\r
88 mov ds, ax\r
89 mov es, ax\r
90 mov fs, ax\r
91 mov gs, ax\r
92 mov ss, ax\r
93 DB 0bch ; mov esp, imm32\r
94gSmiStack DD ?\r
95 mov eax, offset gSmiHandlerIdtr\r
96 lidt fword ptr [eax]\r
97 jmp ProtFlatMode\r
98\r
99ProtFlatMode:\r
100 DB 0b8h ; mov eax, imm32\r
101gSmiCr3 DD ?\r
102 mov cr3, eax\r
103;\r
104; Need to test for CR4 specific bit support\r
105;\r
106 mov eax, 1\r
107 cpuid ; use CPUID to determine if specific CR4 bits are supported\r
108 xor eax, eax ; Clear EAX\r
109 test edx, BIT2 ; Check for DE capabilities\r
110 jz @f\r
111 or eax, BIT3\r
112@@:\r
113 test edx, BIT6 ; Check for PAE capabilities\r
114 jz @f\r
115 or eax, BIT5\r
116@@:\r
117 test edx, BIT7 ; Check for MCE capabilities\r
118 jz @f\r
119 or eax, BIT6\r
120@@:\r
121 test edx, BIT24 ; Check for FXSR capabilities\r
122 jz @f\r
123 or eax, BIT9\r
124@@:\r
125 test edx, BIT25 ; Check for SSE capabilities\r
126 jz @f\r
127 or eax, BIT10\r
128@@: ; as cr4.PGE is not set here, refresh cr3\r
129 mov cr4, eax ; in PreModifyMtrrs() to flush TLB.\r
130 mov ebx, cr0\r
131 or ebx, 080000000h ; enable paging\r
132 mov cr0, ebx\r
133 lea ebx, [edi + DSC_OFFSET]\r
134 mov ax, [ebx + DSC_DS]\r
135 mov ds, eax\r
136 mov ax, [ebx + DSC_OTHERSEG]\r
137 mov es, eax\r
138 mov fs, eax\r
139 mov gs, eax\r
140 mov ax, [ebx + DSC_SS]\r
141 mov ss, eax\r
142\r
143 cmp FeaturePcdGet (PcdCpuSmmStackGuard), 0\r
144 jz @F\r
145\r
146; Load TSS\r
147 mov byte ptr [ebp + TSS_SEGMENT + 5], 89h ; clear busy flag\r
148 mov eax, TSS_SEGMENT\r
149 ltr ax\r
150@@:\r
151; jmp _SmiHandler ; instruction is not needed\r
152\r
153_SmiHandler PROC\r
154 cmp FeaturePcdGet (PcdCpuSmmDebug), 0\r
155 jz @3\r
156 call @1\r
157@1:\r
158 pop ebp\r
159 mov eax, 80000001h\r
160 cpuid\r
161 bt edx, 29 ; check cpuid to identify X64 or IA32\r
162 lea edi, [ebp - (@1 - _SmiEntryPoint) + 7fc8h]\r
163 lea esi, [edi + 4]\r
164 jnc @2\r
165 add esi, 4\r
166@2:\r
167 mov ecx, [esi]\r
168 mov edx, [edi]\r
169@5:\r
170 mov dr6, ecx\r
171 mov dr7, edx ; restore DR6 & DR7 before running C code\r
172@3:\r
173 mov ecx, [esp] ; CPU Index\r
174\r
175 push ecx\r
176 mov eax, SmiRendezvous\r
177 call eax\r
178 pop ecx\r
179\r
180 cmp FeaturePcdGet (PcdCpuSmmDebug), 0\r
181 jz @4\r
182\r
183 mov ecx, dr6\r
184 mov edx, dr7\r
185 mov [esi], ecx\r
186 mov [edi], edx\r
187@4:\r
188 rsm\r
189_SmiHandler ENDP\r
190\r
191gcSmiHandlerSize DW $ - _SmiEntryPoint\r
192\r
193 END\r