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

1.47.4.7! ad          1: /*     $NetBSD: locore.S,v 1.47.4.6 2007/10/09 13:37:55 ad Exp $       */
1.1       fvdl        2:
                      3: /*-
1.47.4.1  ad          4:  * Copyright (c) 1998, 2000, 2004, 2006, 2007 The NetBSD Foundation, Inc.
1.1       fvdl        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_oldboot.h"
1.1       fvdl       74: #include "opt_cputype.h"
                     75: #include "opt_ddb.h"
                     76: #include "opt_realmem.h"
1.18      christos   77: #include "opt_vm86.h"
1.1       fvdl       78:
                     79: #include "npx.h"
                     80: #include "assym.h"
                     81: #include "lapic.h"
                     82: #include "ioapic.h"
1.8       fvdl       83: #include "ksyms.h"
1.1       fvdl       84:
                     85: #include <sys/errno.h>
                     86: #include <sys/syscall.h>
                     87:
                     88: #include <machine/cputypes.h>
                     89: #include <machine/segments.h>
                     90: #include <machine/specialreg.h>
                     91: #include <machine/trap.h>
                     92: #include <machine/i82489reg.h>
1.37      jmmv       93: #include <machine/multiboot.h>
1.1       fvdl       94: #include <machine/asm.h>
1.47.4.1  ad         95: #include <machine/frameasm.h>
                     96: #include <machine/i82489reg.h>
1.1       fvdl       97:
                     98: /* XXX temporary kluge; these should not be here */
                     99: /* Get definitions for IOM_BEGIN, IOM_END, and IOM_SIZE */
                    100: #include <dev/isa/isareg.h>
                    101:
                    102: /*
                    103:  * Initialization
                    104:  */
                    105:        .data
                    106:
                    107:        .globl  _C_LABEL(cpu)
1.38      jmmv      108:        .globl  _C_LABEL(esym)
                    109:        .globl  _C_LABEL(atdevbase)
1.40      yamt      110:        .globl  _C_LABEL(proc0uarea),_C_LABEL(PDPpaddr)
1.1       fvdl      111:        .globl  _C_LABEL(gdt)
                    112:        .globl  _C_LABEL(idt)
1.30      junyoung  113:        .globl  _C_LABEL(lapic_tpr)
                    114:
1.1       fvdl      115: #if NLAPIC > 0
                    116: #ifdef __ELF__
1.7       thorpej   117:        .align  PAGE_SIZE
1.1       fvdl      118: #else
                    119:        .align  12
                    120: #endif
                    121:        .globl _C_LABEL(local_apic), _C_LABEL(lapic_id)
                    122: _C_LABEL(local_apic):
                    123:        .space  LAPIC_ID
1.30      junyoung  124: _C_LABEL(lapic_id):
1.1       fvdl      125:        .long   0x00000000
                    126:        .space  LAPIC_TPRI-(LAPIC_ID+4)
1.30      junyoung  127: _C_LABEL(lapic_tpr):
1.1       fvdl      128:        .space  LAPIC_PPRI-LAPIC_TPRI
1.30      junyoung  129: _C_LABEL(lapic_ppr):
1.1       fvdl      130:        .space  LAPIC_ISR-LAPIC_PPRI
                    131: _C_LABEL(lapic_isr):
1.7       thorpej   132:        .space  PAGE_SIZE-LAPIC_ISR
1.1       fvdl      133: #else
1.30      junyoung  134: _C_LABEL(lapic_tpr):
1.1       fvdl      135:        .long 0
                    136: #endif
1.30      junyoung  137:
1.47.4.1  ad        138: _C_LABEL(cpu):         .long   0       # are we 80486, Pentium, or..
1.1       fvdl      139: _C_LABEL(atdevbase):   .long   0       # location of start of iomem in virtual
1.40      yamt      140: _C_LABEL(proc0uarea):  .long   0
1.31      junyoung  141: _C_LABEL(PDPpaddr):    .long   0       # paddr of PDP, for libkvm
1.30      junyoung  142:
1.1       fvdl      143:        .space 512
                    144: tmpstk:
                    145:
                    146:
1.35      yamt      147: #define        _RELOC(x)       ((x) - KERNBASE)
1.1       fvdl      148: #define        RELOC(x)        _RELOC(_C_LABEL(x))
                    149:
                    150:        .text
                    151:        .globl  _C_LABEL(kernel_text)
                    152:        .set    _C_LABEL(kernel_text),KERNTEXTOFF
                    153:
                    154:        .globl  start
                    155: start: movw    $0x1234,0x472                   # warm boot
                    156:
1.37      jmmv      157: #if defined(MULTIBOOT)
                    158:        jmp     1f
                    159:
                    160:        .align  4
                    161:        .globl  Multiboot_Header
                    162: _C_LABEL(Multiboot_Header):
1.44      jmmv      163: #define MULTIBOOT_HEADER_FLAGS (MULTIBOOT_HEADER_WANT_MEMORY)
1.37      jmmv      164:        .long   MULTIBOOT_HEADER_MAGIC
                    165:        .long   MULTIBOOT_HEADER_FLAGS
                    166:        .long   -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
                    167:
                    168: 1:
                    169:        /* Check if we are being executed by a Multiboot-compliant boot
                    170:         * loader. */
                    171:        cmpl    $MULTIBOOT_INFO_MAGIC,%eax
                    172:        jne     1f
                    173:
