[BACK]Return to locore.S CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / arch / i386 / i386

Annotation of src/sys/arch/i386/i386/locore.S, Revision 1.145.6.2

1.145.6.2! snj         1: /*     $NetBSD: locore.S,v 1.145.6.1 2017/07/05 19:59:29 snj Exp $     */
1.53      yamt        2:
                      3: /*
                      4:  * Copyright-o-rama!
                      5:  */
                      6:
                      7: /*
1.127     maxv        8:  * Copyright (c) 1998, 2000, 2004, 2006, 2007, 2009, 2016
                      9:  * The NetBSD Foundation, Inc., All rights reserved.
                     10:  *
                     11:  * This code is derived from software contributed to The NetBSD Foundation
                     12:  * by Charles M. Hannum, by Andrew Doran and by Maxime Villard.
                     13:  *
                     14:  * Redistribution and use in source and binary forms, with or without
                     15:  * modification, are permitted provided that the following conditions
                     16:  * are met:
                     17:  * 1. Redistributions of source code must retain the above copyright
                     18:  *    notice, this list of conditions and the following disclaimer.
                     19:  * 2. Redistributions in binary form must reproduce the above copyright
                     20:  *    notice, this list of conditions and the following disclaimer in the
                     21:  *    documentation and/or other materials provided with the distribution.
                     22:  *
                     23:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     24:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     25:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     26:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     27:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     28:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     29:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     30:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     31:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     32:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     33:  * POSSIBILITY OF SUCH DAMAGE.
                     34:  */
                     35:
                     36: /*
1.62      bouyer     37:  * Copyright (c) 2006 Manuel Bouyer.
                     38:  *
                     39:  * Redistribution and use in source and binary forms, with or without
                     40:  * modification, are permitted provided that the following conditions
                     41:  * are met:
                     42:  * 1. Redistributions of source code must retain the above copyright
                     43:  *    notice, this list of conditions and the following disclaimer.
                     44:  * 2. Redistributions in binary form must reproduce the above copyright
                     45:  *    notice, this list of conditions and the following disclaimer in the
                     46:  *    documentation and/or other materials provided with the distribution.
                     47:  *
                     48:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     49:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     50:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     51:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
                     52:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
                     53:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                     54:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                     55:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                     56:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
                     57:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     58:  *
                     59:  */
                     60:
                     61: /*
1.53      yamt       62:  * Copyright (c) 2001 Wasabi Systems, Inc.
                     63:  * All rights reserved.
                     64:  *
                     65:  * Written by Frank van der Linden for Wasabi Systems, Inc.
                     66:  *
                     67:  * Redistribution and use in source and binary forms, with or without
                     68:  * modification, are permitted provided that the following conditions
                     69:  * are met:
                     70:  * 1. Redistributions of source code must retain the above copyright
                     71:  *    notice, this list of conditions and the following disclaimer.
                     72:  * 2. Redistributions in binary form must reproduce the above copyright
                     73:  *    notice, this list of conditions and the following disclaimer in the
                     74:  *    documentation and/or other materials provided with the distribution.
                     75:  * 3. All advertising materials mentioning features or use of this software
                     76:  *    must display the following acknowledgement:
                     77:  *      This product includes software developed for the NetBSD Project by
                     78:  *      Wasabi Systems, Inc.
                     79:  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
                     80:  *    or promote products derived from this software without specific prior
                     81:  *    written permission.
                     82:  *
                     83:  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
                     84:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     85:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     86:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
                     87:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     88:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     89:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     90:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     91:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     92:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     93:  * POSSIBILITY OF SUCH DAMAGE.
                     94:  */
                     95:
1.1       fvdl       96: /*-
                     97:  * Copyright (c) 1990 The Regents of the University of California.
                     98:  * All rights reserved.
                     99:  *
                    100:  * This code is derived from software contributed to Berkeley by
                    101:  * William Jolitz.
                    102:  *
                    103:  * Redistribution and use in source and binary forms, with or without
                    104:  * modification, are permitted provided that the following conditions
                    105:  * are met:
                    106:  * 1. Redistributions of source code must retain the above copyright
                    107:  *    notice, this list of conditions and the following disclaimer.
                    108:  * 2. Redistributions in binary form must reproduce the above copyright
                    109:  *    notice, this list of conditions and the following disclaimer in the
                    110:  *    documentation and/or other materials provided with the distribution.
1.12      agc       111:  * 3. Neither the name of the University nor the names of its contributors
1.1       fvdl      112:  *    may be used to endorse or promote products derived from this software
                    113:  *    without specific prior written permission.
                    114:  *
                    115:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                    116:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                    117:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                    118:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                    119:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                    120:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                    121:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                    122:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                    123:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                    124:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                    125:  * SUCH DAMAGE.
                    126:  *
                    127:  *     @(#)locore.s    7.3 (Berkeley) 5/13/91
                    128:  */
                    129:
1.59      lukem     130: #include <machine/asm.h>
1.145.6.2! snj       131: __KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.145.6.1 2017/07/05 19:59:29 snj Exp $");
1.59      lukem     132:
1.18      christos  133: #include "opt_compat_oldboot.h"
1.114     uebayasi  134: #include "opt_copy_symtab.h"
1.1       fvdl      135: #include "opt_ddb.h"
1.83      apb       136: #include "opt_modular.h"
1.78      joerg     137: #include "opt_multiboot.h"
1.1       fvdl      138: #include "opt_realmem.h"
1.18      christos  139: #include "opt_vm86.h"
1.62      bouyer    140: #include "opt_xen.h"
1.1       fvdl      141:
                    142: #include "assym.h"
                    143: #include "lapic.h"
                    144: #include "ioapic.h"
1.8       fvdl      145: #include "ksyms.h"
1.1       fvdl      146:
                    147: #include <sys/errno.h>
                    148: #include <sys/syscall.h>
                    149:
                    150: #include <machine/segments.h>
                    151: #include <machine/specialreg.h>
                    152: #include <machine/trap.h>
                    153: #include <machine/i82489reg.h>
1.48      yamt      154: #include <machine/frameasm.h>
                    155: #include <machine/i82489reg.h>
1.127     maxv      156: #include <machine/cputypes.h>
                    157:
1.62      bouyer    158: #ifndef XEN
                    159: #include <machine/multiboot.h>
                    160: #endif
1.1       fvdl      161:
                    162: /* Get definitions for IOM_BEGIN, IOM_END, and IOM_SIZE */
                    163: #include <dev/isa/isareg.h>
                    164:
1.104     uebayasi  165: #ifndef XEN
                    166: #define        _RELOC(x)       ((x) - KERNBASE)
                    167: #else
                    168: #define        _RELOC(x)       ((x))
                    169: #endif /* XEN */
                    170: #define        RELOC(x)        _RELOC(_C_LABEL(x))
                    171:
1.119     maxv      172: /* 32bit version of PG_NX */
                    173: #define PG_NX32        0x80000000
                    174:
1.115     maxv      175: #ifndef PAE
                    176: #define        PROC0_PDIR_OFF  0
                    177: #else
                    178: #define PROC0_L3_OFF   0
                    179: #define PROC0_PDIR_OFF 1 * PAGE_SIZE
                    180: #endif
                    181:
                    182: #define        PROC0_STK_OFF   (PROC0_PDIR_OFF + PDP_SIZE * PAGE_SIZE)
                    183: #define        PROC0_PTP1_OFF  (PROC0_STK_OFF + UPAGES * PAGE_SIZE)
                    184:
                    185: /*
                    186:  * fillkpt - Fill in a kernel page table
                    187:  *     eax = pte (page frame | control | status)
                    188:  *     ebx = page table address
                    189:  *     ecx = number of pages to map
                    190:  *
                    191:  * For PAE, each entry is 8 bytes long: we must set the 4 upper bytes to 0.
                    192:  * This is done by the first instruction of fillkpt. In the non-PAE case, this
                    193:  * instruction just clears the page table entry.
                    194:  */
                    195: #define fillkpt        \
1.125     maxv      196:        cmpl    $0,%ecx                 ;       /* zero-sized? */       \
                    197:        je      2f                      ; \
1.115     maxv      198: 1:     movl    $0,(PDE_SIZE-4)(%ebx)   ;       /* upper 32 bits: 0 */  \
                    199:        movl    %eax,(%ebx)             ;       /* store phys addr */   \
                    200:        addl    $PDE_SIZE,%ebx          ;       /* next PTE/PDE */      \
                    201:        addl    $PAGE_SIZE,%eax         ;       /* next phys page */    \
1.125     maxv      202:        loop    1b                      ; \
                    203: 2:                                     ;
1.115     maxv      204:
1.118     maxv      205: /*
1.120     maxv      206:  * fillkpt_nox - Same as fillkpt, but sets the NX/XD bit.
                    207:  */
                    208: #define fillkpt_nox \
1.125     maxv      209:        cmpl    $0,%ecx                 ;       /* zero-sized? */       \
                    210:        je      2f                      ; \
