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

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

CVSweb <webmaster@jp.NetBSD.org>