mpboot.S revision 26812
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 * $Id: mpboot.s,v 1.1 1997/04/26 11:45:17 peter Exp $ 35 */ 36 37 38#include <machine/asmacros.h> /* miscellaneous asm macros */ 39#include <machine/apic.h> 40#include <machine/specialreg.h> 41 42#include "assym.s" 43 44/* 45 * this code MUST be enabled here and in mp_machdep.c 46 * it follows the very early stages of AP boot by placing values in CMOS ram. 47 * it NORMALLY will never be needed and thus the primitive method for enabling. 48 * 49#define CHECK_POINTS 50 */ 51 52#if defined(CHECK_POINTS) 53 54#define CMOS_REG (0x70) 55#define CMOS_DATA (0x71) 56 57#define CHECKPOINT(A,D) \ 58 movb $(A),%al ; \ 59 outb %al,$CMOS_REG ; \ 60 movb $(D),%al ; \ 61 outb %al,$CMOS_DATA 62 63#else 64 65#define CHECKPOINT(A,D) 66 67#endif /* CHECK_POINTS */ 68 69 70/* 71 * the APs enter here from their trampoline code (bootMP, below) 72 */ 73 .align 4 74 75NON_GPROF_ENTRY(MPentry) 76 CHECKPOINT(0x36, 3) 77 movl $mp_stk-KERNBASE,%esp /* mp boot stack end loc. */ 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 $0x80000011,%eax 84 movl %eax,%cr0 /* let the games begin! */ 85 movl $mp_stk,%esp /* mp boot stack end loc. */ 86 87 pushl $mp_begin /* jump to high mem */ 88 ret 89 90 /* 91 * Wait for the booting CPU to signal startup 92 */ 93mp_begin: /* now running relocated at KERNBASE */ 94 CHECKPOINT(0x37, 4) 95 call _init_secondary /* load i386 tables */ 96 CHECKPOINT(0x38, 5) 97 98 /* disable the APIC, just to be SURE */ 99 movl lapic_svr, %eax /* get spurious vector reg. */ 100 andl $~APIC_SVR_SWEN, %eax /* clear software enable bit */ 101 movl %eax, lapic_svr 102 103 /* signal our startup to the BSP */ 104 movl lapic_ver, %eax /* our version reg contents */ 105 movl %eax, _cpu_apic_versions /* into [ 0 ] */ 106 incl _mp_ncpus /* signal BSP */ 107 108 /* One at a time, we are running on the shared mp_stk */ 109 /* This is the Intel reccomended semaphore method */ 110#define BL_SET 0xff 111#define BL_CLR 0x00 112 movb $BL_SET, %al 1131: 114 xchgb %al, bootlock /* xchg is implicitly locked */ 115 cmpb $BL_SET, %al /* was is set? */ 116 jz 1b /* yes, keep trying... */ 117 CHECKPOINT(0x39, 6) 118 119 /* Now, let's do some REAL WORK :-) */ 120 call _secondary_main 121/* NOT REACHED */ 1222: hlt 123 jmp 2b 124 125/* 126 * Let a CPU past the semaphore so it can use mp_stk 127 */ 128ENTRY(boot_unlock) 129 movb $BL_CLR, %al 130 xchgb %al, bootlock /* xchg is implicitly locked */ 131 ret 132 133/* 134 * This is the embedded trampoline or bootstrap that is 135 * copied into 'real-mode' low memory, it is where the 136 * secondary processor "wakes up". When it is executed 137 * the processor will eventually jump into the routine 138 * MPentry, which resides in normal kernel text above 139 * 1Meg. -jackv 140 */ 141 142#define data32 .byte 0x66 143#define addr32 .byte 0x67 144 145 .data 146 ALIGN_DATA /* just to be sure */ 147 148BOOTMP1: 149 150NON_GPROF_ENTRY(bootMP) 151 cli 152 CHECKPOINT(0x34, 1) 153 /* First guarantee a 'clean slate' */ 154 data32 155 xorl %eax, %eax 156 data32 157 movl %eax, %ebx 158 data32 159 movl %eax, %ecx 160 data32 161 movl %eax, %edx 162 data32 163 movl %eax, %esi 164 data32 165 movl %eax, %edi 166 167 /* set up data segments */ 168 mov %cs, %ax 169 mov %ax, %ds 170 mov %ax, %es 171 mov %ax, %fs 172 mov %ax, %gs 173 mov %ax, %ss 174 mov $(boot_stk-_bootMP), %sp 175 176 /* Now load the global descriptor table */ 177 addr32 178 data32 179 /* XXX: sigh: lgdt MP_GDTptr-_bootMP GAS BUG! */ 180 .byte 0x0f, 0x01, 0x15 /* XXX hand assemble! */ 181 .long MP_GDTptr-_bootMP /* XXX hand assemble! */ 182 183 /* Enable protected mode */ 184 data32 185 movl %cr0, %eax 186 data32 187 orl $CR0_PE, %eax 188 data32 189 movl %eax, %cr0 190 191 /* 192 * make intrasegment jump to flush the processor pipeline and 193 * reload CS register 194 */ 195 data32 196 pushl $0x18 197 data32 198 pushl $(protmode-_bootMP) 199 data32 200 lret 201 202protmode: 203 CHECKPOINT(0x35, 2) 204 205 /* 206 * we are NOW running for the first time with %eip 207 * having the full physical address, BUT we still 208 * are using a segment descriptor with the origin 209 * not matching the booting kernel. 210 * 211 * SO NOW... for the BIG Jump into kernel's segment 212 * and physical text above 1 Meg. 213 */ 214 mov $0x10, %ebx 215 movw %bx, %ds 216 movw %bx, %es 217 movw %bx, %fs 218 movw %bx, %gs 219 movw %bx, %ss 220 221 .globl _bigJump 222_bigJump: 223 /* this will be modified by mpInstallTramp() */ 224 ljmp $0x08, $0 /* far jmp to MPentry() */ 225 226dead: hlt /* We should never get here */ 227 jmp dead 228 229/* 230 * MP boot strap Global Descriptor Table 231 */ 232 .align 4 233 .globl _MP_GDT 234 .globl _bootCodeSeg 235 .globl _bootDataSeg 236_MP_GDT: 237 238nulldesc: /* offset = 0x0 */ 239 240 .word 0x0 241 .word 0x0 242 .byte 0x0 243 .byte 0x0 244 .byte 0x0 245 .byte 0x0 246 247kernelcode: /* offset = 0x08 */ 248 249 .word 0xffff /* segment limit 0..15 */ 250 .word 0x0000 /* segment base 0..15 */ 251 .byte 0x0 /* segment base 16..23; set for 0K */ 252 .byte 0x9f /* flags; Type */ 253 .byte 0xcf /* flags; Limit */ 254 .byte 0x0 /* segment base 24..32 */ 255 256kerneldata: /* offset = 0x10 */ 257 258 .word 0xffff /* segment limit 0..15 */ 259 .word 0x0000 /* segment base 0..15 */ 260 .byte 0x0 /* segment base 16..23; set for 0k */ 261 .byte 0x93 /* flags; Type */ 262 .byte 0xcf /* flags; Limit */ 263 .byte 0x0 /* segment base 24..32 */ 264 265bootcode: /* offset = 0x18 */ 266 267 .word 0xffff /* segment limit 0..15 */ 268_bootCodeSeg: /* this will be modified by mpInstallTramp() */ 269 .word 0x0000 /* segment base 0..15 */ 270 .byte 0x00 /* segment base 16...23; set for 0x000xx000 */ 271 .byte 0x9e /* flags; Type */ 272 .byte 0xcf /* flags; Limit */ 273 .byte 0x0 /*segment base 24..32 */ 274 275bootdata: /* offset = 0x20 */ 276 277 .word 0xffff 278_bootDataSeg: /* this will be modified by mpInstallTramp() */ 279 .word 0x0000 /* segment base 0..15 */ 280 .byte 0x00 /* segment base 16...23; set for 0x000xx000 */ 281 .byte 0x92 282 .byte 0xcf 283 .byte 0x0 284 285/* 286 * GDT pointer for the lgdt call 287 */ 288 .globl _mp_gdtbase 289 290MP_GDTptr: 291_mp_gdtlimit: 292 .word 0x0028 293_mp_gdtbase: /* this will be modified by mpInstallTramp() */ 294 .long 0 295 296 .space 0x100 /* space for boot_stk - 1st temporary stack */ 297boot_stk: 298 299BOOTMP2: 300 .globl _bootMP_size 301_bootMP_size: 302 .long BOOTMP2 - BOOTMP1 303 304 /* 305 * Temporary stack used while booting AP's 306 * It is protected by: 307 * 1: only one cpu is started at a time and it ends up waiting 308 * for smp_active before continuing. 309 * 2: Once smp_active != 0; further access is limited by _bootlock. 310 */ 311 .globl mp_stk 312 .space 0x2000 /* space for mp_stk - 2nd temporary stack */ 313mp_stk: 314 315 .globl bootlock 316bootlock: .byte BL_SET 317