xref: /netbsd-src/sys/arch/sparc/include/userret.h (revision 946379e7b37692fc43f68eb0d1c10daa0a7f3b6c)
1 /*	$NetBSD: userret.h,v 1.8 2007/11/05 20:37:48 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  again:
67 	mi_userret(l);
68 
69 	if (cpuinfo.ci_want_ast) {
70 		cpuinfo.ci_want_ast = 0;
71 		if (l->l_pflag & LP_OWEUPC) {
72 			l->l_pflag &= ~LP_OWEUPC;
73 			ADDUPROF(l);
74 		}
75 	}
76 	if (cpuinfo.ci_want_resched) {
77 		/*
78 		 * We are being preempted.
79 		 */
80 		preempt();
81 		goto again;
82 	}
83 
84 	/*
85 	 * If profiling, charge recent system time to the trapped pc.
86 	 */
87 	if (p->p_stflag & PST_PROFIL)
88 		addupc_task(l, pc, (int)(p->p_sticks - oticks));
89 }
90 
91 /*
92  * If someone stole the FPU while we were away, do not enable it
93  * on return.  This is not done in userret() above as it must follow
94  * the ktrsysret() in syscall().  Actually, it is likely that the
95  * ktrsysret should occur before the call to userret.
96  */
97 static __inline void share_fpu(struct lwp *l, struct trapframe *tf)
98 {
99 	if ((tf->tf_psr & PSR_EF) != 0 && cpuinfo.fplwp != l)
100 		tf->tf_psr &= ~PSR_EF;
101 }
102