1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
;/*++
; This file contains an 'Intel Peripheral Driver' and uniquely
; identified as "Intel Reference Module" and is
; licensed for Intel CPUs and chipsets under the terms of your
; license agreement with Intel or your vendor. This file may
; be modified by the user, subject to additional terms of the
; license agreement
;--*/
;
;/*++
;
; Copyright (c) 1999 - 2011 Intel Corporation. All rights reserved
; This software and associated documentation (if any) is furnished
; under a license and may only be used or copied in accordance
; with the terms of the license. Except as permitted by such
; license, no part of this software or documentation may be
; reproduced, stored in a retrieval system, or transmitted in any
; form or by any means without the express written consent of
; Intel Corporation.
;
;
; Module Name:
;
; TxtPeiAp.asm
;
; Abstract:
;
; This file contains AP initialization code in PEI phase
;
;--*/
.XLIST
include txt.inc
.LIST
.586p
.MMX
TxtSegment16 SEGMENT PARA USE16 PUBLIC 'TXTCODE'
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
; Procedure:
;
; Input: None
;
; Output: None
;
; Registers: None are preserved
;
; Description: Entry point of AP startup code. Target of SIPI vector.
;
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
;
; This point is 4K aligned somewhere in boot block.
;
jmp code16bitStart
ORG 10h
GDTAddress:
dw GDTLen ; The length of the GDT
dd OFFSET GDTStart ; The 32-bit physical address
;
; AP GDT table
;
ALIGN 16
GDTStart LABEL BYTE
SEG_DESCRIPTOR <> ; Unused (selector 0)
;
; Selector 8
;
TXT_DATA32 EQU $ - GDTStart
TXT_DATA32_OFF SEG_DESCRIPTOR {0FFFFh,\
0000h, \
00h, \
<SEG_PRESENT, 0, APPLSEGMENT, DATATYPE>, \
<PAGEGRANULARITY, BIGSEGMENT,,,0Fh>, \
00h}
GDTLen EQU $ - GDTStart - 1
code16bitStart:
;L1: jmp $
cli
mov si, OFFSET GDTAddress
;
; Set DS and ES limits
;
db 66h ; Force 32 bit load
lgdt FWORD PTR cs:[si]
mov eax, CR0 ; get CPU control word 0
or al, 01 ; enable CPU protected mode
mov CR0, eax ; write back to CPU control word 0
jmp target
target:
mov ax, TXT_DATA32
mov ds, ax ; set DS limit
mov es, ax ; set ES limit
mov fs, ax ; set FS limit
mov gs, ax ; set GS limit
mov ss, ax ; set SS limit
;
; Disable protected mode
;
mov eax, CR0 ; get CPU control word 0
and al, 0FEh ; disable CPU protected mode
mov CR0, eax ; write back to CPU control word 0
jmp target3
target3:
xor ax, ax
mov ds, ax ; set flat DS
mov es, ax ; set flat ES
;
; Fall through to main code
;
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
;
; Procedure: LoadVsmcuRetNS - Variable Size Processor Microcode Update (Stackless)
;
; Input: SP = Return address
;
; Output: None
;
; Registers: All but SP are modified
;
; Description:
; Load MCU into processor.
;
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
LoadVsmcuRetNS PROC NEAR PUBLIC
;
; Check uCode was loaded or not
;
xor eax, eax
xor edx, edx
mov ecx, MCU_REV_MSR
wrmsr
mov eax, 1
cpuid
mov ecx, MCU_REV_MSR
rdmsr
or edx, edx
jnz uCode_loaded
;
; Restore MCU address from scratch register
;
mov eax, 1
cpuid
mov eax, TXT_PUBLIC_BASE + MCU_BASE_ADDR
mov eax, [eax]
lea eax, [eax + SIZEOF MCU] ; EAX -> MCU data (after header)
xor edx, edx
mov ecx, MCU_LOAD_MSR ; Trigger to load MCU
wrmsr ; Load MCU
mov eax, 1
cpuid
uCode_loaded:
;
; Fall through
;
LoadVsmcuRetNS ENDP
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
; Procedure: TxtPrepareCacheForAcModuleRetNS
;
; Input: None
;
; Output: None
;
; Registers: None are preserved
;
; Description: Cache initialization per TXT BIOS spec
;
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
TxtPrepareCacheForAcModuleRetNS PROC NEAR PUBLIC
;
; Ensure CR0.CD and CR0.NW are cleared
;
mov eax, cr0 ;
and eax, NOT (CR0_CD_MASK + CR0_NW_MASK)
mov cr0, eax
;
; Fall through
;
TxtPrepareCacheForAcModuleRetNS ENDP
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
; Procedure: TxtCleanMcaNS
;
; Input: None
;
; Output: None
;
; Registers: None are preserved
;
; Description: MCA registers are cleaned
;
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
TxtCleanMcaNS PROC NEAR PUBLIC
;
; Clean MC[i]_STATUS MSR registers
; SCLEAN will generate GPF otherwise
;
mov ecx, MCG_CAP
rdmsr
movzx ebx, al ; Bank count to ebx
sub eax, eax ; Write 0 into all MCi_STATUS registers
sub edx, edx
mov ecx, MC0_STATUS
McaErrorCleanLoopStart:
wrmsr
dec ebx
jz continue
add ecx, 4 ; Number of MSRs per bank
jmp McaErrorCleanLoopStart
continue:
;
; Fall through
;
TxtCleanMcaNS ENDP
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
; Procedure: TxtHaltLoopNS
;
; Input: None
;
; Output: None
;
; Registers: None are preserved
;
; Description: APs enter halt loop
;
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
TxtHaltLoopNS PROC NEAR PUBLIC
mov eax, CR4
or eax, CR4_OSFXSR + CR4_DE + CR4_SMXE
mov CR4, eax
mov eax, 1
cpuid
shr ebx, 24 ; ebx is initial APIC ID shifted rightmostly
;
; Since accesses to semaphore cannot be serialized, accesses among different CPUs
; are orchestrated as following:
; BSP will only READ semaphore
; All APs will keep READING semaphore until its value EQUALS to that AP's
; APIC ID minus 1. Only AFTER that AP will INCREMENT semaphore.
; This allows BSP to judge WHEN all APs finished.
;
mov ecx, [TXT_PUBLIC_BASE + SEMAPHORE]
keepWaiting:
mov eax, [ecx]
inc eax
cmp eax, ebx
jb keepWaiting
ja hltLoop
mov [ecx], eax
hltLoop:
cli
hlt
jmp hltLoop
TxtHaltLoopNS ENDP
TxtSegment16 ENDS
END
|