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

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

CVSweb <webmaster@jp.NetBSD.org>