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

1.58.6.3! bouyer      1: /*     $NetBSD$        */
1.53      yamt        2:
                      3: /*
                      4:  * Copyright-o-rama!
                      5:  */
                      6:
                      7: /*
1.58.6.2  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.58.6.1  bouyer    143: #include <machine/asm.h>
1.58.6.3! bouyer    144: __KERNEL_RCSID(0, "$NetBSD$");
1.58.6.1  bouyer    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.58.6.2  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.58.6.2  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.58.6.2  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.58.6.2  bouyer    247:        .space 1024
1.1       fvdl      248: tmpstk:
                    249:
1.58.6.2  bouyer    250: #ifndef XEN
1.35      yamt      251: #define        _RELOC(x)       ((x) - KERNBASE)
1.58.6.2  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.58.6.2  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.58.6.2  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.58      ad        915:        /* Set curlwp. */
                    916:        movl    %edi,CPUVAR(CURLWP)
                    917:
                    918:        /* Skip the rest if returning to a pinned LWP. */
                    919:        testl   %edx,%edx
                    920:        jnz     4f
                    921:
1.58.6.2  bouyer    922: #ifdef XEN
1.58.6.3! bouyer    923:        pushl   %edi
1.58.6.2  bouyer    924:        call    _C_LABEL(i386_switch_context)
                    925:        addl    $4,%esp
                    926: #else /* XEN */
1.58.6.3! bouyer    927:        /* Switch ring0 esp */
        !           928:        movl    PCB_ESP0(%ebx),%eax
        !           929:        movl    %eax,CPUVAR(ESP0)
1.1       fvdl      930:
                    931:        /* Don't bother with the rest if switching to a system process. */
1.48      yamt      932:        testl   $LW_SYSTEM,L_FLAG(%edi)
                    933:        jnz     4f
1.1       fvdl      934:
1.54      ad        935:        /* Restore thread-private %fs/%gs descriptors. */
1.58.6.3! bouyer    936:        movl    CPUVAR(GDT),%ecx
1.55      ad        937:        movl    PCB_FSD(%ebx), %eax
                    938:        movl    PCB_FSD+4(%ebx), %edx
1.54      ad        939:        movl    %eax, (GUFS_SEL*8)(%ecx)
                    940:        movl    %edx, (GUFS_SEL*8+4)(%ecx)
1.55      ad        941:        movl    PCB_GSD(%ebx), %eax
                    942:        movl    PCB_GSD+4(%ebx), %edx
1.54      ad        943:        movl    %eax, (GUGS_SEL*8)(%ecx)
                    944:        movl    %edx, (GUGS_SEL*8+4)(%ecx)
1.58.6.2  bouyer    945: #endif /* XEN */
1.54      ad        946:
1.58.6.3! bouyer    947:        /* Switch I/O bitmap */
        !           948:        movl    PCB_IOMAP(%ebx),%eax
        !           949:        orl     %eax,%eax
        !           950:        jnz,pn  .Lcopy_iobitmap
        !           951:        movl    $(IOMAP_INVALOFF << 16),CPUVAR(IOBASE)
        !           952: .Liobitmap_done:
        !           953:
1.56      ad        954:        /* Is this process using RAS (restartable atomic sequences)? */
                    955:        movl    L_PROC(%edi),%eax
                    956:        cmpl    $0,P_RASLIST(%eax)
                    957:        jne     5f
                    958:
1.48      yamt      959:        /*
                    960:         * Restore cr0 (including FPU state).  Raise the IPL to IPL_IPI.
                    961:         * FPU IPIs can alter the LWP's saved cr0.  Dropping the priority
                    962:         * is deferred until mi_switch(), when cpu_switchto() returns.
                    963:         */
1.58.6.2  bouyer    964: 2:
                    965: #ifndef XEN
                    966:        movl    $IPL_IPI,CPUVAR(ILEVEL)
1.48      yamt      967:        movl    PCB_CR0(%ebx),%ecx
                    968:        movl    %cr0,%edx
1.1       fvdl      969:
1.30      junyoung  970:        /*
1.22      wiz       971:         * If our floating point registers are on a different CPU,
1.48      yamt      972:         * set CR0_TS so we'll trap rather than reuse bogus state.
1.1       fvdl      973:         */
1.48      yamt      974:        movl    PCB_FPCPU(%ebx),%eax
                    975:        cmpl    CPUVAR(SELF),%eax
                    976:        je      3f
