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

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

CVSweb <webmaster@jp.NetBSD.org>