xref: /netbsd-src/sys/arch/sparc64/include/userret.h (revision 33ec454f0ce611d0027b05660eafa39f69d07ae6)
1*33ec454fSnakayama /*	$NetBSD: userret.h,v 1.9 2009/10/17 08:50:49 nakayama Exp $ */
241565563Schristos 
341565563Schristos /*
441565563Schristos  * Copyright (c) 1996-2002 Eduardo Horvath.  All rights reserved.
541565563Schristos  * Copyright (c) 1996
641565563Schristos  *	The President and Fellows of Harvard College. All rights reserved.
741565563Schristos  * Copyright (c) 1992, 1993
841565563Schristos  *	The Regents of the University of California.  All rights reserved.
941565563Schristos  *
1041565563Schristos  * This software was developed by the Computer Systems Engineering group
1141565563Schristos  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
1241565563Schristos  * contributed to Berkeley.
1341565563Schristos  *
1441565563Schristos  * All advertising materials mentioning features or use of this software
1541565563Schristos  * must display the following acknowledgement:
1641565563Schristos  *	This product includes software developed by the University of
1741565563Schristos  *	California, Lawrence Berkeley Laboratory.
1841565563Schristos  *	This product includes software developed by Harvard University.
1941565563Schristos  *
2041565563Schristos  * Redistribution and use in source and binary forms, with or without
2141565563Schristos  * modification, are permitted provided that the following conditions
2241565563Schristos  * are met:
2341565563Schristos  * 1. Redistributions of source code must retain the above copyright
2441565563Schristos  *    notice, this list of conditions and the following disclaimer.
2541565563Schristos  * 2. Redistributions in binary form must reproduce the above copyright
2641565563Schristos  *    notice, this list of conditions and the following disclaimer in the
2741565563Schristos  *    documentation and/or other materials provided with the distribution.
2841565563Schristos  * 3. All advertising materials mentioning features or use of this software
2941565563Schristos  *    must display the following acknowledgement:
3041565563Schristos  *	This product includes software developed by the University of
3141565563Schristos  *	California, Berkeley and its contributors.
3241565563Schristos  *	This product includes software developed by Harvard University.
3341565563Schristos  * 4. Neither the name of the University nor the names of its contributors
3441565563Schristos  *    may be used to endorse or promote products derived from this software
3541565563Schristos  *    without specific prior written permission.
3641565563Schristos  *
3741565563Schristos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
3841565563Schristos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3941565563Schristos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4041565563Schristos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
4141565563Schristos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
4241565563Schristos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
4341565563Schristos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4441565563Schristos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
4541565563Schristos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
4641565563Schristos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
4741565563Schristos  * SUCH DAMAGE.
4841565563Schristos  *
4941565563Schristos  *	@(#)trap.c	8.4 (Berkeley) 9/23/93
5041565563Schristos  */
5141565563Schristos 
5241565563Schristos #include <sys/userret.h>
5341565563Schristos 
54d0f8217fScdi static __inline void userret(struct lwp *, int,  u_quad_t);
5541565563Schristos /*
5641565563Schristos  * Define the code needed before returning to user mode, for
5741565563Schristos  * trap, mem_access_fault, and syscall.
5841565563Schristos  */
59fbae48b9Sperry static __inline void
userret(struct lwp * l,int pc,u_quad_t oticks)6041565563Schristos userret(struct lwp *l, int pc, u_quad_t oticks)
6141565563Schristos {
6241565563Schristos 	struct proc *p = l->l_proc;
6341565563Schristos 
6441565563Schristos 	mi_userret(l);
6541565563Schristos 
6641565563Schristos 	/*
6741565563Schristos 	 * If profiling, charge recent system time to the trapped pc.
6841565563Schristos 	 */
69b07ec3fcSad 	if (p->p_stflag & PST_PROFIL)
70b07ec3fcSad 		addupc_task(l, pc, (int)(p->p_sticks - oticks));
7141565563Schristos }
7241565563Schristos 
73d0f8217fScdi static __inline void share_fpu(struct lwp *, struct trapframe64 *);
7441565563Schristos /*
7541565563Schristos  * If someone stole the FPU while we were away, do not enable it
7641565563Schristos  * on return.  This is not done in userret() above as it must follow
7741565563Schristos  * the ktrsysret() in syscall().  Actually, it is likely that the
7841565563Schristos  * ktrsysret should occur before the call to userret.
7941565563Schristos  *
8041565563Schristos  * Oh, and don't touch the FPU bit if we're returning to the kernel.
8141565563Schristos  */
82fbae48b9Sperry static __inline void
share_fpu(struct lwp * l,struct trapframe64 * tf)8341565563Schristos share_fpu(struct lwp *l, struct trapframe64 *tf)
8441565563Schristos {
85fa9b4713Snakayama 	if (!(tf->tf_tstate & TSTATE_PRIV) && fplwp != l)
86fa9b4713Snakayama 		tf->tf_tstate &= ~TSTATE_PEF;
8741565563Schristos }
88