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

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

CVSweb <webmaster@jp.NetBSD.org>