1 /* $NetBSD: ast.c,v 1.20 2010/12/20 00:25:26 matt 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 <sys/cdefs.h> 44 __KERNEL_RCSID(0, "$NetBSD: ast.c,v 1.20 2010/12/20 00:25:26 matt Exp $"); 45 46 #include "opt_ddb.h" 47 48 #include <sys/param.h> 49 #include <sys/proc.h> 50 #include <sys/acct.h> 51 #include <sys/systm.h> 52 #include <sys/kernel.h> 53 #include <sys/signal.h> 54 #include <sys/vmmeter.h> 55 #include <sys/userret.h> 56 57 #include <machine/cpu.h> 58 #include <machine/frame.h> 59 60 #include <arm/cpufunc.h> 61 62 #include <uvm/uvm_extern.h> 63 64 #ifdef acorn26 65 #include <machine/machdep.h> 66 #endif 67 68 /* 69 * Prototypes 70 */ 71 void ast(struct trapframe *); 72 73 void 74 userret(struct lwp *l) 75 { 76 /* Invoke MI userret code */ 77 mi_userret(l); 78 79 #if defined(__PROG32) && defined(DIAGNOSTIC) 80 { 81 struct pcb *pcb = lwp_getpcb(l); 82 KASSERT((pcb->pcb_tf->tf_spsr & IF32_bits) == 0); 83 } 84 #endif 85 } 86 87 88 /* 89 * Handle asynchronous system traps. 90 * This is called from the irq handler to deliver signals 91 * and switch processes if required. 92 */ 93 94 void 95 ast(struct trapframe *tf) 96 { 97 struct lwp *l = curlwp; 98 struct proc *p; 99 100 #ifdef acorn26 101 /* Enable interrupts if they were enabled before the trap. */ 102 if ((tf->tf_r15 & R15_IRQ_DISABLE) == 0) 103 int_on(); 104 #else 105 /* Interrupts were restored by exception_exit. */ 106 #endif 107 108 #ifdef __PROG32 109 KASSERT((tf->tf_spsr & IF32_bits) == 0); 110 #endif 111 112 113 curcpu()->ci_data.cpu_ntrap++; 114 //curcpu()->ci_data.cpu_nast++; 115 116 #ifdef DEBUG 117 KDASSERT(curcpu()->ci_cpl == IPL_NONE); 118 if (l == NULL) 119 panic("ast: no curlwp!"); 120 if (lwp_getpcb(l) == NULL) 121 panic("ast: no pcb!"); 122 #endif 123 124 p = l->l_proc; 125 126 if (l->l_pflag & LP_OWEUPC) { 127 l->l_pflag &= ~LP_OWEUPC; 128 ADDUPROF(l); 129 } 130 131 /* Allow a forced task switch. */ 132 if (l->l_cpu->ci_want_resched) 133 preempt(); 134 135 userret(l); 136 } 137