1 ;------------------------------------------------------------------------------ ;
2 ; Copyright (c) 2009 - 2015, 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 ; Code template of the SMI handler for a particular processor
19 ;-------------------------------------------------------------------------------
33 PROTECT_MODE_CS EQU 08h
34 PROTECT_MODE_DS EQU 20h
39 EXTERNDEF gcSmiHandlerTemplate:BYTE
40 EXTERNDEF gcSmiHandlerSize:WORD
41 EXTERNDEF gSmiCr3:DWORD
42 EXTERNDEF gSmiStack:DWORD
43 EXTERNDEF gSmbase:DWORD
44 EXTERNDEF FeaturePcdGet (PcdCpuSmmDebug):BYTE
45 EXTERNDEF FeaturePcdGet (PcdCpuSmmStackGuard):BYTE
46 EXTERNDEF gSmiHandlerIdtr:FWORD
50 gcSmiHandlerTemplate LABEL BYTE
53 DB 0bbh ; mov bx, imm16
54 DW offset _GdtDesc - _SmiEntryPoint + 8000h
55 DB 2eh, 0a1h ; mov ax, cs:[offset16]
56 DW DSC_OFFSET + DSC_GDTSIZ
58 mov cs:[edi], eax ; mov cs:[bx], ax
59 DB 66h, 2eh, 0a1h ; mov eax, cs:[offset16]
60 DW DSC_OFFSET + DSC_GDTPTR
61 mov cs:[edi + 2], ax ; mov cs:[bx + 2], eax
62 mov bp, ax ; ebp = GDT base
64 lgdt fword ptr cs:[edi] ; lgdt fword ptr cs:[bx]
65 ; Patch ProtectedMode Segment
66 DB 0b8h ; mov ax, imm16
67 DW PROTECT_MODE_CS ; set AX for segment directly
68 mov cs:[edi - 2], eax ; mov cs:[bx - 2], ax
69 ; Patch ProtectedMode entry
70 DB 66h, 0bfh ; mov edi, SMBASE
73 lea ax, [edi + (@32bit - _SmiEntryPoint) + 8000h]
74 mov cs:[edi - 6], ax ; mov cs:[bx - 6], eax
87 mov ax, PROTECT_MODE_DS
93 DB 0bch ; mov esp, imm32
95 mov eax, offset gSmiHandlerIdtr
100 DB 0b8h ; mov eax, imm32
104 ; Need to test for CR4 specific bit support
107 cpuid ; use CPUID to determine if specific CR4 bits are supported
108 xor eax, eax ; Clear EAX
109 test edx, BIT2 ; Check for DE capabilities
113 test edx, BIT6 ; Check for PAE capabilities
117 test edx, BIT7 ; Check for MCE capabilities
121 test edx, BIT24 ; Check for FXSR capabilities
125 test edx, BIT25 ; Check for SSE capabilities
128 @@: ; as cr4.PGE is not set here, refresh cr3
129 mov cr4, eax ; in PreModifyMtrrs() to flush TLB.
131 or ebx, 080000000h ; enable paging
133 lea ebx, [edi + DSC_OFFSET]
134 mov ax, [ebx + DSC_DS]
136 mov ax, [ebx + DSC_OTHERSEG]
140 mov ax, [ebx + DSC_SS]
143 cmp FeaturePcdGet (PcdCpuSmmStackGuard), 0
147 mov byte ptr [ebp + TSS_SEGMENT + 5], 89h ; clear busy flag
151 ; jmp _SmiHandler ; instruction is not needed
154 cmp FeaturePcdGet (PcdCpuSmmDebug), 0
161 bt edx, 29 ; check cpuid to identify X64 or IA32
162 lea edi, [ebp - (@1 - _SmiEntryPoint) + 7fc8h]
171 mov dr7, edx ; restore DR6 & DR7 before running C code
173 mov ecx, [esp] ; CPU Index
176 mov eax, SmiRendezvous
180 cmp FeaturePcdGet (PcdCpuSmmDebug), 0
191 gcSmiHandlerSize DW $ - _SmiEntryPoint