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

1.11    ! drochner    1: /*     $NetBSD: locore.S,v 1.10 2003/05/13 09:35:16 fvdl Exp $ */
1.1       fvdl        2:
                      3: /*-
                      4:  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
                      5:  * All rights reserved.
                      6:  *
                      7:  * This code is derived from software contributed to The NetBSD Foundation
                      8:  * by Charles M. Hannum.
                      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:  * 3. All advertising materials mentioning features or use of this software
                     19:  *    must display the following acknowledgement:
                     20:  *        This product includes software developed by the NetBSD
                     21:  *        Foundation, Inc. and its contributors.
                     22:  * 4. Neither the name of The NetBSD Foundation nor the names of its
                     23:  *    contributors may be used to endorse or promote products derived
                     24:  *    from this software without specific prior written permission.
                     25:  *
                     26:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     27:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     28:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     29:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     30:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     31:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     32:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     33:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     34:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     35:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     36:  * POSSIBILITY OF SUCH DAMAGE.
                     37:  */
                     38:
                     39: /*-
                     40:  * Copyright (c) 1990 The Regents of the University of California.
                     41:  * All rights reserved.
                     42:  *
                     43:  * This code is derived from software contributed to Berkeley by
                     44:  * William Jolitz.
                     45:  *
                     46:  * Redistribution and use in source and binary forms, with or without
                     47:  * modification, are permitted provided that the following conditions
                     48:  * are met:
                     49:  * 1. Redistributions of source code must retain the above copyright
                     50:  *    notice, this list of conditions and the following disclaimer.
                     51:  * 2. Redistributions in binary form must reproduce the above copyright
                     52:  *    notice, this list of conditions and the following disclaimer in the
                     53:  *    documentation and/or other materials provided with the distribution.
                     54:  * 3. All advertising materials mentioning features or use of this software
                     55:  *    must display the following acknowledgement:
                     56:  *     This product includes software developed by the University of
                     57:  *     California, Berkeley and its contributors.
                     58:  * 4. Neither the name of the University nor the names of its contributors
                     59:  *    may be used to endorse or promote products derived from this software
                     60:  *    without specific prior written permission.
                     61:  *
                     62:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     63:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     64:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     65:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     66:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     67:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     68:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     69:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     70:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     71:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     72:  * SUCH DAMAGE.
                     73:  *
                     74:  *     @(#)locore.s    7.3 (Berkeley) 5/13/91
                     75:  */
                     76:
                     77: #include "opt_cputype.h"
                     78: #include "opt_ddb.h"
                     79: #include "opt_ipkdb.h"
                     80: #include "opt_vm86.h"
                     81: #include "opt_user_ldt.h"
                     82: #include "opt_dummy_nops.h"
                     83: #include "opt_compat_oldboot.h"
                     84: #include "opt_multiprocessor.h"
                     85: #include "opt_lockdebug.h"
                     86: #include "opt_realmem.h"
                     87:
                     88: #include "npx.h"
                     89: #include "assym.h"
                     90: #include "apm.h"
                     91: #include "lapic.h"
                     92: #include "ioapic.h"
1.8       fvdl       93: #include "ksyms.h"
1.1       fvdl       94:
                     95: #include <sys/errno.h>
                     96: #include <sys/syscall.h>
                     97:
                     98: #include <machine/cputypes.h>
                     99: #include <machine/param.h>
                    100: #include <machine/pte.h>
                    101: #include <machine/segments.h>
                    102: #include <machine/specialreg.h>
                    103: #include <machine/trap.h>
                    104: #include <machine/bootinfo.h>
                    105:
                    106: #if NLAPIC > 0
                    107: #include <machine/i82489reg.h>
                    108: #endif
                    109:
                    110: /* LINTSTUB: include <sys/types.h> */
                    111: /* LINTSTUB: include <machine/cpu.h> */
                    112: /* LINTSTUB: include <sys/systm.h> */
                    113:
                    114: #include <machine/asm.h>
                    115:
                    116: #if defined(MULTIPROCESSOR)
                    117:
1.5       thorpej   118: #define SET_CURLWP(lwp,cpu)                            \
1.1       fvdl      119:        movl    CPUVAR(SELF),cpu                ;       \
1.5       thorpej   120:        movl    lwp,CPUVAR(CURLWP)      ;       \
                    121:        movl    cpu,L_CPU(lwp)
1.1       fvdl      122:
                    123: #else
                    124:
1.5       thorpej   125: #define SET_CURLWP(lwp,tcpu)           movl    lwp,CPUVAR(CURLWP)
                    126: #define GET_CURLWP(reg)                        movl    CPUVAR(CURLWP),reg
1.1       fvdl      127:
                    128: #endif
                    129:
                    130: #define GET_CURPCB(reg)                        movl    CPUVAR(CURPCB),reg
                    131: #define SET_CURPCB(reg)                        movl    reg,CPUVAR(CURPCB)
                    132:
                    133: #define CLEAR_RESCHED(reg)             movl    reg,CPUVAR(RESCHED)
                    134:
                    135: /* XXX temporary kluge; these should not be here */
                    136: /* Get definitions for IOM_BEGIN, IOM_END, and IOM_SIZE */
                    137: #include <dev/isa/isareg.h>
                    138:
                    139:
                    140: /* Disallow old names for REALBASEMEM */
                    141: #ifdef BIOSBASEMEM
                    142: #error BIOSBASEMEM option deprecated; use REALBASEMEM only if memory size reported by latest boot block is incorrect
                    143: #endif
                    144:
                    145: /* Disallow old names for REALEXTMEM */
                    146: #ifdef EXTMEM_SIZE
                    147: #error EXTMEM_SIZE option deprecated; use REALEXTMEM only if memory size reported by latest boot block is incorrect
                    148: #endif
                    149: #ifdef BIOSEXTMEM
                    150: #error BIOSEXTMEM option deprecated; use REALEXTMEM only if memory size reported by latest boot block is incorrect
                    151: #endif
                    152:
                    153: #include <machine/frameasm.h>
                    154:
                    155:
                    156: #ifdef MULTIPROCESSOR
                    157: #include <machine/i82489reg.h>
                    158: #endif
                    159:
                    160: /*
                    161:  * PTmap is recursive pagemap at top of virtual address space.
                    162:  * Within PTmap, the page directory can be found (third indirection).
                    163:  *
                    164:  * XXX 4 == sizeof pde
                    165:  */
                    166:        .set    _C_LABEL(PTmap),(PDSLOT_PTE << PDSHIFT)
1.7       thorpej   167:        .set    _C_LABEL(PTD),(_C_LABEL(PTmap) + PDSLOT_PTE * PAGE_SIZE)
1.1       fvdl      168:        .set    _C_LABEL(PTDpde),(_C_LABEL(PTD) + PDSLOT_PTE * 4)
                    169:
                    170: /*
                    171:  * APTmap, APTD is the alternate recursive pagemap.
                    172:  * It's used when modifying another process's page tables.
                    173:  *
                    174:  * XXX 4 == sizeof pde
                    175:  */
                    176:        .set    _C_LABEL(APTmap),(PDSLOT_APTE << PDSHIFT)
1.7       thorpej   177:        .set    _C_LABEL(APTD),(_C_LABEL(APTmap) + PDSLOT_APTE * PAGE_SIZE)
1.1       fvdl      178:        .set    _C_LABEL(APTDpde),(_C_LABEL(PTD) + PDSLOT_APTE * 4)
                    179:
                    180:
                    181: /*
                    182:  * Initialization
                    183:  */
                    184:        .data
                    185:
                    186:        .globl  _C_LABEL(cpu)
                    187:        .globl  _C_LABEL(esym),_C_LABEL(boothowto)
                    188:        .globl  _C_LABEL(bootinfo),_C_LABEL(atdevbase)
                    189: #ifdef COMPAT_OLDBOOT
                    190:        .globl  _C_LABEL(bootdev)
                    191: #endif
                    192:        .globl  _C_LABEL(proc0paddr),_C_LABEL(PTDpaddr)
                    193:        .globl  _C_LABEL(biosbasemem),_C_LABEL(biosextmem)
                    194:        .globl  _C_LABEL(gdt)
                    195: #ifdef I586_CPU
                    196:        .globl  _C_LABEL(idt)
                    197: #endif
                    198:        .globl  _C_LABEL(lapic_tpr)
                    199:
                    200: #if NLAPIC > 0
                    201: #ifdef __ELF__
1.7       thorpej   202:        .align  PAGE_SIZE
1.1       fvdl      203: #else
                    204:        .align  12
                    205: #endif
                    206:        .globl _C_LABEL(local_apic), _C_LABEL(lapic_id)
                    207: _C_LABEL(local_apic):
                    208:        .space  LAPIC_ID
                    209: _C_LABEL(lapic_id):
                    210:        .long   0x00000000
                    211:        .space  LAPIC_TPRI-(LAPIC_ID+4)
                    212: _C_LABEL(lapic_tpr):
                    213:        .space  LAPIC_PPRI-LAPIC_TPRI
                    214: _C_LABEL(lapic_ppr):
                    215:        .space  LAPIC_ISR-LAPIC_PPRI
                    216: _C_LABEL(lapic_isr):