1.43      mrg       174:        /*
                    175:         * Indeed, a multiboot-compliant boot loader executed us.  We copy
1.37      jmmv      176:         * the received Multiboot information structure into kernel's data
                    177:         * space to process it later -- after we are relocated.  It will
1.43      mrg       178:         * be safer to run complex C code than doing it at this point.
                    179:         */
1.37      jmmv      180:        pushl   %ebx            # Address of Multiboot information
                    181:        call    _C_LABEL(multiboot_pre_reloc)
                    182:        addl    $4,%esp
1.38      jmmv      183:        jmp     2f
1.37      jmmv      184: #endif
                    185:
                    186: 1:
1.1       fvdl      187:        /*
1.38      jmmv      188:         * At this point, we know that a NetBSD-specific boot loader
                    189:         * booted this kernel.  The stack carries the following parameters:
1.41      jmmv      190:         * (boothowto, [bootdev], bootinfo, esym, biosextmem, biosbasemem),
1.38      jmmv      191:         * 4 bytes each.
1.1       fvdl      192:         */
1.38      jmmv      193:        addl    $4,%esp         # Discard return address to boot loader
                    194:        call    _C_LABEL(native_loader)
                    195:        addl    $24,%esp
1.1       fvdl      196:
                    197: 2:
                    198:        /* First, reset the PSL. */
                    199:        pushl   $PSL_MBO
                    200:        popfl
                    201:
                    202:        /* Clear segment registers; always null in proc0. */
                    203:        xorl    %eax,%eax
                    204:        movw    %ax,%fs
                    205:        movw    %ax,%gs
                    206:        decl    %eax
                    207:        movl    %eax,RELOC(cpu_info_primary)+CPU_INFO_LEVEL
                    208:
                    209:        /* Find out our CPU type. */
                    210:
                    211: try386:        /* Try to toggle alignment check flag; does not exist on 386. */
                    212:        pushfl
                    213:        popl    %eax
                    214:        movl    %eax,%ecx
                    215:        orl     $PSL_AC,%eax
                    216:        pushl   %eax
                    217:        popfl
                    218:        pushfl
                    219:        popl    %eax
                    220:        xorl    %ecx,%eax
                    221:        andl    $PSL_AC,%eax
                    222:        pushl   %ecx
                    223:        popfl
                    224:
                    225:        testl   %eax,%eax
                    226:        jnz     try486
                    227:
                    228:        /*
                    229:         * Try the test of a NexGen CPU -- ZF will not change on a DIV
                    230:         * instruction on a NexGen, it will on an i386.  Documented in
                    231:         * Nx586 Processor Recognition Application Note, NexGen, Inc.
                    232:         */
                    233:        movl    $0x5555,%eax
                    234:        xorl    %edx,%edx
                    235:        movl    $2,%ecx
                    236:        divl    %ecx
                    237:        jnz     is386
                    238:
                    239: isnx586:
                    240:        /*
                    241:         * Don't try cpuid, as Nx586s reportedly don't support the
                    242:         * PSL_ID bit.
                    243:         */
                    244:        movl    $CPU_NX586,RELOC(cpu)
                    245:        jmp     2f
                    246:
                    247: is386:
                    248:        movl    $CPU_386,RELOC(cpu)
                    249:        jmp     2f
                    250:
                    251: try486:        /* Try to toggle identification flag; does not exist on early 486s. */
                    252:        pushfl
                    253:        popl    %eax
                    254:        movl    %eax,%ecx
                    255:        xorl    $PSL_ID,%eax
                    256:        pushl   %eax
                    257:        popfl
                    258:        pushfl
                    259:        popl    %eax
                    260:        xorl    %ecx,%eax
                    261:        andl    $PSL_ID,%eax
                    262:        pushl   %ecx
                    263:        popfl
                    264:
                    265:        testl   %eax,%eax
                    266:        jnz     try586
                    267: is486: movl    $CPU_486,RELOC(cpu)
                    268:        /*
                    269:         * Check Cyrix CPU
                    270:         * Cyrix CPUs do not change the undefined flags following
                    271:         * execution of the divide instruction which divides 5 by 2.
                    272:         *
                    273:         * Note: CPUID is enabled on M2, so it passes another way.
                    274:         */
                    275:        pushfl
                    276:        movl    $0x5555, %eax
                    277:        xorl    %edx, %edx
                    278:        movl    $2, %ecx
                    279:        clc
                    280:        divl    %ecx
                    281:        jnc     trycyrix486
                    282:        popfl
                    283:        jmp 2f
                    284: trycyrix486:
                    285:        movl    $CPU_6x86,RELOC(cpu)    # set CPU type
                    286:        /*
                    287:         * Check for Cyrix 486 CPU by seeing if the flags change during a
                    288:         * divide. This is documented in the Cx486SLC/e SMM Programmer's
                    289:         * Guide.
                    290:         */
                    291:        xorl    %edx,%edx
                    292:        cmpl    %edx,%edx               # set flags to known state
                    293:        pushfl
                    294:        popl    %ecx                    # store flags in ecx
                    295:        movl    $-1,%eax
                    296:        movl    $4,%ebx
                    297:        divl    %ebx                    # do a long division
                    298:        pushfl
                    299:        popl    %eax
                    300:        xorl    %ecx,%eax               # are the flags different?
                    301:        testl   $0x8d5,%eax             # only check C|PF|AF|Z|N|V
                    302:        jne     2f                      # yes; must be Cyrix 6x86 CPU
                    303:        movl    $CPU_486DLC,RELOC(cpu)  # set CPU type
                    304:
                    305: #ifndef CYRIX_CACHE_WORKS
                    306:        /* Disable caching of the ISA hole only. */
                    307:        invd
                    308:        movb    $CCR0,%al               # Configuration Register index (CCR0)
                    309:        outb    %al,$0x22
                    310:        inb     $0x23,%al
                    311:        orb     $(CCR0_NC1|CCR0_BARB),%al
                    312:        movb    %al,%ah
                    313:        movb    $CCR0,%al
                    314:        outb    %al,$0x22
                    315:        movb    %ah,%al
                    316:        outb    %al,$0x23
                    317:        invd
                    318: #else /* CYRIX_CACHE_WORKS */
                    319:        /* Set cache parameters */
                    320:        invd                            # Start with guaranteed clean cache
                    321:        movb    $CCR0,%al               # Configuration Register index (CCR0)
                    322:        outb    %al,$0x22
                    323:        inb     $0x23,%al
                    324:        andb    $~CCR0_NC0,%al
                    325: #ifndef CYRIX_CACHE_REALLY_WORKS
                    326:        orb     $(CCR0_NC1|CCR0_BARB),%al
                    327: #else
                    328:        orb     $CCR0_NC1,%al
                    329: #endif
                    330:        movb    %al,%ah
                    331:        movb    $CCR0,%al
                    332:        outb    %al,$0x22
                    333:        movb    %ah,%al
                    334:        outb    %al,$0x23
                    335:        /* clear non-cacheable region 1 */
                    336:        movb    $(NCR1+2),%al
                    337:        outb    %al,$0x22
                    338:        movb    $NCR_SIZE_0K,%al
                    339:        outb    %al,$0x23
                    340:        /* clear non-cacheable region 2 */
                    341:        movb    $(NCR2+2),%al
                    342:        outb    %al,$0x22
                    343:        movb    $NCR_SIZE_0K,%al
                    344:        outb    %al,$0x23
                    345:        /* clear non-cacheable region 3 */
                    346:        movb    $(NCR3+2),%al
                    347:        outb    %al,$0x22
                    348:        movb    $NCR_SIZE_0K,%al
                    349:        outb    %al,$0x23
                    350:        /* clear non-cacheable region 4 */
                    351:        movb    $(NCR4+2),%al
                    352:        outb    %al,$0x22
                    353:        movb    $NCR_SIZE_0K,%al
                    354:        outb    %al,$0x23
                    355:        /* enable caching in CR0 */
                    356:        movl    %cr0,%eax
                    357:        andl    $~(CR0_CD|CR0_NW),%eax
                    358:        movl    %eax,%cr0
                    359:        invd
                    360: #endif /* CYRIX_CACHE_WORKS */
                    361:
                    362:        jmp     2f
                    363:
                    364: try586:        /* Use the `cpuid' instruction. */
                    365:        xorl    %eax,%eax
                    366:        cpuid
                    367:        movl    %eax,RELOC(cpu_info_primary)+CPU_INFO_LEVEL
                    368:
                    369: 2:
                    370:        /*
                    371:         * Finished with old stack; load new %esp now instead of later so we
                    372:         * can trace this code without having to worry about the trace trap
                    373:         * clobbering the memory test or the zeroing of the bss+bootstrap page
                    374:         * tables.
                    375:         *
                    376:         * The boot program should check:
                    377:         *      text+data <= &stack_variable - more_space_for_stack
                    378:         *      text+data+bss+pad+space_for_page_tables <= end_of_memory
                    379:         * Oops, the gdt is in the carcass of the boot program so clearing
                    380:         * the rest of memory is still not possible.
                    381:         */
                    382:        movl    $_RELOC(tmpstk),%esp    # bootstrap stack end location
                    383:
                    384: /*
                    385:  * Virtual address space of kernel:
                    386:  *
1.30      junyoung  387:  * text | data | bss | [syms] | page dir | proc0 kstack
1.1       fvdl      388:  *                           0          1       2      3
                    389:  */
