1 /* $NetBSD: userret.h,v 1.7 2007/10/17 19:57:13 garbled Exp $ */
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.
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.
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.
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions
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.
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
48 * @(#)trap.c 8.4 (Berkeley) 9/23/93
51 #include <sys/userret.h>
53 static __inline
void userret(struct lwp
*, int, u_quad_t
);
54 static __inline
void share_fpu(struct lwp
*, struct trapframe
*);
58 * Define the code needed before returning to user mode, for
59 * trap, mem_access_fault, and syscall.
62 userret(struct lwp
*l
, int pc
, u_quad_t oticks
)
64 struct proc
*p
= l
->l_proc
;
69 if (cpuinfo
.ci_want_ast
) {
70 cpuinfo
.ci_want_ast
= 0;
71 if (l
->l_pflag
& LP_OWEUPC
) {
72 l
->l_pflag
&= ~LP_OWEUPC
;
76 if (cpuinfo
.ci_want_resched
) {
78 * We are being preempted.
85 * If profiling, charge recent system time to the trapped pc.
87 if (p
->p_stflag
& PST_PROFIL
)
88 addupc_task(l
, pc
, (int)(p
->p_sticks
- oticks
));
92 * If someone stole the FPU while we were away, do not enable it
93 * on return. This is not done in userret() above as it must follow
94 * the ktrsysret() in syscall(). Actually, it is likely that the
95 * ktrsysret should occur before the call to userret.
97 static __inline
void share_fpu(struct lwp
*l
, struct trapframe
*tf
)
99 if ((tf
->tf_psr
& PSR_EF
) != 0 && cpuinfo
.fplwp
!= l
)
100 tf
->tf_psr
&= ~PSR_EF
;