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

Cache object: 0d42533c07406db9b89e20dfef5decd7


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