1.7       thorpej   217:        .space  PAGE_SIZE-LAPIC_ISR
1.1       fvdl      218: #else
                    219: _C_LABEL(lapic_tpr):
                    220:        .long 0
                    221: #endif
                    222:
                    223:
                    224: _C_LABEL(cpu):         .long   0       # are we 386, 386sx, or 486,
                    225:                                        #   or Pentium, or..
                    226: _C_LABEL(esym):                .long   0       # ptr to end of syms
                    227: _C_LABEL(atdevbase):   .long   0       # location of start of iomem in virtual
                    228: _C_LABEL(proc0paddr):  .long   0
                    229: _C_LABEL(PTDpaddr):    .long   0       # paddr of PTD, for libkvm
                    230: #ifndef REALBASEMEM
                    231: _C_LABEL(biosbasemem): .long   0       # base memory reported by BIOS
                    232: #else
                    233: _C_LABEL(biosbasemem): .long   REALBASEMEM
                    234: #endif
                    235: #ifndef REALEXTMEM
                    236: _C_LABEL(biosextmem):  .long   0       # extended memory reported by BIOS
                    237: #else
                    238: _C_LABEL(biosextmem):  .long   REALEXTMEM
                    239: #endif
                    240:
                    241:        .space 512
                    242: tmpstk:
                    243:
                    244:
                    245: #define        _RELOC(x)       ((x) - KERNBASE)
                    246: #define        RELOC(x)        _RELOC(_C_LABEL(x))
                    247:
                    248:        .text
                    249:        .globl  _C_LABEL(kernel_text)
                    250:        .set    _C_LABEL(kernel_text),KERNTEXTOFF
                    251:
                    252:        .globl  start
                    253: start: movw    $0x1234,0x472                   # warm boot
                    254:
                    255:        /*
                    256:         * Load parameters from stack
                    257:         * (howto, [bootdev], bootinfo, esym, basemem, extmem).
                    258:         */
                    259:        movl    4(%esp),%eax
                    260:        movl    %eax,RELOC(boothowto)
                    261: #ifdef COMPAT_OLDBOOT
                    262:        movl    8(%esp),%eax
                    263:        movl    %eax,RELOC(bootdev)
                    264: #endif
                    265:        movl    12(%esp),%eax
                    266:
                    267:        testl   %eax, %eax
                    268:        jz      1f
                    269:        movl    (%eax), %ebx            /* number of entries */
                    270:        movl    $RELOC(bootinfo), %edi
                    271:        movl    %ebx, (%edi)
                    272:        addl    $4, %edi
                    273: 2:
                    274:        testl   %ebx, %ebx
                    275:        jz      1f
                    276:        addl    $4, %eax
                    277:        movl    (%eax), %ecx            /* address of entry */
                    278:        pushl   %eax
                    279:        pushl   (%ecx)                  /* len */
                    280:        pushl   %ecx
                    281:        pushl   %edi
                    282:        addl    (%ecx), %edi            /* update dest pointer */
                    283:        cmpl    $_RELOC(_C_LABEL(bootinfo) + BOOTINFO_MAXSIZE), %edi
                    284:        jg      2f
                    285:        call    _C_LABEL(memcpy)
                    286:        addl    $12, %esp
                    287:        popl    %eax
                    288:        subl    $1, %ebx
                    289:        jmp     2b
                    290: 2:     /* cleanup for overflow case */
                    291:        addl    $16, %esp
                    292:        movl    $RELOC(bootinfo), %edi
                    293:        subl    %ebx, (%edi)            /* correct number of entries */
                    294: 1:
                    295:
                    296:        movl    16(%esp),%eax
                    297:        testl   %eax,%eax
                    298:        jz      1f
                    299:        addl    $KERNBASE,%eax
                    300: 1:     movl    %eax,RELOC(esym)
                    301:
                    302:        movl    RELOC(biosextmem),%eax
                    303:        testl   %eax,%eax
                    304:        jnz     1f
                    305:        movl    20(%esp),%eax
                    306:        movl    %eax,RELOC(biosextmem)
                    307: 1:
                    308:        movl    RELOC(biosbasemem),%eax
                    309:        testl   %eax,%eax
                    310:        jnz     1f
                    311:        movl    24(%esp),%eax
                    312:        movl    %eax,RELOC(biosbasemem)
                    313: 1:
                    314:
                    315:        /* First, reset the PSL. */
                    316:        pushl   $PSL_MBO
                    317:        popfl
                    318:
                    319:        /* Clear segment registers; always null in proc0. */
                    320:        xorl    %eax,%eax
                    321:        movw    %ax,%fs
                    322:        movw    %ax,%gs
                    323:        decl    %eax
                    324:        movl    %eax,RELOC(cpu_info_primary)+CPU_INFO_LEVEL
                    325:
                    326:        /* Find out our CPU type. */
                    327:
                    328: try386:        /* Try to toggle alignment check flag; does not exist on 386. */
                    329:        pushfl
                    330:        popl    %eax
                    331:        movl    %eax,%ecx
                    332:        orl     $PSL_AC,%eax
                    333:        pushl   %eax
                    334:        popfl
                    335:        pushfl
                    336:        popl    %eax
                    337:        xorl    %ecx,%eax
                    338:        andl    $PSL_AC,%eax
                    339:        pushl   %ecx
                    340:        popfl
                    341:
                    342:        testl   %eax,%eax
                    343:        jnz     try486
                    344:
                    345:        /*
                    346:         * Try the test of a NexGen CPU -- ZF will not change on a DIV
                    347:         * instruction on a NexGen, it will on an i386.  Documented in
                    348:         * Nx586 Processor Recognition Application Note, NexGen, Inc.
                    349:         */
                    350:        movl    $0x5555,%eax
                    351:        xorl    %edx,%edx
                    352:        movl    $2,%ecx
                    353:        divl    %ecx
                    354:        jnz     is386
                    355:
                    356: isnx586:
                    357:        /*
                    358:         * Don't try cpuid, as Nx586s reportedly don't support the
                    359:         * PSL_ID bit.
                    360:         */
                    361:        movl    $CPU_NX586,RELOC(cpu)
                    362:        jmp     2f
                    363:
                    364: is386:
                    365:        movl    $CPU_386,RELOC(cpu)
                    366:        jmp     2f
                    367:
                    368: try486:        /* Try to toggle identification flag; does not exist on early 486s. */
                    369:        pushfl
                    370:        popl    %eax
                    371:        movl    %eax,%ecx
                    372:        xorl    $PSL_ID,%eax
                    373:        pushl   %eax
                    374:        popfl
                    375:        pushfl
                    376:        popl    %eax
                    377:        xorl    %ecx,%eax
                    378:        andl    $PSL_ID,%eax
                    379:        pushl   %ecx
                    380:        popfl
                    381:
                    382:        testl   %eax,%eax
                    383:        jnz     try586
                    384: is486: movl    $CPU_486,RELOC(cpu)
                    385:        /*
                    386:         * Check Cyrix CPU
                    387:         * Cyrix CPUs do not change the undefined flags following
                    388:         * execution of the divide instruction which divides 5 by 2.
                    389:         *
                    390:         * Note: CPUID is enabled on M2, so it passes another way.
                    391:         */
                    392:        pushfl
                    393:        movl    $0x5555, %eax
                    394:        xorl    %edx, %edx
                    395:        movl    $2, %ecx
                    396:        clc
                    397:        divl    %ecx
                    398:        jnc     trycyrix486
                    399:        popfl
                    400:        jmp 2f
                    401: trycyrix486:
                    402:        movl    $CPU_6x86,RELOC(cpu)    # set CPU type
                    403:        /*
                    404:         * Check for Cyrix 486 CPU by seeing if the flags change during a
                    405:         * divide. This is documented in the Cx486SLC/e SMM Programmer's
                    406:         * Guide.
                    407:         */
                    408:        xorl    %edx,%edx
                    409:        cmpl    %edx,%edx               # set flags to known state
                    410:        pushfl
                    411:        popl    %ecx                    # store flags in ecx
                    412:        movl    $-1,%eax
                    413:        movl    $4,%ebx
                    414:        divl    %ebx                    # do a long division
                    415:        pushfl
                    416:        popl    %eax
                    417:        xorl    %ecx,%eax               # are the flags different?
                    418:        testl   $0x8d5,%eax             # only check C|PF|AF|Z|N|V
                    419:        jne     2f                      # yes; must be Cyrix 6x86 CPU
                    420:        movl    $CPU_486DLC,RELOC(cpu)  # set CPU type
                    421:
                    422: #ifndef CYRIX_CACHE_WORKS
                    423:        /* Disable caching of the ISA hole only. */
                    424:        invd
                    425:        movb    $CCR0,%al               # Configuration Register index (CCR0)
                    426:        outb    %al,$0x22
                    427:        inb     $0x23,%al
                    428:        orb     $(CCR0_NC1|CCR0_BARB),%al
                    429:        movb    %al,%ah
                    430:        movb    $CCR0,%al
                    431:        outb    %al,$0x22
                    432:        movb    %ah,%al
                    433:        outb    %al,$0x23
                    434:        invd
                    435: #else /* CYRIX_CACHE_WORKS */
                    436:        /* Set cache parameters */
                    437:        invd                            # Start with guaranteed clean cache
                    438:        movb    $CCR0,%al               # Configuration Register index (CCR0)
                    439:        outb    %al,$0x22
                    440:        inb     $0x23,%al
                    441:        andb    $~CCR0_NC0,%al
                    442: #ifndef CYRIX_CACHE_REALLY_WORKS
                    443:        orb     $(CCR0_NC1|CCR0_BARB),%al
                    444: #else
                    445:        orb     $CCR0_NC1,%al
                    446: #endif
                    447:        movb    %al,%ah
                    448:        movb    $CCR0,%al
                    449:        outb    %al,$0x22
                    450:        movb    %ah,%al
                    451:        outb    %al,$0x23
                    452:        /* clear non-cacheable region 1 */
                    453:        movb    $(NCR1+2),%al
                    454:        outb    %al,$0x22
                    455:        movb    $NCR_SIZE_0K,%al
                    456:        outb    %al,$0x23
                    457:        /* clear non-cacheable region 2 */
                    458:        movb    $(NCR2+2),%al
                    459:        outb    %al,$0x22
                    460:        movb    $NCR_SIZE_0K,%al
                    461:        outb    %al,$0x23
                    462:        /* clear non-cacheable region 3 */
                    463:        movb    $(NCR3+2),%al
                    464:        outb    %al,$0x22
                    465:        movb    $NCR_SIZE_0K,%al
                    466:        outb    %al,$0x23
                    467:        /* clear non-cacheable region 4 */
                    468:        movb    $(NCR4+2),%al
                    469:        outb    %al,$0x22
                    470:        movb    $NCR_SIZE_0K,%al
                    471:        outb    %al,$0x23
                    472:        /* enable caching in CR0 */
                    473:        movl    %cr0,%eax
                    474:        andl    $~(CR0_CD|CR0_NW),%eax
                    475:        movl    %eax,%cr0
                    476:        invd
                    477: #endif /* CYRIX_CACHE_WORKS */
                    478:
                    479:        jmp     2f
                    480:
                    481: try586:        /* Use the `cpuid' instruction. */
                    482:        xorl    %eax,%eax
                    483:        cpuid
                    484:        movl    %eax,RELOC(cpu_info_primary)+CPU_INFO_LEVEL
                    485:
                    486: 2:
                    487:        /*
                    488:         * Finished with old stack; load new %esp now instead of later so we
                    489:         * can trace this code without having to worry about the trace trap
                    490:         * clobbering the memory test or the zeroing of the bss+bootstrap page
                    491:         * tables.
                    492:         *
                    493:         * The boot program should check:
                    494:         *      text+data <= &stack_variable - more_space_for_stack
                    495:         *      text+data+bss+pad+space_for_page_tables <= end_of_memory
                    496:         * Oops, the gdt is in the carcass of the boot program so clearing
                    497:         * the rest of memory is still not possible.
                    498:         */
                    499:        movl    $_RELOC(tmpstk),%esp    # bootstrap stack end location
                    500:
                    501: /*
                    502:  * Virtual address space of kernel:
                    503:  *
                    504:  * text | data | bss | [syms] | page dir | proc0 kstack
                    505:  *                           0          1       2      3
                    506:  */
1.7       thorpej   507: #define        PROC0PDIR       ((0)              * PAGE_SIZE)
                    508: #define        PROC0STACK      ((1)              * PAGE_SIZE)
                    509: #define        SYSMAP          ((1+UPAGES)       * PAGE_SIZE)
                    510: #define        TABLESIZE       ((1+UPAGES) * PAGE_SIZE) /* + nkpde * PAGE_SIZE */
1.1       fvdl      511:
                    512:        /* Find end of kernel image. */
                    513:        movl    $RELOC(end),%edi
1.8       fvdl      514: #if (NKSYMS || defined(DDB) || defined(LKM)) && !defined(SYMTAB_SPACE)
1.1       fvdl      515:        /* Save the symbols (if loaded). */
                    516:        movl    RELOC(esym),%eax
                    517:        testl   %eax,%eax
                    518:        jz      1f
                    519:        subl    $KERNBASE,%eax
                    520:        movl    %eax,%edi
                    521: 1:
                    522: #endif
                    523:
                    524:        /* Calculate where to start the bootstrap tables. */
                    525:        movl    %edi,%esi                       # edi = esym ? esym : end
                    526:        addl    $PGOFSET,%esi                   # page align up
                    527:        andl    $~PGOFSET,%esi
                    528:
                    529:        /*
                    530:         * Calculate the size of the kernel page table directory, and
                    531:         * how many entries it will have.
                    532:         */
                    533:        movl    RELOC(nkpde),%ecx               # get nkpde
                    534:        cmpl    $NKPTP_MIN,%ecx                 # larger than min?
                    535:        jge     1f
                    536:        movl    $NKPTP_MIN,%ecx                 # set at min
                    537:        jmp     2f
                    538: 1:     cmpl    $NKPTP_MAX,%ecx                 # larger than max?
                    539:        jle     2f
                    540:        movl    $NKPTP_MAX,%ecx
                    541: 2:
                    542:
                    543:        /* Clear memory for bootstrap tables. */
                    544:        shll    $PGSHIFT,%ecx
                    545:        addl    $TABLESIZE,%ecx
                    546:        addl    %esi,%ecx                       # end of tables
                    547:        subl    %edi,%ecx                       # size of tables
                    548:        shrl    $2,%ecx
                    549:        xorl    %eax,%eax
                    550:        cld
                    551:        rep
                    552:        stosl
                    553:
                    554: /*
                    555:  * fillkpt
                    556:  *     eax = pte (page frame | control | status)
                    557:  *     ebx = page table address
                    558:  *     ecx = number of pages to map
                    559:  */
                    560: #define        fillkpt         \
                    561: 1:     movl    %eax,(%ebx)     ; \
