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

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

CVSweb <webmaster@jp.NetBSD.org>