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.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * mpboot.s: FreeBSD machine support for the Intel MP Spec
27 * multiprocessor systems.
34 #include <machine/asmacros.h> /* miscellaneous asm macros */
35 #include <x86/apicreg.h>
36 #include <machine/specialreg.h>
40 #define R(x) ((x)-KERNBASE)
43 * this code MUST be enabled here and in mp_machdep.c
44 * it follows the very early stages of AP boot by placing values in CMOS ram.
45 * it NORMALLY will never be needed and thus the primitive method for enabling.
50 #if defined(CHECK_POINTS) && !defined(PC98)
52 #define CMOS_REG (0x70)
53 #define CMOS_DATA (0x71)
55 #define CHECKPOINT(A,D) \
57 outb %al,$CMOS_REG ; \
63 #define CHECKPOINT(A,D)
65 #endif /* CHECK_POINTS */
69 * the APs enter here from their trampoline code (bootMP, below)
73 NON_GPROF_ENTRY(MPentry)
76 * Enable features on this processor. We don't support SMP on
77 * CPUs older than a Pentium, so we know that we can use the cpuid
81 cpuid /* Retrieve features */
86 orl $CR4_PSE,%eax /* Enable PSE */
92 orl $CR4_PGE,%eax /* Enable PGE */
97 orl $CR4_VME,%eax /* Enable VME */
101 /* Now enable paging mode */
103 movl R(IdlePDPT), %eax
109 movl R(IdlePTD), %eax
113 orl $CR0_PE|CR0_PG,%eax /* enable paging */
114 movl %eax,%cr0 /* let the games begin! */
115 movl bootSTK,%esp /* boot stack end loc. */
117 pushl $mp_begin /* jump to high mem */
121 * Wait for the booting CPU to signal startup
123 mp_begin: /* now running relocated at KERNBASE */
125 call init_secondary /* load i386 tables */
128 * This is the embedded trampoline or bootstrap that is
129 * copied into 'real-mode' low memory, it is where the
130 * secondary processor "wakes up". When it is executed
131 * the processor will eventually jump into the routine
132 * MPentry, which resides in normal kernel text above
137 ALIGN_DATA /* just to be sure */
141 NON_GPROF_ENTRY(bootMP)
145 /* First guarantee a 'clean slate' */
153 /* set up data segments */
160 mov $(boot_stk-bootMP), %esp
162 /* Now load the global descriptor table */
163 lgdt MP_GDTptr-bootMP
165 /* Enable protected mode */
171 * make intrasegment jump to flush the processor pipeline and
175 pushl $(protmode-bootMP)
183 * we are NOW running for the first time with %eip
184 * having the full physical address, BUT we still
185 * are using a segment descriptor with the origin
186 * not matching the booting kernel.
188 * SO NOW... for the BIG Jump into kernel's segment
189 * and physical text above 1 Meg.
200 /* this will be modified by mpInstallTramp() */
201 ljmp $0x08, $0 /* far jmp to MPentry() */
203 dead: hlt /* We should never get here */
207 * MP boot strap Global Descriptor Table
215 nulldesc: /* offset = 0x0 */
224 kernelcode: /* offset = 0x08 */
226 .word 0xffff /* segment limit 0..15 */
227 .word 0x0000 /* segment base 0..15 */
228 .byte 0x0 /* segment base 16..23; set for 0K */
229 .byte 0x9f /* flags; Type */
230 .byte 0xcf /* flags; Limit */
231 .byte 0x0 /* segment base 24..32 */
233 kerneldata: /* offset = 0x10 */
235 .word 0xffff /* segment limit 0..15 */
236 .word 0x0000 /* segment base 0..15 */
237 .byte 0x0 /* segment base 16..23; set for 0k */
238 .byte 0x93 /* flags; Type */
239 .byte 0xcf /* flags; Limit */
240 .byte 0x0 /* segment base 24..32 */
242 bootcode: /* offset = 0x18 */
244 .word 0xffff /* segment limit 0..15 */
245 bootCodeSeg: /* this will be modified by mpInstallTramp() */
246 .word 0x0000 /* segment base 0..15 */
247 .byte 0x00 /* segment base 16...23; set for 0x000xx000 */
248 .byte 0x9e /* flags; Type */
249 .byte 0xcf /* flags; Limit */
250 .byte 0x0 /*segment base 24..32 */
252 bootdata: /* offset = 0x20 */
255 bootDataSeg: /* this will be modified by mpInstallTramp() */
256 .word 0x0000 /* segment base 0..15 */
257 .byte 0x00 /* segment base 16...23; set for 0x000xx000 */
263 * GDT pointer for the lgdt call
270 mp_gdtbase: /* this will be modified by mpInstallTramp() */
273 .space 0x100 /* space for boot_stk - 1st temporary stack */
279 .long BOOTMP2 - BOOTMP1