1.7       thorpej   562:        addl    $PAGE_SIZE,%eax ; /* increment physical address */ \
1.1       fvdl      563:        addl    $4,%ebx         ; /* next pte */ \
                    564:        loop    1b              ;
                    565:
                    566: /*
                    567:  * Build initial page tables.
                    568:  */
                    569:        /* Calculate end of text segment, rounded to a page. */
                    570:        leal    (RELOC(etext)+PGOFSET),%edx
                    571:        andl    $~PGOFSET,%edx
                    572:
                    573:        /* Skip over the first 1MB. */
                    574:        movl    $_RELOC(KERNTEXTOFF),%eax
                    575:        movl    %eax,%ecx
                    576:        shrl    $PGSHIFT,%ecx
                    577:        leal    (SYSMAP)(%esi,%ecx,4),%ebx
                    578:
                    579:        /* Map the kernel text read-only. */
                    580:        movl    %edx,%ecx
                    581:        subl    %eax,%ecx
                    582:        shrl    $PGSHIFT,%ecx
                    583:        orl     $(PG_V|PG_KR),%eax
                    584:        fillkpt
                    585:
                    586:        /* Map the data, BSS, and bootstrap tables read-write. */
                    587:        leal    (PG_V|PG_KW)(%edx),%eax
                    588:        movl    RELOC(nkpde),%ecx
                    589:        shll    $PGSHIFT,%ecx
                    590:        addl    $TABLESIZE,%ecx
                    591:        addl    %esi,%ecx                               # end of tables
                    592:        subl    %edx,%ecx                               # subtract end of text
                    593:        shrl    $PGSHIFT,%ecx
                    594:        fillkpt
                    595:
                    596:        /* Map ISA I/O memory. */
                    597:        movl    $(IOM_BEGIN|PG_V|PG_KW/*|PG_N*/),%eax   # having these bits set
                    598:        movl    $(IOM_SIZE>>PGSHIFT),%ecx               # for this many pte s,
                    599:        fillkpt
                    600:
                    601: /*
                    602:  * Construct a page table directory.
                    603:  */
                    604:        /* Install PDEs for temporary double map of kernel. */
                    605:        movl    RELOC(nkpde),%ecx                       # for this many pde s,
                    606:        leal    (PROC0PDIR+0*4)(%esi),%ebx              # which is where temp maps!
                    607:        leal    (SYSMAP+PG_V|PG_KW)(%esi),%eax          # pte for KPT in proc 0,
                    608:        fillkpt
                    609:
                    610:        /* Map kernel PDEs. */
                    611:        movl    RELOC(nkpde),%ecx                       # for this many pde s,
                    612:        leal    (PROC0PDIR+PDSLOT_KERN*4)(%esi),%ebx    # kernel pde offset
                    613:        leal    (SYSMAP+PG_V|PG_KW)(%esi),%eax          # pte for KPT in proc 0,
                    614:        fillkpt
                    615:
                    616:        /* Install a PDE recursively mapping page directory as a page table! */
                    617:        leal    (PROC0PDIR+PG_V|PG_KW)(%esi),%eax       # pte for ptd
                    618:        movl    %eax,(PROC0PDIR+PDSLOT_PTE*4)(%esi)     # recursive PD slot
                    619:
                    620:        /* Save phys. addr of PTD, for libkvm. */
                    621:        movl    %esi,RELOC(PTDpaddr)
                    622:
                    623:        /* Load base of page directory and enable mapping. */
                    624:        movl    %esi,%eax               # phys address of ptd in proc 0
                    625:        movl    %eax,%cr3               # load ptd addr into mmu
                    626:        movl    %cr0,%eax               # get control word
                    627:                                        # enable paging & NPX emulation
                    628:        orl     $(CR0_PE|CR0_PG|CR0_NE|CR0_TS|CR0_EM|CR0_MP),%eax
                    629:        movl    %eax,%cr0               # and let's page NOW!
                    630:
                    631:        pushl   $begin                  # jump to high mem
                    632:        ret
                    633:
                    634: begin:
                    635:        /* Now running relocated at KERNBASE.  Remove double mapping. */
                    636:        movl    _C_LABEL(nkpde),%ecx            # for this many pde s,
                    637:        leal    (PROC0PDIR+0*4)(%esi),%ebx      # which is where temp maps!
                    638:        addl    $(KERNBASE), %ebx       # now use relocated address
                    639: 1:     movl    $0,(%ebx)
                    640:        addl    $4,%ebx # next pde
                    641:        loop    1b
                    642:
                    643:        /* Relocate atdevbase. */
                    644:        movl    _C_LABEL(nkpde),%edx
                    645:        shll    $PGSHIFT,%edx
                    646:        addl    $(TABLESIZE+KERNBASE),%edx
                    647:        addl    %esi,%edx
                    648:        movl    %edx,_C_LABEL(atdevbase)
                    649:
                    650:        /* Set up bootstrap stack. */
                    651:        leal    (PROC0STACK+KERNBASE)(%esi),%eax
                    652:        movl    %eax,_C_LABEL(proc0paddr)
                    653:        leal    (USPACE-FRAMESIZE)(%eax),%esp
                    654:        movl    %esi,PCB_CR3(%eax)      # pcb->pcb_cr3
                    655:        xorl    %ebp,%ebp               # mark end of frames
                    656:
                    657:        subl    $NGDT*8, %esp           # space for temporary gdt
                    658:        pushl   %esp
                    659:        call    _C_LABEL(initgdt)
                    660:        addl    $4,%esp
                    661:
                    662:        movl    _C_LABEL(nkpde),%eax
                    663:        shll    $PGSHIFT,%eax
                    664:        addl    $TABLESIZE,%eax
                    665:        addl    %esi,%eax               # skip past stack and page tables
                    666:
                    667:        pushl   %eax
                    668:        call    _C_LABEL(init386)       # wire 386 chip for unix operation
                    669:        addl    $4+NGDT*8,%esp          # pop temporary gdt
                    670:
                    671: #ifdef SAFARI_FIFO_HACK
                    672:        movb    $5,%al
                    673:        movw    $0x37b,%dx
                    674:        outb    %al,%dx
                    675:        movw    $0x37f,%dx
                    676:        inb     %dx,%al
                    677:        movb    %al,%cl
                    678:
                    679:        orb     $1,%cl
                    680:
                    681:        movb    $5,%al
                    682:        movw    $0x37b,%dx
                    683:        outb    %al,%dx
                    684:        movw    $0x37f,%dx
                    685:        movb    %cl,%al
                    686:        outb    %al,%dx
                    687: #endif /* SAFARI_FIFO_HACK */
                    688:
                    689:        call    _C_LABEL(main)
                    690:
                    691: /*
                    692:  * void proc_trampoline(void);
                    693:  * This is a trampoline function pushed onto the stack of a newly created
                    694:  * process in order to do some additional setup.  The trampoline is entered by
                    695:  * cpu_switch()ing to the process, so we abuse the callee-saved registers used
                    696:  * by cpu_switch() to store the information about the stub to call.
                    697:  * NOTE: This function does not have a normal calling sequence!
                    698:  */
                    699: /* LINTSTUB: Func: void proc_trampoline(void) */
                    700: NENTRY(proc_trampoline)
                    701: #ifdef MULTIPROCESSOR
                    702:        call    _C_LABEL(proc_trampoline_mp)
                    703: #endif
                    704:        movl    $IPL_NONE,CPUVAR(ILEVEL)
                    705:        pushl   %ebx
                    706:        call    *%esi
                    707:        addl    $4,%esp
                    708:        INTRFASTEXIT
                    709:        /* NOTREACHED */
                    710:
                    711: /*****************************************************************************/
                    712:
                    713: /*
                    714:  * Signal trampoline; copied to top of user stack.
                    715:  */
                    716: /* LINTSTUB: Var: char sigcode[1], esigcode[1]; */
                    717: NENTRY(sigcode)
                    718:        /*
                    719:         * Handler has returned here as if we called it.  The sigcontext
                    720:         * is on the stack after the 3 args "we" pushed.
                    721:         */
                    722:        leal    12(%esp),%eax           # get pointer to sigcontext
                    723:        movl    %eax,4(%esp)            # put it in the argument slot
                    724:                                        # fake return address already there
                    725:        movl    $SYS___sigreturn14,%eax
                    726:        int     $0x80                   # enter kernel with args on stack
                    727:        movl    $SYS_exit,%eax
                    728:        int     $0x80                   # exit if sigreturn fails
                    729:        .globl  _C_LABEL(esigcode)
                    730: _C_LABEL(esigcode):
                    731:
                    732: /*****************************************************************************/
                    733:
                    734: /*
                    735:  * The following primitives are used to fill and copy regions of memory.
                    736:  */
                    737:
                    738: /*
                    739:  * XXX No section 9 man page for fillw.
                    740:  * fillw seems to be very sparsely used (only in pccons it seems.)
                    741:  * One wonders if it couldn't be done without.
                    742:  * -- Perry Metzger, May 7, 2001
                    743:  */
                    744: /*
                    745:  * void fillw(short pattern, void *addr, size_t len);
                    746:  * Write len copies of pattern at addr.
                    747:  */
                    748: /* LINTSTUB: Func: void fillw(short pattern, void *addr, size_t len) */
                    749: ENTRY(fillw)
                    750:        pushl   %edi
                    751:        movl    8(%esp),%eax
                    752:        movl    12(%esp),%edi
                    753:        movw    %ax,%cx
                    754:        rorl    $16,%eax
                    755:        movw    %cx,%ax
                    756:        cld
                    757:        movl    16(%esp),%ecx
                    758:        shrl    %ecx                    # do longwords
                    759:        rep
                    760:        stosl
                    761:        movl    16(%esp),%ecx
                    762:        andl    $1,%ecx                 # do remainder
                    763:        rep
                    764:        stosw
                    765:        popl    %edi
                    766:        ret
                    767:
                    768: /*
                    769:  * int kcopy(const void *from, void *to, size_t len);
                    770:  * Copy len bytes, abort on fault.
                    771:  */
                    772: /* LINTSTUB: Func: int kcopy(const void *from, void *to, size_t len) */
                    773: ENTRY(kcopy)
                    774:        pushl   %esi
                    775:        pushl   %edi
                    776:        GET_CURPCB(%eax)                # load curpcb into eax and set on-fault
                    777:        pushl   PCB_ONFAULT(%eax)
                    778:        movl    $_C_LABEL(copy_fault), PCB_ONFAULT(%eax)
                    779:
                    780:        movl    16(%esp),%esi
                    781:        movl    20(%esp),%edi
                    782:        movl    24(%esp),%ecx
                    783:        movl    %edi,%eax
                    784:        subl    %esi,%eax
                    785:        cmpl    %ecx,%eax               # overlapping?
                    786:        jb      1f
                    787:        cld                             # nope, copy forward
                    788:        shrl    $2,%ecx                 # copy by 32-bit words
                    789:        rep
                    790:        movsl
                    791:        movl    24(%esp),%ecx
                    792:        andl    $3,%ecx                 # any bytes left?
                    793:        rep
                    794:        movsb
                    795:
                    796:        GET_CURPCB(%edx)                # XXX save curpcb?
                    797:        popl    PCB_ONFAULT(%edx)
                    798:        popl    %edi
                    799:        popl    %esi
                    800:        xorl    %eax,%eax
                    801:        ret
                    802:
                    803:        ALIGN_TEXT
                    804: 1:     addl    %ecx,%edi               # copy backward
                    805:        addl    %ecx,%esi
                    806:        std
                    807:        andl    $3,%ecx                 # any fractional bytes?
                    808:        decl    %edi
                    809:        decl    %esi
                    810:        rep
                    811:        movsb
                    812:        movl    24(%esp),%ecx           # copy remainder by 32-bit words
                    813:        shrl    $2,%ecx
                    814:        subl    $3,%esi
                    815:        subl    $3,%edi
                    816:        rep
                    817:        movsl
                    818:        cld
                    819:
                    820:        GET_CURPCB(%edx)
                    821:        popl    PCB_ONFAULT(%edx)
                    822:        popl    %edi
                    823:        popl    %esi
                    824:        xorl    %eax,%eax
                    825:        ret
                    826:
                    827: /*****************************************************************************/
                    828:
                    829: /*
                    830:  * The following primitives are used to copy data in and out of the user's
                    831:  * address space.
                    832:  */
                    833:
                    834: /*
                    835:  * Default to the lowest-common-denominator.  We will improve it
                    836:  * later.
                    837:  */
                    838: #if defined(I386_CPU)
                    839: #define        DEFAULT_COPYOUT         _C_LABEL(i386_copyout)
                    840: #define        DEFAULT_COPYIN          _C_LABEL(i386_copyin)
                    841: #elif defined(I486_CPU)
                    842: #define        DEFAULT_COPYOUT         _C_LABEL(i486_copyout)
                    843: #define        DEFAULT_COPYIN          _C_LABEL(i386_copyin)
                    844: #elif defined(I586_CPU)
                    845: #define        DEFAULT_COPYOUT         _C_LABEL(i486_copyout)  /* XXX */
                    846: #define        DEFAULT_COPYIN          _C_LABEL(i386_copyin)   /* XXX */
                    847: #elif defined(I686_CPU)
                    848: #define        DEFAULT_COPYOUT         _C_LABEL(i486_copyout)  /* XXX */
                    849: #define        DEFAULT_COPYIN          _C_LABEL(i386_copyin)   /* XXX */
                    850: #endif
                    851:
                    852:        .data
                    853:
                    854:        .globl  _C_LABEL(copyout_func)
                    855: _C_LABEL(copyout_func):
                    856:        .long   DEFAULT_COPYOUT
                    857:
                    858:        .globl  _C_LABEL(copyin_func)
                    859: _C_LABEL(copyin_func):
                    860:        .long   DEFAULT_COPYIN
                    861:
                    862:        .text
                    863:
                    864: /*
                    865:  * int copyout(const void *from, void *to, size_t len);
                    866:  * Copy len bytes into the user's address space.
                    867:  * see copyout(9)
                    868:  */
                    869: /* LINTSTUB: Func: int copyout(const void *kaddr, void *uaddr, size_t len) */
                    870: ENTRY(copyout)
                    871:        jmp     *_C_LABEL(copyout_func)
                    872:
                    873: #if defined(I386_CPU)
                    874: /* LINTSTUB: Func: int i386_copyout(const void *kaddr, void *uaddr, size_t len) */
                    875: ENTRY(i386_copyout)
                    876:        pushl   %esi
                    877:        pushl   %edi
                    878:        pushl   $0
                    879:
                    880:        movl    16(%esp),%esi
                    881:        movl    20(%esp),%edi
                    882:        movl    24(%esp),%eax
                    883:
                    884:        /*
                    885:         * We check that the end of the destination buffer is not past the end
                    886:         * of the user's address space.  If it's not, then we only need to
                    887:         * check that each page is writable.  The 486 will do this for us; the
                    888:         * 386 will not.  (We assume that pages in user space that are not
                    889:         * writable by the user are not writable by the kernel either.)
                    890:         */
                    891:        movl    %edi,%edx
                    892:        addl    %eax,%edx
                    893:        jc      _C_LABEL(copy_efault)
                    894:        cmpl    $VM_MAXUSER_ADDRESS,%edx
                    895:        ja      _C_LABEL(copy_efault)
                    896:
                    897:        testl   %eax,%eax               # anything to do?
                    898:        jz      3f
                    899:
                    900:        /*
                    901:         * We have to check each PTE for (write) permission, since the CPU
                    902:         * doesn't do it for us.
                    903:         */
                    904:
                    905:        /* Compute number of pages. */
                    906:        movl    %edi,%ecx
                    907:        andl    $PGOFSET,%ecx
                    908:        addl    %eax,%ecx
                    909:        decl    %ecx
                    910:        shrl    $PGSHIFT,%ecx
                    911:
                    912:        /* Compute PTE offset for start address. */
                    913:        shrl    $PGSHIFT,%edi
                    914:
                    915:        GET_CURPCB(%edx)
                    916:        movl    $2f,PCB_ONFAULT(%edx)
                    917:
                    918: 1:     /* Check PTE for each page. */
                    919:        testb   $PG_RW,_C_LABEL(PTmap)(,%edi,4)
                    920:        jz      2f
                    921:
                    922: 4:     incl    %edi
                    923:        decl    %ecx
                    924:        jns     1b
                    925:
                    926:        movl    20(%esp),%edi
                    927:        movl    24(%esp),%eax
                    928:        jmp     3f
                    929:
                    930: 2:     /* Simulate a trap. */
                    931:        pushl   %ecx
                    932:        movl    %edi,%eax
                    933:        shll    $PGSHIFT,%eax
                    934:        pushl   %eax
                    935:        call    _C_LABEL(trapwrite)     # trapwrite(addr)
                    936:        addl    $4,%esp                 # pop argument
                    937:        popl    %ecx
                    938:        testl   %eax,%eax               # if not ok, return EFAULT
                    939:        jz      4b
                    940:        jmp     _C_LABEL(copy_efault)
                    941:
                    942: 3:     GET_CURPCB(%edx)
                    943:        movl    $_C_LABEL(copy_fault),PCB_ONFAULT(%edx)
                    944:
                    945:        /* bcopy(%esi, %edi, %eax); */
                    946:        cld
                    947:        movl    %eax,%ecx
                    948:        shrl    $2,%ecx
                    949:        rep
                    950:        movsl
                    951:        movl    %eax,%ecx
                    952:        andl    $3,%ecx
                    953:        rep
                    954:        movsb
                    955:
                    956:        popl    PCB_ONFAULT(%edx)
                    957:        popl    %edi
                    958:        popl    %esi
                    959:        xorl    %eax,%eax
                    960:        ret
                    961: #endif /* I386_CPU */
                    962:
                    963: #if defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU)
                    964: /* LINTSTUB: Func: int i486_copyout(const void *kaddr, void *uaddr, size_t len) */
                    965: ENTRY(i486_copyout)
                    966:        pushl   %esi
                    967:        pushl   %edi
                    968:        pushl   $0
                    969:
                    970:        movl    16(%esp),%esi
                    971:        movl    20(%esp),%edi
                    972:        movl    24(%esp),%eax
                    973:
                    974:        /*
                    975:         * We check that the end of the destination buffer is not past the end
                    976:         * of the user's address space.
                    977:         */
                    978:        movl    %edi,%edx
                    979:        addl    %eax,%edx
                    980:        jc      _C_LABEL(copy_efault)
                    981:        cmpl    $VM_MAXUSER_ADDRESS,%edx
                    982:        ja      _C_LABEL(copy_efault)
                    983:
                    984:        GET_CURPCB(%edx)
                    985:        movl    $_C_LABEL(copy_fault),PCB_ONFAULT(%edx)
                    986:
                    987:        /* bcopy(%esi, %edi, %eax); */
                    988:        cld
                    989:        movl    %eax,%ecx
                    990:        shrl    $2,%ecx
                    991:        rep
                    992:        movsl
                    993:        movl    %eax,%ecx
                    994:        andl    $3,%ecx
                    995:        rep
                    996:        movsb
                    997:
                    998:        popl    PCB_ONFAULT(%edx)
                    999:        popl    %edi
                   1000:        popl    %esi
                   1001:        xorl    %eax,%eax
                   1002:        ret
                   1003: #endif /* I486_CPU || I586_CPU || I686_CPU */
                   1004:
                   1005: /*
                   1006:  * int copyin(const void *from, void *to, size_t len);
                   1007:  * Copy len bytes from the user's address space.
                   1008:  * see copyin(9)
                   1009:  */
                   1010: /* LINTSTUB: Func: int copyin(const void *uaddr, void *kaddr, size_t len) */
                   1011: ENTRY(copyin)
                   1012:        jmp     *_C_LABEL(copyin_func)
                   1013:
                   1014: #if defined(I386_CPU) || defined(I486_CPU) || defined(I586_CPU) || \
                   1015:     defined(I686_CPU)
                   1016: /* LINTSTUB: Func: int i386_copyin(const void *uaddr, void *kaddr, size_t len) */
                   1017: ENTRY(i386_copyin)
                   1018:        pushl   %esi
                   1019:        pushl   %edi
                   1020:        GET_CURPCB(%eax)
                   1021:        pushl   $0
                   1022:        movl    $_C_LABEL(copy_fault),PCB_ONFAULT(%eax)
                   1023:
                   1024:        movl    16(%esp),%esi
                   1025:        movl    20(%esp),%edi
                   1026:        movl    24(%esp),%eax
                   1027:
                   1028:        /*
                   1029:         * We check that the end of the destination buffer is not past the end
                   1030:         * of the user's address space.  If it's not, then we only need to
                   1031:         * check that each page is readable, and the CPU will do that for us.
                   1032:         */
                   1033:        movl    %esi,%edx
                   1034:        addl    %eax,%edx
                   1035:        jc      _C_LABEL(copy_efault)
                   1036:        cmpl    $VM_MAXUSER_ADDRESS,%edx
                   1037:        ja      _C_LABEL(copy_efault)
                   1038:
                   1039:        /* bcopy(%esi, %edi, %eax); */
                   1040:        cld
                   1041:        movl    %eax,%ecx
                   1042:        shrl    $2,%ecx
                   1043:        rep
                   1044:        movsl
                   1045:        movl    %eax,%ecx
                   1046:        andl    $3,%ecx
                   1047:        rep
                   1048:        movsb
                   1049:
                   1050:        GET_CURPCB(%edx)
                   1051:        popl    PCB_ONFAULT(%edx)
                   1052:        popl    %edi
                   1053:        popl    %esi
                   1054:        xorl    %eax,%eax
                   1055:        ret
                   1056: #endif /* I386_CPU || I486_CPU || I586_CPU || I686_CPU */
                   1057:
                   1058: /* LINTSTUB: Ignore */
                   1059: NENTRY(copy_efault)
                   1060:        movl    $EFAULT,%eax
                   1061:
                   1062: /* LINTSTUB: Ignore */
                   1063: NENTRY(copy_fault)
                   1064:        GET_CURPCB(%edx)
                   1065:        popl    PCB_ONFAULT(%edx)
                   1066:        popl    %edi
                   1067:        popl    %esi
                   1068:        ret
                   1069:
                   1070: /*
                   1071:  * int copyoutstr(const void *from, void *to, size_t maxlen, size_t *lencopied);
                   1072:  * Copy a NUL-terminated string, at most maxlen characters long, into the
                   1073:  * user's address space.  Return the number of characters copied (including the
                   1074:  * NUL) in *lencopied.  If the string is too long, return ENAMETOOLONG; else
                   1075:  * return 0 or EFAULT.
                   1076:  * see copyoutstr(9)
                   1077:  */
                   1078: /* LINTSTUB: Func: int copyoutstr(const void *kaddr, void *uaddr, size_t len, size_t *done) */
                   1079: ENTRY(copyoutstr)
                   1080:        pushl   %esi
                   1081:        pushl   %edi
                   1082:
                   1083:        movl    12(%esp),%esi           # esi = from
                   1084:        movl    16(%esp),%edi           # edi = to
                   1085:        movl    20(%esp),%edx           # edx = maxlen
                   1086:
                   1087: #if defined(I386_CPU)
                   1088: #if defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU)
                   1089:        cmpl    $CPUCLASS_386,_C_LABEL(cpu_class)
                   1090:        jne     5f
                   1091: #endif /* I486_CPU || I586_CPU || I686_CPU */
                   1092:
                   1093:        /* Compute number of bytes in first page. */
                   1094:        movl    %edi,%eax
                   1095:        andl    $PGOFSET,%eax