1.1       fvdl      977:        orl     $CR0_TS,%ecx
1.48      yamt      978:
                    979:        /* Reloading CR0 is very expensive - avoid if possible. */
                    980: 3:     cmpl    %edx,%ecx
                    981:        je      4f
1.1       fvdl      982:        movl    %ecx,%cr0
1.58.6.2  bouyer    983: #endif /* XEN */
1.1       fvdl      984:
1.48      yamt      985:        /* Return to the new LWP, returning 'oldlwp' in %eax. */
                    986: 4:     movl    %esi,%eax
1.1       fvdl      987:        popl    %edi
                    988:        popl    %esi
                    989:        popl    %ebx
                    990:        ret
1.20      dsl       991:
1.48      yamt      992:        /* Check for restartable atomic sequences (RAS). */
                    993: 5:     movl    L_MD_REGS(%edi),%ecx
                    994:        pushl   TF_EIP(%ecx)
1.20      dsl       995:        pushl   %eax
                    996:        call    _C_LABEL(ras_lookup)
                    997:        addl    $8,%esp
                    998:        cmpl    $-1,%eax
1.48      yamt      999:        je      2b
1.49      ad       1000:        movl    L_MD_REGS(%edi),%ecx
                   1001:        movl    %eax,TF_EIP(%ecx)
1.48      yamt     1002:        jmp     2b
1.1       fvdl     1003:
1.58.6.3! bouyer   1004: .Lcopy_iobitmap:
        !          1005:        /* Copy I/O bitmap. */
        !          1006:        movl    $(IOMAPSIZE/4),%ecx
        !          1007:        pushl   %esi
        !          1008:        pushl   %edi
        !          1009:        movl    %eax,%esi               /* pcb_iomap */
        !          1010:        movl    CPUVAR(SELF),%edi
        !          1011:        leal    CPU_INFO_IOMAP(%edi),%edi
        !          1012:        rep
        !          1013:        movsl
        !          1014:        popl    %edi
        !          1015:        popl    %esi
        !          1016:        movl    $((CPU_INFO_IOMAP - CPU_INFO_TSS) << 16),CPUVAR(IOBASE)
        !          1017:        jmp     .Liobitmap_done
        !          1018:
1.1       fvdl     1019: /*
                   1020:  * void savectx(struct pcb *pcb);
1.48      yamt     1021:  *
1.1       fvdl     1022:  * Update pcb, saving current processor state.
                   1023:  */
                   1024: ENTRY(savectx)
1.47      skrll    1025:        movl    4(%esp),%edx            # edx = pcb
1.1       fvdl     1026:        movl    %esp,PCB_ESP(%edx)
                   1027:        movl    %ebp,PCB_EBP(%edx)
                   1028:        ret
                   1029:
                   1030: /*
1.48      yamt     1031:  * osyscall()
                   1032:  *
1.1       fvdl     1033:  * Old call gate entry for syscall
                   1034:  */
                   1035: IDTVEC(osyscall)
1.48      yamt     1036:        pushfl                  # set eflags in trap frame
1.1       fvdl     1037:        popl    8(%esp)
                   1038:        pushl   $7              # size of instruction for restart
                   1039:        jmp     syscall1
                   1040:
                   1041: /*
1.48      yamt     1042:  * syscall()
                   1043:  *
1.1       fvdl     1044:  * Trap gate entry for syscall
                   1045:  */
                   1046: IDTVEC(syscall)
                   1047:        pushl   $2              # size of instruction for restart
                   1048: syscall1:
                   1049:        pushl   $T_ASTFLT       # trap # for doing ASTs
                   1050:        INTRENTRY
                   1051:
                   1052: #ifdef DIAGNOSTIC
1.24      yamt     1053:        cmpl    $0, CPUVAR(WANT_PMAPLOAD)
                   1054:        jz      1f
                   1055:        pushl   $6f
                   1056:        call    _C_LABEL(printf)
                   1057:        addl    $4, %esp
                   1058: 1:
1.1       fvdl     1059:        movl    CPUVAR(ILEVEL),%ebx
                   1060:        testl   %ebx,%ebx
                   1061:        jz      1f
                   1062:        pushl   $5f
                   1063:        call    _C_LABEL(printf)
                   1064:        addl    $4,%esp
                   1065: #ifdef DDB
                   1066:        int     $3
                   1067: #endif
1.30      junyoung 1068: 1:
1.1       fvdl     1069: #endif /* DIAGNOSTIC */
1.5       thorpej  1070:        movl    CPUVAR(CURLWP),%edx
                   1071:        movl    %esp,L_MD_REGS(%edx)    # save pointer to frame
                   1072:        movl    L_PROC(%edx),%edx