1.120     maxv      211:        pushl   %ebp                    ; \
                    212:        movl    RELOC(nox_flag),%ebp    ; \
                    213: 1:     movl    %ebp,(PDE_SIZE-4)(%ebx) ;       /* upper 32 bits: NX */ \
                    214:        movl    %eax,(%ebx)             ;       /* store phys addr */   \
                    215:        addl    $PDE_SIZE,%ebx          ;       /* next PTE/PDE */      \
                    216:        addl    $PAGE_SIZE,%eax         ;       /* next phys page */    \
                    217:        loop    1b                      ; \
1.125     maxv      218:        popl    %ebp                    ; \
                    219: 2:                                     ;
1.120     maxv      220:
                    221: /*
1.129     maxv      222:  * fillkpt_blank - Fill in a kernel page table with blank entries
                    223:  *     ebx = page table address
                    224:  *     ecx = number of pages to map
                    225:  */
                    226: #define fillkpt_blank  \
                    227:        cmpl    $0,%ecx                 ;       /* zero-sized? */       \
                    228:        je      2f                      ; \
                    229: 1:     movl    $0,(PDE_SIZE-4)(%ebx)   ;       /* upper 32 bits: 0 */  \
                    230:        movl    $0,(%ebx)               ;       /* lower 32 bits: 0 */  \
                    231:        addl    $PDE_SIZE,%ebx          ;       /* next PTE/PDE */      \
                    232:        loop    1b                      ; \
                    233: 2:                                     ;
                    234:
                    235: /*
1.118     maxv      236:  * killkpt - Destroy a kernel page table
                    237:  *     ebx = page table address
                    238:  *     ecx = number of pages to destroy
                    239:  */
                    240: #define killkpt \
                    241: 1:     movl    $0,(PDE_SIZE-4)(%ebx)   ;       /* upper bits (for PAE) */ \
                    242:        movl    $0,(%ebx)               ; \
                    243:        addl    $PDE_SIZE,%ebx          ; \
                    244:        loop    1b                      ;
                    245:
1.115     maxv      246:
1.62      bouyer    247: #ifdef XEN
                    248: /*
                    249:  * Xen guest identifier and loader selection
                    250:  */
                    251: .section __xen_guest
                    252:        .ascii  "GUEST_OS=netbsd,GUEST_VER=3.0,XEN_VER=xen-3.0"
1.106     uebayasi  253:        .ascii  ",VIRT_BASE=0xc0000000" /* KERNBASE */
                    254:        .ascii  ",ELF_PADDR_OFFSET=0xc0000000" /* KERNBASE */
                    255:        .ascii  ",VIRT_ENTRY=0xc0100000" /* KERNTEXTOFF */
                    256:        .ascii  ",HYPERCALL_PAGE=0x00000101"
1.62      bouyer    257:                /* (???+HYPERCALL_PAGE_OFFSET)/PAGE_SIZE) */
1.66      bouyer    258: #ifdef PAE
1.106     uebayasi  259:        .ascii  ",PAE=yes[extended-cr3]"
1.66      bouyer    260: #endif
1.62      bouyer    261:        .ascii  ",LOADER=generic"
1.114     uebayasi  262: #if (NKSYMS || defined(DDB) || defined(MODULAR)) && !defined(makeoptions_COPY_SYMTAB)
1.62      bouyer    263:        .ascii  ",BSD_SYMTAB=yes"
                    264: #endif
                    265:        .byte   0
1.106     uebayasi  266: #endif /* XEN */
1.62      bouyer    267:
1.1       fvdl      268: /*
                    269:  * Initialization
                    270:  */
                    271:        .data
                    272:
1.127     maxv      273:        .globl  _C_LABEL(tablesize)
                    274:        .globl  _C_LABEL(nox_flag)
                    275:        .globl  _C_LABEL(cputype)
                    276:        .globl  _C_LABEL(cpuid_level)
                    277:        .globl  _C_LABEL(esym)
                    278:        .globl  _C_LABEL(eblob)
                    279:        .globl  _C_LABEL(atdevbase)
                    280:        .globl  _C_LABEL(PDPpaddr)
                    281:        .globl  _C_LABEL(lwp0uarea)
                    282:        .globl  _C_LABEL(gdt)
                    283:        .globl  _C_LABEL(idt)
                    284:
1.126     maxv      285:        .type   _C_LABEL(tablesize), @object
                    286: _C_LABEL(tablesize):   .long   0
                    287: END(tablesize)
1.119     maxv      288:        .type   _C_LABEL(nox_flag), @object
                    289: LABEL(nox_flag)                .long   0       /* 32bit NOX flag, set if supported */
                    290: END(nox_flag)
1.104     uebayasi  291:        .type   _C_LABEL(cputype), @object
1.115     maxv      292: LABEL(cputype)         .long   0       /* are we 80486, Pentium, or.. */
1.104     uebayasi  293: END(cputype)
                    294:        .type   _C_LABEL(cpuid_level), @object
1.128     maxv      295: LABEL(cpuid_level)     .long   -1      /* max. level accepted by cpuid instr */
1.104     uebayasi  296: END(cpuid_level)
                    297:        .type   _C_LABEL(atdevbase), @object
1.115     maxv      298: LABEL(atdevbase)       .long   0       /* location of start of iomem in virt */
1.104     uebayasi  299: END(atdevbase)
                    300:        .type   _C_LABEL(lwp0uarea), @object
                    301: LABEL(lwp0uarea)       .long   0
                    302: END(lwp0uarea)
                    303:        .type   _C_LABEL(PDPpaddr), @object
1.115     maxv      304: LABEL(PDPpaddr)                .long   0       /* paddr of PDP, for libkvm */
1.104     uebayasi  305: END(PDPpaddr)
1.115     maxv      306:
                    307:        /* Space for the temporary stack */
1.104     uebayasi  308:        .size   tmpstk, tmpstk - .
1.115     maxv      309:        .space  512
1.1       fvdl      310: tmpstk:
1.96      cherry    311: #ifdef XEN
1.115     maxv      312:        .align          PAGE_SIZE, 0x0  /* Align on page boundary */
1.104     uebayasi  313: LABEL(tmpgdt)
1.115     maxv      314:        .space          PAGE_SIZE       /* Xen expects a page */
1.104     uebayasi  315: END(tmpgdt)
1.96      cherry    316: #endif /* XEN */
1.1       fvdl      317:
                    318:        .text
                    319:        .globl  _C_LABEL(kernel_text)
                    320:        .set    _C_LABEL(kernel_text),KERNTEXTOFF
                    321:
1.104     uebayasi  322: ENTRY(start)
1.62      bouyer    323: #ifndef XEN
1.115     maxv      324:
                    325:        /* Warm boot */
                    326:        movw    $0x1234,0x472
                    327:
1.37      jmmv      328: #if defined(MULTIBOOT)
                    329:        jmp     1f
                    330:
                    331:        .align  4
                    332:        .globl  Multiboot_Header
                    333: _C_LABEL(Multiboot_Header):
1.44      jmmv      334: #define MULTIBOOT_HEADER_FLAGS (MULTIBOOT_HEADER_WANT_MEMORY)
1.37      jmmv      335:        .long   MULTIBOOT_HEADER_MAGIC
                    336:        .long   MULTIBOOT_HEADER_FLAGS
                    337:        .long   -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
                    338:
                    339: 1:
                    340:        /* Check if we are being executed by a Multiboot-compliant boot
                    341:         * loader. */
                    342:        cmpl    $MULTIBOOT_INFO_MAGIC,%eax
                    343:        jne     1f
                    344:
1.43      mrg       345:        /*
1.145.6.2! snj       346:         * Indeed, a multiboot-compliant boot loader executed us. We switch
        !           347:         * to the temporary stack, and copy the received Multiboot information
        !           348:         * structure into kernel's data space to process it later -- after we
        !           349:         * are relocated. It will be safer to run complex C code than doing it
        !           350:         * at this point.
1.43      mrg       351:         */
1.145.6.2! snj       352:        movl    $_RELOC(tmpstk),%esp
1.115     maxv      353:        pushl   %ebx            /* Address of Multiboot information */
1.37      jmmv      354:        call    _C_LABEL(multiboot_pre_reloc)
                    355:        addl    $4,%esp
1.38      jmmv      356:        jmp     2f
1.37      jmmv      357: #endif
                    358:
                    359: 1:
1.1       fvdl      360:        /*
1.38      jmmv      361:         * At this point, we know that a NetBSD-specific boot loader
1.117     maxv      362:         * booted this kernel.
                    363:         *
                    364:         * Load parameters from the stack (32 bits):
                    365:         *     boothowto, [bootdev], bootinfo, esym, biosextmem, biosbasemem
                    366:         * We are not interested in 'bootdev'.
1.1       fvdl      367:         */
1.117     maxv      368:
1.115     maxv      369:        addl    $4,%esp         /* Discard return address to boot loader */
1.38      jmmv      370:        call    _C_LABEL(native_loader)
                    371:        addl    $24,%esp
