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

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

CVSweb <webmaster@jp.NetBSD.org>