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