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

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

CVSweb <webmaster@jp.NetBSD.org>