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