The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/i386/i386/locore.s

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 1990 The Regents of the University of California.
    3  * All rights reserved.
    4  *
    5  * This code is derived from software contributed to Berkeley by
    6  * William Jolitz.
    7  *
    8  * Redistribution and use in source and binary forms, with or without
    9  * modification, are permitted provided that the following conditions
   10  * are met:
   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.
   19  *
   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
   30  * SUCH DAMAGE.
   31  *
   32  *      from: @(#)locore.s      7.3 (Berkeley) 5/13/91
   33  * $FreeBSD$
   34  *
   35  *              originally from: locore.s, by William F. Jolitz
   36  *
   37  *              Substantially rewritten by David Greenman, Rod Grimes,
   38  *                      Bruce Evans, Wolfgang Solfrank, Poul-Henning Kamp
   39  *                      and many others.
   40  */
   41 
   42 #include "opt_bootp.h"
   43 #include "opt_nfsroot.h"
   44 #include "opt_pmap.h"
   45 
   46 #include <sys/reboot.h>
   47 
   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>
   53 
   54 #include "assym.inc"
   55 
   56 /*
   57  * PTmap is recursive pagemap at top of virtual address space.
   58  * Within PTmap, the page directory can be found (third indirection).
   59  */
   60         .globl  PTmap,PTD,PTDpde
   61         .set    PTmap,(PTDPTDI << PDRSHIFT)
   62         .set    PTD,PTmap + (PTDPTDI * PAGE_SIZE)
   63         .set    PTDpde,PTD + (PTDPTDI * PDESIZE)
   64 
   65 /*
   66  * Compiled KERNBASE location and the kernel load address, now identical.
   67  */
   68         .globl  kernbase
   69         .set    kernbase,KERNBASE
   70         .globl  kernload
   71         .set    kernload,KERNLOAD
   72 
   73 /*
   74  * Globals
   75  */
   76         .data
   77         ALIGN_DATA                      /* just to be sure */
   78 
   79         .space  0x2000                  /* space for tmpstk - temporary stack */
   80 tmpstk:
   81 
   82         .globl  bootinfo
   83 bootinfo:       .space  BOOTINFO_SIZE   /* bootinfo that we can handle */
   84 
   85         .text
   86 /**********************************************************************
   87  *
   88  * This is where the bootblocks start us, set the ball rolling...
   89  *
   90  */
   91 NON_GPROF_ENTRY(btext)
   92 
   93 /* Tell the bios to warmboot next time */
   94         movw    $0x1234,0x472
   95 
   96 /* Set up a real frame in case the double return in newboot is executed. */
   97         xorl    %ebp,%ebp
   98         pushl   %ebp
   99         movl    %esp, %ebp
  100 
  101 /* Don't trust what the BIOS gives for eflags. */
  102         pushl   $PSL_KERNEL
  103         popfl
  104 
  105 /*
  106  * Don't trust what the BIOS gives for %fs and %gs.  Trust the bootstrap
  107  * to set %cs, %ds, %es and %ss.
  108  */
  109         mov     %ds, %ax
  110         mov     %ax, %fs
  111         mov     %ax, %gs
  112 
  113 /*
  114  * Clear the bss.  Not all boot programs do it, and it is our job anyway.
  115  *
  116  * XXX we don't check that there is memory for our bss and page tables
  117  * before using it.
  118  *
  119  * Note: we must be careful to not overwrite an active gdt or idt.  They
  120  * inactive from now until we switch to new ones, since we don't load any
  121  * more segment registers or permit interrupts until after the switch.
  122  */
  123         movl    $__bss_end,%ecx
  124         movl    $__bss_start,%edi
  125         subl    %edi,%ecx
  126         xorl    %eax,%eax
  127         cld
  128         rep
  129         stosb
  130 
  131         call    recover_bootinfo
  132 
  133 /* Get onto a stack that we can trust. */
  134 /*
  135  * XXX this step is delayed in case recover_bootinfo needs to return via
  136  * the old stack, but it need not be, since recover_bootinfo actually
  137  * returns via the old frame.
  138  */
  139         movl    $tmpstk,%esp
  140 
  141         call    identify_cpu
  142         call    pmap_cold
  143 
  144         /* set up bootstrap stack */
  145         movl    proc0kstack,%eax        /* location of in-kernel stack */
  146 
  147         /*
  148          * Only use bottom page for init386().  init386() calculates the
  149          * PCB + FPU save area size and returns the true top of stack.
  150          */
  151         leal    PAGE_SIZE(%eax),%esp
  152 
  153         xorl    %ebp,%ebp               /* mark end of frames */
  154 
  155         pushl   physfree                /* value of first for init386(first) */
  156         call    init386                 /* wire 386 chip for unix operation */
  157 
  158         /*
  159          * Clean up the stack in a way that db_numargs() understands, so
  160          * that backtraces in ddb don't underrun the stack.  Traps for
  161          * inaccessible memory are more fatal than usual this early.
  162          */
  163         addl    $4,%esp
  164 
  165         /* Switch to true top of stack. */
  166         movl    %eax,%esp
  167 
  168         call    mi_startup              /* autoconfiguration, mountroot etc */
  169         /* NOTREACHED */
  170         addl    $0,%esp                 /* for db_numargs() again */
  171 
  172 /**********************************************************************
  173  *
  174  * Recover the bootinfo passed to us from the boot program
  175  *
  176  */
  177 recover_bootinfo:
  178         /*
  179          * This code is called in different ways depending on what loaded
  180          * and started the kernel.  This is used to detect how we get the
  181          * arguments from the other code and what we do with them.
  182          *
  183          * Old disk boot blocks:
  184          *      (*btext)(howto, bootdev, cyloffset, esym);
  185          *      [return address == 0, and can NOT be returned to]
  186          *      [cyloffset was not supported by the FreeBSD boot code
  187          *       and always passed in as 0]
  188          *      [esym is also known as total in the boot code, and
  189          *       was never properly supported by the FreeBSD boot code]
  190          *
  191          * Old diskless netboot code:
  192          *      (*btext)(0,0,0,0,&nfsdiskless,0,0,0);
  193          *      [return address != 0, and can NOT be returned to]
  194          *      If we are being booted by this code it will NOT work,
  195          *      so we are just going to halt if we find this case.
  196          *
  197          * New uniform boot code:
  198          *      (*btext)(howto, bootdev, 0, 0, 0, &bootinfo)
  199          *      [return address != 0, and can be returned to]
  200          *
  201          * There may seem to be a lot of wasted arguments in here, but
  202          * that is so the newer boot code can still load very old kernels
  203          * and old boot code can load new kernels.
  204          */
  205 
  206         /*
  207          * The old style disk boot blocks fake a frame on the stack and
  208          * did an lret to get here.  The frame on the stack has a return
  209          * address of 0.
  210          */
  211         cmpl    $0,4(%ebp)
  212         je      olddiskboot
  213 
  214         /*
  215          * We have some form of return address, so this is either the
  216          * old diskless netboot code, or the new uniform code.  That can
  217          * be detected by looking at the 5th argument, if it is 0
  218          * we are being booted by the new uniform boot code.
  219          */
  220         cmpl    $0,24(%ebp)
  221         je      newboot
  222 
  223         /*
  224          * Seems we have been loaded by the old diskless boot code, we
  225          * don't stand a chance of running as the diskless structure
  226          * changed considerably between the two, so just halt.
  227          */
  228          hlt
  229 
  230         /*
  231          * We have been loaded by the new uniform boot code.
  232          * Let's check the bootinfo version, and if we do not understand
  233          * it we return to the loader with a status of 1 to indicate this error
  234          */
  235 newboot:
  236         movl    28(%ebp),%ebx           /* &bootinfo.version */
  237         movl    BI_VERSION(%ebx),%eax
  238         cmpl    $1,%eax                 /* We only understand version 1 */
  239         je      1f
  240         movl    $1,%eax                 /* Return status */
  241         leave
  242         /*
  243          * XXX this returns to our caller's caller (as is required) since
  244          * we didn't set up a frame and our caller did.
  245          */
  246         ret
  247 
  248 1:
  249         /*
  250          * If we have a kernelname copy it in
  251          */
  252         movl    BI_KERNELNAME(%ebx),%esi
  253         cmpl    $0,%esi
  254         je      2f                      /* No kernelname */
  255         movl    $MAXPATHLEN,%ecx        /* Brute force!!! */
  256         movl    $kernelname,%edi
  257         cmpb    $'/',(%esi)             /* Make sure it starts with a slash */
  258         je      1f
  259         movb    $'/',(%edi)
  260         incl    %edi
  261         decl    %ecx
  262 1:
  263         cld
  264         rep
  265         movsb
  266 
  267 2:
  268         /*
  269          * Determine the size of the boot loader's copy of the bootinfo
  270          * struct.  This is impossible to do properly because old versions
  271          * of the struct don't contain a size field and there are 2 old
  272          * versions with the same version number.
  273          */
  274         movl    $BI_ENDCOMMON,%ecx      /* prepare for sizeless version */
  275         testl   $RB_BOOTINFO,8(%ebp)    /* bi_size (and bootinfo) valid? */
  276         je      got_bi_size             /* no, sizeless version */
  277         movl    BI_SIZE(%ebx),%ecx
  278 got_bi_size:
  279 
  280         /*
  281          * Copy the common part of the bootinfo struct
  282          */
  283         movl    %ebx,%esi
  284         movl    $bootinfo,%edi
  285         cmpl    $BOOTINFO_SIZE,%ecx
  286         jbe     got_common_bi_size
  287         movl    $BOOTINFO_SIZE,%ecx
  288 got_common_bi_size:
  289         cld
  290         rep
  291         movsb
  292 
  293 #ifdef NFS_ROOT
  294 #ifndef BOOTP_NFSV3
  295         /*
  296          * If we have a nfs_diskless structure copy it in
  297          */
  298         movl    BI_NFS_DISKLESS(%ebx),%esi
  299         cmpl    $0,%esi
  300         je      olddiskboot
  301         movl    $nfs_diskless,%edi
  302         movl    $NFSDISKLESS_SIZE,%ecx
  303         cld
  304         rep
  305         movsb
  306         movl    $nfs_diskless_valid,%edi
  307         movl    $1,(%edi)
  308 #endif
  309 #endif
  310 
  311         /*
  312          * The old style disk boot.
  313          *      (*btext)(howto, bootdev, cyloffset, esym);
  314          * Note that the newer boot code just falls into here to pick
  315          * up howto and bootdev, cyloffset and esym are no longer used
  316          */
  317 olddiskboot:
  318         movl    8(%ebp),%eax
  319         movl    %eax,boothowto
  320         movl    12(%ebp),%eax
  321         movl    %eax,bootdev
  322 
  323         ret
  324 
  325 
  326 /**********************************************************************
  327  *
  328  * Identify the CPU and initialize anything special about it
  329  *
  330  */
  331 ENTRY(identify_cpu)
  332 
  333         pushl   %ebx
  334 
  335         /* Try to toggle alignment check flag; does not exist on 386. */
  336         pushfl
  337         popl    %eax
  338         movl    %eax,%ecx
  339         orl     $PSL_AC,%eax
  340         pushl   %eax
  341         popfl
  342         pushfl
  343         popl    %eax
  344         xorl    %ecx,%eax
  345         andl    $PSL_AC,%eax
  346         pushl   %ecx
  347         popfl
  348 
  349         testl   %eax,%eax
  350         jnz     try486
  351 
  352         /* NexGen CPU does not have alignment check flag. */
  353         pushfl
  354         movl    $0x5555, %eax
  355         xorl    %edx, %edx
  356         movl    $2, %ecx
  357         clc
  358         divl    %ecx
  359         jz      trynexgen
  360         popfl
  361         movl    $CPU_386,cpu
  362         jmp     3f
  363 
  364 trynexgen:
  365         popfl
  366         movl    $CPU_NX586,cpu
  367         movl    $0x4778654e,cpu_vendor          # store vendor string
  368         movl    $0x72446e65,cpu_vendor+4
  369         movl    $0x6e657669,cpu_vendor+8
  370         movl    $0,cpu_vendor+12
  371         jmp     3f
  372 
  373 try486: /* Try to toggle identification flag; does not exist on early 486s. */
  374         pushfl
  375         popl    %eax
  376         movl    %eax,%ecx
  377         xorl    $PSL_ID,%eax
  378         pushl   %eax
  379         popfl
  380         pushfl
  381         popl    %eax
  382         xorl    %ecx,%eax
  383         andl    $PSL_ID,%eax
  384         pushl   %ecx
  385         popfl
  386 
  387         testl   %eax,%eax
  388         jnz     trycpuid
  389         movl    $CPU_486,cpu
  390 
  391         /*
  392          * Check Cyrix CPU
  393          * Cyrix CPUs do not change the undefined flags following
  394          * execution of the divide instruction which divides 5 by 2.
  395          *
  396          * Note: CPUID is enabled on M2, so it passes another way.
  397          */
  398         pushfl
  399         movl    $0x5555, %eax
  400         xorl    %edx, %edx
  401         movl    $2, %ecx
  402         clc
  403         divl    %ecx
  404         jnc     trycyrix
  405         popfl
  406         jmp     3f              /* You may use Intel CPU. */
  407 
  408 trycyrix:
  409         popfl
  410         /*
  411          * IBM Bluelighting CPU also doesn't change the undefined flags.
  412          * Because IBM doesn't disclose the information for Bluelighting
  413          * CPU, we couldn't distinguish it from Cyrix's (including IBM
  414          * brand of Cyrix CPUs).
  415          */
  416         movl    $0x69727943,cpu_vendor          # store vendor string
  417         movl    $0x736e4978,cpu_vendor+4
  418         movl    $0x64616574,cpu_vendor+8
  419         jmp     3f
  420 
  421 trycpuid:       /* Use the `cpuid' instruction. */
  422         xorl    %eax,%eax
  423         cpuid                                   # cpuid 0
  424         movl    %eax,cpu_high                   # highest capability
  425         movl    %ebx,cpu_vendor                 # store vendor string
  426         movl    %edx,cpu_vendor+4
  427         movl    %ecx,cpu_vendor+8
  428         movb    $0,cpu_vendor+12
  429 
  430         movl    $1,%eax
  431         cpuid                                   # cpuid 1
  432         movl    %eax,cpu_id                     # store cpu_id
  433         movl    %ebx,cpu_procinfo               # store cpu_procinfo
  434         movl    %edx,cpu_feature                # store cpu_feature
  435         movl    %ecx,cpu_feature2               # store cpu_feature2
  436         rorl    $8,%eax                         # extract family type
  437         andl    $15,%eax
  438         cmpl    $5,%eax
  439         jae     1f
  440 
  441         /* less than Pentium; must be 486 */
  442         movl    $CPU_486,cpu
  443         jmp     3f
  444 1:
  445         /* a Pentium? */
  446         cmpl    $5,%eax
  447         jne     2f
  448         movl    $CPU_586,cpu
  449         jmp     3f
  450 2:
  451         /* Greater than Pentium...call it a Pentium Pro */
  452         movl    $CPU_686,cpu
  453 3:
  454         popl    %ebx
  455         ret
  456 END(identify_cpu)
  457 
  458 #ifdef XENHVM
  459 /* Xen Hypercall page */
  460         .text
  461 .p2align PAGE_SHIFT, 0x90       /* Hypercall_page needs to be PAGE aligned */
  462 
  463 NON_GPROF_ENTRY(hypercall_page)
  464         .skip   0x1000, 0x90    /* Fill with "nop"s */
  465 #endif

Cache object: d486936e259c2ca637e3c79026277431


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.