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. All advertising materials mentioning features or use of this software
   17  *    must display the following acknowledgement:
   18  *      This product includes software developed by the University of
   19  *      California, Berkeley and its contributors.
   20  * 4. Neither the name of the University nor the names of its contributors
   21  *    may be used to endorse or promote products derived from this software
   22  *    without specific prior written permission.
   23  *
   24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   34  * SUCH DAMAGE.
   35  *
   36  *      from: @(#)locore.s      7.3 (Berkeley) 5/13/91
   37  * $FreeBSD$
   38  *
   39  *              originally from: locore.s, by William F. Jolitz
   40  *
   41  *              Substantially rewritten by David Greenman, Rod Grimes,
   42  *                      Bruce Evans, Wolfgang Solfrank, Poul-Henning Kamp
   43  *                      and many others.
   44  */
   45 
   46 #include "apm.h"
   47 #include "opt_bootp.h"
   48 #include "opt_ddb.h"
   49 #include "opt_nfsroot.h"
   50 #include "opt_userconfig.h"
   51 #include "opt_vm86.h"
   52 
   53 #include <sys/syscall.h>
   54 #include <sys/reboot.h>
   55 
   56 #include <machine/asmacros.h>
   57 #include <machine/cputypes.h>
   58 #include <machine/psl.h>
   59 #include <machine/pmap.h>
   60 #include <machine/specialreg.h>
   61 
   62 #include "assym.s"
   63 
   64 /*
   65  *      XXX
   66  *
   67  * Note: This version greatly munged to avoid various assembler errors
   68  * that may be fixed in newer versions of gas. Perhaps newer versions
   69  * will have more pleasant appearance.
   70  */
   71 
   72 /*
   73  * PTmap is recursive pagemap at top of virtual address space.
   74  * Within PTmap, the page directory can be found (third indirection).
   75  */
   76         .globl  _PTmap,_PTD,_PTDpde
   77         .set    _PTmap,(PTDPTDI << PDRSHIFT)
   78         .set    _PTD,_PTmap + (PTDPTDI * PAGE_SIZE)
   79         .set    _PTDpde,_PTD + (PTDPTDI * PDESIZE)
   80 
   81 /*
   82  * APTmap, APTD is the alternate recursive pagemap.
   83  * It's used when modifying another process's page tables.
   84  */
   85         .globl  _APTmap,_APTD,_APTDpde
   86         .set    _APTmap,APTDPTDI << PDRSHIFT
   87         .set    _APTD,_APTmap + (APTDPTDI * PAGE_SIZE)
   88         .set    _APTDpde,_PTD + (APTDPTDI * PDESIZE)
   89 
   90 /*
   91  * Globals
   92  */
   93         .data
   94         ALIGN_DATA              /* just to be sure */
   95 
   96         .globl  tmpstk
   97         .space  0x2000          /* space for tmpstk - temporary stack */
   98 tmpstk:
   99 
  100         .globl  _boothowto,_bootdev
  101 
  102         .globl  _cpu,_cpu_vendor,_cpu_id,_bootinfo
  103         .globl  _cpu_high, _cpu_feature
  104 
  105 _cpu:   .long   0                               /* are we 386, 386sx, or 486 */
  106 _cpu_id:        .long   0                       /* stepping ID */
  107 _cpu_high:      .long   0                       /* highest arg to CPUID */
  108 _cpu_feature:   .long   0                       /* features */
  109 _cpu_vendor:    .space  20                      /* CPU origin code */
  110 _bootinfo:      .space  BOOTINFO_SIZE           /* bootinfo that we can handle */
  111 
  112 _KERNend:       .long   0                       /* phys addr end of kernel (just after bss) */
  113 physfree:       .long   0                       /* phys addr of next free page */
  114 
  115 #ifdef SMP
  116 cpu0pp:         .long   0                       /* phys addr cpu0 private pg */
  117 cpu0pt:         .long   0                       /* phys addr cpu0 private pt */
  118 
  119                 .globl  _cpu0prvpage,_cpu0prvpt
  120 _cpu0prvpage:   .long   0                       /* relocated version */
  121 _cpu0prvpt:     .long   0                       /* relocated version */
  122 #endif /* SMP */
  123 
  124         .globl  _IdlePTD
  125 _IdlePTD:       .long   0                       /* phys addr of kernel PTD */
  126 
  127 #ifdef SMP
  128         .globl  _KPTphys
  129 #endif
  130 _KPTphys:       .long   0                       /* phys addr of kernel page tables */
  131 
  132         .globl  _proc0paddr
  133 _proc0paddr:    .long   0                       /* address of proc 0 address space */
  134 p0upa:          .long   0                       /* phys addr of proc0's UPAGES */
  135 
  136 #ifdef VM86
  137 vm86phystk:     .long   0                       /* PA of vm86/bios stack */
  138 
  139         .globl  _vm86paddr, _vm86pa
  140 _vm86paddr:     .long   0                       /* address of vm86 region */
  141 _vm86pa:        .long   0                       /* phys addr of vm86 region */
  142 #endif
  143 
  144 #ifdef BDE_DEBUGGER
  145         .globl  _bdb_exists                     /* flag to indicate BDE debugger is present */
  146 _bdb_exists:    .long   0
  147 #endif
  148 
  149 #ifdef PC98
  150         .globl  _pc98_system_parameter
  151 _pc98_system_parameter:
  152         .space  0x240
  153 #endif
  154 
  155 /**********************************************************************
  156  *
  157  * Some handy macros
  158  *
  159  */
  160 
  161 #define R(foo) ((foo)-KERNBASE)
  162 
  163 #define ALLOCPAGES(foo) \
  164         movl    R(physfree), %esi ; \
  165         movl    $((foo)*PAGE_SIZE), %eax ; \
  166         addl    %esi, %eax ; \
  167         movl    %eax, R(physfree) ; \
  168         movl    %esi, %edi ; \
  169         movl    $((foo)*PAGE_SIZE),%ecx ; \
  170         xorl    %eax,%eax ; \
  171         cld ; \
  172         rep ; \
  173         stosb
  174 
  175 /*
  176  * fillkpt
  177  *      eax = page frame address
  178  *      ebx = index into page table
  179  *      ecx = how many pages to map
  180  *      base = base address of page dir/table
  181  *      prot = protection bits
  182  */
  183 #define fillkpt(base, prot)               \
  184         shll    $2,%ebx                 ; \
  185         addl    base,%ebx               ; \
  186         orl     $PG_V,%eax              ; \
  187         orl     prot,%eax               ; \
  188 1:      movl    %eax,(%ebx)             ; \
  189         addl    $PAGE_SIZE,%eax         ; /* increment physical address */ \
  190         addl    $4,%ebx                 ; /* next pte */ \
  191         loop    1b
  192 
  193 /*
  194  * fillkptphys(prot)
  195  *      eax = physical address
  196  *      ecx = how many pages to map
  197  *      prot = protection bits
  198  */
  199 #define fillkptphys(prot)                 \
  200         movl    %eax, %ebx              ; \
  201         shrl    $PAGE_SHIFT, %ebx       ; \
  202         fillkpt(R(_KPTphys), prot)
  203 
  204         .text
  205 /**********************************************************************
  206  *
  207  * This is where the bootblocks start us, set the ball rolling...
  208  *
  209  */
  210 NON_GPROF_ENTRY(btext)
  211 
  212 #ifdef PC98
  213         /* save SYSTEM PARAMETER for resume (NS/T or other) */
  214         movl    $0xa1400,%esi
  215         movl    $R(_pc98_system_parameter),%edi
  216         movl    $0x0240,%ecx
  217         cld
  218         rep
  219         movsb
  220 #else   /* IBM-PC */
  221 #ifdef BDE_DEBUGGER
  222 #ifdef BIOS_STEALS_3K
  223         cmpl    $0x0375c339,0x95504
  224 #else
  225         cmpl    $0x0375c339,0x96104     /* XXX - debugger signature */
  226 #endif
  227         jne     1f
  228         movb    $1,R(_bdb_exists)
  229 1:
  230 #endif
  231 /* Tell the bios to warmboot next time */
  232         movw    $0x1234,0x472
  233 #endif  /* PC98 */
  234 
  235 /* Set up a real frame in case the double return in newboot is executed. */
  236         pushl   %ebp
  237         movl    %esp, %ebp
  238 
  239 /* Don't trust what the BIOS gives for eflags. */
  240         pushl   $PSL_KERNEL
  241         popfl
  242 
  243 /*
  244  * Don't trust what the BIOS gives for %fs and %gs.  Trust the bootstrap
  245  * to set %cs, %ds, %es and %ss.
  246  */
  247         mov     %ds, %ax
  248         mov     %ax, %fs
  249         mov     %ax, %gs
  250 
  251 /*
  252  * Clear the bss.  Not all boot programs do it, and it is our job anyway.
  253  *
  254  * XXX we don't check that there is memory for our bss and page tables
  255  * before using it.
  256  *
  257  * Note: we must be careful to not overwrite an active gdt or idt.  In
  258  * the !BDE_DEBUGGER case they are inactive from now until we switch to
  259  * new ones, since we don't load any more segment registers or permit
  260  * interrupts until after the switch.  In the BDE_DEBUGGER case, we depend
  261  * on the convention that the boot program is below 1MB and we are above
  262  * 1MB to keep the gdt and idt away from the bss and page tables.
  263  */
  264         movl    $R(_end),%ecx
  265         movl    $R(_edata),%edi
  266         subl    %edi,%ecx
  267         xorl    %eax,%eax
  268         cld
  269         rep
  270         stosb
  271 
  272         call    recover_bootinfo
  273 
  274 /* Get onto a stack that we can trust. */
  275 /*
  276  * XXX this step is delayed in case recover_bootinfo needs to return via
  277  * the old stack, but it need not be, since recover_bootinfo actually
  278  * returns via the old frame.
  279  */
  280         movl    $R(tmpstk),%esp
  281 
  282 #ifdef PC98
  283         /* pc98_machine_type & M_EPSON_PC98 */
  284         testb   $0x02,R(_pc98_system_parameter)+220
  285         jz      3f
  286         /* epson_machine_id <= 0x0b */
  287         cmpb    $0x0b,R(_pc98_system_parameter)+224
  288         ja      3f
  289 
  290         /* count up memory */
  291         movl    $0x100000,%eax          /* next, talley remaining memory */
  292         movl    $0xFFF-0x100,%ecx
  293 1:      movl    0(%eax),%ebx            /* save location to check */
  294         movl    $0xa55a5aa5,0(%eax)     /* write test pattern */
  295         cmpl    $0xa55a5aa5,0(%eax)     /* does not check yet for rollover */
  296         jne     2f
  297         movl    %ebx,0(%eax)            /* restore memory */
  298         addl    $PAGE_SIZE,%eax
  299         loop    1b
  300 2:      subl    $0x100000,%eax
  301         shrl    $17,%eax
  302         movb    %al,R(_pc98_system_parameter)+1
  303 3:
  304 
  305         movw    R(_pc98_system_parameter+0x86),%ax
  306         movw    %ax,R(_cpu_id)
  307 #endif
  308 
  309         call    identify_cpu
  310 
  311 #if NAPM > 0
  312 #ifndef VM86
  313 /*
  314  * XXX it's not clear that APM can live in the current environonment.
  315  * Only pc-relative addressing works.
  316  */
  317         call    _apm_setup
  318 #endif
  319 #endif
  320 
  321         call    create_pagetables
  322 
  323 #ifdef VM86
  324 /*
  325  * If the CPU has support for VME, turn it on.
  326  */ 
  327         testl   $CPUID_VME, R(_cpu_feature)
  328         jz      1f
  329         movl    %cr4, %eax
  330         orl     $CR4_VME, %eax
  331         movl    %eax, %cr4
  332 1:
  333 #endif /* VM86 */
  334 
  335 #ifdef BDE_DEBUGGER
  336 /*
  337  * Adjust as much as possible for paging before enabling paging so that the
  338  * adjustments can be traced.
  339  */
  340         call    bdb_prepare_paging
  341 #endif
  342 
  343 /* Now enable paging */
  344         movl    R(_IdlePTD), %eax
  345         movl    %eax,%cr3                       /* load ptd addr into mmu */
  346         movl    %cr0,%eax                       /* get control word */
  347         orl     $CR0_PE|CR0_PG,%eax             /* enable paging */
  348         movl    %eax,%cr0                       /* and let's page NOW! */
  349 
  350 #ifdef BDE_DEBUGGER
  351 /*
  352  * Complete the adjustments for paging so that we can keep tracing through
  353  * initi386() after the low (physical) addresses for the gdt and idt become
  354  * invalid.
  355  */
  356         call    bdb_commit_paging
  357 #endif
  358 
  359         pushl   $begin                          /* jump to high virtualized address */
  360         ret
  361 
  362 /* now running relocated at KERNBASE where the system is linked to run */
  363 begin:
  364         /* set up bootstrap stack */
  365         movl    _proc0paddr,%esp        /* location of in-kernel pages */
  366         addl    $UPAGES*PAGE_SIZE,%esp  /* bootstrap stack end location */
  367         xorl    %eax,%eax                       /* mark end of frames */
  368         movl    %eax,%ebp
  369         movl    _proc0paddr,%eax
  370         movl    _IdlePTD, %esi
  371         movl    %esi,PCB_CR3(%eax)
  372         movl    $_proc0,_curproc
  373 
  374         movl    physfree, %esi
  375         pushl   %esi                            /* value of first for init386(first) */
  376         call    _init386                        /* wire 386 chip for unix operation */
  377         popl    %esi
  378 
  379         .globl  __ucodesel,__udatasel
  380 
  381         pushl   $0                              /* unused */
  382         pushl   __udatasel                      /* ss */
  383         pushl   $0                              /* esp - filled in by execve() */
  384         pushl   $PSL_USER                       /* eflags (IOPL 0, int enab) */
  385         pushl   __ucodesel                      /* cs */
  386         pushl   $0                              /* eip - filled in by execve() */
  387         subl    $(12*4),%esp                    /* space for rest of registers */
  388 
  389         pushl   %esp                            /* call main with frame pointer */
  390         call    _main                           /* autoconfiguration, mountroot etc */
  391 
  392         hlt             /* never returns to here */
  393 
  394 /*
  395  * When starting init, call this to configure the process for user
  396  * mode.  This will be inherited by other processes.
  397  */
  398 NON_GPROF_ENTRY(prepare_usermode)
  399         /*
  400          * Now we've run main() and determined what cpu-type we are, we can
  401          * enable write protection and alignment checking on i486 cpus and
  402          * above.
  403          */
  404 #if defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU)
  405         cmpl    $CPUCLASS_386,_cpu_class
  406         je      1f
  407         movl    %cr0,%eax                       /* get control word */
  408         orl     $CR0_WP|CR0_AM,%eax             /* enable i486 features */
  409         movl    %eax,%cr0                       /* and do it */
  410 1:
  411 #endif
  412         /*
  413          * on return from main(), we are process 1
  414          * set up address space and stack so that we can 'return' to user mode
  415          */
  416         movl    __ucodesel,%eax
  417         movl    __udatasel,%ecx
  418 
  419 #if 0
  420         movl    %cx,%ds
  421 #endif
  422         movl    %cx,%es
  423         movl    %ax,%fs                         /* double map cs to fs */
  424         movl    %cx,%gs                         /* and ds to gs */
  425         ret                                     /* goto user! */
  426 
  427 
  428 #define LCALL(x,y)      .byte 0x9a ; .long y ; .word x
  429 
  430 /*
  431  * Signal trampoline, copied to top of user stack
  432  */
  433 NON_GPROF_ENTRY(sigcode)
  434         call    SIGF_HANDLER(%esp)
  435         lea     SIGF_SC(%esp),%eax              /* scp (the copy at 8(%esp) */
  436         pushl   %eax                            /* may have been clobbered) */
  437         testl   $PSL_VM,SC_PS(%eax)
  438         jne     9f
  439         movl    SC_FS(%eax),%fs                 /* restore %fs */
  440         movl    SC_GS(%eax),%gs                 /* restore %gs */
  441 9:
  442         pushl   %eax                            /* junk to fake return addr */
  443         movl    $SYS_sigreturn,%eax             /* sigreturn() */
  444         LCALL(0x7,0)                            /* enter kernel with args */
  445 0:      jmp     0b
  446         ALIGN_TEXT
  447 _esigcode:
  448 
  449         .data
  450         .globl  _szsigcode
  451 _szsigcode:
  452         .long   _esigcode-_sigcode
  453         .text
  454 
  455 /**********************************************************************
  456  *
  457  * Recover the bootinfo passed to us from the boot program
  458  *
  459  */
  460 recover_bootinfo:
  461         /*
  462          * This code is called in different ways depending on what loaded
  463          * and started the kernel.  This is used to detect how we get the
  464          * arguments from the other code and what we do with them.
  465          *
  466          * Old disk boot blocks:
  467          *      (*btext)(howto, bootdev, cyloffset, esym);
  468          *      [return address == 0, and can NOT be returned to]
  469          *      [cyloffset was not supported by the FreeBSD boot code
  470          *       and always passed in as 0]
  471          *      [esym is also known as total in the boot code, and
  472          *       was never properly supported by the FreeBSD boot code]
  473          *
  474          * Old diskless netboot code:
  475          *      (*btext)(0,0,0,0,&nfsdiskless,0,0,0);
  476          *      [return address != 0, and can NOT be returned to]
  477          *      If we are being booted by this code it will NOT work,
  478          *      so we are just going to halt if we find this case.
  479          *
  480          * New uniform boot code:
  481          *      (*btext)(howto, bootdev, 0, 0, 0, &bootinfo)
  482          *      [return address != 0, and can be returned to]
  483          *
  484          * There may seem to be a lot of wasted arguments in here, but
  485          * that is so the newer boot code can still load very old kernels
  486          * and old boot code can load new kernels.
  487          */
  488 
  489         /*
  490          * The old style disk boot blocks fake a frame on the stack and
  491          * did an lret to get here.  The frame on the stack has a return
  492          * address of 0.
  493          */
  494         cmpl    $0,4(%ebp)
  495         je      olddiskboot
  496 
  497         /*
  498          * We have some form of return address, so this is either the
  499          * old diskless netboot code, or the new uniform code.  That can
  500          * be detected by looking at the 5th argument, if it is 0
  501          * we are being booted by the new uniform boot code.
  502          */
  503         cmpl    $0,24(%ebp)
  504         je      newboot
  505 
  506         /*
  507          * Seems we have been loaded by the old diskless boot code, we
  508          * don't stand a chance of running as the diskless structure
  509          * changed considerably between the two, so just halt.
  510          */
  511          hlt
  512 
  513         /*
  514          * We have been loaded by the new uniform boot code.
  515          * Let's check the bootinfo version, and if we do not understand
  516          * it we return to the loader with a status of 1 to indicate this error
  517          */
  518 newboot:
  519         movl    28(%ebp),%ebx           /* &bootinfo.version */
  520         movl    BI_VERSION(%ebx),%eax
  521         cmpl    $1,%eax                 /* We only understand version 1 */
  522         je      1f
  523         movl    $1,%eax                 /* Return status */
  524         leave
  525         /*
  526          * XXX this returns to our caller's caller (as is required) since
  527          * we didn't set up a frame and our caller did.
  528          */
  529         ret
  530 
  531 1:
  532         /*
  533          * If we have a kernelname copy it in
  534          */
  535         movl    BI_KERNELNAME(%ebx),%esi
  536         cmpl    $0,%esi
  537         je      2f                      /* No kernelname */
  538         movl    $MAXPATHLEN,%ecx        /* Brute force!!! */
  539         movl    $R(_kernelname),%edi
  540         cmpb    $'/',(%esi)             /* Make sure it starts with a slash */
  541         je      1f
  542         movb    $'/',(%edi)
  543         incl    %edi
  544         decl    %ecx
  545 1:
  546         cld
  547         rep
  548         movsb
  549 
  550 2:
  551         /*
  552          * Determine the size of the boot loader's copy of the bootinfo
  553          * struct.  This is impossible to do properly because old versions
  554          * of the struct don't contain a size field and there are 2 old
  555          * versions with the same version number.
  556          */
  557         movl    $BI_ENDCOMMON,%ecx      /* prepare for sizeless version */
  558         testl   $RB_BOOTINFO,8(%ebp)    /* bi_size (and bootinfo) valid? */
  559         je      got_bi_size             /* no, sizeless version */
  560         movl    BI_SIZE(%ebx),%ecx
  561 got_bi_size:
  562 
  563         /*
  564          * Copy the common part of the bootinfo struct
  565          */
  566         movl    %ebx,%esi
  567         movl    $R(_bootinfo),%edi
  568         cmpl    $BOOTINFO_SIZE,%ecx
  569         jbe     got_common_bi_size
  570         movl    $BOOTINFO_SIZE,%ecx
  571 got_common_bi_size:
  572         cld
  573         rep
  574         movsb
  575 
  576 #ifdef NFS_ROOT
  577 #ifndef BOOTP_NFSV3
  578         /*
  579          * If we have a nfs_diskless structure copy it in
  580          */
  581         movl    BI_NFS_DISKLESS(%ebx),%esi
  582         cmpl    $0,%esi
  583         je      olddiskboot
  584         movl    $R(_nfs_diskless),%edi
  585         movl    $NFSDISKLESS_SIZE,%ecx
  586         cld
  587         rep
  588         movsb
  589         movl    $R(_nfs_diskless_valid),%edi
  590         movl    $1,(%edi)
  591 #endif
  592 #endif
  593 
  594         /*
  595          * The old style disk boot.
  596          *      (*btext)(howto, bootdev, cyloffset, esym);
  597          * Note that the newer boot code just falls into here to pick
  598          * up howto and bootdev, cyloffset and esym are no longer used
  599          */
  600 olddiskboot:
  601         movl    8(%ebp),%eax
  602         movl    %eax,R(_boothowto)
  603         movl    12(%ebp),%eax
  604         movl    %eax,R(_bootdev)
  605 
  606         ret
  607 
  608 
  609 /**********************************************************************
  610  *
  611  * Identify the CPU and initialize anything special about it
  612  *
  613  */
  614 identify_cpu:
  615 
  616         /* Try to toggle alignment check flag; does not exist on 386. */
  617         pushfl
  618         popl    %eax
  619         movl    %eax,%ecx
  620         orl     $PSL_AC,%eax
  621         pushl   %eax
  622         popfl
  623         pushfl
  624         popl    %eax
  625         xorl    %ecx,%eax
  626         andl    $PSL_AC,%eax
  627         pushl   %ecx
  628         popfl
  629 
  630         testl   %eax,%eax
  631         jnz     try486
  632 
  633         /* NexGen CPU does not have aligment check flag. */
  634         pushfl
  635         movl    $0x5555, %eax
  636         xorl    %edx, %edx
  637         movl    $2, %ecx
  638         clc
  639         divl    %ecx
  640         jz      trynexgen
  641         popfl
  642         movl    $CPU_386,R(_cpu)
  643         jmp     3f
  644 
  645 trynexgen:
  646         popfl
  647         movl    $CPU_NX586,R(_cpu)
  648         movl    $0x4778654e,R(_cpu_vendor)      # store vendor string
  649         movl    $0x72446e65,R(_cpu_vendor+4)
  650         movl    $0x6e657669,R(_cpu_vendor+8)
  651         movl    $0,R(_cpu_vendor+12)
  652         jmp     3f
  653 
  654 try486: /* Try to toggle identification flag; does not exist on early 486s. */
  655         pushfl
  656         popl    %eax
  657         movl    %eax,%ecx
  658         xorl    $PSL_ID,%eax
  659         pushl   %eax
  660         popfl
  661         pushfl
  662         popl    %eax
  663         xorl    %ecx,%eax
  664         andl    $PSL_ID,%eax
  665         pushl   %ecx
  666         popfl
  667 
  668         testl   %eax,%eax
  669         jnz     trycpuid
  670         movl    $CPU_486,R(_cpu)
  671 
  672         /*
  673          * Check Cyrix CPU
  674          * Cyrix CPUs do not change the undefined flags following
  675          * execution of the divide instruction which divides 5 by 2.
  676          *
  677          * Note: CPUID is enabled on M2, so it passes another way.
  678          */
  679         pushfl
  680         movl    $0x5555, %eax
  681         xorl    %edx, %edx
  682         movl    $2, %ecx
  683         clc
  684         divl    %ecx
  685         jnc     trycyrix
  686         popfl
  687         jmp     3f              /* You may use Intel CPU. */
  688 
  689 trycyrix:
  690         popfl
  691         /*
  692          * IBM Bluelighting CPU also doesn't change the undefined flags.
  693          * Because IBM doesn't disclose the information for Bluelighting
  694          * CPU, we couldn't distinguish it from Cyrix's (including IBM
  695          * brand of Cyrix CPUs).
  696          */
  697         movl    $0x69727943,R(_cpu_vendor)      # store vendor string
  698         movl    $0x736e4978,R(_cpu_vendor+4)
  699         movl    $0x64616574,R(_cpu_vendor+8)
  700         jmp     3f
  701 
  702 trycpuid:       /* Use the `cpuid' instruction. */
  703         xorl    %eax,%eax
  704         .byte   0x0f,0xa2                       # cpuid 0
  705         movl    %eax,R(_cpu_high)               # highest capability
  706         movl    %ebx,R(_cpu_vendor)             # store vendor string
  707         movl    %edx,R(_cpu_vendor+4)
  708         movl    %ecx,R(_cpu_vendor+8)
  709         movb    $0,R(_cpu_vendor+12)
  710 
  711         movl    $1,%eax
  712         .byte   0x0f,0xa2                       # cpuid 1
  713         movl    %eax,R(_cpu_id)                 # store cpu_id
  714         movl    %edx,R(_cpu_feature)            # store cpu_feature
  715         rorl    $8,%eax                         # extract family type
  716         andl    $15,%eax
  717         cmpl    $5,%eax
  718         jae     1f
  719 
  720         /* less than Pentium; must be 486 */
  721         movl    $CPU_486,R(_cpu)
  722         jmp     3f
  723 1:
  724         /* a Pentium? */
  725         cmpl    $5,%eax
  726         jne     2f
  727         movl    $CPU_586,R(_cpu)
  728         jmp     3f
  729 2:
  730         /* Greater than Pentium...call it a Pentium Pro */
  731         movl    $CPU_686,R(_cpu)
  732 3:
  733         ret
  734 
  735 
  736 /**********************************************************************
  737  *
  738  * Create the first page directory and its page tables.
  739  *
  740  */
  741 
  742 create_pagetables:
  743 
  744         testl   $CPUID_PGE, R(_cpu_feature)
  745         jz      1f
  746         movl    %cr4, %eax
  747         orl     $CR4_PGE, %eax
  748         movl    %eax, %cr4
  749 1:
  750 
  751 /* Find end of kernel image (rounded up to a page boundary). */
  752         movl    $R(_end),%esi
  753 
  754 /* include symbols if loaded and useful */
  755 #ifdef DDB
  756         movl    R(_bootinfo+BI_ESYMTAB),%edi
  757         testl   %edi,%edi
  758         je      over_symalloc
  759         movl    %edi,%esi
  760         movl    $KERNBASE,%edi
  761         addl    %edi,R(_bootinfo+BI_SYMTAB)
  762         addl    %edi,R(_bootinfo+BI_ESYMTAB)
  763 over_symalloc:
  764 #endif
  765 
  766 /* If we are told where the end of the kernel space is, believe it. */
  767         movl    R(_bootinfo+BI_KERNEND),%edi
  768         testl   %edi,%edi
  769         je      no_kernend
  770         movl    %edi,%esi
  771 no_kernend:
  772         
  773         addl    $PAGE_MASK,%esi
  774         andl    $~PAGE_MASK,%esi
  775         movl    %esi,R(_KERNend)        /* save end of kernel */
  776         movl    %esi,R(physfree)        /* next free page is at end of kernel */
  777 
  778 /* Allocate Kernel Page Tables */
  779         ALLOCPAGES(NKPT)
  780         movl    %esi,R(_KPTphys)
  781 
  782 /* Allocate Page Table Directory */
  783         ALLOCPAGES(1)
  784         movl    %esi,R(_IdlePTD)
  785 
  786 /* Allocate UPAGES */
  787         ALLOCPAGES(UPAGES)
  788         movl    %esi,R(p0upa)
  789         addl    $KERNBASE, %esi
  790         movl    %esi, R(_proc0paddr)
  791 
  792 #ifdef VM86
  793         ALLOCPAGES(1)                   /* vm86/bios stack */
  794         movl    %esi,R(vm86phystk)
  795 
  796         ALLOCPAGES(3)                   /* pgtable + ext + IOPAGES */
  797         movl    %esi,R(_vm86pa)
  798         addl    $KERNBASE, %esi
  799         movl    %esi, R(_vm86paddr)
  800 #endif /* VM86 */
  801 
  802 #ifdef SMP
  803 /* Allocate cpu0's private data page */
  804         ALLOCPAGES(1)
  805         movl    %esi,R(cpu0pp)
  806         addl    $KERNBASE, %esi
  807         movl    %esi, R(_cpu0prvpage)   /* relocated to KVM space */
  808 
  809 /* Allocate cpu0's private page table for mapping priv page, apic, etc */
  810         ALLOCPAGES(1)
  811         movl    %esi,R(cpu0pt)
  812         addl    $KERNBASE, %esi
  813         movl    %esi, R(_cpu0prvpt)     /* relocated to KVM space */
  814 #endif  /* SMP */
  815 
  816 /* Map read-only from zero to the end of the kernel text section */
  817         xorl    %eax, %eax
  818 #ifdef BDE_DEBUGGER
  819 /* If the debugger is present, actually map everything read-write. */
  820         cmpl    $0,R(_bdb_exists)
  821         jne     map_read_write
  822 #endif
  823         xorl    %edx,%edx
  824 
  825 #if !defined(SMP)
  826         testl   $CPUID_PGE, R(_cpu_feature)
  827         jz      2f
  828         orl     $PG_G,%edx
  829 #endif
  830         
  831 2:      movl    $R(_etext),%ecx
  832         addl    $PAGE_MASK,%ecx
  833         shrl    $PAGE_SHIFT,%ecx
  834         fillkptphys(%edx)
  835 
  836 /* Map read-write, data, bss and symbols */
  837         movl    $R(_etext),%eax
  838         addl    $PAGE_MASK, %eax
  839         andl    $~PAGE_MASK, %eax
  840 map_read_write:
  841         movl    $PG_RW,%edx
  842 #if !defined(SMP)
  843         testl   $CPUID_PGE, R(_cpu_feature)
  844         jz      1f
  845         orl     $PG_G,%edx
  846 #endif
  847         
  848 1:      movl    R(_KERNend),%ecx
  849         subl    %eax,%ecx
  850         shrl    $PAGE_SHIFT,%ecx
  851         fillkptphys(%edx)
  852 
  853 /* Map page directory. */
  854         movl    R(_IdlePTD), %eax
  855         movl    $1, %ecx
  856         fillkptphys($PG_RW)
  857 
  858 /* Map proc0's UPAGES in the physical way ... */
  859         movl    R(p0upa), %eax
  860         movl    $UPAGES, %ecx
  861         fillkptphys($PG_RW)
  862 
  863 /* Map ISA hole */
  864         movl    $ISA_HOLE_START, %eax
  865         movl    $ISA_HOLE_LENGTH>>PAGE_SHIFT, %ecx
  866         fillkptphys($PG_RW)
  867 
  868 #ifdef VM86
  869 /* Map space for the vm86 region */
  870         movl    R(vm86phystk), %eax
  871         movl    $4, %ecx
  872         fillkptphys($PG_RW)
  873 
  874 /* Map page 0 into the vm86 page table */
  875         movl    $0, %eax
  876         movl    $0, %ebx
  877         movl    $1, %ecx
  878         fillkpt(R(_vm86pa), $PG_RW|PG_U)
  879 
  880 /* ...likewise for the ISA hole */
  881         movl    $ISA_HOLE_START, %eax
  882         movl    $ISA_HOLE_START>>PAGE_SHIFT, %ebx
  883         movl    $ISA_HOLE_LENGTH>>PAGE_SHIFT, %ecx
  884         fillkpt(R(_vm86pa), $PG_RW|PG_U)
  885 #endif /* VM86 */
  886 
  887 #ifdef SMP
  888 /* Map cpu0's private page into global kmem (4K @ cpu0prvpage) */
  889         movl    R(cpu0pp), %eax
  890         movl    $1, %ecx
  891         fillkptphys($PG_RW)
  892 
  893 /* Map cpu0's private page table into global kmem FWIW */
  894         movl    R(cpu0pt), %eax
  895         movl    $1, %ecx
  896         fillkptphys($PG_RW)
  897 
  898 /* Map the private page into the private page table into private space */
  899         movl    R(cpu0pp), %eax
  900         movl    $0, %ebx                /* pte offset = 0 */
  901         movl    $1, %ecx                /* one private page coming right up */
  902         fillkpt(R(cpu0pt), $PG_RW)
  903 
  904 /* Map the page table page into private space */
  905         movl    R(cpu0pt), %eax
  906         movl    $1, %ebx                /* pte offset = 1 */
  907         movl    $1, %ecx                /* one private pt coming right up */
  908         fillkpt(R(cpu0pt), $PG_RW)
  909 
  910 /* ... and put the page table table in the pde. */
  911         movl    R(cpu0pt), %eax
  912         movl    $MPPTDI, %ebx
  913         movl    $1, %ecx
  914         fillkpt(R(_IdlePTD), $PG_RW)
  915 
  916 /* Fakeup VA for the local apic to allow early traps. */
  917         ALLOCPAGES(1)
  918         movl    %esi, %eax
  919         movl    $2, %ebx                /* pte offset = 2 */
  920         movl    $1, %ecx                /* one private pt coming right up */
  921         fillkpt(R(cpu0pt), $PG_RW)
  922 
  923 /* Initialize mp lock to allow early traps */
  924         movl    $1, R(_mp_lock)
  925 
  926 /* Initialize my_idlePTD to IdlePTD */          
  927         movl    R(cpu0pp), %eax
  928         movl    R(_IdlePTD), %ecx
  929         movl    %ecx,GD_MY_IDLEPTD(%eax)
  930 /* Initialize IdlePTDS[0] */
  931         addl    $KERNBASE, %ecx
  932         movl    %ecx, R(CNAME(IdlePTDS))
  933                 
  934 #endif  /* SMP */
  935 
  936 /* install a pde for temporary double map of bottom of VA */
  937         movl    R(_KPTphys), %eax
  938         xorl    %ebx, %ebx
  939         movl    $1, %ecx
  940         fillkpt(R(_IdlePTD), $PG_RW)
  941 
  942 /* install pde's for pt's */
  943         movl    R(_KPTphys), %eax
  944         movl    $KPTDI, %ebx
  945         movl    $NKPT, %ecx
  946         fillkpt(R(_IdlePTD), $PG_RW)
  947 
  948 /* install a pde recursively mapping page directory as a page table */
  949         movl    R(_IdlePTD), %eax
  950         movl    $PTDPTDI, %ebx
  951         movl    $1,%ecx
  952         fillkpt(R(_IdlePTD), $PG_RW)
  953 
  954         ret
  955 
  956 #ifdef BDE_DEBUGGER
  957 bdb_prepare_paging:
  958         cmpl    $0,R(_bdb_exists)
  959         je      bdb_prepare_paging_exit
  960 
  961         subl    $6,%esp
  962 
  963         /*
  964          * Copy and convert debugger entries from the bootstrap gdt and idt
  965          * to the kernel gdt and idt.  Everything is still in low memory.
  966          * Tracing continues to work after paging is enabled because the
  967          * low memory addresses remain valid until everything is relocated.
  968          * However, tracing through the setidt() that initializes the trace
  969          * trap will crash.
  970          */
  971         sgdt    (%esp)
  972         movl    2(%esp),%esi            /* base address of bootstrap gdt */
  973         movl    $R(_gdt),%edi
  974         movl    %edi,2(%esp)            /* prepare to load kernel gdt */
  975         movl    $8*18/4,%ecx
  976         cld
  977         rep                             /* copy gdt */
  978         movsl
  979         movl    $R(_gdt),-8+2(%edi)     /* adjust gdt self-ptr */
  980         movb    $0x92,-8+5(%edi)
  981         lgdt    (%esp)
  982 
  983         sidt    (%esp)
  984         movl    2(%esp),%esi            /* base address of current idt */
  985         movl    8+4(%esi),%eax          /* convert dbg descriptor to ... */
  986         movw    8(%esi),%ax
  987         movl    %eax,R(bdb_dbg_ljmp+1)  /* ... immediate offset ... */
  988         movl    8+2(%esi),%eax
  989         movw    %ax,R(bdb_dbg_ljmp+5)   /* ... and selector for ljmp */
  990         movl    24+4(%esi),%eax         /* same for bpt descriptor */
  991         movw    24(%esi),%ax
  992         movl    %eax,R(bdb_bpt_ljmp+1)
  993         movl    24+2(%esi),%eax
  994         movw    %ax,R(bdb_bpt_ljmp+5)
  995         movl    $R(_idt),%edi
  996         movl    %edi,2(%esp)            /* prepare to load kernel idt */
  997         movl    $8*4/4,%ecx
  998         cld
  999         rep                             /* copy idt */
 1000         movsl
 1001         lidt    (%esp)
 1002 
 1003         addl    $6,%esp
 1004 
 1005 bdb_prepare_paging_exit:
 1006         ret
 1007 
 1008 /* Relocate debugger gdt entries and gdt and idt pointers. */
 1009 bdb_commit_paging:
 1010         cmpl    $0,_bdb_exists
 1011         je      bdb_commit_paging_exit
 1012 
 1013         movl    $_gdt+8*9,%eax          /* adjust slots 9-17 */
 1014         movl    $9,%ecx
 1015 reloc_gdt:
 1016         movb    $KERNBASE>>24,7(%eax)   /* top byte of base addresses, was 0, */
 1017         addl    $8,%eax                 /* now KERNBASE>>24 */
 1018         loop    reloc_gdt
 1019 
 1020         subl    $6,%esp
 1021         sgdt    (%esp)
 1022         addl    $KERNBASE,2(%esp)
 1023         lgdt    (%esp)
 1024         sidt    (%esp)
 1025         addl    $KERNBASE,2(%esp)
 1026         lidt    (%esp)
 1027         addl    $6,%esp
 1028 
 1029         int     $3
 1030 
 1031 bdb_commit_paging_exit:
 1032         ret
 1033 
 1034 #endif /* BDE_DEBUGGER */

Cache object: a8c9e67c42c673c15ee58deda92776a9


[ 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.