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