1*6a602769Sragge /* $NetBSD: userret.h,v 1.15 2017/05/22 17:12:11 ragge Exp $ */
289589990Schristos
389589990Schristos /*
489589990Schristos * Copyright (c) 1994 Ludd, University of Lule}, Sweden.
589589990Schristos * All rights reserved.
689589990Schristos *
789589990Schristos * Redistribution and use in source and binary forms, with or without
889589990Schristos * modification, are permitted provided that the following conditions
989589990Schristos * are met:
1089589990Schristos * 1. Redistributions of source code must retain the above copyright
1189589990Schristos * notice, this list of conditions and the following disclaimer.
1289589990Schristos * 2. Redistributions in binary form must reproduce the above copyright
1389589990Schristos * notice, this list of conditions and the following disclaimer in the
1489589990Schristos * documentation and/or other materials provided with the distribution.
1589589990Schristos *
1689589990Schristos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1789589990Schristos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1889589990Schristos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1989589990Schristos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2089589990Schristos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2189589990Schristos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2289589990Schristos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2389589990Schristos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2489589990Schristos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2589589990Schristos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2689589990Schristos */
2789589990Schristos
28f7d7a7a0Smatt #include <sys/userret.h>
29e950a585Smatt #include <sys/ras.h>
3089589990Schristos
3189589990Schristos /*
326ea9f5a7Ssnj * Common code used by various exception handlers to
3389589990Schristos * return to usermode.
3489589990Schristos */
3589589990Schristos static __inline void
userret(struct lwp * l,struct trapframe * tf,u_quad_t oticks)369b5b6463Smatt userret(struct lwp *l, struct trapframe *tf, u_quad_t oticks)
3789589990Schristos {
389b5b6463Smatt struct proc * const p = l->l_proc;
3989589990Schristos
40af5e5382Shans mi_userret(l);
4189589990Schristos
4289589990Schristos /*
43e950a585Smatt * Check to see if a RAS was interrupted and restart it if it was.
44e950a585Smatt */
45e950a585Smatt if (__predict_false(p->p_raslist != NULL)) {
46e950a585Smatt void * const ras_pc = ras_lookup(p, (void *) tf->tf_pc);
47e950a585Smatt if (ras_pc != (void *) -1)
48e950a585Smatt tf->tf_pc = (vaddr_t) ras_pc;
49e950a585Smatt }
50e950a585Smatt
51e950a585Smatt /*
5289589990Schristos * If profiling, charge system time to the trapped pc.
5389589990Schristos */
5486e995e9Sad if ((p->p_stflag & PST_PROFIL) != 0) {
5589589990Schristos extern int psratio;
5689589990Schristos
579b5b6463Smatt addupc_task(l, tf->tf_pc,
5889589990Schristos (int)(p->p_sticks - oticks) * psratio);
5989589990Schristos }
6089589990Schristos }
61