1.7       thorpej  1096:        movl    $PAGE_SIZE,%ecx
                   1097:        subl    %eax,%ecx               # ecx = PAGE_SIZE - (src % PAGE_SIZE)
1.1       fvdl     1098:
                   1099:        GET_CURPCB(%eax)
                   1100:        movl    $6f,PCB_ONFAULT(%eax)
                   1101:
                   1102: 1:     /*
                   1103:         * Once per page, check that we are still within the bounds of user
                   1104:         * space, and check for a write fault.
                   1105:         */
                   1106:        cmpl    $VM_MAXUSER_ADDRESS,%edi
                   1107:        jae     _C_LABEL(copystr_efault)
                   1108:
                   1109:        /* Compute PTE offset. */
                   1110:        movl    %edi,%eax
                   1111:        shrl    $PGSHIFT,%eax           # calculate pte address
                   1112:
                   1113:        testb   $PG_RW,_C_LABEL(PTmap)(,%eax,4)
                   1114:        jnz     2f
                   1115:
                   1116: 6:     /* Simulate a trap. */
                   1117:        pushl   %edx
                   1118:        pushl   %edi
                   1119:        call    _C_LABEL(trapwrite)     # trapwrite(addr)
                   1120:        addl    $4,%esp                 # clear argument from stack
                   1121:        popl    %edx
                   1122:        testl   %eax,%eax
                   1123:        jnz     _C_LABEL(copystr_efault)
                   1124:
                   1125: 2:     /* Copy up to end of this page. */
                   1126:        subl    %ecx,%edx               # predecrement total count
                   1127:        jnc     3f
                   1128:        addl    %edx,%ecx               # ecx += (edx - ecx) = edx
                   1129:        xorl    %edx,%edx
                   1130:
                   1131: 3:     decl    %ecx
                   1132:        js      4f
                   1133:        lodsb
                   1134:        stosb
                   1135:        testb   %al,%al
                   1136:        jnz     3b
                   1137:
                   1138:        /* Success -- 0 byte reached. */
                   1139:        addl    %ecx,%edx               # add back residual for this page
                   1140:        xorl    %eax,%eax
                   1141:        jmp     copystr_return
                   1142:
                   1143: 4:     /* Go to next page, if any. */
