xref: /netbsd-src/sys/arch/sparc64/include/pcb.h (revision 5e8ba6d46557a58357d4e75283e0fe908a059101)
1*5e8ba6d4Spooka /*	$NetBSD: pcb.h,v 1.16 2009/10/13 22:41:57 pooka Exp $ */
2aad01611Sagc 
3aad01611Sagc /*
4aad01611Sagc  * Copyright (c) 1992, 1993
5aad01611Sagc  *	The Regents of the University of California.  All rights reserved.
6aad01611Sagc  *
7aad01611Sagc  * This software was developed by the Computer Systems Engineering group
8aad01611Sagc  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9aad01611Sagc  * contributed to Berkeley.
10aad01611Sagc  *
11aad01611Sagc  * All advertising materials mentioning features or use of this software
12aad01611Sagc  * must display the following acknowledgement:
13aad01611Sagc  *	This product includes software developed by the University of
14aad01611Sagc  *	California, Lawrence Berkeley Laboratory.
15aad01611Sagc  *
16aad01611Sagc  * Redistribution and use in source and binary forms, with or without
17aad01611Sagc  * modification, are permitted provided that the following conditions
18aad01611Sagc  * are met:
19aad01611Sagc  * 1. Redistributions of source code must retain the above copyright
20aad01611Sagc  *    notice, this list of conditions and the following disclaimer.
21aad01611Sagc  * 2. Redistributions in binary form must reproduce the above copyright
22aad01611Sagc  *    notice, this list of conditions and the following disclaimer in the
23aad01611Sagc  *    documentation and/or other materials provided with the distribution.
24aad01611Sagc  * 3. Neither the name of the University nor the names of its contributors
25aad01611Sagc  *    may be used to endorse or promote products derived from this software
26aad01611Sagc  *    without specific prior written permission.
27aad01611Sagc  *
28aad01611Sagc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29aad01611Sagc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30aad01611Sagc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31aad01611Sagc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32aad01611Sagc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33aad01611Sagc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34aad01611Sagc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35aad01611Sagc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36aad01611Sagc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37aad01611Sagc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38aad01611Sagc  * SUCH DAMAGE.
39aad01611Sagc  *
40aad01611Sagc  *	@(#)pcb.h	8.1 (Berkeley) 6/11/93
41aad01611Sagc  */
4201e2e698Seeh 
4301e2e698Seeh /*
44e8ff5b27Seeh  * Copyright (c) 1996-2002 Eduardo Horvath.  All rights reserved.
4501e2e698Seeh  *
4601e2e698Seeh  * Redistribution and use in source and binary forms, with or without
4701e2e698Seeh  * modification, are permitted provided that the following conditions
4801e2e698Seeh  * are met:
4901e2e698Seeh  * 1. Redistributions of source code must retain the above copyright
5001e2e698Seeh  *    notice, this list of conditions and the following disclaimer.
5101e2e698Seeh  * 2. Redistributions in binary form must reproduce the above copyright
5201e2e698Seeh  *    notice, this list of conditions and the following disclaimer in the
5301e2e698Seeh  *    documentation and/or other materials provided with the distribution.
545f1ffa71Seeh  * 3. Neither the name of the author nor the names of its contributors
5501e2e698Seeh  *    may be used to endorse or promote products derived from this software
5601e2e698Seeh  *    without specific prior written permission.
5701e2e698Seeh  *
585f1ffa71Seeh  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
5901e2e698Seeh  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
6001e2e698Seeh  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
6101e2e698Seeh  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
6201e2e698Seeh  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
6301e2e698Seeh  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
6401e2e698Seeh  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
6501e2e698Seeh  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
6601e2e698Seeh  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
6701e2e698Seeh  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6801e2e698Seeh  * SUCH DAMAGE.
6901e2e698Seeh  *
7001e2e698Seeh  *	@(#)pcb.h	8.1 (Berkeley) 6/11/93
7101e2e698Seeh  */
7201e2e698Seeh 
73*5e8ba6d4Spooka #ifndef _SPARC64_PCB_H_
74*5e8ba6d4Spooka #define _SPARC64_PCB_H_
75*5e8ba6d4Spooka 
7601e2e698Seeh #include <machine/reg.h>
7701e2e698Seeh 
7801e2e698Seeh #ifdef notyet
7901e2e698Seeh #define	PCB_MAXWIN	32	/* architectural limit */
8001e2e698Seeh #else
8101e2e698Seeh #define	PCB_MAXWIN	8	/* worried about u area sizes ... */
8201e2e698Seeh #endif
8301e2e698Seeh 
8401e2e698Seeh /*
8501e2e698Seeh  * SPARC Process Control Block.
8601e2e698Seeh  *
8701e2e698Seeh  * pcb_uw is positive if there are any user windows that are
8801e2e698Seeh  * are currently in the CPU windows rather than on the user
8901e2e698Seeh  * stack.  Whenever we are running in the kernel with traps
9001e2e698Seeh  * enabled, we decrement pcb_uw for each ``push'' of a CPU
9101e2e698Seeh  * register window into the stack, and we increment it for
9201e2e698Seeh  * each ``pull'' from the stack into the CPU.  (If traps are
9301e2e698Seeh  * disabled, or if we are in user mode, pcb_uw is junk.)
9401e2e698Seeh  *
9501e2e698Seeh  * To ease computing pcb_uw on traps from user mode, we keep track
9601e2e698Seeh  * of the log base 2 of the single bit that is set in %wim.
9701e2e698Seeh  *
9801e2e698Seeh  * If an overflow occurs while the associated user stack pages
9901e2e698Seeh  * are invalid (paged out), we have to store the registers
10001e2e698Seeh  * in a page that is locked in core while the process runs,
10101e2e698Seeh  * i.e., right here in the pcb.  We also need the stack pointer
10201e2e698Seeh  * for the last such window (but only the last, as the others
10301e2e698Seeh  * are in each window) and the count of windows saved.  We
10401e2e698Seeh  * cheat by having a whole window structure for that one %sp.
10501e2e698Seeh  * Thus, to save window pcb_rw[i] to memory, we write it at
10601e2e698Seeh  * pcb_rw[i + 1].rw_in[6].
10701e2e698Seeh  *
10801e2e698Seeh  * pcb_nsaved has three `kinds' of values.  If 0, it means no
10901e2e698Seeh  * registers are in the PCB (though if pcb_uw is positive,
11001e2e698Seeh  * there may be the next time you look).  If positive, it means
11101e2e698Seeh  * there are no user registers in the CPU, but there are some
11201e2e698Seeh  * saved in pcb_rw[].  As a special case, traps that needed
11301e2e698Seeh  * assistance to pull user registers from the stack also store
11401e2e698Seeh  * the registers in pcb_rw[], and set pcb_nsaved to -1.  This
11501e2e698Seeh  * special state is normally short-term: it can only last until the
11601e2e698Seeh  * trap returns, and it can never persist across entry to user code.
11701e2e698Seeh  */
11801e2e698Seeh /*
11901e2e698Seeh  * v9 addendum:
12001e2e698Seeh  *
12101e2e698Seeh  * Window handling between v8 and v9 has changed somewhat.  There
12201e2e698Seeh  * is no %wim.  Instead, we have a %cwp, %cansave, %canrestore,
12301e2e698Seeh  * %cleanwin, and %otherwin.  By definition:
12401e2e698Seeh  *
12501e2e698Seeh  *	 %cansave + %canrestore + %otherwin = NWINDOWS - 2
12601e2e698Seeh  *
12701e2e698Seeh  * In addition, %cleanwin >= %canrestore since restorable windows
12801e2e698Seeh  * are considered clean.  This means that by storing %canrestore
12901e2e698Seeh  * and %otherwin, we should be able to compute the values of all
13001e2e698Seeh  * the other registers.
13101e2e698Seeh  *
13201e2e698Seeh  * The only other register we need to save is %cwp because it cannot
13301e2e698Seeh  * be trivially computed from the other registers.  The %cwp is
13401e2e698Seeh  * stored in the %tstate register, but if the machine was in a register
13501e2e698Seeh  * window spill/fill handler, the value of that %cwp may be off by
13601e2e698Seeh  * as much as 2 register windows.  We will also store %cwp.  [We will
13701e2e698Seeh  * try to steal pcb_uw or pcb_nsaved for this purpose eventually.]
13801e2e698Seeh  *
13901e2e698Seeh  * To calculate what registers are in the pcb, start with pcb_cwp
14001e2e698Seeh  * and proceed to (pcb_cwp - pcb_canrestore) % NWINDOWS.  These should
14101e2e698Seeh  * be saved to their appropriate register windows.  The client routine
14201e2e698Seeh  * (trap handler) is responsible for saving pcb_cwp + 1 [%o1-%o7] in
14301e2e698Seeh  * the trap frame or on the stack.
14401e2e698Seeh  *
14501e2e698Seeh  *
14601e2e698Seeh  * Even more addendum:
14701e2e698Seeh  *
14801e2e698Seeh  * With the new system for keeping track of register windows we don't
14901e2e698Seeh  * care about anything other than pcb_uw which keeps track of how many
15001e2e698Seeh  * full windows we have.  As soon as a flush traps, we dump all user
15101e2e698Seeh  * windows to the pcb, handle the fault, then restore all user windows.
15201e2e698Seeh  *
15301e2e698Seeh  * XXX we are using pcb_nsaved as the counter.  pcb_uw is still a mask.
15401e2e698Seeh  * change this as soon as the new scheme is debugged.
15501e2e698Seeh  */
15601e2e698Seeh struct pcb {
157d50f0c62Scdi 	uint64_t	pcb_sp;		/* sp (%o6) when switch() was called */
158d50f0c62Scdi 	uint64_t	pcb_pc;		/* pc (%o7) when switch() was called */
15953524e44Schristos 	void *	pcb_onfault;	/* for copyin/out */
16001e2e698Seeh 	short	pcb_pstate;	/* %pstate when switch() was called -- may be useful if we support multiple memory models */
16101e2e698Seeh 	char	pcb_nsaved;	/* number of windows saved in pcb */
16201e2e698Seeh 
16301e2e698Seeh 	/* The rest is probably not needed except for pcb_rw */
16401e2e698Seeh 	char	pcb_cwp;	/* %cwp when switch() was called */
16501e2e698Seeh 	char	pcb_pil;	/* %pil when switch() was called -- prolly not needed */
16601e2e698Seeh 
16740095eb6Smrg 	const char *lastcall;	/* DEBUG -- name of last system call */
16801e2e698Seeh 	/* the following MUST be aligned on a 64-bit boundary */
16901e2e698Seeh 	struct	rwindow64 pcb_rw[PCB_MAXWIN];	/* saved windows */
17001e2e698Seeh };
17101e2e698Seeh 
17201e2e698Seeh /*
17301e2e698Seeh  * The pcb is augmented with machine-dependent additional data for
17401e2e698Seeh  * core dumps.  Note that the trapframe here is a copy of the one
17501e2e698Seeh  * from the top of the kernel stack (included here so that the kernel
17601e2e698Seeh  * stack itself need not be dumped).
17701e2e698Seeh  */
1787b60d6a0Seeh struct md_coredump32 {
17901e2e698Seeh 	struct	trapframe32 md_tf;
1807b60d6a0Seeh 	struct	fpstate32 md_fpstate;
1817b60d6a0Seeh };
1827b60d6a0Seeh 
1837b60d6a0Seeh struct md_coredump {
1845f326297Seeh 	struct	trapframe64 md_tf;
1857b60d6a0Seeh 	struct	fpstate64 md_fpstate;
1867b60d6a0Seeh };
1877b60d6a0Seeh 
188d49bc810Scdi #ifndef _KERNEL
189793cc7a4Seeh /* Let gdb compile.  We need fancier macros to make these make sense. */
190793cc7a4Seeh #define pcb_psr	pcb_pstate
191793cc7a4Seeh #define pcb_wim	pcb_cwp
19201e2e698Seeh #endif /* _KERNEL */
193*5e8ba6d4Spooka 
194*5e8ba6d4Spooka #endif /* _SPARC64_PCB_H_ */
195