From e58eb48f2511afe874a9ad775ab7434a68458c5d Mon Sep 17 00:00:00 2001 From: mycroft Date: Tue, 12 Dec 2000 05:21:02 +0000 Subject: [PATCH] Begin cleaning up the syscall path, a la i386. --- sys/arch/arm32/arm32/ast.c | 17 +--- sys/arch/arm32/arm32/fault.c | 15 ++-- sys/arch/arm32/arm32/syscall.c | 128 +++++-------------------------- sys/arch/arm32/arm32/undefined.c | 21 +---- sys/arch/arm32/include/cpu.h | 6 +- 5 files changed, 33 insertions(+), 154 deletions(-) diff --git a/sys/arch/arm32/arm32/ast.c b/sys/arch/arm32/arm32/ast.c index 7caf39227958..6957e2cdd981 100644 --- a/sys/arch/arm32/arm32/ast.c +++ b/sys/arch/arm32/arm32/ast.c @@ -1,4 +1,4 @@ -/* $NetBSD: ast.c,v 1.19 2000/06/29 08:52:57 mrg Exp $ */ +/* $NetBSD: ast.c,v 1.20 2000/12/12 05:21:02 mycroft Exp $ */ /* * Copyright (c) 1994,1995 Mark Brinicombe @@ -61,10 +61,8 @@ int want_resched = 0; void -userret(p, pc, oticks) +userret(p) struct proc *p; - int pc; - u_quad_t oticks; { int sig; @@ -105,15 +103,6 @@ userret(p, pc, oticks) } } - /* - * Not sure if this profiling bit is working yet ... Not been tested - */ - - if (p->p_flag & P_PROFIL) { - extern int psratio; - addupc_task(p, pc, (int)(p->p_sticks - oticks) * psratio); - } - curcpu()->ci_schedstate.spc_curpriority = p->p_priority; #ifdef DIAGNOSTIC @@ -159,7 +148,7 @@ ast(frame) ADDUPROF(p); } - userret(p, frame->tf_pc, p->p_sticks); + userret(p); } /* End of ast.c */ diff --git a/sys/arch/arm32/arm32/fault.c b/sys/arch/arm32/arm32/fault.c index afcb56833fde..90d79011677d 100644 --- a/sys/arch/arm32/arm32/fault.c +++ b/sys/arch/arm32/arm32/fault.c @@ -1,4 +1,4 @@ -/* $NetBSD: fault.c,v 1.46 2000/11/21 06:30:05 chs Exp $ */ +/* $NetBSD: fault.c,v 1.47 2000/12/12 05:21:02 mycroft Exp $ */ /* * Copyright (c) 1994-1997 Mark Brinicombe. @@ -143,7 +143,6 @@ data_abort_handler(frame) u_int fault_instruction; int fault_code; int user; - u_quad_t sticks = 0; int error; void *onfault; @@ -233,8 +232,6 @@ copyfault: /* Were we in user mode when the abort occurred ? */ if ((frame->tf_spsr & PSR_MODE) == PSR_USR32_MODE) { - sticks = p->p_sticks; - /* * Note that the fault was from USR mode. */ @@ -360,7 +357,7 @@ copyfault: * priveledged mode but uses USR mode * permissions for its accesses. */ - userret(p, frame->tf_pc, p->p_sticks); + userret(p); return; } map = kernel_map; @@ -452,7 +449,7 @@ copyfault: out: /* Call userret() if it was a USR mode fault */ if (user) - userret(p, frame->tf_pc, sticks); + userret(p); } @@ -478,7 +475,6 @@ prefetch_abort_handler(frame) register struct proc *p; register struct pcb *pcb; u_int fault_instruction; - u_quad_t sticks; pt_entry_t *pte; int error; @@ -539,7 +535,6 @@ prefetch_abort_handler(frame) /* Was the prefectch abort from USR32 mode ? */ if ((frame->tf_spsr & PSR_MODE) == PSR_USR32_MODE) { - sticks = p->p_sticks; p->p_md.md_regs = frame; } else { /* @@ -563,7 +558,7 @@ prefetch_abort_handler(frame) fault_pc); #endif trapsignal(p, SIGSEGV, fault_pc); - userret(p, frame->tf_pc, sticks); + userret(p); return; } @@ -614,7 +609,7 @@ prefetch_abort_handler(frame) #endif /* DIAGNOSTIC */ } - userret(p, frame->tf_pc, sticks); + userret(p); } int diff --git a/sys/arch/arm32/arm32/syscall.c b/sys/arch/arm32/arm32/syscall.c index 104b6a918fd4..a12c98043fe7 100644 --- a/sys/arch/arm32/arm32/syscall.c +++ b/sys/arch/arm32/arm32/syscall.c @@ -1,4 +1,4 @@ -/* $NetBSD: syscall.c,v 1.31 2000/11/26 15:13:50 chs Exp $ */ +/* $NetBSD: syscall.c,v 1.32 2000/12/12 05:21:02 mycroft Exp $ */ /* * Copyright (c) 1994-1998 Mark Brinicombe. @@ -72,7 +72,7 @@ u_int arm700bugcount = 0; /* Macors to simplify the switch statement below */ #define SYSCALL_SPECIAL_RETURN \ - userret(p, frame->tf_pc, sticks); \ + userret(p); \ return; /* @@ -89,11 +89,9 @@ syscall(frame, code) caddr_t params; const struct sysent *callp; struct proc *p; - int error, opc; + int error; u_int argsize; int args[8], rval[2]; - int nsys; - u_quad_t sticks; int regparams; /* @@ -106,32 +104,13 @@ syscall(frame, code) uvmexp.syscalls++; - /* - * Trap SWI instructions executed in non-USR32 mode - * - * CONTINUE_AFTER_NONUSR_SYSCALL is used to determine whether the - * kernel should continue running following a swi instruction in - * non-USR32 mode. This was used for debugging and can problably - * be removed altogether - */ +#ifdef DEBUG + if ((GetCPSR() & PSR_MODE) != PSR_SVC32_MODE) + panic("syscall: Not in SVC32 mode\n"); +#endif /* DEBUG */ -#ifdef DIAGNOSTIC - if ((frame->tf_spsr & PSR_MODE) != PSR_USR32_MODE) { - printf("syscall: swi 0x%x from non USR32 mode\n", code); - printf("syscall: trapframe=%p\n", frame); - -#ifdef CONTINUE_AFTER_NONUSR_SYSCALL - printf("syscall: The system should now be considered very unstable :-(\n"); - sigexit(curproc, SIGILL); - - /* Not reached */ - - panic("syscall: How did we get here ?\n"); -#else - panic("syscall in non USR32 mode\n"); -#endif /* CONTINUE_AFTER_NONUSR_SYSCALL */ - } -#endif /* DIAGNOSTIC */ + p = curproc; + p->p_md.md_regs = frame; #ifdef CPU_ARM7 /* @@ -151,45 +130,17 @@ syscall(frame, code) * then we hit the bug. */ if ((ReadWord(frame->tf_pc - INSN_SIZE) & 0x0f000000) != 0x0f000000) { -#ifdef ARM700BUGTRACK - /* Verbose bug tracking */ - - int loop; - - printf("ARM700 just stumbled at 0x%08x\n", frame->tf_pc - INSN_SIZE); - printf("Code leading up to this was\n"); - for (loop = frame->tf_pc - 32; loop < frame->tf_pc; loop += 4) - disassemble(loop); - - printf("CPU ID=%08x\n", cpu_id()); - printf("MMU Fault address=%08x status=%08x\n", cpu_faultaddress(), cpu_faultstatus()); - printf("Page table entry for 0x%08x at %p = 0x%08x\n", - frame->tf_pc - INSN_SIZE, vtopte(frame->tf_pc - INSN_SIZE), - *vtopte(frame->tf_pc - INSN_SIZE)); -#endif /* ARM700BUGTRACK */ - frame->tf_pc -= INSN_SIZE; ++arm700bugcount; - - userret(curproc, frame->tf_pc, curproc->p_sticks); - + userret(p); return; } #endif /* CPU_ARM7 */ -#ifdef DIAGNOSTIC - if ((GetCPSR() & PSR_MODE) != PSR_SVC32_MODE) - panic("syscall: Not in SVC32 mode\n"); -#endif /* DIAGNOSTIC */ - - p = curproc; - sticks = p->p_sticks; - p->p_md.md_regs = frame; - /* * Support for architecture dependant SWIs */ - if (code > 0x00f00000) { + if (code & 0x00f00000) { /* * Support for the Architecture defined SWI's in case the * processor does not support them. @@ -204,41 +155,19 @@ syscall(frame, code) break; default: /* Undefined so illegal instruction */ - trapsignal(p, SIGILL, ReadWord(frame->tf_pc - 4)); + trapsignal(p, SIGILL, ReadWord(frame->tf_pc - INSN_SIZE)); break; } - userret(p, frame->tf_pc, sticks); + userret(p); return; } -#ifdef PMAP_DEBUG - /* Debug info */ - if (pmap_debug_level >= -1) - printf("SYSCALL: code=%08x lr=%08x pid=%d\n", - code, frame->tf_pc, p->p_pid); -#endif /* PMAP_DEBUG */ - - opc = frame->tf_pc; params = (caddr_t)&frame->tf_r0; regparams = 4; - nsys = p->p_emul->e_nsysent; callp = p->p_emul->e_sysent; switch (code) { -#if defined(DDB) && defined(PORTMASTER) - /* Sometimes I want to enter the debugger outside of the interrupt handler */ - case 0x102e: - if (securelevel > 0) { - frame->tf_r0 = EPERM; - frame->tf_spsr |= PSR_C_bit; /* carry bit */ - SYSCALL_SPECIAL_RETURN; - } - Debugger(); - SYSCALL_SPECIAL_RETURN; - break; -#endif /* DDB && PORTMASTER */ - case SYS_syscall: /* Don't have to look in user space, we have it in the trapframe */ /* code = fuword(params);*/ @@ -263,19 +192,7 @@ syscall(frame, code) break; } - /* Validate syscall range */ - if (code < 0 || code >= nsys) - callp += p->p_emul->e_nosys; /* illegal */ - else - callp += code; - -#ifdef VERBOSE_ARM32 - /* Is the syscal valid ? */ - if (callp->sy_call == sys_nosys) { - printf("syscall: nosys code=%d lr=%08x proc=%08x pid=%d %s\n", - code, frame->tf_pc, (u_int)p, p->p_pid, p->p_comm); - } -#endif + callp += (code & (SYS_NSYSENT - 1)); argsize = callp->sy_argsize; if (argsize > (regparams * sizeof(int))) @@ -307,14 +224,6 @@ syscall(frame, code) switch (error) { case 0: - /* - * Reinitialize proc pointer `p' as it may be different - * if this is a child returning from fork syscall. - * - * XXX fork now returns via the child_return so is this - * needed ? - */ - p = curproc; frame->tf_r0 = rval[0]; frame->tf_r1 = rval[1]; frame->tf_spsr &= ~PSR_C_bit; /* carry bit */ @@ -322,10 +231,9 @@ syscall(frame, code) case ERESTART: /* - * Reconstruct the pc. opc contains the old pc address which is - * the instruction after the swi. + * Reconstruct the pc to point at the swi. */ - frame->tf_pc = opc - 4; + frame->tf_pc -= INSN_SIZE; break; case EJUSTRETURN: @@ -343,7 +251,7 @@ bad: scdebug_ret(p, code, error, rval[0]); #endif - userret(p, frame->tf_pc, sticks); + userret(p); #ifdef KTRACE if (KTRPOINT(p, KTR_SYSRET)) @@ -363,7 +271,7 @@ child_return(arg) frame->tf_r0 = 0; frame->tf_spsr &= ~PSR_C_bit; /* carry bit */ - userret(p, frame->tf_pc, 0); + userret(p); #ifdef KTRACE if (KTRPOINT(p, KTR_SYSRET)) diff --git a/sys/arch/arm32/arm32/undefined.c b/sys/arch/arm32/arm32/undefined.c index 473ab6cd82cc..eaf17fa81829 100644 --- a/sys/arch/arm32/arm32/undefined.c +++ b/sys/arch/arm32/arm32/undefined.c @@ -1,4 +1,4 @@ -/* $NetBSD: undefined.c,v 1.20 2000/07/27 10:12:31 bjh21 Exp $ */ +/* $NetBSD: undefined.c,v 1.21 2000/12/12 05:21:02 mycroft Exp $ */ /* * Copyright (c) 1995 Mark Brinicombe. @@ -126,7 +126,6 @@ undefinedinstruction(frame) u_int fault_pc; int fault_instruction; int fault_code; - u_quad_t sticks = 0; int coprocessor; /* Enable interrupts if they were enabled before the exception. */ @@ -168,9 +167,7 @@ undefinedinstruction(frame) p = &proc0; if ((frame->tf_spsr & PSR_MODE) == PSR_USR32_MODE) { - sticks = p->p_sticks; - - /* Modify the fault_code to reflect the USR/SVC state at time of fault */ + /* Modify the fault_code to reflect the USR/SVC state at time of fault */ fault_code = FAULT_USER; p->p_md.md_regs = frame; @@ -255,23 +252,11 @@ undefinedinstruction(frame) } } - /* - * The profiling bit is commented out at the moment. This - * can be reinstated later on. Currently addupc_task is - * not written. - */ - - if (p->p_flag & P_PROFIL) { - extern int psratio; - addupc_task(p, frame->tf_pc, - (int)(p->p_sticks - sticks) * psratio); - } - curcpu()->ci_schedstate.spc_curpriority = p->p_priority; } #else - userret(p, frame->tf_pc, sticks); + userret(p); #endif } diff --git a/sys/arch/arm32/include/cpu.h b/sys/arch/arm32/include/cpu.h index 4b38b1dac470..28bf90c21519 100644 --- a/sys/arch/arm32/include/cpu.h +++ b/sys/arch/arm32/include/cpu.h @@ -1,4 +1,4 @@ -/* $NetBSD: cpu.h,v 1.22 2000/08/25 01:04:07 thorpej Exp $ */ +/* $NetBSD: cpu.h,v 1.23 2000/12/12 05:21:03 mycroft Exp $ */ /* * Copyright (c) 1994-1996 Mark Brinicombe. @@ -219,6 +219,8 @@ /* Hack to treat FPE time as interrupt time so we can measure it */ #define CLKF_INTR(frame) ((current_intr_depth > 1) || (frame->if_spsr & PSR_MODE) == PSR_UND32_MODE) +#define PROC_PC(p) ((p)->p_md.md_regs->tf_pc) + /* * definitions of cpu-dependent requirements * referenced in generic code @@ -266,7 +268,7 @@ struct pcb; void savectx __P((struct pcb *pcb)); /* ast.c */ -void userret __P((register struct proc *p, int pc, u_quad_t oticks)); +void userret __P((register struct proc *p)); /* machdep.h */ void bootsync __P((void));