1.7       thorpej  1144:        movl    $PAGE_SIZE,%ecx
1.1       fvdl     1145:        testl   %edx,%edx
                   1146:        jnz     1b
                   1147:
                   1148:        /* edx is zero -- return ENAMETOOLONG. */
                   1149:        movl    $ENAMETOOLONG,%eax
                   1150:        jmp     copystr_return
                   1151: #endif /* I386_CPU */
                   1152:
                   1153: #if defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU)
                   1154: 5:     GET_CURPCB(%eax)
                   1155:        movl    $_C_LABEL(copystr_fault),PCB_ONFAULT(%eax)
                   1156:        /*
                   1157:         * Get min(%edx, VM_MAXUSER_ADDRESS-%edi).
                   1158:         */
                   1159:        movl    $VM_MAXUSER_ADDRESS,%eax
                   1160:        subl    %edi,%eax
                   1161:        cmpl    %edx,%eax
                   1162:        jae     1f
                   1163:        movl    %eax,%edx
                   1164:        movl    %eax,20(%esp)
                   1165:
                   1166: 1:     incl    %edx
                   1167:        cld
                   1168:
                   1169: 1:     decl    %edx
                   1170:        jz      2f
                   1171:        lodsb
                   1172:        stosb
                   1173:        testb   %al,%al
                   1174:        jnz     1b
                   1175:
                   1176:        /* Success -- 0 byte reached. */
                   1177:        decl    %edx
                   1178:        xorl    %eax,%eax
                   1179:        jmp     copystr_return
                   1180:
                   1181: 2:     /* edx is zero -- return EFAULT or ENAMETOOLONG. */
                   1182:        cmpl    $VM_MAXUSER_ADDRESS,%edi
                   1183:        jae     _C_LABEL(copystr_efault)
                   1184:        movl    $ENAMETOOLONG,%eax
                   1185:        jmp     copystr_return
                   1186: #endif /* I486_CPU || I586_CPU || I686_CPU */
                   1187:
                   1188: /*
                   1189:  * int copyinstr(const void *from, void *to, size_t maxlen, size_t *lencopied);
                   1190:  * Copy a NUL-terminated string, at most maxlen characters long, from the
                   1191:  * user's address space.  Return the number of characters copied (including the
                   1192:  * NUL) in *lencopied.  If the string is too long, return ENAMETOOLONG; else
                   1193:  * return 0 or EFAULT.
                   1194:  * see copyinstr(9)
                   1195:  */
                   1196: /* LINTSTUB: Func: int copyinstr(const void *uaddr, void *kaddr, size_t len, size_t *done) */
                   1197: ENTRY(copyinstr)
                   1198:        pushl   %esi
                   1199:        pushl   %edi
                   1200:        GET_CURPCB(%ecx)
                   1201:        movl    $_C_LABEL(copystr_fault),PCB_ONFAULT(%ecx)
                   1202:
                   1203:        movl    12(%esp),%esi           # %esi = from
                   1204:        movl    16(%esp),%edi           # %edi = to
                   1205:        movl    20(%esp),%edx           # %edx = maxlen
                   1206:
                   1207:        /*
                   1208:         * Get min(%edx, VM_MAXUSER_ADDRESS-%esi).
                   1209:         */
                   1210:        movl    $VM_MAXUSER_ADDRESS,%eax
                   1211:        subl    %esi,%eax
                   1212:        cmpl    %edx,%eax
                   1213:        jae     1f
                   1214:        movl    %eax,%edx
                   1215:        movl    %eax,20(%esp)
                   1216:
                   1217: 1:     incl    %edx
                   1218:        cld
                   1219:
                   1220: 1:     decl    %edx
                   1221:        jz      2f
                   1222:        lodsb
                   1223:        stosb
                   1224:        testb   %al,%al
                   1225:        jnz     1b
                   1226:
                   1227:        /* Success -- 0 byte reached. */
                   1228:        decl    %edx
                   1229:        xorl    %eax,%eax
                   1230:        jmp     copystr_return
                   1231:
                   1232: 2:     /* edx is zero -- return EFAULT or ENAMETOOLONG. */
                   1233:        cmpl    $VM_MAXUSER_ADDRESS,%esi
                   1234:        jae     _C_LABEL(copystr_efault)
                   1235:        movl    $ENAMETOOLONG,%eax
                   1236:        jmp     copystr_return
                   1237:
                   1238: /* LINTSTUB: Ignore */
                   1239: NENTRY(copystr_efault)
                   1240:        movl    $EFAULT,%eax
                   1241:
                   1242: /* LINTSTUB: Ignore */
                   1243: NENTRY(copystr_fault)
                   1244: copystr_return:
                   1245:        /* Set *lencopied and return %eax. */
                   1246:        GET_CURPCB(%ecx)
                   1247:        movl    $0,PCB_ONFAULT(%ecx)
                   1248:        movl    20(%esp),%ecx
                   1249:        subl    %edx,%ecx
                   1250:        movl    24(%esp),%edx
                   1251:        testl   %edx,%edx
                   1252:        jz      8f
                   1253:        movl    %ecx,(%edx)
                   1254:
                   1255: 8:     popl    %edi
                   1256:        popl    %esi
                   1257:        ret
                   1258:
                   1259: /*
                   1260:  * int copystr(const void *from, void *to, size_t maxlen, size_t *lencopied);
                   1261:  * Copy a NUL-terminated string, at most maxlen characters long.  Return the
                   1262:  * number of characters copied (including the NUL) in *lencopied.  If the
                   1263:  * string is too long, return ENAMETOOLONG; else return 0.
                   1264:  * see copystr(9)
                   1265:  */
                   1266: /* LINTSTUB: Func: int copystr(const void *kfaddr, void *kdaddr, size_t len, size_t *done) */
                   1267: ENTRY(copystr)
                   1268:        pushl   %esi
                   1269:        pushl   %edi
                   1270:
                   1271:        movl    12(%esp),%esi           # esi = from
                   1272:        movl    16(%esp),%edi           # edi = to
                   1273:        movl    20(%esp),%edx           # edx = maxlen
                   1274:        incl    %edx
                   1275:        cld
                   1276:
                   1277: 1:     decl    %edx
                   1278:        jz      4f
                   1279:        lodsb
                   1280:        stosb
                   1281:        testb   %al,%al
                   1282:        jnz     1b
                   1283:
                   1284:        /* Success -- 0 byte reached. */
                   1285:        decl    %edx
                   1286:        xorl    %eax,%eax
                   1287:        jmp     6f
                   1288:
                   1289: 4:     /* edx is zero -- return ENAMETOOLONG. */
                   1290:        movl    $ENAMETOOLONG,%eax
                   1291:
                   1292: 6:     /* Set *lencopied and return %eax. */
                   1293:        movl    20(%esp),%ecx
                   1294:        subl    %edx,%ecx
                   1295:        movl    24(%esp),%edx
                   1296:        testl   %edx,%edx
                   1297:        jz      7f
                   1298:        movl    %ecx,(%edx)
                   1299:
                   1300: 7:     popl    %edi
                   1301:        popl    %esi
                   1302:        ret
                   1303:
                   1304: /*
                   1305:  * long fuword(const void *uaddr);
                   1306:  * Fetch an int from the user's address space.
                   1307:  * see fuword(9)
                   1308:  */
                   1309: /* LINTSTUB: Func: long fuword(const void *base) */
                   1310: ENTRY(fuword)
                   1311:        movl    4(%esp),%edx
                   1312:        cmpl    $VM_MAXUSER_ADDRESS-4,%edx
                   1313:        ja      _C_LABEL(fusuaddrfault)
                   1314:        GET_CURPCB(%ecx)
                   1315:        movl    $_C_LABEL(fusufault),PCB_ONFAULT(%ecx)
                   1316:        movl    (%edx),%eax
                   1317:        movl    $0,PCB_ONFAULT(%ecx)
                   1318:        ret
                   1319:
                   1320: /*
                   1321:  * int fusword(const void *uaddr);
                   1322:  * Fetch a short from the user's address space.
                   1323:  * see fusword(9)
                   1324:  */
                   1325: /* LINTSTUB: Func: int fusword(const void *base) */
                   1326: ENTRY(fusword)
                   1327:        movl    4(%esp),%edx
                   1328:        cmpl    $VM_MAXUSER_ADDRESS-2,%edx
                   1329:        ja      _C_LABEL(fusuaddrfault)
                   1330:        GET_CURPCB(%ecx)
                   1331:        movl    $_C_LABEL(fusufault),PCB_ONFAULT(%ecx)
                   1332:        movzwl  (%edx),%eax
                   1333:        movl    $0,PCB_ONFAULT(%ecx)
                   1334:        ret
                   1335:
                   1336: /*
                   1337:  * int fuswintr(const void *uaddr);
                   1338:  * Fetch a short from the user's address space.  Can be called during an
                   1339:  * interrupt.
                   1340:  * see fuswintr(9)
                   1341:  */
                   1342: /* LINTSTUB: Func: int fuswintr(const void *base) */
                   1343: ENTRY(fuswintr)
                   1344:        movl    4(%esp),%edx
                   1345:        cmpl    $VM_MAXUSER_ADDRESS-2,%edx
                   1346:        ja      _C_LABEL(fusuaddrfault)
1.5       thorpej  1347:        movl    CPUVAR(CURLWP),%ecx
                   1348:        movl    L_ADDR(%ecx),%ecx
