FreeBSD/Linux Kernel Cross Reference
sys/i386/i386/mpboot.s
1 /*
2 * Copyright (c) 1995, Jack F. Vogel
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Jack F. Vogel
16 * 4. The name of the developer may be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * mpboot.s: FreeBSD machine support for the Intel MP Spec
32 * multiprocessor systems.
33 *
34 * $FreeBSD$
35 */
36
37 #include "opt_vm86.h"
38
39 #include <machine/asmacros.h> /* miscellaneous asm macros */
40 #include <machine/apic.h>
41 #include <machine/specialreg.h>
42
43 #include "assym.s"
44
45 /*
46 * this code MUST be enabled here and in mp_machdep.c
47 * it follows the very early stages of AP boot by placing values in CMOS ram.
48 * it NORMALLY will never be needed and thus the primitive method for enabling.
49 *
50 #define CHECK_POINTS
51 */
52
53 #if defined(CHECK_POINTS) && !defined(PC98)
54
55 #define CMOS_REG (0x70)
56 #define CMOS_DATA (0x71)
57
58 #define CHECKPOINT(A,D) \
59 movb $(A),%al ; \
60 outb %al,$CMOS_REG ; \
61 movb $(D),%al ; \
62 outb %al,$CMOS_DATA
63
64 #else
65
66 #define CHECKPOINT(A,D)
67
68 #endif /* CHECK_POINTS */
69
70
71 /*
72 * the APs enter here from their trampoline code (bootMP, below)
73 */
74 .p2align 4
75
76 NON_GPROF_ENTRY(MPentry)
77 CHECKPOINT(0x36, 3)
78 /* Now enable paging mode */
79 movl _bootPTD-KERNBASE, %eax
80 movl %eax,%cr3
81 movl %cr0,%eax
82 orl $CR0_PE|CR0_PG,%eax /* enable paging */
83 movl %eax,%cr0 /* let the games begin! */
84 movl $_idlestack_top,%esp /* boot stack end loc. */
85
86 pushl $mp_begin /* jump to high mem */
87 ret
88
89 /*
90 * Wait for the booting CPU to signal startup
91 */
92 mp_begin: /* now running relocated at KERNBASE */
93 CHECKPOINT(0x37, 4)
94 call _init_secondary /* load i386 tables */
95 CHECKPOINT(0x38, 5)
96
97 #ifdef VM86
98 /*
99 * If the [BSP] CPU has support for VME, turn it on.
100 */
101 testl $CPUID_VME, _cpu_feature /* XXX WRONG! BSP! */
102 jz 1f
103 movl %cr4, %eax
104 orl $CR4_VME, %eax
105 movl %eax, %cr4
106 1:
107 #endif
108
109 /* disable the APIC, just to be SURE */
110 movl lapic_svr, %eax /* get spurious vector reg. */
111 andl $~APIC_SVR_SWEN, %eax /* clear software enable bit */
112 movl %eax, lapic_svr
113
114 /* signal our startup to the BSP */
115 movl lapic_ver, %eax /* our version reg contents */
116 movl %eax, _cpu_apic_versions /* into [ 0 ] */
117 incl _mp_ncpus /* signal BSP */
118
119 CHECKPOINT(0x39, 6)
120
121 /* wait till we can get into the kernel */
122 call _boot_get_mplock
123
124 /* Now, let's prepare for some REAL WORK :-) */
125 call _ap_init
126
127 call _rel_mplock
128 2:
129 cmpl $0, CNAME(smp_started) /* Wait for last AP to be ready */
130 jz 2b
131 call _get_mplock
132
133 /* let her rip! (loads new stack) */
134 jmp _cpu_switch
135
136 /*
137 * This is the embedded trampoline or bootstrap that is
138 * copied into 'real-mode' low memory, it is where the
139 * secondary processor "wakes up". When it is executed
140 * the processor will eventually jump into the routine
141 * MPentry, which resides in normal kernel text above
142 * 1Meg. -jackv
143 */
144
145 #define data32 .byte 0x66
146 #define addr32 .byte 0x67
147
148 .data
149 ALIGN_DATA /* just to be sure */
150
151 BOOTMP1:
152
153 NON_GPROF_ENTRY(bootMP)
154 cli
155 CHECKPOINT(0x34, 1)
156 /* First guarantee a 'clean slate' */
157 data32
158 xorl %eax, %eax
159 data32
160 movl %eax, %ebx
161 data32
162 movl %eax, %ecx
163 data32
164 movl %eax, %edx
165 data32
166 movl %eax, %esi
167 data32
168 movl %eax, %edi
169
170 /* set up data segments */
171 mov %cs, %ax
172 mov %ax, %ds
173 mov %ax, %es
174 mov %ax, %fs
175 mov %ax, %gs
176 mov %ax, %ss
177 data32
178 mov $boot_stk-_bootMP, %esp
179
180 /* Now load the global descriptor table */
181 addr32
182 data32
183 /* XXX: sigh: lgdt MP_GDTptr-_bootMP GAS BUG! */
184 .byte 0x0f, 0x01, 0x15 /* XXX hand assemble! */
185 .long MP_GDTptr-_bootMP /* XXX hand assemble! */
186
187 /* Enable protected mode */
188 data32
189 movl %cr0, %eax
190 data32
191 orl $CR0_PE, %eax
192 data32
193 movl %eax, %cr0
194
195 /*
196 * make intrasegment jump to flush the processor pipeline and
197 * reload CS register
198 */
199 data32
200 pushl $0x18
201 data32
202 pushl $(protmode-_bootMP)
203 data32
204 lret
205
206 protmode:
207 CHECKPOINT(0x35, 2)
208
209 /*
210 * we are NOW running for the first time with %eip
211 * having the full physical address, BUT we still
212 * are using a segment descriptor with the origin
213 * not matching the booting kernel.
214 *
215 * SO NOW... for the BIG Jump into kernel's segment
216 * and physical text above 1 Meg.
217 */
218 mov $0x10, %ebx
219 movw %bx, %ds
220 movw %bx, %es
221 movw %bx, %fs
222 movw %bx, %gs
223 movw %bx, %ss
224
225 .globl _bigJump
226 _bigJump:
227 /* this will be modified by mpInstallTramp() */
228 ljmp $0x08, $0 /* far jmp to MPentry() */
229
230 dead: hlt /* We should never get here */
231 jmp dead
232
233 /*
234 * MP boot strap Global Descriptor Table
235 */
236 .p2align 4
237 .globl _MP_GDT
238 .globl _bootCodeSeg
239 .globl _bootDataSeg
240 _MP_GDT:
241
242 nulldesc: /* offset = 0x0 */
243
244 .word 0x0
245 .word 0x0
246 .byte 0x0
247 .byte 0x0
248 .byte 0x0
249 .byte 0x0
250
251 kernelcode: /* offset = 0x08 */
252
253 .word 0xffff /* segment limit 0..15 */
254 .word 0x0000 /* segment base 0..15 */
255 .byte 0x0 /* segment base 16..23; set for 0K */
256 .byte 0x9f /* flags; Type */
257 .byte 0xcf /* flags; Limit */
258 .byte 0x0 /* segment base 24..32 */
259
260 kerneldata: /* offset = 0x10 */
261
262 .word 0xffff /* segment limit 0..15 */
263 .word 0x0000 /* segment base 0..15 */
264 .byte 0x0 /* segment base 16..23; set for 0k */
265 .byte 0x93 /* flags; Type */
266 .byte 0xcf /* flags; Limit */
267 .byte 0x0 /* segment base 24..32 */
268
269 bootcode: /* offset = 0x18 */
270
271 .word 0xffff /* segment limit 0..15 */
272 _bootCodeSeg: /* this will be modified by mpInstallTramp() */
273 .word 0x0000 /* segment base 0..15 */
274 .byte 0x00 /* segment base 16...23; set for 0x000xx000 */
275 .byte 0x9e /* flags; Type */
276 .byte 0xcf /* flags; Limit */
277 .byte 0x0 /*segment base 24..32 */
278
279 bootdata: /* offset = 0x20 */
280
281 .word 0xffff
282 _bootDataSeg: /* this will be modified by mpInstallTramp() */
283 .word 0x0000 /* segment base 0..15 */
284 .byte 0x00 /* segment base 16...23; set for 0x000xx000 */
285 .byte 0x92
286 .byte 0xcf
287 .byte 0x0
288
289 /*
290 * GDT pointer for the lgdt call
291 */
292 .globl _mp_gdtbase
293
294 MP_GDTptr:
295 _mp_gdtlimit:
296 .word 0x0028
297 _mp_gdtbase: /* this will be modified by mpInstallTramp() */
298 .long 0
299
300 .space 0x100 /* space for boot_stk - 1st temporary stack */
301 boot_stk:
302
303 BOOTMP2:
304 .globl _bootMP_size
305 _bootMP_size:
306 .long BOOTMP2 - BOOTMP1
Cache object: 3123c78eb1a04a3f04071dfd8971c768
|