1.7       thorpej   390: #define        PROC0PDIR       ((0)              * PAGE_SIZE)
                    391: #define        PROC0STACK      ((1)              * PAGE_SIZE)
                    392: #define        SYSMAP          ((1+UPAGES)       * PAGE_SIZE)
                    393: #define        TABLESIZE       ((1+UPAGES) * PAGE_SIZE) /* + nkpde * PAGE_SIZE */
1.1       fvdl      394:
                    395:        /* Find end of kernel image. */
                    396:        movl    $RELOC(end),%edi
1.8       fvdl      397: #if (NKSYMS || defined(DDB) || defined(LKM)) && !defined(SYMTAB_SPACE)
1.1       fvdl      398:        /* Save the symbols (if loaded). */
                    399:        movl    RELOC(esym),%eax
                    400:        testl   %eax,%eax
                    401:        jz      1f
1.35      yamt      402:        subl    $KERNBASE,%eax
1.1       fvdl      403:        movl    %eax,%edi
                    404: 1:
                    405: #endif
                    406:
                    407:        /* Calculate where to start the bootstrap tables. */
                    408:        movl    %edi,%esi                       # edi = esym ? esym : end
                    409:        addl    $PGOFSET,%esi                   # page align up
                    410:        andl    $~PGOFSET,%esi
                    411:
                    412:        /*
                    413:         * Calculate the size of the kernel page table directory, and
1.29      mycroft   414:         * how many entries it will have.  Adjust nkpde to the actual
                    415:         * kernel size automatically.  Account for the bootstrap tables,
                    416:         * round up, and add an extra 4MB.
1.1       fvdl      417:         */
1.29      mycroft   418:        leal    TABLESIZE+NBPD+PDOFSET(%edi),%eax
                    419:        shrl    $PDSHIFT,%eax
