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

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

CVSweb <webmaster@jp.NetBSD.org>