1.1       fvdl      372:
                    373: 2:
                    374:        /* First, reset the PSL. */
                    375:        pushl   $PSL_MBO
                    376:        popfl
                    377:
                    378:        /* Clear segment registers; always null in proc0. */
                    379:        xorl    %eax,%eax
                    380:        movw    %ax,%fs
                    381:        movw    %ax,%gs
                    382:
                    383:        /* Find out our CPU type. */
                    384:
                    385: try386:        /* Try to toggle alignment check flag; does not exist on 386. */
                    386:        pushfl
                    387:        popl    %eax
                    388:        movl    %eax,%ecx
                    389:        orl     $PSL_AC,%eax
                    390:        pushl   %eax
                    391:        popfl
                    392:        pushfl
                    393:        popl    %eax
                    394:        xorl    %ecx,%eax
                    395:        andl    $PSL_AC,%eax
                    396:        pushl   %ecx
                    397:        popfl
                    398:
                    399:        testl   %eax,%eax
                    400:        jnz     try486
                    401:
                    402:        /*
                    403:         * Try the test of a NexGen CPU -- ZF will not change on a DIV
                    404:         * instruction on a NexGen, it will on an i386.  Documented in
                    405:         * Nx586 Processor Recognition Application Note, NexGen, Inc.
                    406:         */
                    407:        movl    $0x5555,%eax
                    408:        xorl    %edx,%edx
                    409:        movl    $2,%ecx
                    410:        divl    %ecx
                    411:        jnz     is386
                    412:
                    413: isnx586:
                    414:        /*
                    415:         * Don't try cpuid, as Nx586s reportedly don't support the
                    416:         * PSL_ID bit.
                    417:         */
1.100     chs       418:        movl    $CPU_NX586,RELOC(cputype)
1.1       fvdl      419:        jmp     2f
                    420:
                    421: is386:
1.100     chs       422:        movl    $CPU_386,RELOC(cputype)
1.1       fvdl      423:        jmp     2f
                    424:
                    425: try486:        /* Try to toggle identification flag; does not exist on early 486s. */
                    426:        pushfl
                    427:        popl    %eax
                    428:        movl    %eax,%ecx
                    429:        xorl    $PSL_ID,%eax
                    430:        pushl   %eax
                    431:        popfl
                    432:        pushfl
                    433:        popl    %eax
                    434:        xorl    %ecx,%eax
                    435:        andl    $PSL_ID,%eax
                    436:        pushl   %ecx
                    437:        popfl
                    438:
                    439:        testl   %eax,%eax
                    440:        jnz     try586
1.100     chs       441: is486: movl    $CPU_486,RELOC(cputype)
1.1       fvdl      442:        /*
                    443:         * Check Cyrix CPU
                    444:         * Cyrix CPUs do not change the undefined flags following
                    445:         * execution of the divide instruction which divides 5 by 2.
                    446:         *
                    447:         * Note: CPUID is enabled on M2, so it passes another way.
                    448:         */
                    449:        pushfl
                    450:        movl    $0x5555, %eax
                    451:        xorl    %edx, %edx
                    452:        movl    $2, %ecx
                    453:        clc
                    454:        divl    %ecx
                    455:        jnc     trycyrix486
                    456:        popfl
                    457:        jmp 2f
                    458: trycyrix486:
1.115     maxv      459:        movl    $CPU_6x86,RELOC(cputype)        /* set CPU type */
1.1       fvdl      460:        /*
                    461:         * Check for Cyrix 486 CPU by seeing if the flags change during a
                    462:         * divide. This is documented in the Cx486SLC/e SMM Programmer's
                    463:         * Guide.
                    464:         */
                    465:        xorl    %edx,%edx
1.115     maxv      466:        cmpl    %edx,%edx               /* set flags to known state */
1.1       fvdl      467:        pushfl
1.115     maxv      468:        popl    %ecx                    /* store flags in ecx */
1.1       fvdl      469:        movl    $-1,%eax
                    470:        movl    $4,%ebx
1.115     maxv      471:        divl    %ebx                    /* do a long division */
1.1       fvdl      472:        pushfl
                    473:        popl    %eax
1.115     maxv      474:        xorl    %ecx,%eax               /* are the flags different? */
                    475:        testl   $0x8d5,%eax             /* only check C|PF|AF|Z|N|V */
                    476:        jne     2f                      /* yes; must be Cyrix 6x86 CPU */
                    477:        movl    $CPU_486DLC,RELOC(cputype)      /* set CPU type */
1.1       fvdl      478:
                    479: #ifndef CYRIX_CACHE_WORKS
                    480:        /* Disable caching of the ISA hole only. */
                    481:        invd
1.115     maxv      482:        movb    $CCR0,%al       /* Configuration Register index (CCR0) */
1.1       fvdl      483:        outb    %al,$0x22
                    484:        inb     $0x23,%al
                    485:        orb     $(CCR0_NC1|CCR0_BARB),%al
                    486:        movb    %al,%ah
                    487:        movb    $CCR0,%al
                    488:        outb    %al,$0x22
                    489:        movb    %ah,%al
                    490:        outb    %al,$0x23
                    491:        invd
                    492: #else /* CYRIX_CACHE_WORKS */
                    493:        /* Set cache parameters */
1.115     maxv      494:        invd                    /* Start with guaranteed clean cache */
                    495:        movb    $CCR0,%al       /* Configuration Register index (CCR0) */
1.1       fvdl      496:        outb    %al,$0x22
                    497:        inb     $0x23,%al
                    498:        andb    $~CCR0_NC0,%al
                    499: #ifndef CYRIX_CACHE_REALLY_WORKS
                    500:        orb     $(CCR0_NC1|CCR0_BARB),%al
                    501: #else
                    502:        orb     $CCR0_NC1,%al
                    503: #endif
                    504:        movb    %al,%ah
                    505:        movb    $CCR0,%al
                    506:        outb    %al,$0x22
                    507:        movb    %ah,%al
                    508:        outb    %al,$0x23
                    509:        /* clear non-cacheable region 1 */
                    510:        movb    $(NCR1+2),%al
                    511:        outb    %al,$0x22
                    512:        movb    $NCR_SIZE_0K,%al
                    513:        outb    %al,$0x23
                    514:        /* clear non-cacheable region 2 */
                    515:        movb    $(NCR2+2),%al
                    516:        outb    %al,$0x22
                    517:        movb    $NCR_SIZE_0K,%al
                    518:        outb    %al,$0x23
                    519:        /* clear non-cacheable region 3 */
                    520:        movb    $(NCR3+2),%al
                    521:        outb    %al,$0x22
                    522:        movb    $NCR_SIZE_0K,%al
                    523:        outb    %al,$0x23
                    524:        /* clear non-cacheable region 4 */
                    525:        movb    $(NCR4+2),%al
                    526:        outb    %al,$0x22
                    527:        movb    $NCR_SIZE_0K,%al
                    528:        outb    %al,$0x23
                    529:        /* enable caching in CR0 */
                    530:        movl    %cr0,%eax
                    531:        andl    $~(CR0_CD|CR0_NW),%eax
                    532:        movl    %eax,%cr0
                    533:        invd
                    534: #endif /* CYRIX_CACHE_WORKS */
                    535:
                    536:        jmp     2f
                    537:
                    538: try586:        /* Use the `cpuid' instruction. */
                    539:        xorl    %eax,%eax
                    540:        cpuid
1.73      ad        541:        movl    %eax,RELOC(cpuid_level)
1.1       fvdl      542:
1.122     maxv      543:        /*
                    544:         * Retrieve the NX/XD flag. We use the 32bit version of PG_NX.
                    545:         */
                    546:        movl    $0x80000001,%eax
                    547:        cpuid
                    548:        andl    $CPUID_NOX,%edx
                    549:        jz      no_NOX
                    550:        movl    $PG_NX32,RELOC(nox_flag)
                    551: no_NOX:
                    552:
1.1       fvdl      553: 2:
                    554:        /*
                    555:         * Finished with old stack; load new %esp now instead of later so we
                    556:         * can trace this code without having to worry about the trace trap
                    557:         * clobbering the memory test or the zeroing of the bss+bootstrap page
                    558:         * tables.
                    559:         *
                    560:         * The boot program should check:
                    561:         *      text+data <= &stack_variable - more_space_for_stack
                    562:         *      text+data+bss+pad+space_for_page_tables <= end_of_memory
1.115     maxv      563:         *
                    564:         * XXX: the gdt is in the carcass of the boot program so clearing
1.1       fvdl      565:         * the rest of memory is still not possible.
                    566:         */