1.1       fvdl     1349:        movl    $_C_LABEL(fusubail),PCB_ONFAULT(%ecx)
                   1350:        movzwl  (%edx),%eax
                   1351:        movl    $0,PCB_ONFAULT(%ecx)
                   1352:        ret
                   1353:
                   1354: /*
                   1355:  * int fubyte(const void *uaddr);
                   1356:  * Fetch a byte from the user's address space.
                   1357:  * see fubyte(9)
                   1358:  */
                   1359: /* LINTSTUB: Func: int fubyte(const void *base) */
                   1360: ENTRY(fubyte)
                   1361:        movl    4(%esp),%edx
                   1362:        cmpl    $VM_MAXUSER_ADDRESS-1,%edx
                   1363:        ja      _C_LABEL(fusuaddrfault)
                   1364:        GET_CURPCB(%ecx)
                   1365:        movl    $_C_LABEL(fusufault),PCB_ONFAULT(%ecx)
                   1366:        movzbl  (%edx),%eax
                   1367:        movl    $0,PCB_ONFAULT(%ecx)
                   1368:        ret
                   1369:
                   1370: /*
                   1371:  * Handle faults from [fs]u*().  Clean up and return -1.
                   1372:  */
                   1373: /* LINTSTUB: Ignore */
                   1374: NENTRY(fusufault)
                   1375:        movl    $0,PCB_ONFAULT(%ecx)
                   1376:        movl    $-1,%eax
                   1377:        ret
                   1378:
                   1379: /*
                   1380:  * Handle faults from [fs]u*().  Clean up and return -1.  This differs from
                   1381:  * fusufault() in that trap() will recognize it and return immediately rather
                   1382:  * than trying to page fault.
                   1383:  */
                   1384: /* LINTSTUB: Ignore */
                   1385: NENTRY(fusubail)
                   1386:        movl    $0,PCB_ONFAULT(%ecx)
                   1387:        movl    $-1,%eax
                   1388:        ret
                   1389:
                   1390: /*
                   1391:  * Handle earlier faults from [fs]u*(), due to our of range addresses.
                   1392:  */
                   1393: /* LINTSTUB: Ignore */
                   1394: NENTRY(fusuaddrfault)
                   1395:        movl    $-1,%eax
                   1396:        ret
                   1397:
                   1398: /*
                   1399:  * int suword(void *uaddr, long x);
                   1400:  * Store an int in the user's address space.
                   1401:  * see suword(9)
                   1402:  */
                   1403: /* LINTSTUB: Func: int suword(void *base, long c) */
                   1404: ENTRY(suword)
                   1405:        movl    4(%esp),%edx
                   1406:        cmpl    $VM_MAXUSER_ADDRESS-4,%edx
                   1407:        ja      _C_LABEL(fusuaddrfault)
                   1408:
                   1409: #if defined(I386_CPU)
                   1410: #if defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU)
                   1411:        cmpl    $CPUCLASS_386,_C_LABEL(cpu_class)
                   1412:        jne     2f
                   1413: #endif /* I486_CPU || I586_CPU || I686_CPU */
                   1414:
                   1415:        GET_CURPCB(%eax)
                   1416:        movl    $3f,PCB_ONFAULT(%eax)
                   1417:
                   1418:        movl    %edx,%eax
                   1419:        shrl    $PGSHIFT,%eax           # calculate pte address
                   1420:        testb   $PG_RW,_C_LABEL(PTmap)(,%eax,4)
                   1421:        jnz     1f
                   1422:
                   1423: 3:     /* Simulate a trap. */
                   1424:        pushl   %edx
                   1425:        pushl   %edx
                   1426:        call    _C_LABEL(trapwrite)     # trapwrite(addr)
                   1427:        addl    $4,%esp                 # clear parameter from the stack
                   1428:        popl    %edx
                   1429:        GET_CURPCB(%ecx)
                   1430:        testl   %eax,%eax
                   1431:        jnz     _C_LABEL(fusufault)
                   1432:
                   1433: 1:     /* XXX also need to check the following 3 bytes for validity! */
                   1434: #endif
                   1435:
                   1436: 2:     GET_CURPCB(%ecx)
                   1437:        movl    $_C_LABEL(fusufault),PCB_ONFAULT(%ecx)
                   1438:
                   1439:        movl    8(%esp),%eax
                   1440:        movl    %eax,(%edx)
                   1441:        xorl    %eax,%eax
                   1442:        movl    %eax,PCB_ONFAULT(%ecx)
                   1443:        ret
                   1444:
                   1445: /*
                   1446:  * int susword(void *uaddr, short x);
                   1447:  * Store a short in the user's address space.
                   1448:  * see susword(9)
                   1449:  */
                   1450: /* LINTSTUB: Func: int susword(void *base, short c) */
                   1451: ENTRY(susword)
                   1452:        movl    4(%esp),%edx
                   1453:        cmpl    $VM_MAXUSER_ADDRESS-2,%edx
                   1454:        ja      _C_LABEL(fusuaddrfault)
                   1455:
                   1456: #if defined(I386_CPU)
                   1457: #if defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU)
                   1458:        cmpl    $CPUCLASS_386,_C_LABEL(cpu_class)
                   1459:        jne     2f
                   1460: #endif /* I486_CPU || I586_CPU || I686_CPU */
                   1461:
                   1462:        GET_CURPCB(%eax)
                   1463:        movl    $3f,PCB_ONFAULT(%eax)
                   1464:
                   1465:        movl    %edx,%eax
                   1466:        shrl    $PGSHIFT,%eax           # calculate pte address
                   1467:        testb   $PG_RW,_C_LABEL(PTmap)(,%eax,4)
                   1468:        jnz     1f
                   1469:
                   1470: 3:     /* Simulate a trap. */
                   1471:        pushl   %edx
                   1472:        pushl   %edx
                   1473:        call    _C_LABEL(trapwrite)     # trapwrite(addr)
                   1474:        addl    $4,%esp                 # clear parameter from the stack
                   1475:        popl    %edx
                   1476:        GET_CURPCB(%ecx)
                   1477:        testl   %eax,%eax
                   1478:        jnz     _C_LABEL(fusufault)
                   1479:
                   1480: 1:     /* XXX also need to check the following byte for validity! */
                   1481: #endif
                   1482:
                   1483: 2:     GET_CURPCB(%ecx)
                   1484:        movl    $_C_LABEL(fusufault),PCB_ONFAULT(%ecx)
                   1485:
                   1486:        movl    8(%esp),%eax
                   1487:        movw    %ax,(%edx)
                   1488:        xorl    %eax,%eax
                   1489:        movl    %eax,PCB_ONFAULT(%ecx)
                   1490:        ret
                   1491:
                   1492: /*
                   1493:  * int suswintr(void *uaddr, short x);
                   1494:  * Store a short in the user's address space.  Can be called during an
                   1495:  * interrupt.
                   1496:  * see suswintr(9)
                   1497:  */
                   1498: /* LINTSTUB: Func: int suswintr(void *base, short c) */
                   1499: ENTRY(suswintr)
                   1500:        movl    4(%esp),%edx
                   1501:        cmpl    $VM_MAXUSER_ADDRESS-2,%edx
                   1502:        ja      _C_LABEL(fusuaddrfault)
1.5       thorpej  1503:        movl    CPUVAR(CURLWP),%ecx
                   1504:        movl    L_ADDR(%ecx),%ecx
1.1       fvdl     1505:        movl    $_C_LABEL(fusubail),PCB_ONFAULT(%ecx)
                   1506:
                   1507: #if defined(I386_CPU)
                   1508: #if defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU)
                   1509:        cmpl    $CPUCLASS_386,_C_LABEL(cpu_class)
                   1510:        jne     2f
                   1511: #endif /* I486_CPU || I586_CPU || I686_CPU */
                   1512:
                   1513:        movl    %edx,%eax
                   1514:        shrl    $PGSHIFT,%eax           # calculate pte address
                   1515:        testb   $PG_RW,_C_LABEL(PTmap)(,%eax,4)
                   1516:        jnz     1f
                   1517:
                   1518:        /* Simulate a trap. */
                   1519:        jmp     _C_LABEL(fusubail)
                   1520:
                   1521: 1:     /* XXX also need to check the following byte for validity! */
                   1522: #endif
                   1523:
                   1524: 2:     movl    8(%esp),%eax
                   1525:        movw    %ax,(%edx)
                   1526:        xorl    %eax,%eax
                   1527:        movl    %eax,PCB_ONFAULT(%ecx)
                   1528:        ret
                   1529:
                   1530: /*
                   1531:  * int subyte(void *uaddr, char x);
                   1532:  * Store a byte in the user's address space.
                   1533:  * see subyte(9)
                   1534:  */
                   1535: /* LINTSTUB: Func: int subyte(void *base, int c) */
                   1536: ENTRY(subyte)
                   1537:        movl    4(%esp),%edx
                   1538:        cmpl    $VM_MAXUSER_ADDRESS-1,%edx
                   1539:        ja      _C_LABEL(fusuaddrfault)
                   1540:
                   1541: #if defined(I386_CPU)
                   1542: #if defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU)
                   1543:        cmpl    $CPUCLASS_386,_C_LABEL(cpu_class)
                   1544:        jne     2f
                   1545: #endif /* I486_CPU || I586_CPU || I686_CPU */
                   1546:
                   1547:        GET_CURPCB(%eax)
                   1548:        movl    $3f,PCB_ONFAULT(%eax)
                   1549:
                   1550:        movl    %edx,%eax
                   1551:        shrl    $PGSHIFT,%eax           # calculate pte address
                   1552:        testb   $PG_RW,_C_LABEL(PTmap)(,%eax,4)
                   1553:        jnz     1f
                   1554:
                   1555: 3:     /* Simulate a trap. */
                   1556:        pushl   %edx
                   1557:        pushl   %edx
                   1558:        call    _C_LABEL(trapwrite)     # trapwrite(addr)
                   1559:        addl    $4,%esp                 # clear parameter from the stack
                   1560:        popl    %edx
                   1561:        GET_CURPCB(%ecx)
                   1562:        testl   %eax,%eax
                   1563:        jnz     _C_LABEL(fusufault)
                   1564:
                   1565: 1:
                   1566: #endif
                   1567:
                   1568: 2:     GET_CURPCB(%ecx)
                   1569:        movl    $_C_LABEL(fusufault),PCB_ONFAULT(%ecx)
                   1570:
                   1571:        movb    8(%esp),%al
                   1572:        movb    %al,(%edx)
                   1573:        xorl    %eax,%eax
                   1574:        movl    %eax,PCB_ONFAULT(%ecx)
                   1575:        ret
                   1576:
                   1577: /*****************************************************************************/
                   1578:
                   1579: /*
                   1580:  * The following is i386-specific nonsense.
                   1581:  */
                   1582:
                   1583: /*
                   1584:  * void lgdt(struct region_descriptor *rdp);
                   1585:  * Load a new GDT pointer (and do any necessary cleanup).
                   1586:  * XXX It's somewhat questionable whether reloading all the segment registers
                   1587:  * is necessary, since the actual descriptor data is not changed except by
                   1588:  * process creation and exit, both of which clean up via task switches.  OTOH,
                   1589:  * this only happens at run time when the GDT is resized.
                   1590:  */
                   1591: /* LINTSTUB: Func: void lgdt(struct region_descriptor *rdp) */
                   1592: NENTRY(lgdt)
                   1593:        /* Reload the descriptor table. */
                   1594:        movl    4(%esp),%eax
                   1595:        lgdt    (%eax)
                   1596:        /* Flush the prefetch queue. */
                   1597:        jmp     1f
                   1598:        nop
                   1599: 1:     /* Reload "stale" selectors. */
                   1600:        movl    $GSEL(GDATA_SEL, SEL_KPL),%eax
                   1601:        movw    %ax,%ds
                   1602:        movw    %ax,%es
                   1603:        movw    %ax,%gs
                   1604:        movw    %ax,%ss
                   1605:        movl    $GSEL(GCPU_SEL, SEL_KPL),%eax
                   1606:        movw    %ax,%fs
                   1607:        /* Reload code selector by doing intersegment return. */
                   1608:        popl    %eax
                   1609:        pushl   $GSEL(GCODE_SEL, SEL_KPL)
                   1610:        pushl   %eax
                   1611:        lret
                   1612:
                   1613: /*****************************************************************************/
                   1614:
                   1615: /*
                   1616:  * These functions are primarily used by DDB.
                   1617:  */
                   1618:
                   1619: /* LINTSTUB: Func: int setjmp (label_t *l) */
                   1620: ENTRY(setjmp)
                   1621:        movl    4(%esp),%eax
                   1622:        movl    %ebx,(%eax)             # save ebx
                   1623:        movl    %esp,4(%eax)            # save esp
                   1624:        movl    %ebp,8(%eax)            # save ebp
                   1625:        movl    %esi,12(%eax)           # save esi
                   1626:        movl    %edi,16(%eax)           # save edi
                   1627:        movl    (%esp),%edx             # get rta
                   1628:        movl    %edx,20(%eax)           # save eip
                   1629:        xorl    %eax,%eax               # return (0);
                   1630:        ret
                   1631:
                   1632: /* LINTSTUB: Func: void longjmp (label_t *l) */
                   1633: ENTRY(longjmp)
                   1634:        movl    4(%esp),%eax
                   1635:        movl    (%eax),%ebx             # restore ebx
                   1636:        movl    4(%eax),%esp            # restore esp
                   1637:        movl    8(%eax),%ebp            # restore ebp
                   1638:        movl    12(%eax),%esi           # restore esi
                   1639:        movl    16(%eax),%edi           # restore edi
                   1640:        movl    20(%eax),%edx           # get rta
                   1641:        movl    %edx,(%esp)             # put in return frame
                   1642:        xorl    %eax,%eax               # return (1);
                   1643:        incl    %eax
                   1644:        ret
                   1645:
                   1646: /*****************************************************************************/
                   1647:
                   1648:        .globl  _C_LABEL(sched_whichqs),_C_LABEL(sched_qs)
                   1649:        .globl  _C_LABEL(uvmexp),_C_LABEL(panic)
                   1650:
                   1651: #ifdef DIAGNOSTIC
                   1652: NENTRY(switch_error)
                   1653:        pushl   $1f
                   1654:        call    _C_LABEL(panic)
                   1655:        /* NOTREACHED */
                   1656: 1:     .asciz  "cpu_switch"
                   1657: #endif /* DIAGNOSTIC */
                   1658:
                   1659: /*
1.5       thorpej  1660:  * void cpu_switch(struct lwp *)
1.1       fvdl     1661:  * Find a runnable process and switch to it.  Wait if necessary.  If the new
                   1662:  * process is the same as the old one, we short-circuit the context save and
                   1663:  * restore.
                   1664:  *
                   1665:  * Note that the stack frame layout is known to "struct switchframe"
                   1666:  * in <machine/frame.h> and to the code in cpu_fork() which initializes
1.5       thorpej  1667:  * it for a new lwp.
1.1       fvdl     1668:  */
                   1669: ENTRY(cpu_switch)
                   1670:        pushl   %ebx
                   1671:        pushl   %esi
                   1672:        pushl   %edi
                   1673:
                   1674: #ifdef DEBUG
                   1675:        cmpl    $IPL_SCHED,CPUVAR(ILEVEL)
                   1676:        jae     1f
1.5       thorpej  1677:        pushl   $2f
1.1       fvdl     1678:        call    _C_LABEL(panic)
                   1679:        /* NOTREACHED */
1.5       thorpej  1680: 2:     .asciz  "not splsched() in cpu_switch!"
1.1       fvdl     1681: 1:
                   1682: #endif /* DEBUG */
                   1683:
1.5       thorpej  1684:        movl    16(%esp),%esi           # current
1.1       fvdl     1685:
                   1686:        /*
1.5       thorpej  1687:         * Clear curlwp so that we don't accumulate system time while idle.
                   1688:         * This also insures that schedcpu() will move the old lwp to
1.1       fvdl     1689:         * the correct queue if it happens to get called from the spllower()
                   1690:         * below and changes the priority.  (See corresponding comment in
                   1691:         * userret()).
                   1692:         */
