2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1997 Berkeley Software Design, Inc. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Berkeley Software Design Inc's name may not be used to endorse or
15 * promote products derived from this software without specific prior
18 * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * from: BSDI: trap.c,v 1.17.2.9 1999/10/19 15:29:52 cp Exp
34 #include <sys/param.h>
35 #include <sys/systm.h>
39 #include <machine/frame.h>
40 #include <machine/pcb.h>
42 CTASSERT((1 << RW_SHIFT) == sizeof(struct rwindow));
45 rwindow_load(struct thread *td, struct trapframe *tf, int n)
52 CTR3(KTR_TRAP, "rwindow_load: td=%p (%s) n=%d",
53 td, td->td_proc->p_comm, n);
56 * In case current window is still only on-chip, push it out;
57 * if it cannot get all the way out, we cannot continue either.
59 if ((error = rwindow_save(td)) != 0)
62 for (i = 0; i < n; i++) {
63 CTR1(KTR_TRAP, "rwindow_load: usp=%#lx", usp);
65 if ((error = (usp & 0x7)) != 0)
67 error = copyin((void *)usp, &rw, sizeof rw);
70 CTR1(KTR_TRAP, "rwindow_load: error=%d", error);
71 return (error == 0 ? 0 : SIGILL);
75 rwindow_save(struct thread *td)
85 CTR3(KTR_TRAP, "rwindow_save: td=%p (%s) nsaved=%d", td,
86 td->td_proc->p_comm, pcb->pcb_nsaved);
89 KASSERT(pcb->pcb_nsaved < MAXWIN,
90 ("rwindow_save: pcb_nsaved > MAXWIN"));
91 if ((i = pcb->pcb_nsaved) == 0)
98 CTR1(KTR_TRAP, "rwindow_save: usp=%#lx", usp);
100 if ((error = (usp & 0x7)) != 0)
102 error = copyout(rw, (void *)usp, sizeof *rw);
108 CTR1(KTR_TRAP, "rwindow_save: error=%d", error);
111 return (error == 0 ? 0 : SIGILL);