1 /* $NetBSD: userret.h,v 1.11 2019/11/29 18:27:33 ad Exp $ */ 2 3 /* 4 * Copyright (c) 1996 5 * The President and Fellows of Harvard College. All rights reserved. 6 * Copyright (c) 1992, 1993 7 * The Regents of the University of California. All rights reserved. 8 * 9 * This software was developed by the Computer Systems Engineering group 10 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 11 * contributed to Berkeley. 12 * 13 * All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by the University of 16 * California, Lawrence Berkeley Laboratory. 17 * This product includes software developed by Harvard University. 18 * 19 * Redistribution and use in source and binary forms, with or without 20 * modification, are permitted provided that the following conditions 21 * are met: 22 * 1. Redistributions of source code must retain the above copyright 23 * notice, this list of conditions and the following disclaimer. 24 * 2. Redistributions in binary form must reproduce the above copyright 25 * notice, this list of conditions and the following disclaimer in the 26 * documentation and/or other materials provided with the distribution. 27 * 3. All advertising materials mentioning features or use of this software 28 * must display the following acknowledgement: 29 * This product includes software developed by the University of 30 * California, Berkeley and its contributors. 31 * This product includes software developed by Harvard University. 32 * 4. Neither the name of the University nor the names of its contributors 33 * may be used to endorse or promote products derived from this software 34 * without specific prior written permission. 35 * 36 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 37 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 39 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 40 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 41 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 42 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 44 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 45 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 46 * SUCH DAMAGE. 47 * 48 * @(#)trap.c 8.4 (Berkeley) 9/23/93 49 */ 50 51 #include <sys/userret.h> 52 53 static __inline void userret(struct lwp *, int, u_quad_t); 54 static __inline void share_fpu(struct lwp *, struct trapframe *); 55 56 57 /* 58 * Define the code needed before returning to user mode, for 59 * trap, mem_access_fault, and syscall. 60 */ 61 static __inline void 62 userret(struct lwp *l, int pc, u_quad_t oticks) 63 { 64 struct proc *p = l->l_proc; 65 66 do { 67 cpuinfo.ci_want_ast = 0; 68 mi_userret(l); 69 } while (cpuinfo.ci_want_ast); 70 71 if (l->l_pflag & LP_OWEUPC) { 72 l->l_pflag &= ~LP_OWEUPC; 73 ADDUPROF(l); 74 } 75 76 /* 77 * If profiling, charge recent system time to the trapped pc. 78 */ 79 if (p->p_stflag & PST_PROFIL) 80 addupc_task(l, pc, (int)(p->p_sticks - oticks)); 81 } 82 83 /* 84 * If someone stole the FPU while we were away, do not enable it 85 * on return. This is not done in userret() above as it must follow 86 * the ktrsysret() in syscall(). Actually, it is likely that the 87 * ktrsysret should occur before the call to userret. 88 */ 89 static __inline void share_fpu(struct lwp *l, struct trapframe *tf) 90 { 91 if ((tf->tf_psr & PSR_EF) != 0 && cpuinfo.fplwp != l) 92 tf->tf_psr &= ~PSR_EF; 93 } 94