1 #------------------------------------------------------------------------------
3 # Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
4 # This program and the accompanying materials
5 # are licensed and made available under the terms and conditions of the BSD License
6 # which accompanies this distribution. The full text of the license may be found at
7 # http://opensource.org/licenses/bsd-license.php.
9 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 # Code template of the SMI handler for a particular processor
20 #------------------------------------------------------------------------------
22 ASM_GLOBAL ASM_PFX(gcSmiHandlerTemplate)
23 ASM_GLOBAL ASM_PFX(gcSmiHandlerSize)
24 ASM_GLOBAL ASM_PFX(gSmiCr3)
25 ASM_GLOBAL ASM_PFX(gSmiStack)
26 ASM_GLOBAL ASM_PFX(gSmbase)
27 ASM_GLOBAL ASM_PFX(mXdSupported)
28 ASM_GLOBAL ASM_PFX(FeaturePcdGet (PcdCpuSmmStackGuard))
29 ASM_GLOBAL ASM_PFX(gSmiHandlerIdtr)
31 .equ MSR_IA32_MISC_ENABLE, 0x1A0
32 .equ MSR_EFER, 0xc0000080
33 .equ MSR_EFER_XD, 0x800
36 # Constants relating to PROCESSOR_SMM_DESCRIPTOR
38 .equ DSC_OFFSET, 0xfb00
46 .equ PROTECT_MODE_CS, 0x08
47 .equ PROTECT_MODE_DS, 0x20
48 .equ TSS_SEGMENT, 0x40
52 ASM_PFX(gcSmiHandlerTemplate):
55 .byte 0xbb # mov bx, imm16
56 .word _GdtDesc - _SmiEntryPoint + 0x8000
57 .byte 0x2e,0xa1 # mov ax, cs:[offset16]
58 .word DSC_OFFSET + DSC_GDTSIZ
60 movl %eax, %cs:(%edi) # mov cs:[bx], ax
61 .byte 0x66,0x2e,0xa1 # mov eax, cs:[offset16]
62 .word DSC_OFFSET + DSC_GDTPTR
64 movw %ax, %bp # ebp = GDT base
67 # Patch ProtectedMode Segment
68 .byte 0xb8 # mov ax, imm16
69 .word PROTECT_MODE_CS # set AX for segment directly
70 movl %eax, %cs:-2(%edi) # mov cs:[bx - 2], ax
71 # Patch ProtectedMode entry
72 .byte 0x66, 0xbf # mov edi, SMBASE
73 ASM_PFX(gSmbase): .space 4
75 lea ((Start32bit - _SmiEntryPoint) + 0x8000)(%edi), %ax
76 movw %ax, %cs:-6(%edi)
79 andl $0x9ffafff3, %ebx
90 movw $PROTECT_MODE_DS, %ax
96 .byte 0xbc # mov esp, imm32
97 ASM_PFX(gSmiStack): .space 4
98 movl $ASM_PFX(gSmiHandlerIdtr), %eax
103 .byte 0xb8 # mov eax, imm32
104 ASM_PFX(gSmiCr3): .space 4
107 # Need to test for CR4 specific bit support
110 cpuid # use CPUID to determine if specific CR4 bits are supported
111 xorl %eax, %eax # Clear EAX
112 testl $BIT2, %edx # Check for DE capabilities
116 testl $BIT6, %edx # Check for PAE capabilities
120 testl $BIT7, %edx # Check for MCE capabilities
124 testl $BIT24, %edx # Check for FXSR capabilities
128 testl $BIT25, %edx # Check for SSE capabilities
131 L12: # as cr4.PGE is not set here, refresh cr3
132 movl %eax, %cr4 # in PreModifyMtrrs() to flush TLB.
134 cmpb $0, ASM_PFX(FeaturePcdGet (PcdCpuSmmStackGuard))
137 movb $0x89, (TSS_SEGMENT + 5)(%ebp) # clear busy flag
138 movl $TSS_SEGMENT, %eax
142 # enable NXE if supported
143 .byte 0xb0 # mov al, imm8
144 ASM_PFX(mXdSupported): .byte 1
148 # Check XD disable bit
150 movl $MSR_IA32_MISC_ENABLE, %ecx
152 pushl %edx # save MSR_IA32_MISC_ENABLE[63-32]
153 testl $BIT2, %edx # MSR_IA32_MISC_ENABLE[34]
155 andw $0x0FFFB, %dx # clear XD Disable bit if it is set
160 orw $MSR_EFER_XD,%ax # enable NXE
168 orl $0x080010023, %ebx # enable paging + WP + NE + MP + PE
170 leal DSC_OFFSET(%edi),%ebx
171 movw DSC_DS(%ebx),%ax
173 movw DSC_OTHERSEG(%ebx),%ax
177 movw DSC_SS(%ebx),%ax
180 # jmp _SmiHandler # instruction is not needed
186 movl $ASM_PFX(CpuSmmDebugEntry), %eax
191 movl $ASM_PFX(SmiRendezvous), %eax
196 movl $ASM_PFX(CpuSmmDebugExit), %eax
200 movl $ASM_PFX(mXdSupported), %eax
204 popl %edx # get saved MSR_IA32_MISC_ENABLE[63-32]
207 movl $MSR_IA32_MISC_ENABLE, %ecx
209 orw $BIT2, %dx # set XD Disable bit if it was set before entering into SMM
215 ASM_PFX(gcSmiHandlerSize): .word . - _SmiEntryPoint