1.1       fvdl      420:        movl    RELOC(nkpde),%ecx               # get nkpde
1.29      mycroft   421:        cmpl    %ecx,%eax
                    422:        jb      1f
                    423:        movl    %eax,%ecx
                    424: 1:     cmpl    $NKPTP_MIN,%ecx                 # larger than min?
1.1       fvdl      425:        jge     1f
                    426:        movl    $NKPTP_MIN,%ecx                 # set at min
                    427:        jmp     2f
                    428: 1:     cmpl    $NKPTP_MAX,%ecx                 # larger than max?
                    429:        jle     2f
                    430:        movl    $NKPTP_MAX,%ecx
1.29      mycroft   431: 2:     movl    %ecx,RELOC(nkpde)
1.1       fvdl      432:
                    433:        /* Clear memory for bootstrap tables. */
                    434:        shll    $PGSHIFT,%ecx
                    435:        addl    $TABLESIZE,%ecx
                    436:        addl    %esi,%ecx                       # end of tables
                    437:        subl    %edi,%ecx                       # size of tables
                    438:        shrl    $2,%ecx
                    439:        xorl    %eax,%eax
                    440:        cld
                    441:        rep
                    442:        stosl
                    443:
                    444: /*
                    445:  * fillkpt
                    446:  *     eax = pte (page frame | control | status)
                    447:  *     ebx = page table address
                    448:  *     ecx = number of pages to map
                    449:  */
                    450: #define        fillkpt         \
                    451: 1:     movl    %eax,(%ebx)     ; \
1.7       thorpej   452:        addl    $PAGE_SIZE,%eax ; /* increment physical address */ \
1.1       fvdl      453:        addl    $4,%ebx         ; /* next pte */ \
                    454:        loop    1b              ;
                    455:
                    456: /*
                    457:  * Build initial page tables.
                    458:  */
                    459:        /* Calculate end of text segment, rounded to a page. */
                    460:        leal    (RELOC(etext)+PGOFSET),%edx
                    461:        andl    $~PGOFSET,%edx
1.30      junyoung  462:
1.1       fvdl      463:        /* Skip over the first 1MB. */
                    464:        movl    $_RELOC(KERNTEXTOFF),%eax
                    465:        movl    %eax,%ecx
                    466:        shrl    $PGSHIFT,%ecx
                    467:        leal    (SYSMAP)(%esi,%ecx,4),%ebx
                    468:
                    469:        /* Map the kernel text read-only. */
                    470:        movl    %edx,%ecx
                    471:        subl    %eax,%ecx
                    472:        shrl    $PGSHIFT,%ecx
                    473:        orl     $(PG_V|PG_KR),%eax
                    474:        fillkpt
                    475:
                    476:        /* Map the data, BSS, and bootstrap tables read-write. */
                    477:        leal    (PG_V|PG_KW)(%edx),%eax
                    478:        movl    RELOC(nkpde),%ecx
                    479:        shll    $PGSHIFT,%ecx
                    480:        addl    $TABLESIZE,%ecx
                    481:        addl    %esi,%ecx                               # end of tables
                    482:        subl    %edx,%ecx                               # subtract end of text
                    483:        shrl    $PGSHIFT,%ecx
                    484:        fillkpt
                    485:
                    486:        /* Map ISA I/O memory. */
                    487:        movl    $(IOM_BEGIN|PG_V|PG_KW/*|PG_N*/),%eax   # having these bits set
                    488:        movl    $(IOM_SIZE>>PGSHIFT),%ecx               # for this many pte s,
                    489:        fillkpt
                    490:
                    491: /*
                    492:  * Construct a page table directory.
                    493:  */
                    494:        /* Install PDEs for temporary double map of kernel. */
                    495:        movl    RELOC(nkpde),%ecx                       # for this many pde s,
                    496:        leal    (PROC0PDIR+0*4)(%esi),%ebx              # which is where temp maps!
                    497:        leal    (SYSMAP+PG_V|PG_KW)(%esi),%eax          # pte for KPT in proc 0,
                    498:        fillkpt
                    499:
                    500:        /* Map kernel PDEs. */
                    501:        movl    RELOC(nkpde),%ecx                       # for this many pde s,
                    502:        leal    (PROC0PDIR+PDSLOT_KERN*4)(%esi),%ebx    # kernel pde offset
                    503:        leal    (SYSMAP+PG_V|PG_KW)(%esi),%eax          # pte for KPT in proc 0,
                    504:        fillkpt
                    505:
                    506:        /* Install a PDE recursively mapping page directory as a page table! */
                    507:        leal    (PROC0PDIR+PG_V|PG_KW)(%esi),%eax       # pte for ptd
                    508:        movl    %eax,(PROC0PDIR+PDSLOT_PTE*4)(%esi)     # recursive PD slot
                    509:
1.31      junyoung  510:        /* Save phys. addr of PDP, for libkvm. */
                    511:        movl    %esi,RELOC(PDPpaddr)
1.1       fvdl      512:
                    513:        /* Load base of page directory and enable mapping. */
                    514:        movl    %esi,%eax               # phys address of ptd in proc 0
                    515:        movl    %eax,%cr3               # load ptd addr into mmu
                    516:        movl    %cr0,%eax               # get control word
                    517:                                        # enable paging & NPX emulation
                    518:        orl     $(CR0_PE|CR0_PG|CR0_NE|CR0_TS|CR0_EM|CR0_MP),%eax
                    519:        movl    %eax,%cr0               # and let's page NOW!
                    520:
                    521:        pushl   $begin                  # jump to high mem
                    522:        ret
                    523:
                    524: begin:
