2 * Copyright (c) 1995, Jack F. Vogel
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
31 * mpboot.s: FreeBSD machine support for the Intel MP Spec
32 * multiprocessor systems.
37 #include <machine/asmacros.h> /* miscellaneous asm macros */
38 #include <machine/apic.h>
39 #include <machine/specialreg.h>
44 * this code MUST be enabled here and in mp_machdep.c
45 * it follows the very early stages of AP boot by placing values in CMOS ram.
46 * it NORMALLY will never be needed and thus the primitive method for enabling.
51 #if defined(CHECK_POINTS) && !defined(PC98)
53 #define CMOS_REG (0x70)
54 #define CMOS_DATA (0x71)
56 #define CHECKPOINT(A,D) \
58 outb %al,$CMOS_REG ; \
64 #define CHECKPOINT(A,D)
66 #endif /* CHECK_POINTS */
70 * the APs enter here from their trampoline code (bootMP, below)
74 NON_GPROF_ENTRY(MPentry)
76 /* Now enable paging mode */
77 movl IdlePTD-KERNBASE, %eax
80 orl $CR0_PE|CR0_PG,%eax /* enable paging */
81 movl %eax,%cr0 /* let the games begin! */
82 movl bootSTK,%esp /* boot stack end loc. */
84 pushl $mp_begin /* jump to high mem */
88 * Wait for the booting CPU to signal startup
90 mp_begin: /* now running relocated at KERNBASE */
92 call init_secondary /* load i386 tables */
96 * If the [BSP] CPU has support for VME, turn it on.
98 testl $CPUID_VME, cpu_feature /* XXX WRONG! BSP! */
105 /* disable the APIC, just to be SURE */
106 movl lapic+LA_SVR, %eax /* get spurious vector reg. */
107 andl $~APIC_SVR_SWEN, %eax /* clear software enable bit */
108 movl %eax, lapic+LA_SVR
110 /* signal our startup to the BSP */
111 movl lapic+LA_VER, %eax /* our version reg contents */
112 movl %eax, cpu_apic_versions /* into [ 0 ] */
113 incl mp_ncpus /* signal BSP */
117 /* Now, let's prepare for some REAL WORK :-) This doesn't return. */
121 * This is the embedded trampoline or bootstrap that is
122 * copied into 'real-mode' low memory, it is where the
123 * secondary processor "wakes up". When it is executed
124 * the processor will eventually jump into the routine
125 * MPentry, which resides in normal kernel text above
130 ALIGN_DATA /* just to be sure */
134 NON_GPROF_ENTRY(bootMP)
138 /* First guarantee a 'clean slate' */
146 /* set up data segments */
153 mov $(boot_stk-bootMP), %esp
155 /* Now load the global descriptor table */
156 lgdt MP_GDTptr-bootMP
158 /* Enable protected mode */
164 * make intrasegment jump to flush the processor pipeline and
168 pushl $(protmode-bootMP)
176 * we are NOW running for the first time with %eip
177 * having the full physical address, BUT we still
178 * are using a segment descriptor with the origin
179 * not matching the booting kernel.
181 * SO NOW... for the BIG Jump into kernel's segment
182 * and physical text above 1 Meg.
193 /* this will be modified by mpInstallTramp() */
194 ljmp $0x08, $0 /* far jmp to MPentry() */
196 dead: hlt /* We should never get here */
200 * MP boot strap Global Descriptor Table
208 nulldesc: /* offset = 0x0 */
217 kernelcode: /* offset = 0x08 */
219 .word 0xffff /* segment limit 0..15 */
220 .word 0x0000 /* segment base 0..15 */
221 .byte 0x0 /* segment base 16..23; set for 0K */
222 .byte 0x9f /* flags; Type */
223 .byte 0xcf /* flags; Limit */
224 .byte 0x0 /* segment base 24..32 */
226 kerneldata: /* offset = 0x10 */
228 .word 0xffff /* segment limit 0..15 */
229 .word 0x0000 /* segment base 0..15 */
230 .byte 0x0 /* segment base 16..23; set for 0k */
231 .byte 0x93 /* flags; Type */
232 .byte 0xcf /* flags; Limit */
233 .byte 0x0 /* segment base 24..32 */
235 bootcode: /* offset = 0x18 */
237 .word 0xffff /* segment limit 0..15 */
238 bootCodeSeg: /* this will be modified by mpInstallTramp() */
239 .word 0x0000 /* segment base 0..15 */
240 .byte 0x00 /* segment base 16...23; set for 0x000xx000 */
241 .byte 0x9e /* flags; Type */
242 .byte 0xcf /* flags; Limit */
243 .byte 0x0 /*segment base 24..32 */
245 bootdata: /* offset = 0x20 */
248 bootDataSeg: /* this will be modified by mpInstallTramp() */
249 .word 0x0000 /* segment base 0..15 */
250 .byte 0x00 /* segment base 16...23; set for 0x000xx000 */
256 * GDT pointer for the lgdt call
263 mp_gdtbase: /* this will be modified by mpInstallTramp() */
266 .space 0x100 /* space for boot_stk - 1st temporary stack */
272 .long BOOTMP2 - BOOTMP1