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

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

CVSweb <webmaster@jp.NetBSD.org>