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

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

CVSweb <webmaster@jp.NetBSD.org>