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

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

CVSweb <webmaster@jp.NetBSD.org>