1.15      fvdl     1073:        pushl   %esp
1.1       fvdl     1074:        call    *P_MD_SYSCALL(%edx)     # get pointer to syscall() function
1.15      fvdl     1075:        addl    $4,%esp
1.27      yamt     1076: .Lsyscall_checkast:
1.24      yamt     1077:        /* Check for ASTs on exit to user mode. */
1.58.6.2  bouyer   1078:        CLI(%eax)
1.5       thorpej  1079:        CHECK_ASTPENDING(%eax)
1.1       fvdl     1080:        je      1f
                   1081:        /* Always returning to user mode here. */
1.5       thorpej  1082:        CLEAR_ASTPENDING(%eax)
1.58.6.2  bouyer   1083:        STI(%eax)
1.1       fvdl     1084:        /* Pushed T_ASTFLT into tf_trapno on entry. */
1.15      fvdl     1085:        pushl   %esp
1.1       fvdl     1086:        call    _C_LABEL(trap)
1.15      fvdl     1087:        addl    $4,%esp
1.27      yamt     1088:        jmp     .Lsyscall_checkast      /* re-check ASTs */
1.53      yamt     1089: 1:     CHECK_DEFERRED_SWITCH
1.24      yamt     1090:        jnz     9f
1.58.6.2  bouyer   1091: #ifdef XEN
                   1092:        STIC(%eax)
                   1093:        jz      14f
                   1094:        call    _C_LABEL(stipending)
                   1095:        testl   %eax,%eax
                   1096:        jz      14f
                   1097:        /* process pending interrupts */
                   1098:        CLI(%eax)
                   1099:        movl    CPUVAR(ILEVEL), %ebx
                   1100:        movl    $.Lsyscall_resume, %esi # address to resume loop at
                   1101: .Lsyscall_resume:
                   1102:        movl    %ebx,%eax       # get cpl
                   1103:        movl    CPUVAR(IUNMASK)(,%eax,4),%eax
                   1104:        andl    CPUVAR(IPENDING),%eax   # any non-masked bits left?
                   1105:        jz      17f
                   1106:        bsrl    %eax,%eax
                   1107:        btrl    %eax,CPUVAR(IPENDING)
                   1108:        movl    CPUVAR(ISOURCES)(,%eax,4),%eax
                   1109:        jmp     *IS_RESUME(%eax)
                   1110: 17:    movl    %ebx, CPUVAR(ILEVEL)    #restore cpl
                   1111:        jmp     .Lsyscall_checkast
                   1112: 14:
                   1113: #endif /* XEN */
1.1       fvdl     1114: #ifndef DIAGNOSTIC
1.24      yamt     1115:        INTRFASTEXIT
1.1       fvdl     1116: #else /* DIAGNOSTIC */
1.24      yamt     1117:        cmpl    $IPL_NONE,CPUVAR(ILEVEL)
1.1       fvdl     1118:        jne     3f
                   1119:        INTRFASTEXIT
1.58.6.2  bouyer   1120: 3:     STI(%eax)
1.1       fvdl     1121:        pushl   $4f
                   1122:        call    _C_LABEL(printf)
                   1123:        addl    $4,%esp
1.58      ad       1124:        pushl   $IPL_NONE
                   1125:        call    _C_LABEL(spllower)
                   1126:        addl    $4,%esp
1.53      yamt     1127:        jmp     .Lsyscall_checkast
1.1       fvdl     1128: 4:     .asciz  "WARNING: SPL NOT LOWERED ON SYSCALL EXIT\n"
1.30      junyoung 1129: 5:     .asciz  "WARNING: SPL NOT ZERO ON SYSCALL ENTRY\n"
                   1130: 6:     .asciz  "WARNING: WANT PMAPLOAD ON SYSCALL ENTRY\n"
1.1       fvdl     1131: #endif /* DIAGNOSTIC */
1.58.6.2  bouyer   1132: 9:     STI(%eax)
1.24      yamt     1133:        call    _C_LABEL(pmap_load)
1.27      yamt     1134:        jmp     .Lsyscall_checkast      /* re-check ASTs */
1.1       fvdl     1135:
                   1136: #if NNPX > 0
                   1137: /*
                   1138:  * Special interrupt handlers.  Someday intr0-intr15 will be used to count
                   1139:  * interrupts.  We'll still need a special exception 16 handler.  The busy
                   1140:  * latch stuff in probintr() can be moved to npxprobe().
                   1141:  */
                   1142:
