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

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

CVSweb <webmaster@jp.NetBSD.org>