xref: /netbsd-src/sys/arch/powerpc/include/frame.h (revision 5bbd2a12505d72a8177929a37b5cee489d0a1cfd)
1 /*	$NetBSD: frame.h,v 1.25 2012/08/01 16:19:42 matt Exp $	*/
2 
3 /*
4  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
5  * Copyright (C) 1995, 1996 TooLs GmbH.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *	This product includes software developed by TooLs GmbH.
19  * 4. The name of TooLs GmbH may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 #ifndef	_POWERPC_FRAME_H_
34 #define	_POWERPC_FRAME_H_
35 
36 #include <machine/types.h>
37 
38 #ifdef _KERNEL
39 #ifdef _KERNEL_OPT
40 #include "opt_ppcarch.h"
41 #endif
42 #endif
43 
44 /*
45  * We have to save all registers on every trap, because
46  *	1. user could attach this process every time
47  *	2. we must be able to restore all user registers in case of fork
48  * Actually, we do not save the fp registers on trap, since
49  * these are not used by the kernel. They are saved only when switching
50  * between processes using the FPU.
51  *
52  * Change ordering to cluster together these register_t's.		XXX
53  */
54 struct reg_sans_pc {
55 	register_t r_fixreg[32];
56 	register_t r_lr;
57 	uint32_t r_cr;
58 	uint32_t r_xer;
59 	register_t r_ctr;
60 };
61 
62 struct utrapframe {
63 	register_t fixreg[32];
64 	register_t lr;
65 	int cr;
66 	int xer;
67 	register_t ctr;
68 	register_t srr0;
69 	register_t srr1;
70 	int vrsave;
71 	int mq;
72 	int spare;
73 };
74 
75 struct clockframe {
76 	register_t cf_srr0;
77 	register_t cf_srr1;
78 	int cf_idepth;
79 };
80 
81 struct trapframe {
82 	struct reg_sans_pc tf_ureg;
83 	struct clockframe tf_cf;
84 	uint32_t tf_exc;
85 #if defined(PPC_OEA) || defined(PPC_OEA64) || defined(PPC_OEA64_BRIDGE)
86 	register_t tf_dar;
87 	register_t tf_pad0[2];
88 	uint32_t tf_dsisr;
89 	uint32_t tf_vrsave;
90 	uint32_t tf_mq;
91 	uint32_t tf_pad1[1];
92 #endif
93 #if defined(PPC_BOOKE) || defined(PPC_IBM4XX)
94 	register_t tf_dear;
95 	register_t tf_mcar;
96 	register_t tf_sprg1;
97 	uint32_t tf_esr;
98 	uint32_t tf_mcsr;
99 	uint32_t tf_pid;
100 	uint32_t tf_spefscr;
101 #endif
102 };
103 #define tf_fixreg	tf_ureg.r_fixreg
104 #define tf_lr		tf_ureg.r_lr
105 #define tf_cr		tf_ureg.r_cr
106 #define tf_xer		tf_ureg.r_xer
107 #define tf_ctr		tf_ureg.r_ctr
108 #define tf_srr0		tf_cf.cf_srr0
109 #define tf_srr1		tf_cf.cf_srr1
110 #define tf_idepth	tf_cf.cf_idepth
111 
112 struct ktrapframe {
113 	register_t ktf_sp;
114 	register_t ktf_lr;
115 	struct trapframe ktf_tf;
116 	register_t ktf_cframe_lr;	/* for DDB */
117 };
118 
119 #if defined(_KERNEL) || defined(_LKM)
120 #ifdef _LP64
121 struct utrapframe32 {
122 	register32_t fixreg[32];
123 	register32_t lr;
124 	int cr;
125 	int xer;
126 	register32_t ctr;
127 	register32_t srr0;
128 	register32_t srr1;
129 	int vrsave;
130 	int mq;
131 	int spare;
132 };
133 #endif
134 #endif /* _KERNEL || _LKM */
135 
136 /*
137  * This is to ensure alignment of the stackpointer
138  */
139 #define	FRAMELEN	roundup(sizeof(struct ktrapframe), CALLFRAMELEN)
140 #define	ktrapframe(l)	((struct ktrapframe *)(uvm_lwp_getuarea(l) + USPACE - CALLFRAMELEN - FRAMELEN))
141 #define	trapframe(l)	(&(ktrapframe(l)->ktf_tf))
142 
143 #define	SFRAMELEN	roundup(sizeof(struct switchframe), CALLFRAMELEN)
144 struct switchframe {
145 	register_t sf_sp;
146 	register_t sf_lr;
147 	register_t sf_user_sr;		/* VSID on IBM4XX */
148 	register_t sf_cr;		/* why?  CR is volatile. */
149 	register_t sf_fixreg2;
150 	register_t sf_fixreg[19];	/* R13-R31 */
151 };
152 
153 /*
154  * Call frame for PowerPC used during fork.
155  */
156 #define	CALLFRAMELEN	sizeof(struct callframe)
157 struct callframe {
158 	register_t cf_sp;
159 	register_t cf_lr;
160 	register_t cf_r30;
161 	register_t cf_r31;
162 };
163 
164 #endif	/* _POWERPC_FRAME_H_ */
165