1.115     maxv      567:        movl    $_RELOC(tmpstk),%esp
1.1       fvdl      568:
                    569: /*
1.117     maxv      570:  * There are two different layouts possible, depending on whether PAE is
                    571:  * enabled or not.
1.1       fvdl      572:  *
1.117     maxv      573:  * If PAE is not enabled, there are two levels of pages: PD -> PT. They will
                    574:  * be referred to as: L2 -> L1. L2 is 1 page long. The BOOTSTRAP TABLES have
                    575:  * the following layout:
                    576:  *     +-----+------------+----+
                    577:  *     | L2 -> PROC0 STK -> L1 |
                    578:  *     +-----+------------+----+
                    579:  *
                    580:  * If PAE is enabled, there are three levels of pages: PDP -> PD -> PT. They
                    581:  * will be referred to as: L3 -> L2 -> L1. L3 is 1 page long, L2 is 4 page
                    582:  * long. The BOOTSTRAP TABLES have the following layout:
                    583:  *     +-----+-----+------------+----+
                    584:  *     | L3 -> L2 -> PROC0 STK -> L1 |
                    585:  *     +-----+-----+------------+----+
                    586:  *
                    587:  * Virtual address space of the kernel in both cases:
                    588:  * +------+--------+------+-----+--------+---------------------+-----------
                    589:  * | TEXT | RODATA | DATA | BSS | [SYMS] | [PRELOADED MODULES] | BOOTSTRAP
                    590:  * +------+--------+------+-----+--------+---------------------+-----------
                    591:  *                             (1)      (2)                   (3)
                    592:  *
1.130     maxv      593:  * -------+-------------+
                    594:  * TABLES | ISA I/O MEM |
                    595:  * -------+-------------+
1.117     maxv      596:  *       (4)
1.93      jym       597:  *
1.117     maxv      598:  * PROC0 STK is obviously not linked as a page level. It just happens to be
                    599:  * caught between L2 and L1.
1.123     maxv      600:  *
                    601:  * Important note: the kernel segments are properly 4k-aligned
                    602:  * (see kern.ldscript), so there's no need to enforce alignment.
1.1       fvdl      603:  */
                    604:
1.117     maxv      605:        /* Find end of kernel image; brings us on (1). */
1.142     maxv      606:        movl    $RELOC(__kernel_end),%edi
1.71      ad        607:
1.114     uebayasi  608: #if (NKSYMS || defined(DDB) || defined(MODULAR)) && !defined(makeoptions_COPY_SYMTAB)
1.117     maxv      609:        /* Save the symbols (if loaded); brinds us on (2). */
1.1       fvdl      610:        movl    RELOC(esym),%eax
                    611:        testl   %eax,%eax
                    612:        jz      1f
1.35      yamt      613:        subl    $KERNBASE,%eax
1.1       fvdl      614:        movl    %eax,%edi
                    615: 1:
                    616: #endif
                    617:
1.117     maxv      618:        /* Skip over any modules/blobs; brings us on (3). */
1.71      ad        619:        movl    RELOC(eblob),%eax
                    620:        testl   %eax,%eax
                    621:        jz      1f
                    622:        subl    $KERNBASE,%eax
                    623:        movl    %eax,%edi
                    624: 1:
1.117     maxv      625:
                    626:        /* We are on (3). Align up for BOOTSTRAP TABLES. */
1.71      ad        627:        movl    %edi,%esi
1.115     maxv      628:        addl    $PGOFSET,%esi
1.1       fvdl      629:        andl    $~PGOFSET,%esi
                    630:
1.53      yamt      631:        /* nkptp[1] = (esi + ~L2_FRAME) >> L2_SHIFT + 1; */
                    632:        movl    %esi,%eax
                    633:        addl    $~L2_FRAME,%eax
                    634:        shrl    $L2_SHIFT,%eax
1.117     maxv      635:        incl    %eax            /* one more PTP for VAs stolen by bootstrap */
1.53      yamt      636: 1:     movl    %eax,RELOC(nkptp)+1*4
                    637:
1.144     maxv      638:        /* tablesize = (PDP_SIZE + UPAGES + nkptp[1]) << PGSHIFT; */
1.93      jym       639:        addl    $(PDP_SIZE+UPAGES),%eax
                    640: #ifdef PAE
1.117     maxv      641:        incl    %eax            /* one more page for L3 */
1.93      jym       642:        shll    $PGSHIFT+1,%eax /* PTP tables are twice larger with PAE */
                    643: #else
1.53      yamt      644:        shll    $PGSHIFT,%eax
1.93      jym       645: #endif
1.53      yamt      646:        movl    %eax,RELOC(tablesize)
                    647:
1.144     maxv      648:        /* Ensure that nkptp[1] covers BOOTSTRAP TABLES, ie:
                    649:         * (esi + tablesize) >> L2_SHIFT + 1 < nkptp[1] */
1.53      yamt      650:        addl    %esi,%eax
                    651:        addl    $~L2_FRAME,%eax
                    652:        shrl    $L2_SHIFT,%eax
                    653:        incl    %eax
                    654:        cmpl    %eax,RELOC(nkptp)+1*4
                    655:        jnz     1b
                    656:
1.117     maxv      657:        /* Now, zero out the BOOTSTRAP TABLES (before filling them in). */
1.105     uebayasi  658:        movl    %esi,%edi
1.1       fvdl      659:        xorl    %eax,%eax
                    660:        cld
1.105     uebayasi  661:        movl    RELOC(tablesize),%ecx
                    662:        shrl    $2,%ecx
1.1       fvdl      663:        rep
1.117     maxv      664:        stosl                           /* copy eax -> edi */
1.1       fvdl      665:
                    666: /*
1.117     maxv      667:  * Build the page tables and levels. We go from L1 to L2/L3, and link the levels
                    668:  * together. Note: RELOC computes &addr - KERNBASE in 32 bits; the value can't
                    669:  * be > 4G, or we can't deal with it anyway, since we are in 32bit mode.
1.1       fvdl      670:  */
1.105     uebayasi  671:        /*
1.117     maxv      672:         * Build L1.
1.105     uebayasi  673:         */
1.117     maxv      674:        leal    (PROC0_PTP1_OFF)(%esi),%ebx
                    675:
1.145     maxv      676:        /* Skip the area below the kernel text. */
1.129     maxv      677:        movl    $(KERNTEXTOFF - KERNBASE),%ecx
                    678:        shrl    $PGSHIFT,%ecx
                    679:        fillkpt_blank
1.1       fvdl      680:
1.121     maxv      681:        /* Map the kernel text RX. */
1.129     maxv      682:        movl    $(KERNTEXTOFF - KERNBASE),%eax  /* start of TEXT */
1.121     maxv      683:        movl    $RELOC(__rodata_start),%ecx
1.1       fvdl      684:        subl    %eax,%ecx
                    685:        shrl    $PGSHIFT,%ecx
                    686:        orl     $(PG_V|PG_KR),%eax
                    687:        fillkpt
                    688:
1.121     maxv      689:        /* Map the kernel rodata R. */
                    690:        movl    $RELOC(__rodata_start),%eax
                    691:        movl    $RELOC(__data_start),%ecx
                    692:        subl    %eax,%ecx
                    693:        shrl    $PGSHIFT,%ecx
                    694:        orl     $(PG_V|PG_KR),%eax
                    695:        fillkpt_nox
                    696:
                    697:        /* Map the kernel data+bss RW. */
                    698:        movl    $RELOC(__data_start),%eax
                    699:        movl    $RELOC(__kernel_end),%ecx
                    700:        subl    %eax,%ecx
1.1       fvdl      701:        shrl    $PGSHIFT,%ecx
1.121     maxv      702:        orl     $(PG_V|PG_KW),%eax
                    703:        fillkpt_nox
                    704:
1.134     maxv      705:        /* Map [SYMS]+[PRELOADED MODULES] RW. */
1.121     maxv      706:        movl    $RELOC(__kernel_end),%eax
                    707:        movl    %esi,%ecx               /* start of BOOTSTRAP TABLES */
1.124     maxv      708:        subl    %eax,%ecx
1.121     maxv      709:        shrl    $PGSHIFT,%ecx
                    710:        orl     $(PG_V|PG_KW),%eax
1.134     maxv      711:        fillkpt_nox
1.1       fvdl      712:
1.124     maxv      713:        /* Map the BOOTSTRAP TABLES RW. */
                    714:        movl    %esi,%eax               /* start of BOOTSTRAP TABLES */
                    715:        movl    RELOC(tablesize),%ecx   /* length of BOOTSTRAP TABLES */
                    716:        shrl    $PGSHIFT,%ecx
                    717:        orl     $(PG_V|PG_KW),%eax
                    718:        fillkpt_nox
                    719:
1.131     maxv      720:        /* We are on (4). Map ISA I/O MEM RW. */
1.130     maxv      721:        movl    $IOM_BEGIN,%eax
                    722:        movl    $IOM_SIZE,%ecx  /* size of ISA I/O MEM */
                    723:        shrl    $PGSHIFT,%ecx
                    724:        orl     $(PG_V|PG_KW/*|PG_N*/),%eax
1.131     maxv      725:        fillkpt_nox
1.1       fvdl      726:
1.117     maxv      727:        /*
                    728:         * Build L2 for identity mapping. Linked to L1.
                    729:         */
1.105     uebayasi  730:        leal    (PROC0_PDIR_OFF)(%esi),%ebx
                    731:        leal    (PROC0_PTP1_OFF)(%esi),%eax
1.117     maxv      732:        orl     $(PG_V|PG_KW),%eax
1.105     uebayasi  733:        movl    RELOC(nkptp)+1*4,%ecx
1.1       fvdl      734:        fillkpt
                    735:
