]>
Commit | Line | Data |
---|---|---|
7947da3c MK |
1 | #------------------------------------------------------------------------------\r |
2 | #\r | |
3 | # Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r | |
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 | |
22 | ASM_GLOBAL ASM_PFX(gcSmiHandlerTemplate)\r | |
23 | ASM_GLOBAL ASM_PFX(gcSmiHandlerSize)\r | |
24 | ASM_GLOBAL ASM_PFX(gSmiCr3)\r | |
25 | ASM_GLOBAL ASM_PFX(gSmiStack)\r | |
26 | ASM_GLOBAL ASM_PFX(gSmbase)\r | |
7947da3c MK |
27 | ASM_GLOBAL ASM_PFX(FeaturePcdGet (PcdCpuSmmStackGuard))\r |
28 | ASM_GLOBAL ASM_PFX(gSmiHandlerIdtr)\r | |
29 | \r | |
30 | .equ DSC_OFFSET, 0xfb00\r | |
31 | .equ DSC_GDTPTR, 0x30\r | |
32 | .equ DSC_GDTSIZ, 0x38\r | |
33 | .equ DSC_CS, 14\r | |
34 | .equ DSC_DS, 16\r | |
35 | .equ DSC_SS, 18\r | |
36 | .equ DSC_OTHERSEG, 20\r | |
37 | \r | |
38 | .equ PROTECT_MODE_CS, 0x08\r | |
39 | .equ PROTECT_MODE_DS, 0x20\r | |
40 | .equ TSS_SEGMENT, 0x40\r | |
41 | \r | |
42 | .text\r | |
43 | \r | |
44 | ASM_PFX(gcSmiHandlerTemplate):\r | |
45 | \r | |
46 | _SmiEntryPoint:\r | |
47 | .byte 0xbb # mov bx, imm16\r | |
48 | .word _GdtDesc - _SmiEntryPoint + 0x8000\r | |
49 | .byte 0x2e,0xa1 # mov ax, cs:[offset16]\r | |
50 | .word DSC_OFFSET + DSC_GDTSIZ\r | |
51 | decl %eax\r | |
52 | movl %eax, %cs:(%edi) # mov cs:[bx], ax\r | |
53 | .byte 0x66,0x2e,0xa1 # mov eax, cs:[offset16]\r | |
54 | .word DSC_OFFSET + DSC_GDTPTR\r | |
55 | movw %ax, %cs:2(%edi)\r | |
56 | movw %ax, %bp # ebp = GDT base\r | |
57 | .byte 0x66\r | |
58 | lgdt %cs:(%edi)\r | |
59 | # Patch ProtectedMode Segment\r | |
60 | .byte 0xb8 # mov ax, imm16\r | |
61 | .word PROTECT_MODE_CS # set AX for segment directly\r | |
62 | movl %eax, %cs:-2(%edi) # mov cs:[bx - 2], ax\r | |
63 | # Patch ProtectedMode entry\r | |
64 | .byte 0x66, 0xbf # mov edi, SMBASE\r | |
65 | ASM_PFX(gSmbase): .space 4\r | |
66 | .byte 0x67\r | |
67 | lea ((Start32bit - _SmiEntryPoint) + 0x8000)(%edi), %ax\r | |
68 | movw %ax, %cs:-6(%edi)\r | |
69 | movl %cr0, %ebx\r | |
70 | .byte 0x66\r | |
71 | andl $0x9ffafff3, %ebx\r | |
72 | .byte 0x66\r | |
73 | orl $0x23, %ebx\r | |
74 | movl %ebx, %cr0\r | |
75 | .byte 0x66,0xea\r | |
76 | .space 4\r | |
77 | .space 2\r | |
78 | _GdtDesc: .space 4\r | |
79 | .space 2\r | |
80 | \r | |
81 | Start32bit:\r | |
82 | movw $PROTECT_MODE_DS, %ax\r | |
83 | movl %eax,%ds\r | |
84 | movl %eax,%es\r | |
85 | movl %eax,%fs\r | |
86 | movl %eax,%gs\r | |
87 | movl %eax,%ss\r | |
88 | .byte 0xbc # mov esp, imm32\r | |
89 | ASM_PFX(gSmiStack): .space 4\r | |
90 | movl $ASM_PFX(gSmiHandlerIdtr), %eax\r | |
91 | lidt (%eax)\r | |
92 | jmp ProtFlatMode\r | |
93 | \r | |
94 | ProtFlatMode:\r | |
95 | .byte 0xb8 # mov eax, imm32\r | |
96 | ASM_PFX(gSmiCr3): .space 4\r | |
97 | movl %eax, %cr3\r | |
98 | #\r | |
99 | # Need to test for CR4 specific bit support\r | |
100 | #\r | |
101 | movl $1, %eax\r | |
102 | cpuid # use CPUID to determine if specific CR4 bits are supported\r | |
103 | xorl %eax, %eax # Clear EAX\r | |
104 | testl $BIT2, %edx # Check for DE capabilities\r | |
105 | jz L8\r | |
106 | orl $BIT3, %eax\r | |
107 | L8:\r | |
108 | testl $BIT6, %edx # Check for PAE capabilities\r | |
109 | jz L9\r | |
110 | orl $BIT5, %eax\r | |
111 | L9:\r | |
112 | testl $BIT7, %edx # Check for MCE capabilities\r | |
113 | jz L10\r | |
114 | orl $BIT6, %eax\r | |
115 | L10:\r | |
116 | testl $BIT24, %edx # Check for FXSR capabilities\r | |
117 | jz L11\r | |
118 | orl $BIT9, %eax\r | |
119 | L11:\r | |
120 | testl $BIT25, %edx # Check for SSE capabilities\r | |
121 | jz L12\r | |
122 | orl $BIT10, %eax\r | |
123 | L12: # as cr4.PGE is not set here, refresh cr3\r | |
124 | movl %eax, %cr4 # in PreModifyMtrrs() to flush TLB.\r | |
125 | movl %cr0, %ebx\r | |
53ba3fb8 | 126 | orl $0x080010000, %ebx # enable paging + WP\r |
7947da3c MK |
127 | movl %ebx, %cr0\r |
128 | leal DSC_OFFSET(%edi),%ebx\r | |
129 | movw DSC_DS(%ebx),%ax\r | |
130 | movl %eax, %ds\r | |
131 | movw DSC_OTHERSEG(%ebx),%ax\r | |
132 | movl %eax, %es\r | |
133 | movl %eax, %fs\r | |
134 | movl %eax, %gs\r | |
135 | movw DSC_SS(%ebx),%ax\r | |
136 | movl %eax, %ss\r | |
137 | \r | |
138 | cmpb $0, ASM_PFX(FeaturePcdGet (PcdCpuSmmStackGuard))\r | |
139 | jz L5\r | |
140 | \r | |
141 | # Load TSS\r | |
142 | movb $0x89, (TSS_SEGMENT + 5)(%ebp) # clear busy flag\r | |
143 | movl $TSS_SEGMENT, %eax\r | |
144 | ltrw %ax\r | |
145 | L5:\r | |
146 | \r | |
147 | # jmp _SmiHandler # instruction is not needed\r | |
148 | \r | |
149 | _SmiHandler:\r | |
f45f2d4a | 150 | movl (%esp), %ebx\r |
7947da3c | 151 | \r |
f45f2d4a JY |
152 | pushl %ebx\r |
153 | movl $ASM_PFX(CpuSmmDebugEntry), %eax\r | |
154 | call *%eax\r | |
155 | popl %ecx\r | |
156 | \r | |
157 | pushl %ebx\r | |
7947da3c MK |
158 | movl $ASM_PFX(SmiRendezvous), %eax\r |
159 | call *%eax\r | |
160 | popl %ecx\r | |
161 | \r | |
f45f2d4a JY |
162 | pushl %ebx\r |
163 | movl $ASM_PFX(CpuSmmDebugExit), %eax\r | |
164 | call *%eax\r | |
165 | popl %ecx\r | |
7947da3c MK |
166 | \r |
167 | rsm\r | |
168 | \r | |
169 | ASM_PFX(gcSmiHandlerSize): .word . - _SmiEntryPoint\r |