Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/arch/i386/i386/locore.S,v rcsdiff: /ftp/cvs/cvsroot/src/sys/arch/i386/i386/locore.S,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.6 retrieving revision 1.24 diff -u -p -r1.6 -r1.24 --- src/sys/arch/i386/i386/locore.S 2003/02/09 15:49:34 1.6 +++ src/sys/arch/i386/i386/locore.S 2004/02/20 17:35:01 1.24 @@ -1,4 +1,4 @@ -/* $NetBSD: locore.S,v 1.6 2003/02/09 15:49:34 drochner Exp $ */ +/* $NetBSD: locore.S,v 1.24 2004/02/20 17:35:01 yamt Exp $ */ /*- * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc. @@ -51,11 +51,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -74,22 +70,23 @@ * @(#)locore.s 7.3 (Berkeley) 5/13/91 */ +#include "opt_compat_netbsd.h" +#include "opt_compat_oldboot.h" #include "opt_cputype.h" #include "opt_ddb.h" #include "opt_ipkdb.h" -#include "opt_vm86.h" -#include "opt_user_ldt.h" -#include "opt_dummy_nops.h" -#include "opt_compat_oldboot.h" -#include "opt_multiprocessor.h" #include "opt_lockdebug.h" +#include "opt_multiprocessor.h" #include "opt_realmem.h" +#include "opt_user_ldt.h" +#include "opt_vm86.h" #include "npx.h" #include "assym.h" #include "apm.h" #include "lapic.h" #include "ioapic.h" +#include "ksyms.h" #include #include @@ -128,7 +125,7 @@ #define GET_CURPCB(reg) movl CPUVAR(CURPCB),reg #define SET_CURPCB(reg) movl reg,CPUVAR(CURPCB) - + #define CLEAR_RESCHED(reg) movl reg,CPUVAR(RESCHED) /* XXX temporary kluge; these should not be here */ @@ -163,7 +160,7 @@ * XXX 4 == sizeof pde */ .set _C_LABEL(PTmap),(PDSLOT_PTE << PDSHIFT) - .set _C_LABEL(PTD),(_C_LABEL(PTmap) + PDSLOT_PTE * NBPG) + .set _C_LABEL(PTD),(_C_LABEL(PTmap) + PDSLOT_PTE * PAGE_SIZE) .set _C_LABEL(PTDpde),(_C_LABEL(PTD) + PDSLOT_PTE * 4) /* @@ -173,7 +170,7 @@ * XXX 4 == sizeof pde */ .set _C_LABEL(APTmap),(PDSLOT_APTE << PDSHIFT) - .set _C_LABEL(APTD),(_C_LABEL(APTmap) + PDSLOT_APTE * NBPG) + .set _C_LABEL(APTD),(_C_LABEL(APTmap) + PDSLOT_APTE * PAGE_SIZE) .set _C_LABEL(APTDpde),(_C_LABEL(PTD) + PDSLOT_APTE * 4) @@ -183,7 +180,6 @@ .data .globl _C_LABEL(cpu) - .globl _C_LABEL(cpu_feature) .globl _C_LABEL(esym),_C_LABEL(boothowto) .globl _C_LABEL(bootinfo),_C_LABEL(atdevbase) #ifdef COMPAT_OLDBOOT @@ -199,7 +195,7 @@ #if NLAPIC > 0 #ifdef __ELF__ - .align NBPG + .align PAGE_SIZE #else .align 12 #endif @@ -214,7 +210,7 @@ _C_LABEL(lapic_tpr): _C_LABEL(lapic_ppr): .space LAPIC_ISR-LAPIC_PPRI _C_LABEL(lapic_isr): - .space NBPG-LAPIC_ISR + .space PAGE_SIZE-LAPIC_ISR #else _C_LABEL(lapic_tpr): .long 0 @@ -223,8 +219,6 @@ _C_LABEL(lapic_tpr): _C_LABEL(cpu): .long 0 # are we 386, 386sx, or 486, # or Pentium, or.. -_C_LABEL(cpu_feature): .long 0 # feature flags from 'cpuid' - # instruction _C_LABEL(esym): .long 0 # ptr to end of syms _C_LABEL(atdevbase): .long 0 # location of start of iomem in virtual _C_LABEL(proc0paddr): .long 0 @@ -244,7 +238,7 @@ _C_LABEL(biosextmem): .long REALEXTMEM tmpstk: -#define _RELOC(x) ((x) - KERNBASE) +#define _RELOC(x) ((x) - KERNBASE_LOCORE) #define RELOC(x) _RELOC(_C_LABEL(x)) .text @@ -298,7 +292,7 @@ start: movw $0x1234,0x472 # warm boot movl 16(%esp),%eax testl %eax,%eax jz 1f - addl $KERNBASE,%eax + addl $KERNBASE_LOCORE,%eax 1: movl %eax,RELOC(esym) movl RELOC(biosextmem),%eax @@ -506,19 +500,19 @@ try586: /* Use the `cpuid' instruction. * text | data | bss | [syms] | page dir | proc0 kstack * 0 1 2 3 */ -#define PROC0PDIR ((0) * NBPG) -#define PROC0STACK ((1) * NBPG) -#define SYSMAP ((1+UPAGES) * NBPG) -#define TABLESIZE ((1+UPAGES) * NBPG) /* + nkpde * NBPG */ +#define PROC0PDIR ((0) * PAGE_SIZE) +#define PROC0STACK ((1) * PAGE_SIZE) +#define SYSMAP ((1+UPAGES) * PAGE_SIZE) +#define TABLESIZE ((1+UPAGES) * PAGE_SIZE) /* + nkpde * PAGE_SIZE */ /* Find end of kernel image. */ movl $RELOC(end),%edi -#if defined(DDB) && !defined(SYMTAB_SPACE) +#if (NKSYMS || defined(DDB) || defined(LKM)) && !defined(SYMTAB_SPACE) /* Save the symbols (if loaded). */ movl RELOC(esym),%eax testl %eax,%eax jz 1f - subl $KERNBASE,%eax + subl $KERNBASE_LOCORE,%eax movl %eax,%edi 1: #endif @@ -561,7 +555,7 @@ try586: /* Use the `cpuid' instruction. */ #define fillkpt \ 1: movl %eax,(%ebx) ; \ - addl $NBPG,%eax ; /* increment physical address */ \ + addl $PAGE_SIZE,%eax ; /* increment physical address */ \ addl $4,%ebx ; /* next pte */ \ loop 1b ; @@ -634,10 +628,10 @@ try586: /* Use the `cpuid' instruction. ret begin: - /* Now running relocated at KERNBASE. Remove double mapping. */ + /* Now running relocated at KERNBASE_LOCORE. Remove double mapping. */ movl _C_LABEL(nkpde),%ecx # for this many pde s, leal (PROC0PDIR+0*4)(%esi),%ebx # which is where temp maps! - addl $(KERNBASE), %ebx # now use relocated address + addl $(KERNBASE_LOCORE), %ebx # now use relocated address 1: movl $0,(%ebx) addl $4,%ebx # next pde loop 1b @@ -645,12 +639,12 @@ begin: /* Relocate atdevbase. */ movl _C_LABEL(nkpde),%edx shll $PGSHIFT,%edx - addl $(TABLESIZE+KERNBASE),%edx + addl $(TABLESIZE+KERNBASE_LOCORE),%edx addl %esi,%edx movl %edx,_C_LABEL(atdevbase) /* Set up bootstrap stack. */ - leal (PROC0STACK+KERNBASE)(%esi),%eax + leal (PROC0STACK+KERNBASE_LOCORE)(%esi),%eax movl %eax,_C_LABEL(proc0paddr) leal (USPACE-FRAMESIZE)(%eax),%esp movl %esi,PCB_CR3(%eax) # pcb->pcb_cr3 @@ -707,11 +701,12 @@ NENTRY(proc_trampoline) pushl %ebx call *%esi addl $4,%esp + DO_DEFERRED_SWITCH(%eax) INTRFASTEXIT /* NOTREACHED */ /*****************************************************************************/ - +#ifdef COMPAT_16 /* * Signal trampoline; copied to top of user stack. */ @@ -724,12 +719,19 @@ NENTRY(sigcode) leal 12(%esp),%eax # get pointer to sigcontext movl %eax,4(%esp) # put it in the argument slot # fake return address already there +#if defined(SYS_compat_16___sigreturn14) + movl $SYS_compat_16___sigreturn14,%eax +#elif defined(SYS___sigreturn14) movl $SYS___sigreturn14,%eax +#else + #error "no sigreturn14 syscall" +#endif int $0x80 # enter kernel with args on stack movl $SYS_exit,%eax int $0x80 # exit if sigreturn fails .globl _C_LABEL(esigcode) _C_LABEL(esigcode): +#endif /*****************************************************************************/ @@ -777,7 +779,7 @@ ENTRY(kcopy) pushl %edi GET_CURPCB(%eax) # load curpcb into eax and set on-fault pushl PCB_ONFAULT(%eax) - movl $_C_LABEL(copy_fault), PCB_ONFAULT(%eax) + movl $_C_LABEL(kcopy_fault), PCB_ONFAULT(%eax) movl 16(%esp),%esi movl 20(%esp),%edi @@ -870,6 +872,7 @@ _C_LABEL(copyin_func): */ /* LINTSTUB: Func: int copyout(const void *kaddr, void *uaddr, size_t len) */ ENTRY(copyout) + DO_DEFERRED_SWITCH(%eax) jmp *_C_LABEL(copyout_func) #if defined(I386_CPU) @@ -1011,6 +1014,7 @@ ENTRY(i486_copyout) */ /* LINTSTUB: Func: int copyin(const void *uaddr, void *kaddr, size_t len) */ ENTRY(copyin) + DO_DEFERRED_SWITCH(%eax) jmp *_C_LABEL(copyin_func) #if defined(I386_CPU) || defined(I486_CPU) || defined(I586_CPU) || \ @@ -1061,6 +1065,19 @@ ENTRY(i386_copyin) NENTRY(copy_efault) movl $EFAULT,%eax +/* + * kcopy_fault is used by kcopy and copy_fault is used by copyin/out. + * + * they're distinguished for lazy pmap switching. see trap(). + */ +/* LINTSTUB: Ignore */ +NENTRY(kcopy_fault) + GET_CURPCB(%edx) + popl PCB_ONFAULT(%edx) + popl %edi + popl %esi + ret + /* LINTSTUB: Ignore */ NENTRY(copy_fault) GET_CURPCB(%edx) @@ -1082,6 +1099,8 @@ ENTRY(copyoutstr) pushl %esi pushl %edi + DO_DEFERRED_SWITCH(%eax) + movl 12(%esp),%esi # esi = from movl 16(%esp),%edi # edi = to movl 20(%esp),%edx # edx = maxlen @@ -1095,8 +1114,8 @@ ENTRY(copyoutstr) /* Compute number of bytes in first page. */ movl %edi,%eax andl $PGOFSET,%eax - movl $NBPG,%ecx - subl %eax,%ecx # ecx = NBPG - (src % NBPG) + movl $PAGE_SIZE,%ecx + subl %eax,%ecx # ecx = PAGE_SIZE - (src % PAGE_SIZE) GET_CURPCB(%eax) movl $6f,PCB_ONFAULT(%eax) @@ -1143,7 +1162,7 @@ ENTRY(copyoutstr) jmp copystr_return 4: /* Go to next page, if any. */ - movl $NBPG,%ecx + movl $PAGE_SIZE,%ecx testl %edx,%edx jnz 1b @@ -1199,6 +1218,9 @@ ENTRY(copyoutstr) ENTRY(copyinstr) pushl %esi pushl %edi + + DO_DEFERRED_SWITCH(%eax) + GET_CURPCB(%ecx) movl $_C_LABEL(copystr_fault),PCB_ONFAULT(%ecx) @@ -1310,6 +1332,7 @@ ENTRY(copystr) */ /* LINTSTUB: Func: long fuword(const void *base) */ ENTRY(fuword) + DO_DEFERRED_SWITCH(%eax) movl 4(%esp),%edx cmpl $VM_MAXUSER_ADDRESS-4,%edx ja _C_LABEL(fusuaddrfault) @@ -1326,6 +1349,7 @@ ENTRY(fuword) */ /* LINTSTUB: Func: int fusword(const void *base) */ ENTRY(fusword) + DO_DEFERRED_SWITCH(%eax) movl 4(%esp),%edx cmpl $VM_MAXUSER_ADDRESS-2,%edx ja _C_LABEL(fusuaddrfault) @@ -1343,6 +1367,8 @@ ENTRY(fusword) */ /* LINTSTUB: Func: int fuswintr(const void *base) */ ENTRY(fuswintr) + cmpl $TLBSTATE_VALID, CPUVAR(TLBSTATE) + jnz _C_LABEL(fusuaddrfault) movl 4(%esp),%edx cmpl $VM_MAXUSER_ADDRESS-2,%edx ja _C_LABEL(fusuaddrfault) @@ -1360,6 +1386,7 @@ ENTRY(fuswintr) */ /* LINTSTUB: Func: int fubyte(const void *base) */ ENTRY(fubyte) + DO_DEFERRED_SWITCH(%eax) movl 4(%esp),%edx cmpl $VM_MAXUSER_ADDRESS-1,%edx ja _C_LABEL(fusuaddrfault) @@ -1404,6 +1431,7 @@ NENTRY(fusuaddrfault) */ /* LINTSTUB: Func: int suword(void *base, long c) */ ENTRY(suword) + DO_DEFERRED_SWITCH(%eax) movl 4(%esp),%edx cmpl $VM_MAXUSER_ADDRESS-4,%edx ja _C_LABEL(fusuaddrfault) @@ -1451,6 +1479,7 @@ ENTRY(suword) */ /* LINTSTUB: Func: int susword(void *base, short c) */ ENTRY(susword) + DO_DEFERRED_SWITCH(%eax) movl 4(%esp),%edx cmpl $VM_MAXUSER_ADDRESS-2,%edx ja _C_LABEL(fusuaddrfault) @@ -1499,6 +1528,8 @@ ENTRY(susword) */ /* LINTSTUB: Func: int suswintr(void *base, short c) */ ENTRY(suswintr) + cmpl $TLBSTATE_VALID, CPUVAR(TLBSTATE) + jnz _C_LABEL(fusuaddrfault) movl 4(%esp),%edx cmpl $VM_MAXUSER_ADDRESS-2,%edx ja _C_LABEL(fusuaddrfault) @@ -1536,6 +1567,7 @@ ENTRY(suswintr) */ /* LINTSTUB: Func: int subyte(void *base, int c) */ ENTRY(subyte) + DO_DEFERRED_SWITCH(%eax) movl 4(%esp),%edx cmpl $VM_MAXUSER_ADDRESS-1,%edx ja _C_LABEL(fusuaddrfault) @@ -1721,7 +1753,7 @@ ENTRY(cpu_switch) */ pushl %esi - call _C_LABEL(pmap_deactivate) # pmap_deactivate(oldproc) + call _C_LABEL(pmap_deactivate2) # pmap_deactivate(oldproc) addl $4,%esp movl L_ADDR(%esi),%esi @@ -1748,11 +1780,6 @@ ENTRY(cpu_switch) movl PCB_ESP(%edi),%esp movl PCB_EBP(%edi),%ebp - - /* Switch address space. */ - movl PCB_CR3(%edi),%ecx - movl %ecx,%cr3 - /* Switch TSS. Reset "task busy" flag before loading. */ #ifdef MULTIPROCESSOR movl CPUVAR(GDT),%eax @@ -1802,6 +1829,7 @@ idle_start: jz idle_loop idle_exit: movl $IPL_HIGH,CPUVAR(ILEVEL) # splhigh + sti #if defined(MULTIPROCESSOR) || defined(LOCKDEBUG) call _C_LABEL(sched_lock_idle) #endif @@ -1852,7 +1880,7 @@ switch_resume: SET_CURLWP(%edi,%ecx) /* Skip context switch if same lwp. */ - movl $1, %eax + xorl %ebx,%ebx cmpl %edi,%esi je switch_return @@ -1870,7 +1898,7 @@ switch_resume: */ pushl %esi - call _C_LABEL(pmap_deactivate) # pmap_deactivate(oldproc) + call _C_LABEL(pmap_deactivate2) # pmap_deactivate(oldproc) addl $4,%esp movl L_ADDR(%esi),%esi @@ -1926,7 +1954,7 @@ switch_restored: movl PCB_CR0(%esi),%ecx #ifdef MULTIPROCESSOR /* - * If our floating point registers are on a different cpu, + * If our floating point registers are on a different CPU, * clear CR0_TS so we'll trap rather than reuse bogus state. */ movl PCB_FPCPU(%esi),%ebx @@ -1948,19 +1976,10 @@ switch_restored: */ movl CPUVAR(CURLWP),%edi movl L_PROC(%edi),%esi - cmpl $0,P_NRAS(%esi) - je 1f - movl L_MD_REGS(%edi),%ebx - movl TF_EIP(%ebx),%eax - pushl %eax - pushl %esi - call _C_LABEL(ras_lookup) - addl $8,%esp - cmpl $-1,%eax - je 1f - movl %eax,TF_EIP(%ebx) + cmpl $0,P_RASLIST(%esi) + jne 2f 1: - xor %eax,%eax + movl $1,%ebx switch_return: #if defined(MULTIPROCESSOR) || defined(LOCKDEBUG) @@ -1970,12 +1989,26 @@ switch_return: call _C_LABEL(Xspllower) # process pending interrupts addl $4,%esp movl $IPL_HIGH,CPUVAR(ILEVEL) # splhigh() + + movl %ebx,%eax popl %edi popl %esi popl %ebx ret +2: # check RAS list + movl L_MD_REGS(%edi),%ebx + movl TF_EIP(%ebx),%eax + pushl %eax + pushl %esi + call _C_LABEL(ras_lookup) + addl $8,%esp + cmpl $-1,%eax + je 1b + movl %eax,TF_EIP(%ebx) + jmp 1b + /* * void cpu_switchto(struct lwp *current, struct lwp *next) * Switch to the specified next LWP. @@ -2020,8 +2053,8 @@ ENTRY(cpu_switchto) jmp switch_resume /* - * void switch_exit(struct lwp *l, void (*exit)(struct lwp *)); - * Switch to the appropriate idle context (lwp0's if uniprocessor; the cpu's + * void cpu_exit(struct lwp *l) + * Switch to the appropriate idle context (lwp0's if uniprocessor; the CPU's * if multiprocessor) and deallocate the address space and kernel stack for p. * Then jump into cpu_switch(), as if we were in the idle proc all along. */ @@ -2030,10 +2063,9 @@ ENTRY(cpu_switchto) #endif .globl _C_LABEL(uvmspace_free),_C_LABEL(kernel_map) .globl _C_LABEL(uvm_km_free),_C_LABEL(tss_free) -/* LINTSTUB: Func: void switch_exit(struct lwp *l, void (*exit)(struct lwp *)) */ -ENTRY(switch_exit) +/* LINTSTUB: Func: void cpu_exit(struct lwp *l) */ +ENTRY(cpu_exit) movl 4(%esp),%edi # old process - movl 8(%esp),%eax # exit func #ifndef MULTIPROCESSOR movl $_C_LABEL(lwp0),%ebx movl L_ADDR(%ebx),%esi @@ -2052,9 +2084,6 @@ ENTRY(switch_exit) movl PCB_ESP(%esi),%esp movl PCB_EBP(%esi),%ebp - /* Save exit func. */ - pushl %eax - /* Load TSS info. */ #ifdef MULTIPROCESSOR movl CPUVAR(GDT),%eax @@ -2063,10 +2092,6 @@ ENTRY(switch_exit) movl _C_LABEL(gdt),%eax #endif - /* Switch address space. */ - movl PCB_CR3(%esi),%ecx - movl %ecx,%cr3 - /* Switch TSS. */ andl $~0x0200,4-SEL_KPL(%eax,%edx,1) ltr %dx @@ -2084,11 +2109,10 @@ ENTRY(switch_exit) sti /* - * Schedule the dead process's vmspace and stack to be freed. + * Schedule the dead LWP's stack to be freed. */ - movl 0(%esp),%eax /* %eax = exit func */ - movl %edi,0(%esp) /* {lwp_}exit2(l) */ - call *%eax + pushl %edi + call _C_LABEL(lwp_exit2) addl $4,%esp /* Jump into cpu_switch() with the right state. */ @@ -2132,6 +2156,12 @@ syscall1: INTRENTRY #ifdef DIAGNOSTIC + cmpl $0, CPUVAR(WANT_PMAPLOAD) + jz 1f + pushl $6f + call _C_LABEL(printf) + addl $4, %esp +1: movl CPUVAR(ILEVEL),%ebx testl %ebx,%ebx jz 1f @@ -2146,8 +2176,11 @@ syscall1: movl CPUVAR(CURLWP),%edx movl %esp,L_MD_REGS(%edx) # save pointer to frame movl L_PROC(%edx),%edx + pushl %esp call *P_MD_SYSCALL(%edx) # get pointer to syscall() function -2: /* Check for ASTs on exit to user mode. */ + addl $4,%esp +syscall_checkast: + /* Check for ASTs on exit to user mode. */ cli CHECK_ASTPENDING(%eax) je 1f @@ -2155,12 +2188,16 @@ syscall1: CLEAR_ASTPENDING(%eax) sti /* Pushed T_ASTFLT into tf_trapno on entry. */ + pushl %esp call _C_LABEL(trap) - jmp 2b + addl $4,%esp + jmp syscall_checkast /* re-check ASTs */ +1: CHECK_DEFERRED_SWITCH(%eax) + jnz 9f #ifndef DIAGNOSTIC -1: INTRFASTEXIT + INTRFASTEXIT #else /* DIAGNOSTIC */ -1: cmpl $IPL_NONE,CPUVAR(ILEVEL) + cmpl $IPL_NONE,CPUVAR(ILEVEL) jne 3f INTRFASTEXIT 3: sti @@ -2174,7 +2211,11 @@ syscall1: jmp 2b 4: .asciz "WARNING: SPL NOT LOWERED ON SYSCALL EXIT\n" 5: .asciz "WARNING: SPL NOT ZERO ON SYSCALL ENTRY\n" +6: .asciz "WARNING: WANT PMAPLOAD ON SYSCALL ENTRY\n" #endif /* DIAGNOSTIC */ +9: sti + call _C_LABEL(pmap_load) + jmp syscall_checkast /* re-check ASTs */ #if NNPX > 0 /*