1.117     maxv      736:        /* Set up L2 entries for actual kernel mapping */
                    737:        leal    (PROC0_PDIR_OFF + L2_SLOT_KERNBASE * PDE_SIZE)(%esi),%ebx
1.105     uebayasi  738:        leal    (PROC0_PTP1_OFF)(%esi),%eax
1.117     maxv      739:        orl     $(PG_V|PG_KW),%eax
1.105     uebayasi  740:        movl    RELOC(nkptp)+1*4,%ecx
1.1       fvdl      741:        fillkpt
                    742:
1.135     maxv      743:        /* Install recursive top level PDE */
1.117     maxv      744:        leal    (PROC0_PDIR_OFF + PDIR_SLOT_PTE * PDE_SIZE)(%esi),%ebx
1.105     uebayasi  745:        leal    (PROC0_PDIR_OFF)(%esi),%eax
                    746:        orl     $(PG_V|PG_KW),%eax
1.93      jym       747:        movl    $PDP_SIZE,%ecx
1.135     maxv      748:        fillkpt_nox
1.93      jym       749:
                    750: #ifdef PAE
1.117     maxv      751:        /*
                    752:         * Build L3. Linked to L2.
                    753:         */
1.93      jym       754:        leal    (PROC0_L3_OFF)(%esi),%ebx
                    755:        leal    (PROC0_PDIR_OFF)(%esi),%eax
                    756:        orl     $(PG_V),%eax
                    757:        movl    $PDP_SIZE,%ecx
                    758:        fillkpt
                    759:
                    760:        /* Enable PAE mode */
                    761:        movl    %cr4,%eax
                    762:        orl     $CR4_PAE,%eax
                    763:        movl    %eax,%cr4
                    764: #endif
1.1       fvdl      765:
1.117     maxv      766:        /* Save physical address of L2. */
1.93      jym       767:        leal    (PROC0_PDIR_OFF)(%esi),%eax
                    768:        movl    %eax,RELOC(PDPpaddr)
1.1       fvdl      769:
1.93      jym       770:        /*
                    771:         * Startup checklist:
1.117     maxv      772:         * 1. Load %cr3 with pointer to L2 (or L3 for PAE).
1.93      jym       773:         */
1.117     maxv      774:        movl    %esi,%eax
                    775:        movl    %eax,%cr3
1.93      jym       776:
1.105     uebayasi  777:        /*
1.119     maxv      778:         * 2. Set NOX in EFER, if available.
                    779:         */
                    780:        movl    RELOC(nox_flag),%ebx
                    781:        cmpl    $0,%ebx
                    782:        je      skip_NOX
                    783:        movl    $MSR_EFER,%ecx
                    784:        rdmsr
                    785:        xorl    %eax,%eax
                    786:        orl     $(EFER_NXE),%eax
                    787:        wrmsr
                    788: skip_NOX:
                    789:
                    790:        /*
                    791:         * 3. Enable paging and the rest of it.
1.105     uebayasi  792:         */
1.115     maxv      793:        movl    %cr0,%eax
1.111     dsl       794:        orl     $(CR0_PE|CR0_PG|CR0_NE|CR0_TS|CR0_MP|CR0_WP|CR0_AM),%eax
1.115     maxv      795:        movl    %eax,%cr0
1.1       fvdl      796:
1.115     maxv      797:        pushl   $begin                  /* jump to high mem */
1.1       fvdl      798:        ret
                    799:
                    800: begin:
1.105     uebayasi  801:        /*
1.117     maxv      802:         * We have arrived. There's no need anymore for the identity mapping in
                    803:         * low memory, remove it.
1.105     uebayasi  804:         */
                    805:        movl    _C_LABEL(nkptp)+1*4,%ecx
1.115     maxv      806:        leal    (PROC0_PDIR_OFF)(%esi),%ebx     /* old, phys address of PDIR */
                    807:        addl    $(KERNBASE), %ebx               /* new, virt address of PDIR */
1.118     maxv      808:        killkpt
1.1       fvdl      809:
                    810:        /* Relocate atdevbase. */
1.53      yamt      811:        movl    $KERNBASE,%edx
                    812:        addl    _C_LABEL(tablesize),%edx
1.1       fvdl      813:        addl    %esi,%edx
                    814:        movl    %edx,_C_LABEL(atdevbase)
                    815:
                    816:        /* Set up bootstrap stack. */
1.105     uebayasi  817:        leal    (PROC0_STK_OFF+KERNBASE)(%esi),%eax
1.91      rmind     818:        movl    %eax,_C_LABEL(lwp0uarea)
1.112     dsl       819:        leal    (USPACE-FRAMESIZE)(%eax),%esp
1.115     maxv      820:        movl    %esi,PCB_CR3(%eax)      /* pcb->pcb_cr3 */
                    821:        xorl    %ebp,%ebp               /* mark end of frames */
1.1       fvdl      822:
1.37      jmmv      823: #if defined(MULTIBOOT)
                    824:        /* It is now safe to parse the Multiboot information structure
                    825:         * we saved before from C code.  Note that we cannot delay its
                    826:         * parsing any more because initgdt (called below) needs to make
                    827:         * use of this information. */
                    828:        call    _C_LABEL(multiboot_post_reloc)
                    829: #endif
                    830:
1.115     maxv      831:        subl    $NGDT*8, %esp           /* space for temporary gdt */
1.1       fvdl      832:        pushl   %esp
                    833:        call    _C_LABEL(initgdt)
                    834:        addl    $4,%esp
1.30      junyoung  835:
1.105     uebayasi  836:        movl    _C_LABEL(tablesize),%eax
1.115     maxv      837:        addl    %esi,%eax               /* skip past stack and page tables */
1.1       fvdl      838:
1.93      jym       839: #ifdef PAE
1.115     maxv      840:        pushl   $0      /* init386() expects a 64 bits paddr_t with PAE */
1.93      jym       841: #endif
1.1       fvdl      842:        pushl   %eax
1.139     maxv      843:        call    _C_LABEL(init386)
1.115     maxv      844:        addl    $PDE_SIZE,%esp          /* pop paddr_t */
                    845:        addl    $NGDT*8,%esp            /* pop temporary gdt */
1.1       fvdl      846:
                    847:        call    _C_LABEL(main)
1.62      bouyer    848: #else /* XEN */
                    849:        /* First, reset the PSL. */
                    850:        pushl   $PSL_MBO
                    851:        popfl
                    852:
                    853:        cld
1.139     maxv      854:
                    855:        /*
                    856:         * Xen info:
                    857:         * - %esp -> stack, *theoretically* the last used page by Xen bootstrap
                    858:         */
                    859:        movl    %esp,%ebx
                    860:        movl    $_RELOC(tmpstk),%esp
1.62      bouyer    861:
1.106     uebayasi  862:        /* Clear BSS. */
1.62      bouyer    863:        xorl    %eax,%eax
                    864:        movl    $RELOC(__bss_start),%edi
                    865:        movl    $RELOC(_end),%ecx
                    866:        subl    %edi,%ecx
1.139     maxv      867:        rep
                    868:        stosb
1.62      bouyer    869:
                    870:        /* Copy the necessary stuff from start_info structure. */
1.105     uebayasi  871:        /* We need to copy shared_info early, so that sti/cli work */
1.62      bouyer    872:        movl    $RELOC(start_info_union),%edi
                    873:        movl    $128,%ecx
1.139     maxv      874:        rep
                    875:        movsl
1.62      bouyer    876:
1.139     maxv      877:        /* Clear segment registers. */
1.62      bouyer    878:        xorl    %eax,%eax
                    879:        movw    %ax,%fs
                    880:        movw    %ax,%gs
                    881:
                    882:        xorl    %eax,%eax
                    883:        cpuid
1.73      ad        884:        movl    %eax,RELOC(cpuid_level)
1.62      bouyer    885:
1.96      cherry    886:        /*
1.139     maxv      887:         * Use a temporary GDT page. We'll re-add it to uvm(9) once we're done
                    888:         * using it.
1.96      cherry    889:         */
1.139     maxv      890:        movl    $RELOC(tmpgdt),%eax
1.115     maxv      891:        pushl   %eax            /* start of temporary gdt */
1.96      cherry    892:        call    _C_LABEL(initgdt)
                    893:        addl    $4,%esp
                    894:
1.140     maxv      895:        call    xen_locore
1.92      jym       896:
1.62      bouyer    897:        /*
1.140     maxv      898:         * The first VA available is returned by xen_locore in %eax. We
1.139     maxv      899:         * use it as the UAREA, and set up the stack here.
1.62      bouyer    900:         */
1.139     maxv      901:        movl    %eax,%esi
                    902:        movl    %esi,_C_LABEL(lwp0uarea)
1.112     dsl       903:        leal    (USPACE-FRAMESIZE)(%eax),%esp
1.115     maxv      904:        xorl    %ebp,%ebp               /* mark end of frames */
1.62      bouyer    905:
1.143     maxv      906:        /* Set first_avail after the DUMMY PAGE (see xen_locore). */
                    907:        addl    $(USPACE+PAGE_SIZE),%esi
