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.1.2.3 retrieving revision 1.9 diff -u -p -r1.1.2.3 -r1.9 --- src/sys/arch/i386/i386/locore.S 2002/12/11 16:00:50 1.1.2.3 +++ src/sys/arch/i386/i386/locore.S 2003/05/13 08:26:32 1.9 @@ -1,4 +1,4 @@ -/* $NetBSD: locore.S,v 1.1.2.3 2002/12/11 16:00:50 thorpej Exp $ */ +/* $NetBSD: locore.S,v 1.9 2003/05/13 08:26:32 fvdl Exp $ */ /*- * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc. @@ -90,6 +90,7 @@ #include "apm.h" #include "lapic.h" #include "ioapic.h" +#include "ksyms.h" #include #include @@ -163,7 +164,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 +174,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) @@ -199,7 +200,7 @@ #if NLAPIC > 0 #ifdef __ELF__ - .align NBPG + .align PAGE_SIZE #else .align 12 #endif @@ -214,7 +215,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 @@ -506,14 +507,14 @@ 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 @@ -561,7 +562,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 ; @@ -1095,8 +1096,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 +1144,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 @@ -1647,84 +1648,9 @@ ENTRY(longjmp) /*****************************************************************************/ -/* - * The following primitives manipulate the run queues. - * _whichqs tells which of the 32 queues _qs - * have processes in them. Setrq puts processes into queues, Remrq - * removes them from queues. The running process is on no queue, - * other processes are on a queue related to p->p_pri, divided by 4 - * actually to shrink the 0-127 range of priorities into the 32 available - * queues. - */ .globl _C_LABEL(sched_whichqs),_C_LABEL(sched_qs) .globl _C_LABEL(uvmexp),_C_LABEL(panic) -/* - * void setrunqueue(struct lwp *p); - * Insert a process on the appropriate queue. Should be called at splclock(). - * See setrunqueue(9) for more details. - */ -/* LINTSTUB: Func: void setrunqueue(struct lwp *p) */ -NENTRY(setrunqueue) - movl 4(%esp),%eax -#ifdef DIAGNOSTIC - cmpl $0,L_BACK(%eax) # should not be on q already - jne 1f - cmpl $0,L_WCHAN(%eax) - jne 1f - cmpb $SRUN,L_STAT(%eax) - jne 1f -#endif /* DIAGNOSTIC */ - movzbl L_PRIORITY(%eax),%edx - shrl $2,%edx - btsl %edx,_C_LABEL(sched_whichqs) # set q full bit - leal _C_LABEL(sched_qs)(,%edx,8),%edx # locate q hdr - movl L_BACK(%edx),%ecx - movl %edx,L_FORW(%eax) # link process on tail of q - movl %eax,L_BACK(%edx) - movl %eax,L_FORW(%ecx) - movl %ecx,L_BACK(%eax) - ret -#ifdef DIAGNOSTIC -1: pushl $2f - call _C_LABEL(panic) - /* NOTREACHED */ -2: .asciz "setrunqueue" -#endif /* DIAGNOSTIC */ - -/* - * void remrunqueue(struct lwp *p); - * Remove a process from its queue. Should be called at splclock(). - * See remrunqueue(9) for more details. - */ -/* LINTSTUB: Func: void remrunqueue(struct lwp *p) */ -NENTRY(remrunqueue) - movl 4(%esp),%ecx - movzbl L_PRIORITY(%ecx),%eax -#ifdef DIAGNOSTIC - shrl $2,%eax - btl %eax,_C_LABEL(sched_whichqs) - jnc 1f -#endif /* DIAGNOSTIC */ - movl L_BACK(%ecx),%edx # unlink process - movl $0,L_BACK(%ecx) # zap reverse link to indicate off list - movl L_FORW(%ecx),%ecx - movl %ecx,L_FORW(%edx) - movl %edx,L_BACK(%ecx) - cmpl %ecx,%edx # q still has something? - jne 2f -#ifndef DIAGNOSTIC - shrl $2,%eax -#endif - btrl %eax,_C_LABEL(sched_whichqs) # no; clear bit -2: ret -#ifdef DIAGNOSTIC -1: pushl $3f - call _C_LABEL(panic) - /* NOTREACHED */ -3: .asciz "remrunqueue" -#endif /* DIAGNOSTIC */ - #ifdef DIAGNOSTIC NENTRY(switch_error) pushl $1f @@ -1751,14 +1677,14 @@ ENTRY(cpu_switch) #ifdef DEBUG cmpl $IPL_SCHED,CPUVAR(ILEVEL) jae 1f - pushl 2f + pushl $2f call _C_LABEL(panic) /* NOTREACHED */ -2: .asciz "not splhigh() in cpu_switch!" +2: .asciz "not splsched() in cpu_switch!" 1: #endif /* DEBUG */ - movl CPUVAR(CURLWP),%esi + movl 16(%esp),%esi # current /* * Clear curlwp so that we don't accumulate system time while idle. @@ -1775,7 +1701,7 @@ ENTRY(cpu_switch) * %eax - queue head, scratch, then zero * %ebx - queue number * %ecx - cached value of whichqs - * %edx - next process in queue + * %edx - next lwp in queue * %esi - old lwp * %edi - new lwp */ @@ -1927,7 +1853,7 @@ switch_resume: SET_CURLWP(%edi,%ecx) /* Skip context switch if same lwp. */ - movl $1, %eax + movl $1, %ebx cmpl %edi,%esi je switch_return @@ -2020,25 +1946,22 @@ switch_restored: /* * Check for restartable atomic sequences (RAS) - * XXX %edi reloads are not necessary here as %edi is callee-saved! */ movl CPUVAR(CURLWP),%edi movl L_PROC(%edi),%esi cmpl $0,P_NRAS(%esi) je 1f - movl L_MD_REGS(%edi),%edx - movl TF_EIP(%edx),%eax + 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 CPUVAR(CURLWP),%edi - movl L_MD_REGS(%edi),%edx - movl %eax,TF_EIP(%edx) + movl %eax,TF_EIP(%ebx) 1: - xor %eax,%eax + xor %ebx,%ebx switch_return: #if defined(MULTIPROCESSOR) || defined(LOCKDEBUG) @@ -2048,25 +1971,19 @@ 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 -#ifdef DIAGNOSTIC -NENTRY(preempt_error) - pushl $1f - call _C_LABEL(panic) - /* NOTREACHED */ -1: .asciz "cpu_preempt" -#endif /* DIAGNOSTIC */ - /* - * void cpu_preempt(struct lwp *current, struct lwp *next) - * Switch to the specified nexxt LWP. + * void cpu_switchto(struct lwp *current, struct lwp *next) + * Switch to the specified next LWP. */ -ENTRY(cpu_preempt) +ENTRY(cpu_switchto) pushl %ebx pushl %esi pushl %edi @@ -2077,11 +1994,11 @@ ENTRY(cpu_preempt) pushl $2f call _C_LABEL(panic) /* NOTREACHED */ -2: .asciz "not splsched() in cpu_preempt!" +2: .asciz "not splsched() in cpu_switchto!" 1: #endif /* DEBUG */ - movl CPUVAR(CURLWP),%esi + movl 16(%esp),%esi # current movl 20(%esp),%edi # next /* @@ -2090,41 +2007,23 @@ ENTRY(cpu_preempt) * the correct queue if it happens to get called from the spllower() * below and changes the priority. (See corresponding comment in * usrret()). + * + * XXX Is this necessary? We know we won't go idle. */ movl $0,CPUVAR(CURLWP) -preempt_dequeue: /* * We're running at splhigh(), but it's otherwise okay to take * interrupts here. */ sti - movzbl L_PRIORITY(%edi),%eax -#ifdef DIAGNOSTIC - shrl $2,%eax - btl %eax,_C_LABEL(sched_whichqs) - jnc _C_LABEL(preempt_error) -#endif /* DIAGNOSTIC */ - movl L_BACK(%edi),%edx # unlink process - movl $0,L_BACK(%edi) # zap reverse link to indicate off list - movl L_FORW(%edi),%ecx - movl %ecx,L_FORW(%edx) - movl %edx,L_BACK(%ecx) - cmpl %ecx,%edx # q still has something? - jne 3f -#ifndef DIAGNOSTIC - shrl $2,%eax -#endif - btrl %eax,_C_LABEL(sched_whichqs) # no; clear bit - -3: /* Jump into the middle of cpu_switch */ xorl %eax,%eax jmp switch_resume /* - * void switch_exit(struct lwp *l); + * void switch_exit(struct lwp *l, void (*exit)(struct lwp *)); * 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. @@ -2134,9 +2033,10 @@ preempt_dequeue: #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) */ +/* LINTSTUB: Func: void switch_exit(struct lwp *l, void (*exit)(struct lwp *)) */ ENTRY(switch_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 @@ -2155,77 +2055,8 @@ ENTRY(switch_exit) movl PCB_ESP(%esi),%esp movl PCB_EBP(%esi),%ebp - /* Load TSS info. */ -#ifdef MULTIPROCESSOR - movl CPUVAR(GDT),%eax -#else - /* Load TSS info. */ - 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 - - /* We're always in the kernel, so we don't need the LDT. */ - - /* Restore cr0 (including FPU state). */ - movl PCB_CR0(%esi),%ecx - movl %ecx,%cr0 - - /* Record new pcb. */ - SET_CURPCB(%esi) - - /* Interrupts are okay again. */ - sti - - /* - * Schedule the dead process's vmspace and stack to be freed. - */ - pushl %edi /* exit2(l) */ - call _C_LABEL(exit2) - addl $4,%esp - - /* Jump into cpu_switch() with the right state. */ - xorl %esi,%esi - movl %esi,CPUVAR(CURLWP) - jmp idle_start - -/* - * switch_lwp_exit(struct lwp *l); - * Switch to the appropriate idle context (lwp0's if uniprocessor; the cpu's - * if multiprocessor) and deallocate the kernel stack for l. - * Then jump into cpu_switch(), as if we were in the idle proc all along. - */ -#ifndef MULTIPROCESSOR - .globl _C_LABEL(lwp0) -#endif - .globl _C_LABEL(uvmspace_free),_C_LABEL(kernel_map) - .globl _C_LABEL(uvm_km_free),_C_LABEL(tss_free) -/* LINTSTUB: Func: void switch_lwp_exit(struct lwp *l) */ -ENTRY(switch_lwp_exit) - movl 4(%esp),%edi # old process -#ifndef MULTIPROCESSOR - movl $_C_LABEL(lwp0),%ebx - movl L_ADDR(%ebx),%esi - movl L_MD_TSS_SEL(%ebx),%edx -#else - movl CPUVAR(IDLE_PCB),%esi - movl CPUVAR(IDLE_TSS_SEL),%edx -#endif - /* In case we fault... */ - movl $0,CPUVAR(CURLWP) - - /* Restore the idle context. */ - cli - - /* Restore stack pointers. */ - movl PCB_ESP(%esi),%esp - movl PCB_EBP(%esi),%ebp + /* Save exit func. */ + pushl %eax /* Load TSS info. */ #ifdef MULTIPROCESSOR @@ -2258,8 +2089,9 @@ ENTRY(switch_lwp_exit) /* * Schedule the dead process's vmspace and stack to be freed. */ - pushl %edi /* lwp_exit2(l) */ - call _C_LABEL(lwp_exit2) + movl 0(%esp),%eax /* %eax = exit func */ + movl %edi,0(%esp) /* {lwp_}exit2(l) */ + call *%eax addl $4,%esp /* Jump into cpu_switch() with the right state. */