1.5       thorpej  1693:        movl    $0,CPUVAR(CURLWP)
1.1       fvdl     1694:        /*
1.5       thorpej  1695:         * First phase: find new lwp.
1.1       fvdl     1696:         *
                   1697:         * Registers:
                   1698:         *   %eax - queue head, scratch, then zero
                   1699:         *   %ebx - queue number
                   1700:         *   %ecx - cached value of whichqs
1.5       thorpej  1701:         *   %edx - next lwp in queue
                   1702:         *   %esi - old lwp
                   1703:         *   %edi - new lwp
1.1       fvdl     1704:         */
                   1705:
1.5       thorpej  1706:        /* Look for new lwp. */
1.1       fvdl     1707:        cli                             # splhigh doesn't do a cli
                   1708:        movl    _C_LABEL(sched_whichqs),%ecx
                   1709:        bsfl    %ecx,%ebx               # find a full q
                   1710:        jnz     switch_dequeue
                   1711:
                   1712:        /*
                   1713:         * idling:      save old context.
                   1714:         *
                   1715:         * Registers:
                   1716:         *   %eax, %ecx - scratch
1.5       thorpej  1717:         *   %esi - old lwp, then old pcb
1.1       fvdl     1718:         *   %edi - idle pcb
                   1719:         */
                   1720:
                   1721:        pushl   %esi
                   1722:        call    _C_LABEL(pmap_deactivate)       # pmap_deactivate(oldproc)
                   1723:        addl    $4,%esp
                   1724:
1.5       thorpej  1725:        movl    L_ADDR(%esi),%esi
1.1       fvdl     1726:
                   1727:        /* Save stack pointers. */
                   1728:        movl    %esp,PCB_ESP(%esi)
                   1729:        movl    %ebp,PCB_EBP(%esi)
                   1730:
                   1731:        /* Find idle PCB for this CPU */
                   1732: #ifndef MULTIPROCESSOR
1.5       thorpej  1733:        movl    $_C_LABEL(lwp0),%ebx
                   1734:        movl    L_ADDR(%ebx),%edi
                   1735:        movl    L_MD_TSS_SEL(%ebx),%edx
1.1       fvdl     1736: #else
                   1737:        movl    CPUVAR(IDLE_PCB),%edi
                   1738:        movl    CPUVAR(IDLE_TSS_SEL),%edx
                   1739: #endif
1.5       thorpej  1740:        movl    $0,CPUVAR(CURLWP)               /* In case we fault... */
1.1       fvdl     1741:
                   1742:        /* Restore the idle context (avoid interrupts) */
                   1743:        cli
                   1744:
                   1745:        /* Restore stack pointers. */
                   1746:        movl    PCB_ESP(%edi),%esp
                   1747:        movl    PCB_EBP(%edi),%ebp
                   1748:
                   1749:
                   1750:        /* Switch address space. */
                   1751:        movl    PCB_CR3(%edi),%ecx
                   1752:        movl    %ecx,%cr3
                   1753:
                   1754:        /* Switch TSS. Reset "task busy" flag before loading. */
                   1755: #ifdef MULTIPROCESSOR
                   1756:        movl    CPUVAR(GDT),%eax
                   1757: #else
                   1758:        movl    _C_LABEL(gdt),%eax
                   1759: #endif
                   1760:        andl    $~0x0200,4-SEL_KPL(%eax,%edx,1)
                   1761:        ltr     %dx
                   1762:
                   1763:        /* We're always in the kernel, so we don't need the LDT. */
                   1764:
                   1765:        /* Restore cr0 (including FPU state). */
                   1766:        movl    PCB_CR0(%edi),%ecx
                   1767:        movl    %ecx,%cr0
                   1768:
                   1769:        /* Record new pcb. */
                   1770:        SET_CURPCB(%edi)
                   1771:
                   1772:        xorl    %esi,%esi
                   1773:        sti
                   1774: idle_unlock:
                   1775: #if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)
                   1776:        call    _C_LABEL(sched_unlock_idle)
                   1777: #endif
                   1778:        /* Interrupts are okay again. */
1.2       fvdl     1779:        pushl   $IPL_NONE               # spl0()
1.1       fvdl     1780:        call    _C_LABEL(Xspllower)     # process pending interrupts
1.2       fvdl     1781:        addl    $4,%esp
1.1       fvdl     1782:        jmp     idle_start
                   1783: idle_zero:
                   1784:        sti
                   1785:        call    _C_LABEL(uvm_pageidlezero)
                   1786:        cli
                   1787:        cmpl    $0,_C_LABEL(sched_whichqs)
                   1788:        jnz     idle_exit
                   1789: idle_loop:
                   1790:        /* Try to zero some pages. */
                   1791:        movl    _C_LABEL(uvm)+UVM_PAGE_IDLE_ZERO,%ecx
                   1792:        testl   %ecx,%ecx
                   1793:        jnz     idle_zero
                   1794:        sti
                   1795:        hlt
                   1796: NENTRY(mpidle)
                   1797: idle_start:
                   1798:        cli
                   1799:        cmpl    $0,_C_LABEL(sched_whichqs)
                   1800:        jz      idle_loop
                   1801: idle_exit:
                   1802:        movl    $IPL_HIGH,CPUVAR(ILEVEL)                # splhigh
                   1803: #if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)
                   1804:        call    _C_LABEL(sched_lock_idle)
                   1805: #endif
                   1806:        movl    _C_LABEL(sched_whichqs),%ecx
                   1807:        bsfl    %ecx,%ebx
                   1808:        jz      idle_unlock
                   1809:
                   1810: switch_dequeue:
                   1811:        /*
                   1812:         * we're running at splhigh(), but it's otherwise okay to take
                   1813:         * interrupts here.
                   1814:         */
                   1815:        sti
                   1816:        leal    _C_LABEL(sched_qs)(,%ebx,8),%eax # select q
                   1817:
1.5       thorpej  1818:        movl    L_FORW(%eax),%edi       # unlink from front of process q
1.1       fvdl     1819: #ifdef DIAGNOSTIC
                   1820:        cmpl    %edi,%eax               # linked to self (i.e. nothing queued)?
                   1821:        je      _C_LABEL(switch_error)  # not possible
                   1822: #endif /* DIAGNOSTIC */
1.5       thorpej  1823:        movl    L_FORW(%edi),%edx
                   1824:        movl    %edx,L_FORW(%eax)
                   1825:        movl    %eax,L_BACK(%edx)
1.1       fvdl     1826:
                   1827:        cmpl    %edx,%eax               # q empty?
                   1828:        jne     3f
                   1829:
                   1830:        btrl    %ebx,%ecx               # yes, clear to indicate empty
                   1831:        movl    %ecx,_C_LABEL(sched_whichqs) # update q status
                   1832:
                   1833: 3:     /* We just did it. */
                   1834:        xorl    %eax,%eax
                   1835:        CLEAR_RESCHED(%eax)
                   1836:
1.5       thorpej  1837: switch_resume:
1.1       fvdl     1838: #ifdef DIAGNOSTIC
1.5       thorpej  1839:        cmpl    %eax,L_WCHAN(%edi)      # Waiting for something?
1.1       fvdl     1840:        jne     _C_LABEL(switch_error)  # Yes; shouldn't be queued.
1.5       thorpej  1841:        cmpb    $LSRUN,L_STAT(%edi)     # In run state?
1.1       fvdl     1842:        jne     _C_LABEL(switch_error)  # No; shouldn't be queued.
                   1843: #endif /* DIAGNOSTIC */
                   1844:
1.5       thorpej  1845:        /* Isolate lwp.  XXX Is this necessary? */
                   1846:        movl    %eax,L_BACK(%edi)
1.1       fvdl     1847:
1.5       thorpej  1848:        /* Record new lwp. */
                   1849:        movb    $LSONPROC,L_STAT(%edi)  # l->l_stat = LSONPROC
                   1850:        SET_CURLWP(%edi,%ecx)
1.1       fvdl     1851:
1.5       thorpej  1852:        /* Skip context switch if same lwp. */
1.10      fvdl     1853:        xorl    %ebx,%ebx
1.1       fvdl     1854:        cmpl    %edi,%esi
                   1855:        je      switch_return
                   1856:
1.5       thorpej  1857:        /* If old lwp exited, don't bother. */
1.1       fvdl     1858:        testl   %esi,%esi
                   1859:        jz      switch_exited
                   1860:
                   1861:        /*
                   1862:         * Second phase: save old context.
                   1863:         *
                   1864:         * Registers:
                   1865:         *   %eax, %ecx - scratch
1.5       thorpej  1866:         *   %esi - old lwp, then old pcb
                   1867:         *   %edi - new lwp
1.1       fvdl     1868:         */
                   1869:
                   1870:        pushl   %esi
                   1871:        call    _C_LABEL(pmap_deactivate)       # pmap_deactivate(oldproc)
                   1872:        addl    $4,%esp
                   1873:
1.5       thorpej  1874:        movl    L_ADDR(%esi),%esi
1.1       fvdl     1875:
                   1876:        /* Save stack pointers. */
                   1877:        movl    %esp,PCB_ESP(%esi)
                   1878:        movl    %ebp,PCB_EBP(%esi)
                   1879:
                   1880: switch_exited:
                   1881:        /*
                   1882:         * Third phase: restore saved context.
                   1883:         *
                   1884:         * Registers:
                   1885:         *   %eax, %ebx, %ecx, %edx - scratch
                   1886:         *   %esi - new pcb
1.5       thorpej  1887:         *   %edi - new lwp
1.1       fvdl     1888:         */
                   1889:
                   1890:        /* No interrupts while loading new state. */
                   1891:        cli
1.5       thorpej  1892:        movl    L_ADDR(%edi),%esi
1.1       fvdl     1893:
                   1894:        /* Restore stack pointers. */
                   1895:        movl    PCB_ESP(%esi),%esp
                   1896:        movl    PCB_EBP(%esi),%ebp
                   1897:
                   1898: #if 0
                   1899:        /* Don't bother with the rest if switching to a system process. */
1.5       thorpej  1900:        testl   $P_SYSTEM,L_FLAG(%edi); XXX NJWLWP lwp's don't have P_SYSTEM!
1.1       fvdl     1901:        jnz     switch_restored
                   1902: #endif
                   1903:
                   1904: #ifdef MULTIPROCESSOR
                   1905:        movl    CPUVAR(GDT),%eax
                   1906: #else
                   1907:        /* Load TSS info. */
                   1908:        movl    _C_LABEL(gdt),%eax
                   1909: #endif
1.5       thorpej  1910:        movl    L_MD_TSS_SEL(%edi),%edx
1.1       fvdl     1911:
                   1912:        /* Switch TSS. Reset "task busy" flag before loading. */
                   1913:        andl    $~0x0200,4(%eax,%edx, 1)
                   1914:        ltr     %dx
                   1915:
                   1916:        pushl   %edi
                   1917:        call    _C_LABEL(pmap_activate)         # pmap_activate(p)
                   1918:        addl    $4,%esp
                   1919:
                   1920: #if 0
                   1921: switch_restored:
                   1922: #endif
                   1923:        /* Restore cr0 (including FPU state). */
                   1924:        movl    PCB_CR0(%esi),%ecx
                   1925: #ifdef MULTIPROCESSOR
                   1926:        /*
                   1927:         * If our floating point registers are on a different cpu,
                   1928:         * clear CR0_TS so we'll trap rather than reuse bogus state.
                   1929:         */
                   1930:        movl    PCB_FPCPU(%esi),%ebx
                   1931:        cmpl    CPUVAR(SELF),%ebx
                   1932:        jz      1f
                   1933:        orl     $CR0_TS,%ecx
                   1934: 1:
                   1935: #endif
                   1936:        movl    %ecx,%cr0
                   1937:
                   1938:        /* Record new pcb. */
                   1939:        SET_CURPCB(%esi)
                   1940:
                   1941:        /* Interrupts are okay again. */
                   1942:        sti
                   1943:
                   1944: /*
                   1945:  *  Check for restartable atomic sequences (RAS)
                   1946:  */
1.5       thorpej  1947:        movl    CPUVAR(CURLWP),%edi
                   1948:        movl    L_PROC(%edi),%esi
                   1949:        cmpl    $0,P_NRAS(%esi)
1.1       fvdl     1950:        je      1f
1.5       thorpej  1951:        movl    L_MD_REGS(%edi),%ebx
1.4       gmcgarry 1952:        movl    TF_EIP(%ebx),%eax
1.1       fvdl     1953:        pushl   %eax
1.5       thorpej  1954:        pushl   %esi
1.1       fvdl     1955:        call    _C_LABEL(ras_lookup)
                   1956:        addl    $8,%esp
                   1957:        cmpl    $-1,%eax
                   1958:        je      1f
