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

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

CVSweb <webmaster@jp.NetBSD.org>