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 * from: @(#)locore.s 7.3 (Berkeley) 5/13/91
35 * originally from: locore.s, by William F. Jolitz
37 * Substantially rewritten by David Greenman, Rod Grimes,
38 * Bruce Evans, Wolfgang Solfrank, Poul-Henning Kamp
42 #include "opt_bootp.h"
43 #include "opt_nfsroot.h"
46 #include <sys/reboot.h>
48 #include <machine/asmacros.h>
49 #include <machine/cputypes.h>
50 #include <machine/psl.h>
51 #include <machine/pmap.h>
52 #include <machine/specialreg.h>
57 * Compiled KERNBASE location and the kernel load address, now identical.
60 .set kernbase,KERNBASE
62 .set kernload,KERNLOAD
68 ALIGN_DATA /* just to be sure */
70 .space 0x2000 /* space for tmpstk - temporary stack */
74 bootinfo: .space BOOTINFO_SIZE /* bootinfo that we can handle */
77 /**********************************************************************
79 * This is where the bootblocks start us, set the ball rolling...
82 NON_GPROF_ENTRY(btext)
84 /* Tell the bios to warmboot next time */
87 /* Set up a real frame in case the double return in newboot is executed. */
92 /* Don't trust what the BIOS gives for eflags. */
97 * Don't trust what the BIOS gives for %fs and %gs. Trust the bootstrap
98 * to set %cs, %ds, %es and %ss.
105 * Clear the bss. Not all boot programs do it, and it is our job anyway.
107 * XXX we don't check that there is memory for our bss and page tables
110 * Note: we must be careful to not overwrite an active gdt or idt. They
111 * inactive from now until we switch to new ones, since we don't load any
112 * more segment registers or permit interrupts until after the switch.
115 movl $__bss_start,%edi
122 call recover_bootinfo
124 /* Get onto a stack that we can trust. */
126 * XXX this step is delayed in case recover_bootinfo needs to return via
127 * the old stack, but it need not be, since recover_bootinfo actually
128 * returns via the old frame.
135 /* set up bootstrap stack */
136 movl proc0kstack,%eax /* location of in-kernel stack */
139 * Only use bottom page for init386(). init386() calculates the
140 * PCB + FPU save area size and returns the true top of stack.
142 leal PAGE_SIZE(%eax),%esp
144 xorl %ebp,%ebp /* mark end of frames */
146 pushl physfree /* value of first for init386(first) */
147 call init386 /* wire 386 chip for unix operation */
150 * Clean up the stack in a way that db_numargs() understands, so
151 * that backtraces in ddb don't underrun the stack. Traps for
152 * inaccessible memory are more fatal than usual this early.
156 /* Switch to true top of stack. */
159 call mi_startup /* autoconfiguration, mountroot etc */
161 addl $0,%esp /* for db_numargs() again */
163 /**********************************************************************
165 * Recover the bootinfo passed to us from the boot program
170 * This code is called in different ways depending on what loaded
171 * and started the kernel. This is used to detect how we get the
172 * arguments from the other code and what we do with them.
174 * Old disk boot blocks:
175 * (*btext)(howto, bootdev, cyloffset, esym);
176 * [return address == 0, and can NOT be returned to]
177 * [cyloffset was not supported by the FreeBSD boot code
178 * and always passed in as 0]
179 * [esym is also known as total in the boot code, and
180 * was never properly supported by the FreeBSD boot code]
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
199 * did an lret to get here. The frame on the stack has a return
206 * We have some form of return address, so this is either the
207 * old diskless netboot code, or the new uniform code. That can
208 * be detected by looking at the 5th argument, if it is 0
209 * we are being booted by the new uniform boot code.
215 * Seems we have been loaded by the old diskless boot code, we
216 * don't stand a chance of running as the diskless structure
217 * changed considerably between the two, so just halt.
222 * We have been loaded by the new uniform boot code.
223 * Let's check the bootinfo version, and if we do not understand
224 * it we return to the loader with a status of 1 to indicate this error
227 movl 28(%ebp),%ebx /* &bootinfo.version */
228 movl BI_VERSION(%ebx),%eax
229 cmpl $1,%eax /* We only understand version 1 */
231 movl $1,%eax /* Return status */
234 * XXX this returns to our caller's caller (as is required) since
235 * we didn't set up a frame and our caller did.
241 * If we have a kernelname copy it in
243 movl BI_KERNELNAME(%ebx),%esi
245 je 2f /* No kernelname */
246 movl $MAXPATHLEN,%ecx /* Brute force!!! */
247 movl $kernelname,%edi
248 cmpb $'/',(%esi) /* Make sure it starts with a slash */
260 * Determine the size of the boot loader's copy of the bootinfo
261 * struct. This is impossible to do properly because old versions
262 * of the struct don't contain a size field and there are 2 old
263 * versions with the same version number.
265 movl $BI_ENDCOMMON,%ecx /* prepare for sizeless version */
266 testl $RB_BOOTINFO,8(%ebp) /* bi_size (and bootinfo) valid? */
267 je got_bi_size /* no, sizeless version */
268 movl BI_SIZE(%ebx),%ecx
272 * Copy the common part of the bootinfo struct
276 cmpl $BOOTINFO_SIZE,%ecx
277 jbe got_common_bi_size
278 movl $BOOTINFO_SIZE,%ecx
287 * If we have a nfs_diskless structure copy it in
289 movl BI_NFS_DISKLESS(%ebx),%esi
292 movl $nfs_diskless,%edi
293 movl $NFSDISKLESS_SIZE,%ecx
297 movl $nfs_diskless_valid,%edi
303 * The old style disk boot.
304 * (*btext)(howto, bootdev, cyloffset, esym);
305 * Note that the newer boot code just falls into here to pick
306 * up howto and bootdev, cyloffset and esym are no longer used
317 /**********************************************************************
319 * Identify the CPU and initialize anything special about it
326 /* Try to toggle alignment check flag; does not exist on 386. */
343 /* NexGen CPU does not have aligment check flag. */
358 movl $0x4778654e,cpu_vendor # store vendor string
359 movl $0x72446e65,cpu_vendor+4
360 movl $0x6e657669,cpu_vendor+8
361 movl $0,cpu_vendor+12
364 try486: /* Try to toggle identification flag; does not exist on early 486s. */
384 * Cyrix CPUs do not change the undefined flags following
385 * execution of the divide instruction which divides 5 by 2.
387 * Note: CPUID is enabled on M2, so it passes another way.
397 jmp 3f /* You may use Intel CPU. */
402 * IBM Bluelighting CPU also doesn't change the undefined flags.
403 * Because IBM doesn't disclose the information for Bluelighting
404 * CPU, we couldn't distinguish it from Cyrix's (including IBM
405 * brand of Cyrix CPUs).
407 movl $0x69727943,cpu_vendor # store vendor string
408 movl $0x736e4978,cpu_vendor+4
409 movl $0x64616574,cpu_vendor+8
412 trycpuid: /* Use the `cpuid' instruction. */
415 movl %eax,cpu_high # highest capability
416 movl %ebx,cpu_vendor # store vendor string
417 movl %edx,cpu_vendor+4
418 movl %ecx,cpu_vendor+8
419 movb $0,cpu_vendor+12
423 movl %eax,cpu_id # store cpu_id
424 movl %ebx,cpu_procinfo # store cpu_procinfo
425 movl %edx,cpu_feature # store cpu_feature
426 movl %ecx,cpu_feature2 # store cpu_feature2
427 rorl $8,%eax # extract family type
432 /* less than Pentium; must be 486 */
442 /* Greater than Pentium...call it a Pentium Pro */
450 /* Xen Hypercall page */
452 .p2align PAGE_SHIFT, 0x90 /* Hypercall_page needs to be PAGE aligned */
454 NON_GPROF_ENTRY(hypercall_page)
455 .skip 0x1000, 0x90 /* Fill with "nop"s */