1.35      yamt      525:        /* Now running relocated at KERNBASE.  Remove double mapping. */
1.1       fvdl      526:        movl    _C_LABEL(nkpde),%ecx            # for this many pde s,
                    527:        leal    (PROC0PDIR+0*4)(%esi),%ebx      # which is where temp maps!
1.35      yamt      528:        addl    $(KERNBASE), %ebx       # now use relocated address
1.1       fvdl      529: 1:     movl    $0,(%ebx)
                    530:        addl    $4,%ebx # next pde
                    531:        loop    1b
                    532:
                    533:        /* Relocate atdevbase. */
                    534:        movl    _C_LABEL(nkpde),%edx
                    535:        shll    $PGSHIFT,%edx
1.35      yamt      536:        addl    $(TABLESIZE+KERNBASE),%edx
1.1       fvdl      537:        addl    %esi,%edx
                    538:        movl    %edx,_C_LABEL(atdevbase)
                    539:
                    540:        /* Set up bootstrap stack. */
1.35      yamt      541:        leal    (PROC0STACK+KERNBASE)(%esi),%eax
1.40      yamt      542:        movl    %eax,_C_LABEL(proc0uarea)
                    543:        leal    (KSTACK_SIZE-FRAMESIZE)(%eax),%esp
                    544:        movl    %esi,(KSTACK_SIZE+PCB_CR3)(%eax)        # pcb->pcb_cr3
1.1       fvdl      545:        xorl    %ebp,%ebp               # mark end of frames
                    546:
1.37      jmmv      547: #if defined(MULTIBOOT)
                    548:        /* It is now safe to parse the Multiboot information structure
                    549:         * we saved before from C code.  Note that we cannot delay its
                    550:         * parsing any more because initgdt (called below) needs to make
                    551:         * use of this information. */
                    552:        call    _C_LABEL(multiboot_post_reloc)
                    553: #endif
                    554:
1.1       fvdl      555:        subl    $NGDT*8, %esp           # space for temporary gdt
                    556:        pushl   %esp
                    557:        call    _C_LABEL(initgdt)
                    558:        addl    $4,%esp
1.30      junyoung  559:
1.1       fvdl      560:        movl    _C_LABEL(nkpde),%eax
                    561:        shll    $PGSHIFT,%eax
                    562:        addl    $TABLESIZE,%eax
                    563:        addl    %esi,%eax               # skip past stack and page tables
                    564:
                    565:        pushl   %eax
                    566:        call    _C_LABEL(init386)       # wire 386 chip for unix operation
                    567:        addl    $4+NGDT*8,%esp          # pop temporary gdt
                    568:
                    569: #ifdef SAFARI_FIFO_HACK
                    570:        movb    $5,%al
                    571:        movw    $0x37b,%dx
                    572:        outb    %al,%dx
                    573:        movw    $0x37f,%dx
                    574:        inb     %dx,%al
                    575:        movb    %al,%cl
                    576:
                    577:        orb     $1,%cl
                    578:
                    579:        movb    $5,%al
                    580:        movw    $0x37b,%dx
                    581:        outb    %al,%dx
                    582:        movw    $0x37f,%dx
                    583:        movb    %cl,%al
                    584:        outb    %al,%dx
                    585: #endif /* SAFARI_FIFO_HACK */
                    586:
                    587:        call    _C_LABEL(main)
                    588:
                    589: /*
1.47.4.1  ad        590:  * void lwp_trampoline(void);
                    591:  *
1.1       fvdl      592:  * This is a trampoline function pushed onto the stack of a newly created
                    593:  * process in order to do some additional setup.  The trampoline is entered by
                    594:  * cpu_switch()ing to the process, so we abuse the callee-saved registers used
                    595:  * by cpu_switch() to store the information about the stub to call.
                    596:  * NOTE: This function does not have a normal calling sequence!
                    597:  */
1.47.4.1  ad        598: NENTRY(lwp_trampoline)
                    599:        pushl   %ebp
                    600:        xorl    %ebp,%ebp
                    601:        pushl   %eax
                    602:        call    _C_LABEL(lwp_startup)
                    603:        addl    $8,%esp
1.1       fvdl      604:        pushl   %ebx
                    605:        call    *%esi
                    606:        addl    $4,%esp
1.24      yamt      607:        DO_DEFERRED_SWITCH(%eax)
1.1       fvdl      608:        INTRFASTEXIT
                    609:        /* NOTREACHED */
                    610:
                    611: /*
1.47.4.1  ad        612:  * sigcode()
                    613:  *
                    614:  * Signal trampoline; copied to top of user stack.  Used only for
                    615:  * compatibility with old releases of NetBSD.
1.1       fvdl      616:  */
                    617: NENTRY(sigcode)
                    618:        /*
                    619:         * Handler has returned here as if we called it.  The sigcontext
                    620:         * is on the stack after the 3 args "we" pushed.
                    621:         */
                    622:        leal    12(%esp),%eax           # get pointer to sigcontext
                    623:        movl    %eax,4(%esp)            # put it in the argument slot
                    624:                                        # fake return address already there
