xref: /netbsd-src/sys/arch/sparc64/include/userret.h (revision aaf4ece63a859a04e37cf3a7229b5fab0157cc06)
1 /*	$NetBSD: userret.h,v 1.3 2005/12/24 20:07:37 perry 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 __P((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
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 	if (want_ast) {
67 		want_ast = 0;
68 		if (p->p_flag & P_OWEUPC) {
69 			p->p_flag &= ~P_OWEUPC;
70 			ADDUPROF(p);
71 		}
72 	}
73 
74 	/*
75 	 * If profiling, charge recent system time to the trapped pc.
76 	 */
77 	if (p->p_flag & P_PROFIL)
78 		addupc_task(p, pc, (int)(p->p_sticks - oticks));
79 
80 	curcpu()->ci_schedstate.spc_curpriority = l->l_priority = l->l_usrpri;
81 }
82 
83 static inline void share_fpu __P((struct lwp *, struct trapframe64 *));
84 /*
85  * If someone stole the FPU while we were away, do not enable it
86  * on return.  This is not done in userret() above as it must follow
87  * the ktrsysret() in syscall().  Actually, it is likely that the
88  * ktrsysret should occur before the call to userret.
89  *
90  * Oh, and don't touch the FPU bit if we're returning to the kernel.
91  */
92 static inline void
93 share_fpu(struct lwp *l, struct trapframe64 *tf)
94 {
95 	if (!(tf->tf_tstate & (PSTATE_PRIV << TSTATE_PSTATE_SHIFT)) &&
96 	    fplwp != l)
97 		tf->tf_tstate &= ~(PSTATE_PEF << TSTATE_PSTATE_SHIFT);
98 }
99