2 * Copyright (c) 1990 The Regents of the University of California.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * originally from: locore.s, by William F. Jolitz
34 * Substantially rewritten by David Greenman, Rod Grimes,
35 * Bruce Evans, Wolfgang Solfrank, Poul-Henning Kamp
39 #include "opt_bootp.h"
40 #include "opt_nfsroot.h"
43 #include <sys/reboot.h>
45 #include <machine/asmacros.h>
46 #include <machine/cputypes.h>
47 #include <machine/psl.h>
48 #include <machine/pmap.h>
49 #include <machine/specialreg.h>
54 * Compiled KERNBASE location and the kernel load address, now identical.
57 .set kernbase,KERNBASE
59 .set kernload,KERNLOAD
65 ALIGN_DATA /* just to be sure */
67 .space 0x2000 /* space for tmpstk - temporary stack */
71 bootinfo: .space BOOTINFO_SIZE /* bootinfo that we can handle */
74 /**********************************************************************
76 * This is where the bootblocks start us, set the ball rolling...
81 /* Tell the bios to warmboot next time */
84 /* Set up a real frame in case the double return in newboot is executed. */
89 /* Don't trust what the BIOS gives for eflags. */
94 * Don't trust what the BIOS gives for %fs and %gs. Trust the bootstrap
95 * to set %cs, %ds, %es and %ss.
102 * Clear the bss. Not all boot programs do it, and it is our job anyway.
104 * XXX we don't check that there is memory for our bss and page tables
107 * Note: we must be careful to not overwrite an active gdt or idt. They
108 * inactive from now until we switch to new ones, since we don't load any
109 * more segment registers or permit interrupts until after the switch.
112 movl $__bss_start,%edi
119 call recover_bootinfo
121 /* Get onto a stack that we can trust. */
123 * XXX this step is delayed in case recover_bootinfo needs to return via
124 * the old stack, but it need not be, since recover_bootinfo actually
125 * returns via the old frame.
132 /* set up bootstrap stack */
133 movl proc0kstack,%eax /* location of in-kernel stack */
136 * Only use bottom page for init386(). init386() calculates the
137 * PCB + FPU save area size and returns the true top of stack.
139 leal PAGE_SIZE(%eax),%esp
141 xorl %ebp,%ebp /* mark end of frames */
143 pushl physfree /* value of first for init386(first) */
144 call init386 /* wire 386 chip for unix operation */
147 * Clean up the stack in a way that db_numargs() understands, so
148 * that backtraces in ddb don't underrun the stack. Traps for
149 * inaccessible memory are more fatal than usual this early.
153 /* Switch to true top of stack. */
156 call mi_startup /* autoconfiguration, mountroot etc */
158 addl $0,%esp /* for db_numargs() again */
160 /**********************************************************************
162 * Recover the bootinfo passed to us from the boot program
167 * This code is called in different ways depending on what loaded
168 * and started the kernel. This is used to detect how we get the
169 * arguments from the other code and what we do with them.
171 * Old disk boot blocks:
172 * (*btext)(howto, bootdev, cyloffset, esym);
173 * [return address == 0, and can NOT be returned to]
174 * [cyloffset was not supported by the FreeBSD boot code
175 * and always passed in as 0]
176 * [esym is also known as total in the boot code, and
177 * was never properly supported by the FreeBSD boot code]
178 * This code from 1.x/2.x doesn't supply now-required metadata and
179 * likely will fail (we test for it to avoid dereferencing stack
182 * Old diskless netboot code:
183 * (*btext)(0,0,0,0,&nfsdiskless,0,0,0);
184 * [return address != 0, and can NOT be returned to]
185 * If we are being booted by this code it will NOT work,
186 * so we are just going to halt if we find this case.
188 * New uniform boot code:
189 * (*btext)(howto, bootdev, 0, 0, 0, &bootinfo)
190 * [return address != 0, and can be returned to]
192 * There may seem to be a lot of wasted arguments in here, but
193 * that is so the newer boot code can still load very old kernels
194 * and old boot code can load new kernels.
198 * The old style disk boot blocks fake a frame on the stack and did an
199 * lret to get here. The frame on the stack has a return address of 0.
200 * This style of boot (from 1.x / 2.x) almost certainly won't work,
201 * since the kernel has required metadata since about 7.x or so and none
208 * We have some form of return address, so this is either the
209 * old diskless netboot code, or the new uniform code. That can
210 * be detected by looking at the 5th argument, if it is 0
211 * we are being booted by the new uniform boot code.
217 * Seems we have been loaded by the old 1.x/2.x diskless boot code, we
218 * don't stand a chance of running as the diskless structure changed
219 * considerably between the two, so just halt.
224 * We have been loaded by the new uniform boot code.
225 * Let's check the bootinfo version, and if we do not understand
226 * it we return to the loader with a status of 1 to indicate this error
229 movl 28(%ebp),%ebx /* &bootinfo.version */
230 movl BI_VERSION(%ebx),%eax
231 cmpl $1,%eax /* We only understand version 1 */
233 testl $RB_BOOTINFO,8(%ebp) /* bi_size (and bootinfo) valid? */
235 movl $1,%eax /* Return status */
238 * XXX this returns to our caller's caller (as is required) since
239 * we didn't set up a frame and our caller did.
245 * If we have a kernelname copy it in
247 movl BI_KERNELNAME(%ebx),%esi
249 je 2f /* No kernelname */
250 movl $MAXPATHLEN,%ecx /* Brute force!!! */
251 movl $kernelname,%edi
252 cmpb $'/',(%esi) /* Make sure it starts with a slash */
264 * Determine the size of the boot loader's copy of the bootinfo
265 * struct. Copy min(our size, loader's size) into our bootinfo.
266 * Incompatible with really old boot loaders from FreeBSD 1.x and 2.0.
270 movl BI_SIZE(%ebx),%ecx
271 cmpl $BOOTINFO_SIZE,%ecx
272 jbe got_common_bi_size
273 movl $BOOTINFO_SIZE,%ecx
282 * If we have a nfs_diskless structure copy it in
284 movl BI_NFS_DISKLESS(%ebx),%esi
287 movl $nfs_diskless,%edi
288 movl $NFSDISKLESS_SIZE,%ecx
292 movl $nfs_diskless_valid,%edi
298 * The old style disk boot.
299 * (*btext)(howto, bootdev, cyloffset, esym);
300 * Note that the newer boot code just falls into here to pick
301 * up howto and bootdev, cyloffset and esym are no longer used
312 /**********************************************************************
314 * Identify the CPU and initialize anything special about it
321 /* Try to toggle alignment check flag; does not exist on 386. */
338 /* NexGen CPU does not have alignment check flag. */
353 movl $0x4778654e,cpu_vendor # store vendor string
354 movl $0x72446e65,cpu_vendor+4
355 movl $0x6e657669,cpu_vendor+8
356 movl $0,cpu_vendor+12
359 try486: /* Try to toggle identification flag; does not exist on early 486s. */
379 * Cyrix CPUs do not change the undefined flags following
380 * execution of the divide instruction which divides 5 by 2.
382 * Note: CPUID is enabled on M2, so it passes another way.
392 jmp 3f /* You may use Intel CPU. */
397 * IBM Bluelighting CPU also doesn't change the undefined flags.
398 * Because IBM doesn't disclose the information for Bluelighting
399 * CPU, we couldn't distinguish it from Cyrix's (including IBM
400 * brand of Cyrix CPUs).
402 movl $0x69727943,cpu_vendor # store vendor string
403 movl $0x736e4978,cpu_vendor+4
404 movl $0x64616574,cpu_vendor+8
407 trycpuid: /* Use the `cpuid' instruction. */
410 movl %eax,cpu_high # highest capability
411 movl %ebx,cpu_vendor # store vendor string
412 movl %edx,cpu_vendor+4
413 movl %ecx,cpu_vendor+8
414 movb $0,cpu_vendor+12
418 movl %eax,cpu_id # store cpu_id
419 movl %ebx,cpu_procinfo # store cpu_procinfo
420 movl %edx,cpu_feature # store cpu_feature
421 movl %ecx,cpu_feature2 # store cpu_feature2
422 rorl $8,%eax # extract family type
427 /* less than Pentium; must be 486 */
437 /* Greater than Pentium...call it a Pentium Pro */
445 /* Xen Hypercall page */
447 .p2align PAGE_SHIFT, 0x90 /* Hypercall_page needs to be PAGE aligned */
449 ENTRY(hypercall_page)
450 .skip 0x1000, 0x90 /* Fill with "nop"s */