1.48      yamt     1143: /*
                   1144:  * void probeintr(void)
                   1145:  */
1.1       fvdl     1146: NENTRY(probeintr)
                   1147:        ss
                   1148:        incl    _C_LABEL(npx_intrs_while_probing)
                   1149:        pushl   %eax
                   1150:        movb    $0x20,%al       # EOI (asm in strings loses cpp features)
                   1151:        outb    %al,$0xa0       # IO_ICU2
                   1152:        outb    %al,$0x20       # IO_ICU1
                   1153:        movb    $0,%al
                   1154:        outb    %al,$0xf0       # clear BUSY# latch
                   1155:        popl    %eax
                   1156:        iret
                   1157:
1.48      yamt     1158: /*
                   1159:  * void probetrap(void)
                   1160:  */
1.1       fvdl     1161: NENTRY(probetrap)
                   1162:        ss
                   1163:        incl    _C_LABEL(npx_traps_while_probing)
                   1164:        fnclex
                   1165:        iret
                   1166:
1.48      yamt     1167: /*
                   1168:  * int npx586bug1(int a, int b)
                   1169:  */
1.1       fvdl     1170: NENTRY(npx586bug1)
                   1171:        fildl   4(%esp)         # x
                   1172:        fildl   8(%esp)         # y
                   1173:        fld     %st(1)
                   1174:        fdiv    %st(1),%st      # x/y
                   1175:        fmulp   %st,%st(1)      # (x/y)*y
                   1176:        fsubrp  %st,%st(1)      # x-(x/y)*y
                   1177:        pushl   $0
                   1178:        fistpl  (%esp)
                   1179:        popl    %eax
                   1180:        ret
                   1181: #endif /* NNPX > 0 */
1.50      ad       1182:
                   1183: /*
                   1184:  * void sse2_zero_page(void *pg)
                   1185:  *
                   1186:  * Zero a page without polluting the cache.
                   1187:  */
                   1188: ENTRY(sse2_zero_page)
                   1189:        pushl   %ebp
                   1190:        movl    %esp,%ebp
                   1191:        movl    8(%esp), %edx
                   1192:        movl    $PAGE_SIZE, %ecx
                   1193:        xorl    %eax, %eax
                   1194:        .align  16
                   1195: 1:
                   1196:        movnti  %eax, 0(%edx)
                   1197:        movnti  %eax, 4(%edx)
                   1198:        movnti  %eax, 8(%edx)
                   1199:        movnti  %eax, 12(%edx)
                   1200:        movnti  %eax, 16(%edx)
                   1201:        movnti  %eax, 20(%edx)
                   1202:        movnti  %eax, 24(%edx)
                   1203:        movnti  %eax, 28(%edx)
                   1204:        subl    $32, %ecx
                   1205:        leal    32(%edx), %edx
                   1206:        jnz     1b
                   1207:        sfence
                   1208:        pop     %ebp
                   1209:        ret
                   1210:
                   1211: /*
                   1212:  * void sse2_copy_page(void *src, void *dst)
                   1213:  *
                   1214:  * Copy a page without polluting the cache.
                   1215:  */
                   1216: ENTRY(sse2_copy_page)
                   1217:        pushl   %ebp
                   1218:        pushl   %ebx
                   1219:        pushl   %esi
                   1220:        pushl   %edi
                   1221:        movl    20(%esp), %esi
                   1222:        movl    24(%esp), %edi
                   1223:        movl    $PAGE_SIZE, %ebp
                   1224:        .align  16
                   1225: 1:
                   1226:        movl    0(%esi), %eax
                   1227:        movl    4(%esi), %ebx
                   1228:        movl    8(%esi), %ecx
                   1229:        movl    12(%esi), %edx
                   1230:        movnti  %eax, 0(%edi)
                   1231:        movnti  %ebx, 4(%edi)
                   1232:        movnti  %ecx, 8(%edi)
                   1233:        movnti  %edx, 12(%edi)
                   1234:        subl    $16, %ebp
                   1235:        leal    16(%esi), %esi
                   1236:        leal    16(%edi), %edi
                   1237:        jnz     1b
                   1238:        sfence
                   1239:        popl    %edi
                   1240:        popl    %esi
                   1241:        popl    %ebx
                   1242:        popl    %ebp
                   1243:        ret

CVSweb <webmaster@jp.NetBSD.org>