1.139     maxv      908:        subl    $KERNBASE,%esi          /* init386 wants a physical address */
1.92      jym       909:
                    910: #ifdef PAE
1.115     maxv      911:        pushl   $0      /* init386() expects a 64 bits paddr_t with PAE */
1.92      jym       912: #endif
1.62      bouyer    913:        pushl   %esi
1.139     maxv      914:        call    _C_LABEL(init386)
1.115     maxv      915:        addl    $PDE_SIZE,%esp          /* pop paddr_t */
1.62      bouyer    916:        call    _C_LABEL(main)
1.106     uebayasi  917: #endif /* XEN */
1.104     uebayasi  918: END(start)
1.62      bouyer    919:
1.101     jym       920: #if defined(XEN)
1.62      bouyer    921: /* space for the hypercall call page */
                    922: #define HYPERCALL_PAGE_OFFSET 0x1000
                    923: .org HYPERCALL_PAGE_OFFSET
                    924: ENTRY(hypercall_page)
                    925: .skip 0x1000
1.104     uebayasi  926: END(hypercall_page)
1.62      bouyer    927:
                    928: /*
                    929:  * void lgdt_finish(void);
                    930:  * Finish load a new GDT pointer (do any necessary cleanup).
                    931:  * XXX It's somewhat questionable whether reloading all the segment registers
                    932:  * is necessary, since the actual descriptor data is not changed except by
                    933:  * process creation and exit, both of which clean up via task switches.  OTOH,
                    934:  * this only happens at run time when the GDT is resized.
                    935:  */
                    936: /* LINTSTUB: Func: void lgdt_finish(void) */
                    937: NENTRY(lgdt_finish)
                    938:        movl    $GSEL(GDATA_SEL, SEL_KPL),%eax
                    939:        movw    %ax,%ds
                    940:        movw    %ax,%es
                    941:        movw    %ax,%gs
                    942:        movw    %ax,%ss
                    943:        movl    $GSEL(GCPU_SEL, SEL_KPL),%eax
                    944:        movw    %ax,%fs
                    945:        /* Reload code selector by doing intersegment return. */
                    946:        popl    %eax
                    947:        pushl   $GSEL(GCODE_SEL, SEL_KPL)
                    948:        pushl   %eax
                    949:        lret
1.72      yamt      950: END(lgdt_finish)
1.62      bouyer    951:
                    952: #endif /* XEN */
1.1       fvdl      953:
                    954: /*
1.48      yamt      955:  * void lwp_trampoline(void);
                    956:  *
1.1       fvdl      957:  * This is a trampoline function pushed onto the stack of a newly created
                    958:  * process in order to do some additional setup.  The trampoline is entered by
1.109     christos  959:  * cpu_switchto()ing to the process, so we abuse the callee-saved
                    960:  * registers used by cpu_switchto() to store the information about the
                    961:  * stub to call.
1.1       fvdl      962:  * NOTE: This function does not have a normal calling sequence!
                    963:  */
1.48      yamt      964: NENTRY(lwp_trampoline)
1.68      ad        965:        movl    %ebp,%edi       /* for .Lsyscall_checkast */
1.48      yamt      966:        xorl    %ebp,%ebp
1.68      ad        967:        pushl   %edi
1.48      yamt      968:        pushl   %eax
                    969:        call    _C_LABEL(lwp_startup)
                    970:        addl    $8,%esp
1.1       fvdl      971:        pushl   %ebx
                    972:        call    *%esi
                    973:        addl    $4,%esp
1.68      ad        974:        jmp     .Lsyscall_checkast
1.1       fvdl      975:        /* NOTREACHED */
1.72      yamt      976: END(lwp_trampoline)
1.1       fvdl      977:
                    978: /*
1.48      yamt      979:  * sigcode()
                    980:  *
                    981:  * Signal trampoline; copied to top of user stack.  Used only for
                    982:  * compatibility with old releases of NetBSD.
1.1       fvdl      983:  */
                    984: NENTRY(sigcode)
                    985:        /*
                    986:         * Handler has returned here as if we called it.  The sigcontext
                    987:         * is on the stack after the 3 args "we" pushed.
                    988:         */
1.115     maxv      989:        leal    12(%esp),%eax           /* get pointer to sigcontext */
                    990:        movl    %eax,4(%esp)            /* put it in the argument slot */
                    991:                                        /* fake return address already there */
1.17      christos  992:        movl    $SYS_compat_16___sigreturn14,%eax
1.115     maxv      993:        int     $0x80                   /* enter kernel with args on stack */
1.1       fvdl      994:        movl    $SYS_exit,%eax
1.115     maxv      995:        int     $0x80                   /* exit if sigreturn fails */
1.1       fvdl      996:        .globl  _C_LABEL(esigcode)
                    997: _C_LABEL(esigcode):
1.72      yamt      998: END(sigcode)
1.1       fvdl      999:
                   1000: /*
1.48      yamt     1001:  * int setjmp(label_t *)
                   1002:  *
                   1003:  * Used primarily by DDB.
1.1       fvdl     1004:  */
                   1005: ENTRY(setjmp)
                   1006:        movl    4(%esp),%eax
1.115     maxv     1007:        movl    %ebx,(%eax)             /* save ebx */
                   1008:        movl    %esp,4(%eax)            /* save esp */
                   1009:        movl    %ebp,8(%eax)            /* save ebp */
                   1010:        movl    %esi,12(%eax)           /* save esi */
                   1011:        movl    %edi,16(%eax)           /* save edi */
                   1012:        movl    (%esp),%edx             /* get rta */
                   1013:        movl    %edx,20(%eax)           /* save eip */
                   1014:        xorl    %eax,%eax               /* return 0 */
1.1       fvdl     1015:        ret
1.72      yamt     1016: END(setjmp)
1.1       fvdl     1017:
1.48      yamt     1018: /*
                   1019:  * int longjmp(label_t *)
                   1020:  *
                   1021:  * Used primarily by DDB.
                   1022:  */
1.1       fvdl     1023: ENTRY(longjmp)
                   1024:        movl    4(%esp),%eax
1.115     maxv     1025:        movl    (%eax),%ebx             /* restore ebx */
                   1026:        movl    4(%eax),%esp            /* restore esp */
                   1027:        movl    8(%eax),%ebp            /* restore ebp */
                   1028:        movl    12(%eax),%esi           /* restore esi */
                   1029:        movl    16(%eax),%edi           /* restore edi */
                   1030:        movl    20(%eax),%edx           /* get rta */
                   1031:        movl    %edx,(%esp)             /* put in return frame */
                   1032:        movl    $1,%eax                 /* return 1 */
1.1       fvdl     1033:        ret
1.72      yamt     1034: END(longjmp)
1.1       fvdl     1035:
1.65      skrll    1036: /*
                   1037:  * void dumpsys(void)
                   1038:  *
                   1039:  * Mimic cpu_switchto() for postmortem debugging.
                   1040:  */
1.64      skrll    1041: ENTRY(dumpsys)
1.115     maxv     1042:        pushl   %ebx                    /* set up fake switchframe */
                   1043:        pushl   %esi                    /* and save context */
                   1044:        pushl   %edi
1.65      skrll    1045:        movl    %esp,_C_LABEL(dumppcb)+PCB_ESP
                   1046:        movl    %ebp,_C_LABEL(dumppcb)+PCB_EBP
1.115     maxv     1047:        call    _C_LABEL(dodumpsys)     /* dump! */
                   1048:        addl    $(3*4), %esp            /* unwind switchframe */
1.64      skrll    1049:        ret
1.72      yamt     1050: END(dumpsys)
1.64      skrll    1051:
1.1       fvdl     1052: /*
1.106     uebayasi 1053:  * struct lwp *cpu_switchto(struct lwp *oldlwp, struct lwp *newlwp,
1.132     maxv     1054:  *     bool returning)
1.30      junyoung 1055:  *
1.48      yamt     1056:  *     1. if (oldlwp != NULL), save its context.
                   1057:  *     2. then, restore context of newlwp.
                   1058:  *
                   1059:  * Note that the stack frame layout is known to "struct switchframe" in
                   1060:  * <machine/frame.h> and to the code in cpu_lwp_fork() which initializes
1.5       thorpej  1061:  * it for a new lwp.
1.1       fvdl     1062:  */
1.48      yamt     1063: ENTRY(cpu_switchto)
1.1       fvdl     1064:        pushl   %ebx
                   1065:        pushl   %esi
                   1066:        pushl   %edi
                   1067:
1.70      ad       1068: #if defined(DIAGNOSTIC) && !defined(XEN)
                   1069:        cmpl    $IPL_SCHED,CPUVAR(ILEVEL)
                   1070:        jbe     0f
1.74      christos 1071:        pushl   CPUVAR(ILEVEL)
1.70      ad       1072:        pushl   $.Lstr
                   1073:        call    _C_LABEL(panic)
1.74      christos 1074:        addl    $8,%esp
                   1075: .Lstr: .string "cpu_switchto: switching above IPL_SCHED (%d)\0"
1.70      ad       1076: 0:
                   1077: #endif
                   1078:
