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

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

CVSweb <webmaster@jp.NetBSD.org>