1 /* $NetBSD: ast.c,v 1.3 2002/03/24 16:10:11 bjh21 Exp $ */ 2 3 /* 4 * Copyright (c) 1994,1995 Mark Brinicombe 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by the RiscBSD team. 18 * 4. The name of the company nor the name of the author may be used to 19 * endorse or promote products derived from this software without specific 20 * prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTERS BE LIABLE FOR ANY DIRECT, 26 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * RiscBSD kernel project 35 * 36 * ast.c 37 * 38 * Code to handle ast's and returns to user mode 39 * 40 * Created : 11/10/94 41 */ 42 43 #include "opt_ddb.h" 44 45 #include <sys/param.h> 46 #include <sys/proc.h> 47 #include <sys/user.h> 48 #include <sys/acct.h> 49 #include <sys/systm.h> 50 #include <sys/kernel.h> 51 #include <sys/signal.h> 52 #include <sys/vmmeter.h> 53 #include <machine/cpu.h> 54 #include <machine/frame.h> 55 #include <machine/cpu.h> 56 57 #include <arm/cpufunc.h> 58 59 #include <uvm/uvm_extern.h> 60 61 #ifdef acorn26 62 #include <machine/machdep.h> 63 #endif 64 65 /* 66 * Prototypes 67 */ 68 void ast __P((struct trapframe *)); 69 70 int want_resched = 0; 71 int astpending; 72 73 void 74 userret(struct proc *p) 75 { 76 int sig; 77 78 /* Take pending signals. */ 79 while ((sig = (CURSIG(p))) != 0) 80 postsig(sig); 81 82 curcpu()->ci_schedstate.spc_curpriority = p->p_priority = p->p_usrpri; 83 } 84 85 86 /* 87 * Handle asynchronous system traps. 88 * This is called from the irq handler to deliver signals 89 * and switch processes if required. 90 */ 91 92 void 93 ast(struct trapframe *tf) 94 { 95 struct proc *p = curproc; 96 97 #ifdef acorn26 98 /* Enable interrupts if they were enabled before the trap. */ 99 if ((tf->tf_r15 & R15_IRQ_DISABLE) == 0) 100 int_on(); 101 #else 102 /* Interrupts were restored by exception_exit. */ 103 #endif 104 105 uvmexp.traps++; 106 uvmexp.softs++; 107 108 #ifdef DEBUG 109 if (p == NULL) 110 panic("ast: no curproc!"); 111 if (&p->p_addr->u_pcb == 0) 112 panic("ast: no pcb!"); 113 #endif 114 115 if (p->p_flag & P_OWEUPC) { 116 p->p_flag &= ~P_OWEUPC; 117 ADDUPROF(p); 118 } 119 120 /* Allow a forced task switch. */ 121 if (want_resched) 122 preempt(NULL); 123 124 userret(p); 125 } 126 127 /* End of ast.c */ 128