1.115     maxv     1079:        movl    16(%esp),%esi           /* oldlwp */
                   1080:        movl    20(%esp),%edi           /* newlwp */
                   1081:        movl    24(%esp),%edx           /* returning */
1.132     maxv     1082:
                   1083:        testl   %esi,%esi               /* oldlwp = NULL ? */
                   1084:        jz      skip_save
1.1       fvdl     1085:
1.48      yamt     1086:        /* Save old context. */
1.91      rmind    1087:        movl    L_PCB(%esi),%eax
1.48      yamt     1088:        movl    %esp,PCB_ESP(%eax)
                   1089:        movl    %ebp,PCB_EBP(%eax)
1.132     maxv     1090: skip_save:
1.48      yamt     1091:
                   1092:        /* Switch to newlwp's stack. */
1.132     maxv     1093:        movl    L_PCB(%edi),%ebx
1.48      yamt     1094:        movl    PCB_EBP(%ebx),%ebp
                   1095:        movl    PCB_ESP(%ebx),%esp
1.1       fvdl     1096:
1.61      ad       1097:        /*
                   1098:         * Set curlwp.  This must be globally visible in order to permit
                   1099:         * non-interlocked mutex release.
                   1100:         */
                   1101:        movl    %edi,%ecx
                   1102:        xchgl   %ecx,CPUVAR(CURLWP)
1.58      ad       1103:
                   1104:        /* Skip the rest if returning to a pinned LWP. */
                   1105:        testl   %edx,%edx
1.132     maxv     1106:        jnz     switch_return
1.58      ad       1107:
1.132     maxv     1108:        /* Switch ring0 stack */
1.62      bouyer   1109: #ifdef XEN
                   1110:        pushl   %edi
                   1111:        call    _C_LABEL(i386_switch_context)
                   1112:        addl    $4,%esp
1.132     maxv     1113: #else
1.60      yamt     1114:        movl    PCB_ESP0(%ebx),%eax
                   1115:        movl    %eax,CPUVAR(ESP0)
1.132     maxv     1116: #endif
1.1       fvdl     1117:
                   1118:        /* Don't bother with the rest if switching to a system process. */
1.48      yamt     1119:        testl   $LW_SYSTEM,L_FLAG(%edi)
1.132     maxv     1120:        jnz     switch_return
1.1       fvdl     1121:
1.97      bouyer   1122: #ifndef XEN
1.54      ad       1123:        /* Restore thread-private %fs/%gs descriptors. */
1.60      yamt     1124:        movl    CPUVAR(GDT),%ecx
1.132     maxv     1125:        movl    PCB_FSD(%ebx),%eax
                   1126:        movl    PCB_FSD+4(%ebx),%edx
                   1127:        movl    %eax,(GUFS_SEL*8)(%ecx)
                   1128:        movl    %edx,(GUFS_SEL*8+4)(%ecx)
                   1129:        movl    PCB_GSD(%ebx),%eax
                   1130:        movl    PCB_GSD+4(%ebx),%edx
                   1131:        movl    %eax,(GUGS_SEL*8)(%ecx)
                   1132:        movl    %edx,(GUGS_SEL*8+4)(%ecx)
1.97      bouyer   1133: #endif /* !XEN */
1.54      ad       1134:
1.60      yamt     1135:        /* Switch I/O bitmap */
                   1136:        movl    PCB_IOMAP(%ebx),%eax
                   1137:        orl     %eax,%eax
1.95      joerg    1138:        jnz     .Lcopy_iobitmap
1.60      yamt     1139:        movl    $(IOMAP_INVALOFF << 16),CPUVAR(IOBASE)
                   1140: .Liobitmap_done:
                   1141:
1.56      ad       1142:        /* Is this process using RAS (restartable atomic sequences)? */
                   1143:        movl    L_PROC(%edi),%eax
                   1144:        cmpl    $0,P_RASLIST(%eax)
1.133     maxv     1145:        je      no_RAS
                   1146:
                   1147:        /* Handle restartable atomic sequences (RAS). */
                   1148:        movl    L_MD_REGS(%edi),%ecx
                   1149:        pushl   TF_EIP(%ecx)
                   1150:        pushl   %eax
                   1151:        call    _C_LABEL(ras_lookup)
                   1152:        addl    $8,%esp
                   1153:        cmpl    $-1,%eax
                   1154:        je      no_RAS
                   1155:        movl    L_MD_REGS(%edi),%ecx
                   1156:        movl    %eax,TF_EIP(%ecx)
                   1157: no_RAS:
1.56      ad       1158:
1.48      yamt     1159:        /*
1.90      rmind    1160:         * Restore cr0 (including FPU state).  Raise the IPL to IPL_HIGH.
1.48      yamt     1161:         * FPU IPIs can alter the LWP's saved cr0.  Dropping the priority
                   1162:         * is deferred until mi_switch(), when cpu_switchto() returns.
                   1163:         */
1.97      bouyer   1164: #ifdef XEN
                   1165:        pushl   %edi
                   1166:        call    _C_LABEL(i386_tls_switch)
                   1167:        addl    $4,%esp
                   1168: #else /* !XEN */
1.108     christos 1169:        movl    $IPL_HIGH,CPUVAR(ILEVEL)
                   1170:        movl    PCB_CR0(%ebx),%ecx              /* has CR0_TS clear */
1.48      yamt     1171:        movl    %cr0,%edx
1.1       fvdl     1172:
1.108     christos 1173:        /*
                   1174:         * If our floating point registers are on a different CPU,
                   1175:         * set CR0_TS so we'll trap rather than reuse bogus state.
                   1176:         */
                   1177:        cmpl    CPUVAR(FPCURLWP),%edi
1.132     maxv     1178:        je      skip_TS
1.108     christos 1179:        orl     $CR0_TS,%ecx
1.132     maxv     1180: skip_TS:
1.108     christos 1181:
1.48      yamt     1182:        /* Reloading CR0 is very expensive - avoid if possible. */
1.132     maxv     1183:        cmpl    %edx,%ecx
                   1184:        je      switch_return
1.1       fvdl     1185:        movl    %ecx,%cr0
1.97      bouyer   1186: #endif /* !XEN */
1.1       fvdl     1187:
1.132     maxv     1188: switch_return:
1.48      yamt     1189:        /* Return to the new LWP, returning 'oldlwp' in %eax. */
1.132     maxv     1190:        movl    %esi,%eax
1.1       fvdl     1191:        popl    %edi
                   1192:        popl    %esi
                   1193:        popl    %ebx
                   1194:        ret
1.20      dsl      1195:
1.60      yamt     1196: .Lcopy_iobitmap:
                   1197:        /* Copy I/O bitmap. */
1.86      ad       1198:        incl    _C_LABEL(pmap_iobmp_evcnt)+EV_COUNT
1.60      yamt     1199:        movl    $(IOMAPSIZE/4),%ecx
                   1200:        pushl   %esi
                   1201:        pushl   %edi
                   1202:        movl    %eax,%esi               /* pcb_iomap */
                   1203:        movl    CPUVAR(SELF),%edi
                   1204:        leal    CPU_INFO_IOMAP(%edi),%edi
                   1205:        rep
                   1206:        movsl
                   1207:        popl    %edi
                   1208:        popl    %esi
                   1209:        movl    $((CPU_INFO_IOMAP - CPU_INFO_TSS) << 16),CPUVAR(IOBASE)
                   1210:        jmp     .Liobitmap_done
1.72      yamt     1211: END(cpu_switchto)
1.60      yamt     1212:
1.1       fvdl     1213: /*
                   1214:  * void savectx(struct pcb *pcb);
1.48      yamt     1215:  *
1.1       fvdl     1216:  * Update pcb, saving current processor state.
                   1217:  */
                   1218: ENTRY(savectx)
1.115     maxv     1219:        movl    4(%esp),%edx            /* edx = pcb */
1.1       fvdl     1220:        movl    %esp,PCB_ESP(%edx)
                   1221:        movl    %ebp,PCB_EBP(%edx)
                   1222:        ret
1.72      yamt     1223: END(savectx)
1.1       fvdl     1224:
                   1225: /*
1.48      yamt     1226:  * syscall()
                   1227:  *
1.1       fvdl     1228:  * Trap gate entry for syscall
                   1229:  */
                   1230: IDTVEC(syscall)
1.115     maxv     1231:        pushl   $2              /* size of instruction for restart */
                   1232:        pushl   $T_ASTFLT       /* trap # for doing ASTs */
1.1       fvdl     1233:        INTRENTRY
1.85      ad       1234:        STI(%eax)
1.1       fvdl     1235: #ifdef DIAGNOSTIC
                   1236:        movl    CPUVAR(ILEVEL),%ebx
                   1237:        testl   %ebx,%ebx
                   1238:        jz      1f
                   1239:        pushl   $5f
1.84      ad       1240:        call    _C_LABEL(panic)
1.1       fvdl     1241:        addl    $4,%esp
                   1242: #ifdef DDB
                   1243:        int     $3
                   1244: #endif
