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

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

CVSweb <webmaster@jp.NetBSD.org>