1.17      christos  625:        movl    $SYS_compat_16___sigreturn14,%eax
1.1       fvdl      626:        int     $0x80                   # enter kernel with args on stack
                    627:        movl    $SYS_exit,%eax
                    628:        int     $0x80                   # exit if sigreturn fails
                    629:        .globl  _C_LABEL(esigcode)
                    630: _C_LABEL(esigcode):
                    631:
                    632: /*
1.47.4.1  ad        633:  * int setjmp(label_t *)
                    634:  *
                    635:  * Used primarily by DDB.
1.1       fvdl      636:  */
                    637: ENTRY(setjmp)
                    638:        movl    4(%esp),%eax
                    639:        movl    %ebx,(%eax)             # save ebx
                    640:        movl    %esp,4(%eax)            # save esp
                    641:        movl    %ebp,8(%eax)            # save ebp
                    642:        movl    %esi,12(%eax)           # save esi
                    643:        movl    %edi,16(%eax)           # save edi
                    644:        movl    (%esp),%edx             # get rta
                    645:        movl    %edx,20(%eax)           # save eip
1.47.4.1  ad        646:        xorl    %eax,%eax               # return 0
1.1       fvdl      647:        ret
                    648:
1.47.4.1  ad        649: /*
                    650:  * int longjmp(label_t *)
                    651:  *
                    652:  * Used primarily by DDB.
                    653:  */
1.1       fvdl      654: ENTRY(longjmp)
                    655:        movl    4(%esp),%eax
                    656:        movl    (%eax),%ebx             # restore ebx
                    657:        movl    4(%eax),%esp            # restore esp
                    658:        movl    8(%eax),%ebp            # restore ebp
                    659:        movl    12(%eax),%esi           # restore esi
                    660:        movl    16(%eax),%edi           # restore edi
                    661:        movl    20(%eax),%edx           # get rta
                    662:        movl    %edx,(%esp)             # put in return frame
1.47.4.1  ad        663:        movl    $1,%eax                 # return 1
1.1       fvdl      664:        ret
                    665:
                    666: /*
1.47.4.2  ad        667:  * struct lwp *cpu_switchto(struct lwp *oldlwp, struct newlwp,
                    668:  *                         bool returning)
1.30      junyoung  669:  *
1.47.4.1  ad        670:  *     1. if (oldlwp != NULL), save its context.
                    671:  *     2. then, restore context of newlwp.
                    672:  *
                    673:  * Note that the stack frame layout is known to "struct switchframe" in
                    674:  * <machine/frame.h> and to the code in cpu_lwp_fork() which initializes
1.5       thorpej   675:  * it for a new lwp.
1.1       fvdl      676:  */
1.47.4.1  ad        677: ENTRY(cpu_switchto)
1.1       fvdl      678:        pushl   %ebx
                    679:        pushl   %esi
                    680:        pushl   %edi
                    681:
1.47.4.1  ad        682:        movl    16(%esp),%esi           # oldlwp
                    683:        movl    20(%esp),%edi           # newlwp
1.47.4.2  ad        684:        movl    24(%esp),%edx           # returning
1.1       fvdl      685:        testl   %esi,%esi
1.47.4.1  ad        686:        jz      1f
1.1       fvdl      687:
1.47.4.1  ad        688:        /* Save old context. */
                    689:        movl    L_ADDR(%esi),%eax
                    690:        movl    %esp,PCB_ESP(%eax)
                    691:        movl    %ebp,PCB_EBP(%eax)
                    692:
                    693:        /* Switch to newlwp's stack. */
                    694: 1:     movl    L_ADDR(%edi),%ebx
                    695:        movl    PCB_EBP(%ebx),%ebp
                    696:        movl    PCB_ESP(%ebx),%esp
1.1       fvdl      697:
1.47.4.2  ad        698:        /* Set curlwp. */
                    699:        movl    %edi,CPUVAR(CURLWP)
                    700:
                    701:        /* Skip the rest if returning to a pinned LWP. */
                    702:        testl   %edx,%edx
                    703:        jnz     4f
                    704:
1.47.4.1  ad        705:        /* Switch TSS.  Reset "task busy" flag before loading. */
1.26      yamt      706:        movl    %cr3,%eax
1.47.4.1  ad        707:        movl    %eax,PCB_CR3(%ebx)      # for TSS gates
1.1       fvdl      708:        movl    CPUVAR(GDT),%eax
1.5       thorpej   709:        movl    L_MD_TSS_SEL(%edi),%edx
1.1       fvdl      710:        andl    $~0x0200,4(%eax,%edx, 1)
                    711:        ltr     %dx
                    712:
1.47.4.1  ad        713:        /* Don't bother with the rest if switching to a system process. */
                    714:        testl   $LW_SYSTEM,L_FLAG(%edi)
                    715:        jnz     4f
                    716:
                    717:        /* Is this process using RAS (restartable atomic sequences)? */
                    718:        movl    L_PROC(%edi),%eax
                    719:        cmpl    $0,P_RASLIST(%eax)
                    720:        jne     5f
                    721:
                    722:        /*
                    723:         * Restore cr0 (including FPU state).  Raise the IPL to IPL_IPI.
                    724:         * FPU IPIs can alter the LWP's saved cr0.  Dropping the priority
                    725:         * is deferred until mi_switch(), when cpu_switchto() returns.
                    726:         */
                    727: 2:     movl    $IPL_IPI,CPUVAR(ILEVEL)
                    728:        movl    PCB_CR0(%ebx),%ecx
                    729:        movl    %cr0,%edx
