xref: /openbsd-src/sys/arch/sparc64/include/pcb.h (revision 1c00236ed922d0b2365e523be77fdc7f5ed0fe80)
1*1c00236eSmiod /*	$OpenBSD: pcb.h,v 1.11 2022/10/21 18:55:42 miod Exp $	*/
2e7110a1dSart /*	$NetBSD: pcb.h,v 1.7 2000/12/29 17:12:05 eeh Exp $ */
3e7110a1dSart 
4e7110a1dSart /*
5e7110a1dSart  * Copyright (c) 1992, 1993
6e7110a1dSart  *	The Regents of the University of California.  All rights reserved.
7e7110a1dSart  *
8e7110a1dSart  * This software was developed by the Computer Systems Engineering group
9e7110a1dSart  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
10e7110a1dSart  * contributed to Berkeley.
11e7110a1dSart  *
12e7110a1dSart  * All advertising materials mentioning features or use of this software
13e7110a1dSart  * must display the following acknowledgement:
14e7110a1dSart  *	This product includes software developed by the University of
15e7110a1dSart  *	California, Lawrence Berkeley Laboratory.
16e7110a1dSart  *
17e7110a1dSart  * Redistribution and use in source and binary forms, with or without
18e7110a1dSart  * modification, are permitted provided that the following conditions
19e7110a1dSart  * are met:
20e7110a1dSart  * 1. Redistributions of source code must retain the above copyright
21e7110a1dSart  *    notice, this list of conditions and the following disclaimer.
22e7110a1dSart  * 2. Redistributions in binary form must reproduce the above copyright
23e7110a1dSart  *    notice, this list of conditions and the following disclaimer in the
24e7110a1dSart  *    documentation and/or other materials provided with the distribution.
2529295d1cSmillert  * 3. Neither the name of the University nor the names of its contributors
26e7110a1dSart  *    may be used to endorse or promote products derived from this software
27e7110a1dSart  *    without specific prior written permission.
28e7110a1dSart  *
29e7110a1dSart  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30e7110a1dSart  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31e7110a1dSart  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32e7110a1dSart  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33e7110a1dSart  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34e7110a1dSart  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35e7110a1dSart  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36e7110a1dSart  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37e7110a1dSart  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38e7110a1dSart  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39e7110a1dSart  * SUCH DAMAGE.
40e7110a1dSart  *
41e7110a1dSart  *	@(#)pcb.h	8.1 (Berkeley) 6/11/93
42e7110a1dSart  */
43e7110a1dSart 
442fa72412Spirofti #ifndef _MACHINE_PCB_H_
452fa72412Spirofti #define _MACHINE_PCB_H_
468ae89abbSpvalchev 
47e7110a1dSart #include <machine/reg.h>
48e7110a1dSart 
49e7110a1dSart #ifdef notyet
50e7110a1dSart #define	PCB_MAXWIN	32	/* architectural limit */
51e7110a1dSart #else
52e7110a1dSart #define	PCB_MAXWIN	8	/* worried about u area sizes ... */
53e7110a1dSart #endif
54e7110a1dSart 
55e7110a1dSart /*
56e7110a1dSart  * SPARC Process Control Block.
57e7110a1dSart  *
58e7110a1dSart  * pcb_uw is positive if there are any user windows that are
59e7110a1dSart  * are currently in the CPU windows rather than on the user
60e7110a1dSart  * stack.  Whenever we are running in the kernel with traps
61e7110a1dSart  * enabled, we decrement pcb_uw for each ``push'' of a CPU
62e7110a1dSart  * register window into the stack, and we increment it for
63e7110a1dSart  * each ``pull'' from the stack into the CPU.  (If traps are
64e7110a1dSart  * disabled, or if we are in user mode, pcb_uw is junk.)
65e7110a1dSart  *
66e7110a1dSart  * To ease computing pcb_uw on traps from user mode, we keep track
67e7110a1dSart  * of the log base 2 of the single bit that is set in %wim.
68e7110a1dSart  *
69e7110a1dSart  * If an overflow occurs while the associated user stack pages
70e7110a1dSart  * are invalid (paged out), we have to store the registers
71e7110a1dSart  * in a page that is locked in core while the process runs,
72e7110a1dSart  * i.e., right here in the pcb.  We also need the stack pointer
73e7110a1dSart  * for the last such window (but only the last, as the others
74e7110a1dSart  * are in each window) and the count of windows saved.  We
75e7110a1dSart  * cheat by having a whole window structure for that one %sp.
76e7110a1dSart  * Thus, to save window pcb_rw[i] to memory, we write it at
77e7110a1dSart  * pcb_rw[i + 1].rw_in[6].
78e7110a1dSart  *
79e7110a1dSart  * pcb_nsaved has three `kinds' of values.  If 0, it means no
80e7110a1dSart  * registers are in the PCB (though if pcb_uw is positive,
81e7110a1dSart  * there may be the next time you look).  If positive, it means
82e7110a1dSart  * there are no user registers in the CPU, but there are some
83e7110a1dSart  * saved in pcb_rw[].  As a special case, traps that needed
84e7110a1dSart  * assistance to pull user registers from the stack also store
85e7110a1dSart  * the registers in pcb_rw[], and set pcb_nsaved to -1.  This
86e7110a1dSart  * special state is normally short-term: it can only last until the
87e7110a1dSart  * trap returns, and it can never persist across entry to user code.
88e7110a1dSart  */
89e7110a1dSart /*
90e7110a1dSart  * v9 addendum:
91e7110a1dSart  *
92e7110a1dSart  * Window handling between v8 and v9 has changed somewhat.  There
93e7110a1dSart  * is no %wim.  Instead, we have a %cwp, %cansave, %canrestore,
94e7110a1dSart  * %cleanwin, and %otherwin.  By definition:
95e7110a1dSart  *
96e7110a1dSart  *	 %cansave + %canrestore + %otherwin = NWINDOWS - 2
97e7110a1dSart  *
98e7110a1dSart  * In addition, %cleanwin >= %canrestore since restorable windows
99e7110a1dSart  * are considered clean.  This means that by storing %canrestore
100e7110a1dSart  * and %otherwin, we should be able to compute the values of all
101e7110a1dSart  * the other registers.
102e7110a1dSart  *
103e7110a1dSart  * The only other register we need to save is %cwp because it cannot
104e7110a1dSart  * be trivially computed from the other registers.  The %cwp is
105e7110a1dSart  * stored in the %tstate register, but if the machine was in a register
106e7110a1dSart  * window spill/fill handler, the value of that %cwp may be off by
107e7110a1dSart  * as much as 2 register windows.  We will also store %cwp.  [We will
108e7110a1dSart  * try to steal pcb_uw or pcb_nsaved for this purpose eventually.]
109e7110a1dSart  *
110e7110a1dSart  * To calculate what registers are in the pcb, start with pcb_cwp
111e7110a1dSart  * and proceed to (pcb_cwp - pcb_canrestore) % NWINDOWS.  These should
112e7110a1dSart  * be saved to their appropriate register windows.  The client routine
113e7110a1dSart  * (trap handler) is responsible for saving pcb_cwp + 1 [%o1-%o7] in
114e7110a1dSart  * the trap frame or on the stack.
115e7110a1dSart  *
116e7110a1dSart  *
117e7110a1dSart  * Even more addendum:
118e7110a1dSart  *
119e7110a1dSart  * With the new system for keeping track of register windows we don't
120e7110a1dSart  * care about anything other than pcb_uw which keeps track of how many
121e7110a1dSart  * full windows we have.  As soon as a flush traps, we dump all user
122e7110a1dSart  * windows to the pcb, handle the fault, then restore all user windows.
123e7110a1dSart  *
124e7110a1dSart  * XXX we are using pcb_nsaved as the counter.  pcb_uw is still a mask.
125e7110a1dSart  * change this as soon as the new scheme is debugged.
126e7110a1dSart  */
127e7110a1dSart struct pcb {
128e7110a1dSart 	u_int64_t	pcb_sp;		/* sp (%o6) when switch() was called */
129e7110a1dSart 	u_int64_t	pcb_pc;		/* pc (%o7) when switch() was called */
130e7110a1dSart 	caddr_t	pcb_onfault;	/* for copyin/out */
131e7110a1dSart 	short	pcb_pstate;	/* %pstate when switch() was called -- may be useful if we support multiple memory models */
132e7110a1dSart 	char	pcb_nsaved;	/* number of windows saved in pcb */
133e7110a1dSart 
134e7110a1dSart 	/* The rest is probably not needed except for pcb_rw */
135e7110a1dSart 	char	pcb_cwp;	/* %cwp when switch() was called */
1368d7c5a97Skrw 	char	pcb_pil;	/* %pil when switch() was called -- probably not needed */
137e7110a1dSart 
138e7110a1dSart 	const char *lastcall;	/* DEBUG -- name of last system call */
139ab81dc66Skettenis 	u_int64_t	pcb_wcookie;
140ab81dc66Skettenis 
141e7110a1dSart 	/* the following MUST be aligned on a 64-bit boundary */
142*1c00236eSmiod 	struct	rwindow pcb_rw[PCB_MAXWIN];	/* saved windows */
143298e1a59Skettenis 	u_int64_t	pcb_rwsp[PCB_MAXWIN];
144e7110a1dSart };
145e7110a1dSart 
1464ced3000Skettenis #ifndef _KERNEL
147e7110a1dSart /* Let gdb compile.  We need fancier macros to make these make sense. */
148e7110a1dSart #define pcb_psr	pcb_pstate
149e7110a1dSart #define pcb_wim	pcb_cwp
150e7110a1dSart #endif /* _KERNEL */
1518ae89abbSpvalchev 
1522fa72412Spirofti #endif /* _MACHINE_PCB_H_ */
153