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

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

CVSweb <webmaster@jp.NetBSD.org>