1.1       fvdl      730:
1.30      junyoung  731:        /*
1.22      wiz       732:         * If our floating point registers are on a different CPU,
1.47.4.1  ad        733:         * set CR0_TS so we'll trap rather than reuse bogus state.
1.1       fvdl      734:         */
1.47.4.1  ad        735:        movl    PCB_FPCPU(%ebx),%eax
                    736:        cmpl    CPUVAR(SELF),%eax
                    737:        je      3f
1.1       fvdl      738:        orl     $CR0_TS,%ecx
                    739:
1.47.4.1  ad        740:        /* Reloading CR0 is very expensive - avoid if possible. */
                    741: 3:     cmpl    %edx,%ecx
                    742:        je      4f
                    743:        movl    %ecx,%cr0
1.30      junyoung  744:
1.47.4.1  ad        745:        /* Return to the new LWP, returning 'oldlwp' in %eax. */
                    746: 4:     movl    %esi,%eax
1.1       fvdl      747:        popl    %edi
                    748:        popl    %esi
                    749:        popl    %ebx
                    750:        ret
1.20      dsl       751:
1.47.4.1  ad        752:        /* Check for restartable atomic sequences (RAS). */
                    753: 5:     movl    L_MD_REGS(%edi),%ecx
                    754:        pushl   TF_EIP(%ecx)
1.20      dsl       755:        pushl   %eax
                    756:        call    _C_LABEL(ras_lookup)
                    757:        addl    $8,%esp
                    758:        cmpl    $-1,%eax
1.47.4.1  ad        759:        je      2b
1.47.4.5  ad        760:        movl    L_MD_REGS(%edi),%ecx
                    761:        movl    %eax,TF_EIP(%ecx)
1.47.4.1  ad        762:        jmp     2b
1.1       fvdl      763:
                    764: /*
                    765:  * void savectx(struct pcb *pcb);
1.47.4.1  ad        766:  *
1.1       fvdl      767:  * Update pcb, saving current processor state.
                    768:  */
                    769: ENTRY(savectx)
1.47      skrll     770:        movl    4(%esp),%edx            # edx = pcb
1.1       fvdl      771:        movl    %esp,PCB_ESP(%edx)
                    772:        movl    %ebp,PCB_EBP(%edx)
                    773:        ret
                    774:
                    775: /*
1.47.4.1  ad        776:  * osyscall()
                    777:  *
1.1       fvdl      778:  * Old call gate entry for syscall
                    779:  */
                    780: IDTVEC(osyscall)
1.47.4.1  ad        781:        pushfl                  # set eflags in trap frame
1.1       fvdl      782:        popl    8(%esp)
                    783:        pushl   $7              # size of instruction for restart
                    784:        jmp     syscall1
                    785:
                    786: /*
1.47.4.1  ad        787:  * syscall()
                    788:  *
1.1       fvdl      789:  * Trap gate entry for syscall
                    790:  */
                    791: IDTVEC(syscall)
                    792:        pushl   $2              # size of instruction for restart
                    793: syscall1:
                    794:        pushl   $T_ASTFLT       # trap # for doing ASTs
                    795:        INTRENTRY
                    796:
                    797: #ifdef DIAGNOSTIC
1.24      yamt      798:        cmpl    $0, CPUVAR(WANT_PMAPLOAD)
                    799:        jz      1f
                    800:        pushl   $6f
                    801:        call    _C_LABEL(printf)
                    802:        addl    $4, %esp
                    803: 1:
1.1       fvdl      804:        movl    CPUVAR(ILEVEL),%ebx
                    805:        testl   %ebx,%ebx
                    806:        jz      1f
                    807:        pushl   $5f
                    808:        call    _C_LABEL(printf)
                    809:        addl    $4,%esp
                    810: #ifdef DDB
                    811:        int     $3
                    812: #endif
1.30      junyoung  813: 1:
1.1       fvdl      814: #endif /* DIAGNOSTIC */
1.5       thorpej   815:        movl    CPUVAR(CURLWP),%edx
                    816:        movl    %esp,L_MD_REGS(%edx)    # save pointer to frame
                    817:        movl    L_PROC(%edx),%edx
1.15      fvdl      818:        pushl   %esp
1.1       fvdl      819:        call    *P_MD_SYSCALL(%edx)     # get pointer to syscall() function
1.15      fvdl      820:        addl    $4,%esp
1.27      yamt      821: .Lsyscall_checkast:
1.24      yamt      822:        /* Check for ASTs on exit to user mode. */
1.1       fvdl      823:        cli
1.5       thorpej   824:        CHECK_ASTPENDING(%eax)
1.1       fvdl      825:        je      1f
                    826:        /* Always returning to user mode here. */
1.5       thorpej   827:        CLEAR_ASTPENDING(%eax)
1.1       fvdl      828:        sti
                    829:        /* Pushed T_ASTFLT into tf_trapno on entry. */
1.15      fvdl      830:        pushl   %esp
1.1       fvdl      831:        call    _C_LABEL(trap)
1.15      fvdl      832:        addl    $4,%esp
1.27      yamt      833:        jmp     .Lsyscall_checkast      /* re-check ASTs */
1.24      yamt      834: 1:     CHECK_DEFERRED_SWITCH(%eax)
                    835:        jnz     9f
1.1       fvdl      836: #ifndef DIAGNOSTIC
1.24      yamt      837:        INTRFASTEXIT
1.1       fvdl      838: #else /* DIAGNOSTIC */
1.24      yamt      839:        cmpl    $IPL_NONE,CPUVAR(ILEVEL)
1.1       fvdl      840:        jne     3f
                    841:        INTRFASTEXIT
                    842: 3:     sti
                    843:        pushl   $4f
                    844:        call    _C_LABEL(printf)
                    845:        addl    $4,%esp
                    846: #ifdef DDB
                    847:        int     $3
                    848: #endif /* DDB */
                    849:        movl    $IPL_NONE,CPUVAR(ILEVEL)
                    850:        jmp     2b
                    851: 4:     .asciz  "WARNING: SPL NOT LOWERED ON SYSCALL EXIT\n"
