1/*	$NetBSD: decode.h,v 1.2 2007/02/21 22:59:45 thorpej Exp $	*/
2
3/* Contributed to the NetBSD Foundation by Cherry G. Mathew <cherry@mahiti.org>
4 * This file contains prototypes to decode unwind descriptors.
5 */
6
7#define MAXSTATERECS 20	/* The maximum number of descriptor records per region */
8
9#define IS_R1(byte) (( (byte) & 0xc0) == 0)
10#define IS_R2(byte) (((byte) & 0xf8) == 0x40)
11#define IS_R3(byte) (((byte) & 0xfc) == 0x60)
12#define IS_P1(byte) (((byte) & 0xe0) == 0x80)
13#define IS_P2(byte) (((byte) & 0xf0) == 0xa0)
14#define IS_P3(byte) (((byte) & 0xf8) == 0xb0)
15#define IS_P4(byte) ((byte) == (char) 0xb8)
16#define IS_P5(byte) ((byte) == (char) 0xb9)
17#define IS_P6(byte) (((byte) & 0xe0) == 0xc0)
18#define IS_P7(byte) (((byte) & 0xf0) == 0xe0)
19#define IS_P8(byte) ((byte) == (char) 0xf0)
20#define IS_P9(byte) ((byte) == (char) 0xf1)
21#define IS_P10(byte) ((byte) ==(char) 0xff)
22#define IS_B1(byte) (((byte) & 0xc0) == 0x80)
23#define IS_B2(byte) (((byte) & 0xe0) == 0xc0)
24#define IS_B3(byte) ((byte) == (char) 0xe0)
25#define IS_B4(byte) (((byte) & 0xf7) == 0xf0)
26#define IS_X1(byte) ((byte) == (char) 0xf9)
27#define IS_X2(byte) ((byte) == (char) 0xfa)
28#define IS_X3(byte) ((byte) == (char) 0xfb)
29#define IS_X4(byte) ((byte) == (char) 0xfc)
30
31struct unwind_desc_R1 {
32	bool r;
33	vsize_t rlen;
34};
35
36struct unwind_desc_R2 {
37	u_int mask;
38#define R2MASKRP	0x8
39#define R2MASKPFS	0x4
40#define R2MASKPSP	0x2
41
42	u_int grsave;
43	vsize_t rlen;
44};
45
46struct unwind_desc_R3 {
47	bool r;
48	vsize_t rlen;
49};
50
51struct unwind_desc_P1 {
52	u_int brmask;
53};
54
55struct unwind_desc_P2 {
56	u_int brmask;
57	u_int gr;
58};
59
60struct unwind_desc_P3 {
61	u_int r;
62	u_int grbr;
63};
64
65struct unwind_desc_P4 {
66	vsize_t imask;
67};
68
69struct unwind_desc_P5 {
70	u_int grmask;
71	u_int frmask;
72};
73
74struct unwind_desc_P6 {
75	bool r;
76	u_int rmask;
77};
78
79struct unwind_desc_P7 {
80	u_int r;
81	vsize_t t;
82	vsize_t size;
83};
84
85struct unwind_desc_P8 {
86	u_int r;
87	vsize_t t;
88};
89
90struct unwind_desc_P9 {
91	u_int grmask;
92	u_int gr;
93};
94
95struct unwind_desc_P10 {
96	u_int abi;
97	u_int context;
98};
99
100struct unwind_desc_B1 {
101	bool r;
102	u_int label;
103};
104
105struct unwind_desc_B2 {
106	u_int ecount;
107	vsize_t t;
108};
109
110struct unwind_desc_B3 {
111	vsize_t t;
112	vsize_t ecount;
113};
114
115struct unwind_desc_B4 {
116	bool r;
117	vsize_t label;
118};
119
120struct unwind_desc_X1 {
121	bool r;
122	bool a;
123	bool b;
124	u_int reg;
125	vsize_t t;
126	vsize_t offset;
127};
128
129struct unwind_desc_X2 {
130	bool x;
131	bool a;
132	bool b;
133	u_int reg;
134	bool y;
135	u_int treg;
136	vsize_t t;
137};
138
139
140
141struct unwind_desc_X3 {
142	bool r;
143	u_int qp;
144	bool a;
145	bool b;
146	u_int reg;
147	vsize_t t;
148	vsize_t offset;
149};
150
151struct unwind_desc_X4 {
152	u_int qp;
153	bool x;
154	bool a;
155	bool b;
156	u_int reg;
157	bool y;
158	u_int treg;
159	vsize_t t;
160};
161
162union unwind_desc {
163	struct unwind_desc_R1 R1;
164	struct unwind_desc_R2 R2;
165	struct unwind_desc_R3 R3;
166
167	struct unwind_desc_P1 P1;
168	struct unwind_desc_P2 P2;
169	struct unwind_desc_P3 P3;
170	struct unwind_desc_P4 P4;
171	struct unwind_desc_P5 P5;
172	struct unwind_desc_P6 P6;
173	struct unwind_desc_P7 P7;
174	struct unwind_desc_P8 P8;
175	struct unwind_desc_P9 P9;
176	struct unwind_desc_P10 P10;
177
178	struct unwind_desc_B1 B1;
179	struct unwind_desc_B2 B2;
180	struct unwind_desc_B3 B3;
181	struct unwind_desc_B4 B4;
182
183	struct unwind_desc_X1 X1;
184	struct unwind_desc_X2 X2;
185	struct unwind_desc_X3 X3;
186	struct unwind_desc_X4 X4;
187};
188
189enum record_type {
190	R1, R2, R3,
191	P1, P2, P3, P4, P5, P6, P7, P8, P9, P10,
192	B1, B2, B3, B4,
193	X1, X2, X3, X4
194};
195
196
197/* A record chain is a decoded unwind descriptor.
198 * It is useful for post processing unwind descriptors.
199 */
200
201struct recordchain {
202	enum record_type type;
203	union unwind_desc udesc;
204};
205
206
207
208/* Decode Function prototypes. */
209
210char *
211unwind_decode_ule128(char *buf, unsigned long *);
212char *
213unwind_decode_R1(char *buf, union unwind_desc *uwd);
214char *
215unwind_decode_R2(char *buf, union unwind_desc *uwd);
216char *
217unwind_decode_R3(char *buf, union unwind_desc *uwd);
218char *
219unwind_decode_P1(char *buf, union unwind_desc *uwd);
220char *
221unwind_decode_P2(char *buf, union unwind_desc *uwd);
222char *
223unwind_decode_P3(char *buf, union unwind_desc *uwd);
224char *
225unwind_decode_P4(char *buf, union unwind_desc *uwd, vsize_t len);
226char *
227unwind_decode_P5(char *buf, union unwind_desc *uwd);
228char *
229unwind_decode_P6(char *buf, union unwind_desc *uwd);
230char *
231unwind_decode_P7(char *buf, union unwind_desc *uwd);
232char *
233unwind_decode_P8(char *buf, union unwind_desc *uwd);
234char *
235unwind_decode_P9(char *buf, union unwind_desc *uwd);
236char *
237unwind_decode_P10(char *buf, union unwind_desc *uwd);
238char *
239unwind_decode_B1(char *buf, union unwind_desc *uwd);
240char *
241unwind_decode_B2(char *buf, union unwind_desc *uwd);
242char *
243unwind_decode_B3(char *buf, union unwind_desc *uwd);
244char *
245unwind_decode_B4(char *buf, union unwind_desc *uwd);
246char *
247unwind_decode_X1(char *buf, union unwind_desc *uwd);
248char *
249unwind_decode_X2(char *buf, union unwind_desc *uwd);
250char *
251unwind_decode_X3(char *buf, union unwind_desc *uwd);
252char *
253unwind_decode_X4(char *buf, union unwind_desc *uwd);
254
255
256
257
258
259
260