1 ;------------------------------------------------------------------------------ ;
2 ; Copyright (c) 2016, 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 ;-------------------------------------------------------------------------------
21 %define DSC_OFFSET 0xfb00
22 %define DSC_GDTPTR 0x30
23 %define DSC_GDTSIZ 0x38
27 %define DSC_OTHERSEG 20
29 %define PROTECT_MODE_CS 0x8
30 %define PROTECT_MODE_DS 0x20
31 %define TSS_SEGMENT 0x40
33 extern ASM_PFX(SmiRendezvous)
34 extern ASM_PFX(FeaturePcdGet (PcdCpuSmmStackGuard))
35 extern ASM_PFX(CpuSmmDebugEntry)
36 extern ASM_PFX(CpuSmmDebugExit)
38 global ASM_PFX(gcSmiHandlerTemplate)
39 global ASM_PFX(gcSmiHandlerSize)
40 global ASM_PFX(gSmiCr3)
41 global ASM_PFX(gSmiStack)
42 global ASM_PFX(gSmbase)
43 extern ASM_PFX(gSmiHandlerIdtr)
48 ASM_PFX(gcSmiHandlerTemplate):
50 mov bx, _GdtDesc - _SmiEntryPoint + 0x8000
51 mov ax,[cs:DSC_OFFSET + DSC_GDTSIZ]
54 mov eax, [cs:DSC_OFFSET + DSC_GDTPTR]
56 mov ebp, eax ; ebp = GDT base
57 o32 lgdt [cs:bx] ; lgdt fword ptr cs:[bx]
58 mov ax, PROTECT_MODE_CS
60 DB 0x66, 0xbf ; mov edi, SMBASE
61 ASM_PFX(gSmbase): DD 0
62 lea eax, [edi + (@32bit - _SmiEntryPoint) + 0x8000]
75 mov ax, PROTECT_MODE_DS
81 DB 0xbc ; mov esp, imm32
82 ASM_PFX(gSmiStack): DD 0
83 mov eax, ASM_PFX(gSmiHandlerIdtr)
88 DB 0xb8 ; mov eax, imm32
89 ASM_PFX(gSmiCr3): DD 0
92 ; Need to test for CR4 specific bit support
95 cpuid ; use CPUID to determine if specific CR4 bits are supported
96 xor eax, eax ; Clear EAX
97 test edx, BIT2 ; Check for DE capabilities
101 test edx, BIT6 ; Check for PAE capabilities
105 test edx, BIT7 ; Check for MCE capabilities
109 test edx, BIT24 ; Check for FXSR capabilities
113 test edx, BIT25 ; Check for SSE capabilities
116 .4: ; as cr4.PGE is not set here, refresh cr3
117 mov cr4, eax ; in PreModifyMtrrs() to flush TLB.
119 or ebx, 0x080010000 ; enable paging + WP
121 lea ebx, [edi + DSC_OFFSET]
122 mov ax, [ebx + DSC_DS]
124 mov ax, [ebx + DSC_OTHERSEG]
128 mov ax, [ebx + DSC_SS]
131 cmp byte [dword ASM_PFX(FeaturePcdGet (PcdCpuSmmStackGuard))], 0
135 mov byte [ebp + TSS_SEGMENT + 5], 0x89 ; clear busy flag
139 ; jmp _SmiHandler ; instruction is not needed
141 global ASM_PFX(SmiHandler)
143 mov ebx, [esp] ; CPU Index
146 mov eax, ASM_PFX(CpuSmmDebugEntry)
151 mov eax, ASM_PFX(SmiRendezvous)
156 mov eax, ASM_PFX(CpuSmmDebugExit)
162 ASM_PFX(gcSmiHandlerSize): DW $ - _SmiEntryPoint