1.30      junyoung  852: 5:     .asciz  "WARNING: SPL NOT ZERO ON SYSCALL ENTRY\n"
                    853: 6:     .asciz  "WARNING: WANT PMAPLOAD ON SYSCALL ENTRY\n"
1.1       fvdl      854: #endif /* DIAGNOSTIC */
1.24      yamt      855: 9:     sti
                    856:        call    _C_LABEL(pmap_load)
1.27      yamt      857:        jmp     .Lsyscall_checkast      /* re-check ASTs */
1.1       fvdl      858:
                    859: #if NNPX > 0
                    860: /*
                    861:  * Special interrupt handlers.  Someday intr0-intr15 will be used to count
                    862:  * interrupts.  We'll still need a special exception 16 handler.  The busy
                    863:  * latch stuff in probintr() can be moved to npxprobe().
                    864:  */
                    865:
1.47.4.1  ad        866: /*
                    867:  * void probeintr(void)
                    868:  */
1.1       fvdl      869: NENTRY(probeintr)
                    870:        ss
                    871:        incl    _C_LABEL(npx_intrs_while_probing)
                    872:        pushl   %eax
                    873:        movb    $0x20,%al       # EOI (asm in strings loses cpp features)
                    874:        outb    %al,$0xa0       # IO_ICU2
                    875:        outb    %al,$0x20       # IO_ICU1
                    876:        movb    $0,%al
                    877:        outb    %al,$0xf0       # clear BUSY# latch
                    878:        popl    %eax
                    879:        iret
                    880:
1.47.4.1  ad        881: /*
                    882:  * void probetrap(void)
                    883:  */
1.1       fvdl      884: NENTRY(probetrap)
                    885:        ss
                    886:        incl    _C_LABEL(npx_traps_while_probing)
                    887:        fnclex
                    888:        iret
                    889:
1.47.4.1  ad        890: /*
                    891:  * int npx586bug1(int a, int b)
                    892:  */
1.1       fvdl      893: NENTRY(npx586bug1)
                    894:        fildl   4(%esp)         # x
                    895:        fildl   8(%esp)         # y
                    896:        fld     %st(1)
                    897:        fdiv    %st(1),%st      # x/y
                    898:        fmulp   %st,%st(1)      # (x/y)*y
                    899:        fsubrp  %st,%st(1)      # x-(x/y)*y
                    900:        pushl   $0
                    901:        fistpl  (%esp)
                    902:        popl    %eax
                    903:        ret
                    904: #endif /* NNPX > 0 */
1.47.4.3  ad        905:
                    906: /*
                    907:  * void sse2_zero_page(void *pg)
                    908:  *
                    909:  * Zero a page without polluting the cache.
                    910:  */
                    911: ENTRY(sse2_zero_page)
                    912:        pushl   %ebp
                    913:        movl    %esp,%ebp
                    914:        movl    8(%esp), %edx
                    915:        movl    $PAGE_SIZE, %ecx
                    916:        xorl    %eax, %eax
                    917:        .align  16
                    918: 1:
                    919:        movnti  %eax, 0(%edx)
                    920:        movnti  %eax, 4(%edx)
                    921:        movnti  %eax, 8(%edx)
                    922:        movnti  %eax, 12(%edx)
                    923:        movnti  %eax, 16(%edx)
                    924:        movnti  %eax, 20(%edx)
                    925:        movnti  %eax, 24(%edx)
                    926:        movnti  %eax, 28(%edx)
                    927:        subl    $32, %ecx
                    928:        leal    32(%edx), %edx
                    929:        jnz     1b
                    930:        sfence
                    931:        pop     %ebp
                    932:        ret
                    933:
                    934: /*
                    935:  * void sse2_copy_page(void *src, void *dst)
                    936:  *
                    937:  * Copy a page without polluting the cache.
                    938:  */
                    939: ENTRY(sse2_copy_page)
                    940:        pushl   %ebp
1.47.4.4  yamt      941:        pushl   %ebx
1.47.4.3  ad        942:        pushl   %esi
                    943:        pushl   %edi
1.47.4.4  yamt      944:        movl    20(%esp), %esi
                    945:        movl    24(%esp), %edi
                    946:        movl    $PAGE_SIZE, %ebp
1.47.4.3  ad        947:        .align  16
                    948: 1:
                    949:        movl    0(%esi), %eax
                    950:        movl    4(%esi), %ebx
                    951:        movl    8(%esi), %ecx
                    952:        movl    12(%esi), %edx
                    953:        movnti  %eax, 0(%edi)
                    954:        movnti  %ebx, 4(%edi)
                    955:        movnti  %ecx, 8(%edi)
                    956:        movnti  %edx, 12(%edi)
                    957:        subl    $16, %ebp
                    958:        leal    16(%esi), %esi
                    959:        leal    16(%edi), %edi
                    960:        jnz     1b
                    961:        sfence
                    962:        popl    %edi
                    963:        popl    %esi
1.47.4.4  yamt      964:        popl    %ebx
1.47.4.3  ad        965:        popl    %ebp
                    966:        ret

CVSweb <webmaster@jp.NetBSD.org>