1.4       gmcgarry 1959:        movl    %eax,TF_EIP(%ebx)
1.1       fvdl     1960: 1:
1.10      fvdl     1961:        movl    $1,%ebx
1.1       fvdl     1962:
                   1963: switch_return:
                   1964: #if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)
                   1965:        call    _C_LABEL(sched_unlock_idle)
                   1966: #endif
1.2       fvdl     1967:        pushl   $IPL_NONE               # spl0()
1.1       fvdl     1968:        call    _C_LABEL(Xspllower)     # process pending interrupts
1.2       fvdl     1969:        addl    $4,%esp
1.1       fvdl     1970:        movl    $IPL_HIGH,CPUVAR(ILEVEL)        # splhigh()
1.9       fvdl     1971:
                   1972:        movl    %ebx,%eax
1.1       fvdl     1973:
                   1974:        popl    %edi
                   1975:        popl    %esi
                   1976:        popl    %ebx
                   1977:        ret
                   1978:
                   1979: /*
1.5       thorpej  1980:  * void cpu_switchto(struct lwp *current, struct lwp *next)
                   1981:  * Switch to the specified next LWP.
                   1982:  */
                   1983: ENTRY(cpu_switchto)
                   1984:        pushl   %ebx
                   1985:        pushl   %esi
                   1986:        pushl   %edi
                   1987:
                   1988: #ifdef DEBUG
                   1989:        cmpl    $IPL_SCHED,CPUVAR(ILEVEL)
                   1990:        jae     1f
                   1991:        pushl   $2f
                   1992:        call    _C_LABEL(panic)
                   1993:        /* NOTREACHED */
                   1994: 2:     .asciz  "not splsched() in cpu_switchto!"
                   1995: 1:
                   1996: #endif /* DEBUG */
                   1997:
                   1998:        movl    16(%esp),%esi           # current
                   1999:        movl    20(%esp),%edi           # next
                   2000:
                   2001:        /*
                   2002:         * Clear curlwp so that we don't accumulate system time while idle.
                   2003:         * This also insures that schedcpu() will move the old process to
                   2004:         * the correct queue if it happens to get called from the spllower()
                   2005:         * below and changes the priority.  (See corresponding comment in
                   2006:         * usrret()).
                   2007:         *
                   2008:         * XXX Is this necessary?  We know we won't go idle.
                   2009:         */
                   2010:        movl    $0,CPUVAR(CURLWP)
                   2011:
                   2012:        /*
                   2013:         * We're running at splhigh(), but it's otherwise okay to take
                   2014:         * interrupts here.
                   2015:         */
                   2016:        sti
                   2017:
                   2018:        /* Jump into the middle of cpu_switch */
                   2019:        xorl    %eax,%eax
                   2020:        jmp     switch_resume
                   2021:
                   2022: /*
                   2023:  * void switch_exit(struct lwp *l, void (*exit)(struct lwp *));
                   2024:  * Switch to the appropriate idle context (lwp0's if uniprocessor; the cpu's
1.1       fvdl     2025:  * if multiprocessor) and deallocate the address space and kernel stack for p.
                   2026:  * Then jump into cpu_switch(), as if we were in the idle proc all along.
                   2027:  */
                   2028: #ifndef MULTIPROCESSOR
1.5       thorpej  2029:        .globl  _C_LABEL(lwp0)
1.1       fvdl     2030: #endif
                   2031:        .globl  _C_LABEL(uvmspace_free),_C_LABEL(kernel_map)
                   2032:        .globl  _C_LABEL(uvm_km_free),_C_LABEL(tss_free)
1.6       drochner 2033: /* LINTSTUB: Func: void switch_exit(struct lwp *l, void (*exit)(struct lwp *)) */
1.1       fvdl     2034: ENTRY(switch_exit)
                   2035:        movl    4(%esp),%edi            # old process
1.5       thorpej  2036:        movl    8(%esp),%eax            # exit func
1.1       fvdl     2037: #ifndef MULTIPROCESSOR
1.5       thorpej  2038:        movl    $_C_LABEL(lwp0),%ebx
                   2039:        movl    L_ADDR(%ebx),%esi
                   2040:        movl    L_MD_TSS_SEL(%ebx),%edx
1.1       fvdl     2041: #else
                   2042:        movl    CPUVAR(IDLE_PCB),%esi
                   2043:        movl    CPUVAR(IDLE_TSS_SEL),%edx
                   2044: #endif
                   2045:        /* In case we fault... */
1.5       thorpej  2046:        movl    $0,CPUVAR(CURLWP)
1.1       fvdl     2047:
                   2048:        /* Restore the idle context. */
                   2049:        cli
                   2050:
                   2051:        /* Restore stack pointers. */
                   2052:        movl    PCB_ESP(%esi),%esp
                   2053:        movl    PCB_EBP(%esi),%ebp
                   2054:
1.5       thorpej  2055:        /* Save exit func. */
                   2056:        pushl   %eax
                   2057:
1.1       fvdl     2058:        /* Load TSS info. */
                   2059: #ifdef MULTIPROCESSOR
                   2060:        movl    CPUVAR(GDT),%eax
                   2061: #else
                   2062:        /* Load TSS info. */
                   2063:        movl    _C_LABEL(gdt),%eax
                   2064: #endif
                   2065:
                   2066:        /* Switch address space. */
                   2067:        movl    PCB_CR3(%esi),%ecx
                   2068:        movl    %ecx,%cr3
                   2069:
                   2070:        /* Switch TSS. */
                   2071:        andl    $~0x0200,4-SEL_KPL(%eax,%edx,1)
                   2072:        ltr     %dx
                   2073:
                   2074:        /* We're always in the kernel, so we don't need the LDT. */
                   2075:
                   2076:        /* Restore cr0 (including FPU state). */
                   2077:        movl    PCB_CR0(%esi),%ecx
                   2078:        movl    %ecx,%cr0
                   2079:
                   2080:        /* Record new pcb. */
                   2081:        SET_CURPCB(%esi)
                   2082:
                   2083:        /* Interrupts are okay again. */
                   2084:        sti
                   2085:
                   2086:        /*
                   2087:         * Schedule the dead process's vmspace and stack to be freed.
                   2088:         */
1.5       thorpej  2089:        movl    0(%esp),%eax            /* %eax = exit func */
                   2090:        movl    %edi,0(%esp)            /* {lwp_}exit2(l) */
                   2091:        call    *%eax
1.1       fvdl     2092:        addl    $4,%esp
                   2093:
                   2094:        /* Jump into cpu_switch() with the right state. */
                   2095:        xorl    %esi,%esi
1.5       thorpej  2096:        movl    %esi,CPUVAR(CURLWP)
1.1       fvdl     2097:        jmp     idle_start
                   2098:
                   2099: /*
                   2100:  * void savectx(struct pcb *pcb);
                   2101:  * Update pcb, saving current processor state.
                   2102:  */
                   2103: /* LINTSTUB: Func: void savectx(struct pcb *pcb) */
                   2104: ENTRY(savectx)
                   2105:        movl    4(%esp),%edx            # edx = p->p_addr
                   2106:
                   2107:        /* Save stack pointers. */
                   2108:        movl    %esp,PCB_ESP(%edx)
                   2109:        movl    %ebp,PCB_EBP(%edx)
                   2110:
                   2111:        ret
                   2112:
                   2113: /*
                   2114:  * Old call gate entry for syscall
                   2115:  */
                   2116: /* LINTSTUB: Var: char Xosyscall[1]; */
                   2117: IDTVEC(osyscall)
                   2118:        /* Set eflags in trap frame. */
                   2119:        pushfl
                   2120:        popl    8(%esp)
                   2121:        pushl   $7              # size of instruction for restart
                   2122:        jmp     syscall1
                   2123:
                   2124: /*
                   2125:  * Trap gate entry for syscall
                   2126:  */
                   2127: /* LINTSTUB: Var: char Xsyscall[1]; */
                   2128: IDTVEC(syscall)
                   2129:        pushl   $2              # size of instruction for restart
                   2130: syscall1:
                   2131:        pushl   $T_ASTFLT       # trap # for doing ASTs
                   2132:        INTRENTRY
                   2133:
                   2134: #ifdef DIAGNOSTIC
                   2135:        movl    CPUVAR(ILEVEL),%ebx
                   2136:        testl   %ebx,%ebx
                   2137:        jz      1f
                   2138:        pushl   $5f
                   2139:        call    _C_LABEL(printf)
                   2140:        addl    $4,%esp
                   2141: #ifdef DDB
                   2142:        int     $3
                   2143: #endif
                   2144: 1:
                   2145: #endif /* DIAGNOSTIC */
1.5       thorpej  2146:        movl    CPUVAR(CURLWP),%edx
                   2147:        movl    %esp,L_MD_REGS(%edx)    # save pointer to frame
                   2148:        movl    L_PROC(%edx),%edx
1.1       fvdl     2149:        call    *P_MD_SYSCALL(%edx)     # get pointer to syscall() function
                   2150: 2:     /* Check for ASTs on exit to user mode. */
                   2151:        cli
1.5       thorpej  2152:        CHECK_ASTPENDING(%eax)
1.1       fvdl     2153:        je      1f
                   2154:        /* Always returning to user mode here. */
1.5       thorpej  2155:        CLEAR_ASTPENDING(%eax)
1.1       fvdl     2156:        sti
                   2157:        /* Pushed T_ASTFLT into tf_trapno on entry. */
                   2158:        call    _C_LABEL(trap)
                   2159:        jmp     2b
                   2160: #ifndef DIAGNOSTIC
                   2161: 1:     INTRFASTEXIT
                   2162: #else /* DIAGNOSTIC */
                   2163: 1:     cmpl    $IPL_NONE,CPUVAR(ILEVEL)
                   2164:        jne     3f
                   2165:        INTRFASTEXIT
                   2166: 3:     sti
                   2167:        pushl   $4f
                   2168:        call    _C_LABEL(printf)
                   2169:        addl    $4,%esp
                   2170: #ifdef DDB
                   2171:        int     $3
                   2172: #endif /* DDB */
                   2173:        movl    $IPL_NONE,CPUVAR(ILEVEL)
                   2174:        jmp     2b
                   2175: 4:     .asciz  "WARNING: SPL NOT LOWERED ON SYSCALL EXIT\n"
                   2176: 5:     .asciz  "WARNING: SPL NOT ZERO ON SYSCALL ENTRY\n"
                   2177: #endif /* DIAGNOSTIC */
                   2178:
                   2179: #if NNPX > 0
                   2180: /*
                   2181:  * Special interrupt handlers.  Someday intr0-intr15 will be used to count
                   2182:  * interrupts.  We'll still need a special exception 16 handler.  The busy
                   2183:  * latch stuff in probintr() can be moved to npxprobe().
                   2184:  */
                   2185:
                   2186: /* LINTSTUB: Func: void probeintr(void) */
                   2187: NENTRY(probeintr)
                   2188:        ss
                   2189:        incl    _C_LABEL(npx_intrs_while_probing)
                   2190:        pushl   %eax
                   2191:        movb    $0x20,%al       # EOI (asm in strings loses cpp features)
                   2192:        outb    %al,$0xa0       # IO_ICU2
                   2193:        outb    %al,$0x20       # IO_ICU1
                   2194:        movb    $0,%al
                   2195:        outb    %al,$0xf0       # clear BUSY# latch
                   2196:        popl    %eax
                   2197:        iret
                   2198:
                   2199: /* LINTSTUB: Func: void probetrap(void) */
                   2200: NENTRY(probetrap)
                   2201:        ss
                   2202:        incl    _C_LABEL(npx_traps_while_probing)
                   2203:        fnclex
                   2204:        iret
                   2205:
                   2206: /* LINTSTUB: Func: int npx586bug1(int a, int b) */
                   2207: NENTRY(npx586bug1)
                   2208:        fildl   4(%esp)         # x
                   2209:        fildl   8(%esp)         # y
                   2210:        fld     %st(1)
                   2211:        fdiv    %st(1),%st      # x/y
                   2212:        fmulp   %st,%st(1)      # (x/y)*y
                   2213:        fsubrp  %st,%st(1)      # x-(x/y)*y
                   2214:        pushl   $0
                   2215:        fistpl  (%esp)
                   2216:        popl    %eax
                   2217:        ret
                   2218: #endif /* NNPX > 0 */

CVSweb <webmaster@jp.NetBSD.org>