xref: /netbsd-src/sys/arch/powerpc/include/frame.h (revision c2f76ff004a2cb67efe5b12d97bd3ef7fe89e18d)
1 /*	$NetBSD: frame.h,v 1.22 2011/01/18 01:02:54 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 	uint32_t tf_dsisr;
88 	uint32_t tf_vrsave;
89 	uint32_t tf_mq;
90 #endif
91 #if defined(PPC_BOOKE) || defined(PPC_IBM4XX)
92 	register_t tf_dear;
93 	register_t tf_mcar;
94 	register_t tf_sprg1;
95 	uint32_t tf_esr;
96 	uint32_t tf_mcsr;
97 	uint32_t tf_pid;
98 	uint32_t tf_spefscr;
99 #endif
100 };
101 #define tf_fixreg	tf_ureg.r_fixreg
102 #define tf_lr		tf_ureg.r_lr
103 #define tf_cr		tf_ureg.r_cr
104 #define tf_xer		tf_ureg.r_xer
105 #define tf_ctr		tf_ureg.r_ctr
106 #define tf_srr0		tf_cf.cf_srr0
107 #define tf_srr1		tf_cf.cf_srr1
108 #define tf_idepth	tf_cf.cf_idepth
109 
110 struct ktrapframe {
111 	register_t ktf_sp;
112 	register_t ktf_lr;
113 	struct trapframe ktf_tf;
114 };
115 
116 #if defined(_KERNEL) || defined(_LKM)
117 #ifdef _LP64
118 struct utrapframe32 {
119 	register32_t fixreg[32];
120 	register32_t lr;
121 	int cr;
122 	int xer;
123 	register32_t ctr;
124 	register32_t srr0;
125 	register32_t srr1;
126 	int vrsave;
127 	int mq;
128 	int spare;
129 };
130 #endif
131 #endif /* _KERNEL || _LKM */
132 
133 /*
134  * This is to ensure alignment of the stackpointer
135  */
136 #define	FRAMELEN	roundup(sizeof(struct ktrapframe), CALLFRAMELEN)
137 #define	ktrapframe(l)	((struct ktrapframe *)(uvm_lwp_getuarea(l) + USPACE - CALLFRAMELEN - FRAMELEN))
138 #define	trapframe(l)	(&(ktrapframe(l)->ktf_tf))
139 
140 #define	SFRAMELEN	roundup(sizeof(struct switchframe), CALLFRAMELEN)
141 struct switchframe {
142 	register_t sf_sp;
143 	register_t sf_lr;
144 	register_t sf_user_sr;		/* VSID on IBM4XX */
145 	register_t sf_cr;		/* why?  CR is volatile. */
146 	register_t sf_fixreg2;
147 	register_t sf_fixreg[19];	/* R13-R31 */
148 };
149 
150 /*
151  * Call frame for PowerPC used during fork.
152  */
153 #define	CALLFRAMELEN	sizeof(struct callframe)
154 struct callframe {
155 	register_t cf_sp;
156 	register_t cf_lr;
157 	register_t cf_r30;
158 	register_t cf_r31;
159 };
160 
161 struct saframe {
162 	register_t saf_r1;	/* stack pointer */
163 	register_t saf_lr;	/* Callee lr save area */
164 #ifndef _LP64
165 	register_t saf_fill[2];	/* Pad to multiple of 16 bytes */
166 #endif
167 };
168 
169 #endif	/* _POWERPC_FRAME_H_ */
170