xref: /netbsd-src/sys/arch/sparc/include/userret.h (revision d48f14661dda8638fee055ba15d35bdfb29b9fa8)
1 /*	$NetBSD: userret.h,v 1.4 2006/02/16 20:17:15 perry 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 	int sig;
66 	mi_userret(l);
67 
68 	if (cpuinfo.want_ast) {
69 		cpuinfo.want_ast = 0;
70 		if (p->p_flag & P_OWEUPC) {
71 			p->p_flag &= ~P_OWEUPC;
72 			ADDUPROF(p);
73 		}
74 	}
75 	if (cpuinfo.want_resched) {
76 		/*
77 		 * We are being preempted.
78 		 */
79 		preempt(0);
80 		while ((sig = CURSIG(l)) != 0)
81 			postsig(sig);
82 	}
83 
84 	/*
85 	 * If profiling, charge recent system time to the trapped pc.
86 	 */
87 	if (p->p_flag & P_PROFIL)
88 		addupc_task(p, pc, (int)(p->p_sticks - oticks));
89 
90 	curcpu()->ci_schedstate.spc_curpriority = l->l_priority;
91 }
92 
93 /*
94  * If someone stole the FPU while we were away, do not enable it
95  * on return.  This is not done in userret() above as it must follow
96  * the ktrsysret() in syscall().  Actually, it is likely that the
97  * ktrsysret should occur before the call to userret.
98  */
99 static __inline void share_fpu(struct lwp *l, struct trapframe *tf)
100 {
101 	if ((tf->tf_psr & PSR_EF) != 0 && cpuinfo.fplwp != l)
102 		tf->tf_psr &= ~PSR_EF;
103 }
104