1.30      junyoung 1245: 1:
1.1       fvdl     1246: #endif /* DIAGNOSTIC */
1.115     maxv     1247:        addl    $1,CPUVAR(NSYSCALL)     /* count it atomically */
                   1248:        adcl    $0,CPUVAR(NSYSCALL)+4   /* count it atomically */
1.68      ad       1249:        movl    CPUVAR(CURLWP),%edi
                   1250:        movl    L_PROC(%edi),%edx
1.115     maxv     1251:        movl    %esp,L_MD_REGS(%edi)    /* save pointer to frame */
1.15      fvdl     1252:        pushl   %esp
1.115     maxv     1253:        call    *P_MD_SYSCALL(%edx)     /* get pointer to syscall() function */
1.15      fvdl     1254:        addl    $4,%esp
1.27      yamt     1255: .Lsyscall_checkast:
1.24      yamt     1256:        /* Check for ASTs on exit to user mode. */
1.62      bouyer   1257:        CLI(%eax)
1.68      ad       1258:        movl    L_MD_ASTPENDING(%edi), %eax
                   1259:        orl     CPUVAR(WANT_PMAPLOAD), %eax
1.24      yamt     1260:        jnz     9f
1.62      bouyer   1261: #ifdef XEN
                   1262:        STIC(%eax)
                   1263:        jz      14f
                   1264:        call    _C_LABEL(stipending)
                   1265:        testl   %eax,%eax
                   1266:        jz      14f
                   1267:        /* process pending interrupts */
                   1268:        CLI(%eax)
                   1269:        movl    CPUVAR(ILEVEL), %ebx
1.115     maxv     1270:        movl    $.Lsyscall_resume, %esi /* address to resume loop at */
1.62      bouyer   1271: .Lsyscall_resume:
1.115     maxv     1272:        movl    %ebx,%eax               /* get cpl */
1.62      bouyer   1273:        movl    CPUVAR(IUNMASK)(,%eax,4),%eax
1.115     maxv     1274:        andl    CPUVAR(IPENDING),%eax   /* any non-masked bits left? */
1.62      bouyer   1275:        jz      17f
                   1276:        bsrl    %eax,%eax
                   1277:        btrl    %eax,CPUVAR(IPENDING)
                   1278:        movl    CPUVAR(ISOURCES)(,%eax,4),%eax
                   1279:        jmp     *IS_RESUME(%eax)
1.115     maxv     1280: 17:    movl    %ebx, CPUVAR(ILEVEL)    /* restore cpl  */
1.62      bouyer   1281:        jmp     .Lsyscall_checkast
                   1282: 14:
                   1283: #endif /* XEN */
1.1       fvdl     1284: #ifndef DIAGNOSTIC
1.24      yamt     1285:        INTRFASTEXIT
1.1       fvdl     1286: #else /* DIAGNOSTIC */
1.24      yamt     1287:        cmpl    $IPL_NONE,CPUVAR(ILEVEL)
1.1       fvdl     1288:        jne     3f
                   1289:        INTRFASTEXIT
1.62      bouyer   1290: 3:     STI(%eax)
1.1       fvdl     1291:        pushl   $4f
1.84      ad       1292:        call    _C_LABEL(panic)
1.1       fvdl     1293:        addl    $4,%esp
1.58      ad       1294:        pushl   $IPL_NONE
                   1295:        call    _C_LABEL(spllower)
                   1296:        addl    $4,%esp
1.53      yamt     1297:        jmp     .Lsyscall_checkast
1.84      ad       1298: 4:     .asciz  "SPL NOT LOWERED ON SYSCALL EXIT\n"
                   1299: 5:     .asciz  "SPL NOT ZERO ON SYSCALL ENTRY\n"
1.1       fvdl     1300: #endif /* DIAGNOSTIC */
1.68      ad       1301: 9:
                   1302:        cmpl    $0, CPUVAR(WANT_PMAPLOAD)
                   1303:        jz      10f
                   1304:        STI(%eax)
1.24      yamt     1305:        call    _C_LABEL(pmap_load)
1.27      yamt     1306:        jmp     .Lsyscall_checkast      /* re-check ASTs */
1.68      ad       1307: 10:
                   1308:        /* Always returning to user mode here. */
                   1309:        movl    $0, L_MD_ASTPENDING(%edi)
                   1310:        STI(%eax)
                   1311:        /* Pushed T_ASTFLT into tf_trapno on entry. */
                   1312:        pushl   %esp
                   1313:        call    _C_LABEL(trap)
                   1314:        addl    $4,%esp
                   1315:        jmp     .Lsyscall_checkast      /* re-check ASTs */
1.72      yamt     1316: IDTVEC_END(syscall)
1.1       fvdl     1317:
1.81      ad       1318: IDTVEC(svr4_fasttrap)
1.115     maxv     1319:        pushl   $2              /* size of instruction for restart */
                   1320:        pushl   $T_ASTFLT       /* trap # for doing ASTs */
1.81      ad       1321:        INTRENTRY
1.85      ad       1322:        STI(%eax)
1.81      ad       1323:        pushl   $RW_READER
                   1324:        pushl   $_C_LABEL(svr4_fasttrap_lock)
                   1325:        call    _C_LABEL(rw_enter)
                   1326:        addl    $8,%esp
                   1327:        call    *_C_LABEL(svr4_fasttrap_vec)
                   1328:        pushl   $_C_LABEL(svr4_fasttrap_lock)
                   1329:        call    _C_LABEL(rw_exit)
                   1330:        addl    $4,%esp
                   1331: 2:     /* Check for ASTs on exit to user mode. */
                   1332:        cli
1.115     maxv     1333:        CHECK_ASTPENDING(%eax)
1.81      ad       1334:        je      1f
                   1335:        /* Always returning to user mode here. */
                   1336:        CLEAR_ASTPENDING(%eax)
                   1337:        sti
                   1338:        /* Pushed T_ASTFLT into tf_trapno on entry. */
                   1339:        pushl   %esp
                   1340:        call    _C_LABEL(trap)
                   1341:        addl    $4,%esp
                   1342:        jmp     2b
                   1343: 1:     CHECK_DEFERRED_SWITCH
                   1344:        jnz     9f
                   1345:        INTRFASTEXIT
                   1346: 9:     sti
                   1347:        call    _C_LABEL(pmap_load)
                   1348:        cli
                   1349:        jmp     2b
                   1350:
1.48      yamt     1351: /*
                   1352:  * int npx586bug1(int a, int b)
1.110     dsl      1353:  * Used when checking for the FDIV bug on first generations pentiums.
                   1354:  * Anything 120MHz or above is fine.
1.48      yamt     1355:  */
1.1       fvdl     1356: NENTRY(npx586bug1)
1.115     maxv     1357:        fildl   4(%esp)         /* x */
                   1358:        fildl   8(%esp)         /* y */
1.1       fvdl     1359:        fld     %st(1)
1.115     maxv     1360:        fdiv    %st(1),%st      /* x/y */
                   1361:        fmulp   %st,%st(1)      /* (x/y)*y */
                   1362:        fsubrp  %st,%st(1)      /* x-(x/y)*y */
1.1       fvdl     1363:        pushl   $0
                   1364:        fistpl  (%esp)
                   1365:        popl    %eax
                   1366:        ret
1.72      yamt     1367: END(npx586bug1)
1.50      ad       1368:
                   1369: /*
1.76      ad       1370:  * void sse2_idlezero_page(void *pg)
1.50      ad       1371:  *
1.76      ad       1372:  * Zero a page without polluting the cache.  Preemption must be
                   1373:  * disabled by the caller. Abort if a preemption is pending.
1.50      ad       1374:  */
1.76      ad       1375: ENTRY(sse2_idlezero_page)
1.50      ad       1376:        pushl   %ebp
                   1377:        movl    %esp,%ebp
                   1378:        movl    8(%esp), %edx
1.76      ad       1379:        movl    $(PAGE_SIZE/32), %ecx
1.50      ad       1380:        xorl    %eax, %eax
                   1381:        .align  16
                   1382: 1:
1.82      ad       1383:        testl   $RESCHED_KPREEMPT, CPUVAR(RESCHED)
1.76      ad       1384:        jnz     2f
1.50      ad       1385:        movnti  %eax, 0(%edx)
                   1386:        movnti  %eax, 4(%edx)
                   1387:        movnti  %eax, 8(%edx)
                   1388:        movnti  %eax, 12(%edx)
                   1389:        movnti  %eax, 16(%edx)
                   1390:        movnti  %eax, 20(%edx)
                   1391:        movnti  %eax, 24(%edx)
                   1392:        movnti  %eax, 28(%edx)
1.76      ad       1393:        addl    $32, %edx
1.75      ad       1394:        decl    %ecx
1.50      ad       1395:        jnz     1b
                   1396:        sfence
1.76      ad       1397:        incl    %eax
1.50      ad       1398:        pop     %ebp
                   1399:        ret
1.76      ad       1400: 2:
1.50      ad       1401:        sfence
                   1402:        popl    %ebp
                   1403:        ret
1.76      ad       1404: END(sse2_idlezero_page)

CVSweb <webmaster@jp.NetBSD.org>