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

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

CVSweb <webmaster@jp.NetBSD.org>