stackframe.c revision 1.8 1 1.8 dholland /* $NetBSD: stackframe.c,v 1.8 2016/07/31 19:22:25 dholland Exp $ */
2 1.1 cherry
3 1.1 cherry /* Contributed to the NetBSD foundation by Cherry G. Mathew <cherry (at) mahiti.org>
4 1.1 cherry * This file contains routines to use decoded unwind descriptor entries
5 1.1 cherry * to build a stack configuration. The unwinder consults the stack
6 1.1 cherry * configuration to fetch registers used to unwind the frame.
7 1.1 cherry * References:
8 1.1 cherry * [1] section. 11.4.2.6., Itanium Software Conventions and
9 1.1 cherry * Runtime Architecture Guide.
10 1.1 cherry */
11 1.1 cherry
12 1.1 cherry #include <sys/cdefs.h>
13 1.1 cherry #include <sys/param.h>
14 1.1 cherry #include <sys/systm.h>
15 1.1 cherry
16 1.1 cherry
17 1.1 cherry #include <ia64/unwind/decode.h>
18 1.1 cherry #include <ia64/unwind/stackframe.h>
19 1.1 cherry
20 1.1 cherry //#define UNWIND_DIAGNOSTIC
21 1.1 cherry
22 1.8 dholland /*
23 1.8 dholland * Global variables:
24 1.8 dholland * array of struct recordchain
25 1.8 dholland * size of record chain array.
26 1.8 dholland */
27 1.1 cherry struct recordchain strc[MAXSTATERECS];
28 1.1 cherry int rec_cnt = 0;
29 1.1 cherry
30 1.8 dholland /*
31 1.8 dholland * Build a recordchain of a region, given the pointer to unwind table
32 1.1 cherry * entry, and the number of entries to decode.
33 1.1 cherry */
34 1.8 dholland void
35 1.8 dholland buildrecordchain(uint64_t unwind_infop, struct recordchain *xxx)
36 1.1 cherry {
37 1.1 cherry uint64_t unwindstart, unwindend;
38 1.1 cherry uint64_t unwindlen;
39 1.1 cherry uint64_t region_len = 0;
40 1.3 thorpej bool region_type = false; /* Prologue */
41 1.1 cherry
42 1.1 cherry struct unwind_hdr_t {
43 1.1 cherry uint64_t uwh;
44 1.1 cherry } *uwhp = (void *) unwind_infop;
45 1.1 cherry
46 1.1 cherry char *nextrecp, *recptr = (char *) unwind_infop + sizeof(uint64_t);
47 1.1 cherry
48 1.1 cherry unwindstart = (uint64_t) recptr;
49 1.1 cherry
50 1.1 cherry if (UNW_VER(uwhp->uwh) != 1) {
51 1.1 cherry printf("Wrong unwind version! \n");
52 1.1 cherry return;
53 1.1 cherry }
54 1.1 cherry
55 1.1 cherry unwindlen = UNW_LENGTH(uwhp->uwh) * sizeof(uint64_t);
56 1.1 cherry unwindend = unwindstart + unwindlen;
57 1.1 cherry
58 1.1 cherry #ifdef UNWIND_DIAGNOSTIC
59 1.1 cherry printf("recptr = %p \n", recptr);
60 1.1 cherry printf("unwindlen = %lx \n", unwindlen);
61 1.1 cherry printf("unwindend = %lx \n", unwindend);
62 1.1 cherry #endif
63 1.1 cherry
64 1.1 cherry /* XXX: Ignore zero length records. */
65 1.1 cherry
66 1.1 cherry
67 1.1 cherry for(rec_cnt = 0; rec_cnt < MAXSTATERECS && (uint64_t)recptr < unwindend;
68 1.1 cherry rec_cnt++) {
69 1.1 cherry if ((nextrecp = unwind_decode_R1(recptr, &strc[rec_cnt].udesc))){
70 1.1 cherry region_len = strc[rec_cnt].udesc.R1.rlen;
71 1.1 cherry region_type = strc[rec_cnt].udesc.R1.r;
72 1.1 cherry strc[rec_cnt].type = R1;
73 1.1 cherry recptr = nextrecp;
74 1.1 cherry continue;
75 1.1 cherry }
76 1.1 cherry
77 1.1 cherry if ((nextrecp = unwind_decode_R2(recptr, &strc[rec_cnt].udesc))){
78 1.1 cherry region_len = strc[rec_cnt].udesc.R2.rlen;
79 1.8 dholland /* R2 regions are prologue regions */
80 1.8 dholland region_type = false;
81 1.1 cherry strc[rec_cnt].type = R2;
82 1.1 cherry recptr = nextrecp;
83 1.1 cherry continue;
84 1.1 cherry }
85 1.1 cherry
86 1.1 cherry if ((nextrecp = unwind_decode_R3(recptr, &strc[rec_cnt].udesc))){
87 1.1 cherry region_len = strc[rec_cnt].udesc.R3.rlen;
88 1.1 cherry region_type = strc[rec_cnt].udesc.R3.r;
89 1.1 cherry strc[rec_cnt].type = R3;
90 1.1 cherry recptr = nextrecp;
91 1.1 cherry continue;
92 1.1 cherry }
93 1.1 cherry
94 1.8 dholland if(region_type == false) {
95 1.8 dholland /* Prologue Region */
96 1.1 cherry if ((nextrecp = unwind_decode_P1(recptr, &strc[rec_cnt].udesc))){
97 1.1 cherry strc[rec_cnt].type = P1;
98 1.1 cherry recptr = nextrecp;
99 1.1 cherry continue;
100 1.1 cherry }
101 1.1 cherry
102 1.1 cherry if ((nextrecp = unwind_decode_P2(recptr, &strc[rec_cnt].udesc))){
103 1.1 cherry strc[rec_cnt].type = P2;
104 1.1 cherry recptr = nextrecp;
105 1.1 cherry continue;
106 1.1 cherry }
107 1.1 cherry
108 1.1 cherry if ((nextrecp = unwind_decode_P3(recptr, &strc[rec_cnt].udesc))){
109 1.1 cherry strc[rec_cnt].type = P3;
110 1.1 cherry recptr = nextrecp;
111 1.1 cherry continue;
112 1.1 cherry }
113 1.1 cherry
114 1.1 cherry
115 1.1 cherry if ((nextrecp = unwind_decode_P4(recptr, &strc[rec_cnt].udesc, region_len))){
116 1.1 cherry strc[rec_cnt].type = P4;
117 1.1 cherry recptr = nextrecp;
118 1.1 cherry break;
119 1.1 cherry }
120 1.1 cherry
121 1.1 cherry
122 1.1 cherry if ((nextrecp = unwind_decode_P5(recptr, &strc[rec_cnt].udesc))){
123 1.1 cherry strc[rec_cnt].type = P5;
124 1.1 cherry recptr = nextrecp;
125 1.1 cherry continue;
126 1.1 cherry }
127 1.1 cherry
128 1.1 cherry if ((nextrecp = unwind_decode_P6(recptr, &strc[rec_cnt].udesc))){
129 1.1 cherry strc[rec_cnt].type = P6;
130 1.1 cherry recptr = nextrecp;
131 1.1 cherry continue;
132 1.1 cherry }
133 1.1 cherry
134 1.1 cherry if ((nextrecp = unwind_decode_P7(recptr, &strc[rec_cnt].udesc))){
135 1.1 cherry strc[rec_cnt].type = P7;
136 1.1 cherry recptr = nextrecp;
137 1.1 cherry continue;
138 1.1 cherry }
139 1.1 cherry
140 1.1 cherry if ((nextrecp = unwind_decode_P8(recptr, &strc[rec_cnt].udesc))){
141 1.1 cherry strc[rec_cnt].type = P8;
142 1.1 cherry recptr = nextrecp;
143 1.1 cherry continue;
144 1.1 cherry }
145 1.1 cherry
146 1.1 cherry if ((nextrecp = unwind_decode_P9(recptr, &strc[rec_cnt].udesc))){
147 1.1 cherry strc[rec_cnt].type = P9;
148 1.1 cherry recptr = nextrecp;
149 1.1 cherry continue;
150 1.1 cherry }
151 1.1 cherry
152 1.1 cherry if ((nextrecp = unwind_decode_P10(recptr, &strc[rec_cnt].udesc))){
153 1.1 cherry strc[rec_cnt].type = P10;
154 1.1 cherry recptr = nextrecp;
155 1.1 cherry continue;
156 1.1 cherry }
157 1.1 cherry
158 1.1 cherry printf("Skipping prologue desc slot :: %d \n", rec_cnt);
159 1.1 cherry }
160 1.1 cherry
161 1.1 cherry else {
162 1.1 cherry
163 1.1 cherry if ((nextrecp = unwind_decode_B1(recptr, &strc[rec_cnt].udesc))){
164 1.1 cherry strc[rec_cnt].type = B1;
165 1.1 cherry recptr = nextrecp;
166 1.1 cherry continue;
167 1.1 cherry }
168 1.1 cherry
169 1.1 cherry if ((nextrecp = unwind_decode_B2(recptr, &strc[rec_cnt].udesc))){
170 1.1 cherry strc[rec_cnt].type = B2;
171 1.1 cherry recptr = nextrecp;
172 1.1 cherry continue;
173 1.1 cherry }
174 1.1 cherry
175 1.1 cherry if ((nextrecp = unwind_decode_B3(recptr, &strc[rec_cnt].udesc))){
176 1.1 cherry strc[rec_cnt].type = B3;
177 1.1 cherry recptr = nextrecp;
178 1.1 cherry continue;
179 1.1 cherry }
180 1.1 cherry
181 1.1 cherry if ((nextrecp = unwind_decode_B4(recptr, &strc[rec_cnt].udesc))){
182 1.1 cherry strc[rec_cnt].type = B4;
183 1.1 cherry recptr = nextrecp;
184 1.1 cherry continue;
185 1.1 cherry }
186 1.1 cherry
187 1.1 cherry if ((nextrecp = unwind_decode_X1(recptr, &strc[rec_cnt].udesc))){
188 1.1 cherry strc[rec_cnt].type = X1;
189 1.1 cherry recptr = nextrecp;
190 1.1 cherry continue;
191 1.1 cherry }
192 1.1 cherry
193 1.1 cherry if ((nextrecp = unwind_decode_X2(recptr, &strc[rec_cnt].udesc))){
194 1.1 cherry strc[rec_cnt].type = X2;
195 1.1 cherry recptr = nextrecp;
196 1.1 cherry continue;
197 1.1 cherry }
198 1.1 cherry
199 1.1 cherry
200 1.1 cherry if ((nextrecp = unwind_decode_X3(recptr, &strc[rec_cnt].udesc))){
201 1.1 cherry strc[rec_cnt].type = X3;
202 1.1 cherry recptr = nextrecp;
203 1.1 cherry continue;
204 1.1 cherry }
205 1.1 cherry
206 1.1 cherry if ((nextrecp = unwind_decode_X4(recptr, &strc[rec_cnt].udesc))){
207 1.1 cherry strc[rec_cnt].type = X4;
208 1.1 cherry recptr = nextrecp;
209 1.1 cherry continue;
210 1.1 cherry }
211 1.1 cherry
212 1.1 cherry printf("Skipping body desc slot :: %d \n", rec_cnt);
213 1.1 cherry }
214 1.1 cherry }
215 1.1 cherry
216 1.1 cherry #ifdef UNWIND_DIAGNOSTIC
217 1.1 cherry int i;
218 1.1 cherry for(i = 0;i < rec_cnt;i++) {
219 1.1 cherry dump_recordchain(&strc[i]);
220 1.1 cherry }
221 1.1 cherry
222 1.1 cherry #endif /* UNWIND_DIAGNOSTIC */
223 1.1 cherry }
224 1.1 cherry
225 1.1 cherry
226 1.1 cherry
227 1.1 cherry
228 1.8 dholland /*
229 1.8 dholland * Debug support: dump a record chain entry
230 1.8 dholland */
231 1.8 dholland void
232 1.8 dholland dump_recordchain(struct recordchain *rchain)
233 1.1 cherry {
234 1.1 cherry
235 1.1 cherry switch(rchain->type) {
236 1.1 cherry case R1:
237 1.1 cherry printf("\t R1:");
238 1.1 cherry if(rchain->udesc.R1.r)
239 1.1 cherry printf("body (");
240 1.1 cherry else
241 1.1 cherry printf("prologue (");
242 1.1 cherry printf("rlen = %ld) \n", rchain->udesc.R1.rlen);
243 1.1 cherry break;
244 1.1 cherry
245 1.1 cherry case R2:
246 1.1 cherry printf("\t R2:");
247 1.1 cherry printf("prologue_gr (");
248 1.1 cherry printf("mask = %x, ", rchain->udesc.R2.mask);
249 1.1 cherry printf("grsave = %d, ", rchain->udesc.R2.grsave);
250 1.1 cherry printf("rlen = %ld )\n", rchain->udesc.R2.rlen);
251 1.1 cherry break;
252 1.1 cherry
253 1.1 cherry case R3:
254 1.1 cherry printf("\t R3:");
255 1.1 cherry if(rchain->udesc.R3.r)
256 1.1 cherry printf("body (");
257 1.1 cherry else
258 1.1 cherry printf("prologue (");
259 1.1 cherry printf("rlen = %ld )\n", rchain->udesc.R3.rlen);
260 1.1 cherry break;
261 1.1 cherry
262 1.1 cherry case P1:
263 1.1 cherry printf("\t\tP1:");
264 1.1 cherry printf("br_mem (brmask = %x) \n", rchain->udesc.P1.brmask);
265 1.1 cherry break;
266 1.1 cherry
267 1.1 cherry case P2:
268 1.1 cherry printf("\t\tP2:");
269 1.1 cherry printf("br_gr(brmask = %x, ", rchain->udesc.P2.brmask);
270 1.1 cherry printf("gr = %d ) \n", rchain->udesc.P2.gr);
271 1.1 cherry break;
272 1.1 cherry
273 1.1 cherry case P3:
274 1.1 cherry printf("\t\tP3:");
275 1.1 cherry switch(rchain->udesc.P3.r) {
276 1.1 cherry case 0:
277 1.1 cherry printf("psp_gr");
278 1.1 cherry break;
279 1.1 cherry case 1:
280 1.1 cherry printf("rp_gr");
281 1.1 cherry break;
282 1.1 cherry case 2:
283 1.1 cherry printf("pfs_gr");
284 1.1 cherry break;
285 1.1 cherry case 3:
286 1.1 cherry printf("preds_gr");
287 1.1 cherry break;
288 1.1 cherry case 4:
289 1.1 cherry printf("unat_gr");
290 1.1 cherry break;
291 1.1 cherry case 5:
292 1.1 cherry printf("lc_gr");
293 1.1 cherry break;
294 1.1 cherry case 6:
295 1.1 cherry printf("rp_br");
296 1.1 cherry break;
297 1.1 cherry case 7:
298 1.1 cherry printf("rnat_gr");
299 1.1 cherry break;
300 1.1 cherry case 8:
301 1.1 cherry printf("bsp_gr");
302 1.1 cherry break;
303 1.1 cherry case 9:
304 1.1 cherry printf("bspstore_gr");
305 1.1 cherry break;
306 1.1 cherry case 10:
307 1.1 cherry printf("fpsr_gr");
308 1.1 cherry break;
309 1.1 cherry case 11:
310 1.1 cherry printf("priunat_gr");
311 1.1 cherry break;
312 1.1 cherry default:
313 1.1 cherry printf("unknown desc: %d", rchain->udesc.P3.r);
314 1.1 cherry
315 1.1 cherry }
316 1.1 cherry printf("(gr/br = %d) \n", rchain->udesc.P3.grbr);
317 1.1 cherry
318 1.1 cherry break;
319 1.1 cherry
320 1.1 cherry case P4:
321 1.1 cherry printf("P4: (unimplemented): \n");
322 1.1 cherry break;
323 1.1 cherry
324 1.1 cherry case P5:
325 1.1 cherry printf("\t\tP5:");
326 1.1 cherry printf("frgr_mem(grmask = %x, frmask = %x )\n",
327 1.1 cherry rchain->udesc.P5.grmask, rchain->udesc.P5.frmask);
328 1.1 cherry break;
329 1.1 cherry
330 1.1 cherry case P6:
331 1.1 cherry printf("\t\tP6: ");
332 1.1 cherry if(rchain->udesc.P6.r)
333 1.1 cherry printf("gr_mem( ");
334 1.1 cherry else
335 1.1 cherry printf("fr_mem( ");
336 1.1 cherry printf("rmask = %x) \n", rchain->udesc.P6.rmask);
337 1.1 cherry break;
338 1.1 cherry
339 1.1 cherry case P7:
340 1.1 cherry printf("\t\tP7:");
341 1.1 cherry switch(rchain->udesc.P7.r) {
342 1.1 cherry case 0:
343 1.1 cherry printf("memstack_f( ");
344 1.1 cherry printf("t = %ld, ", rchain->udesc.P7.t);
345 1.1 cherry printf("size = %ld) \n", rchain->udesc.P7.size);
346 1.1 cherry break;
347 1.1 cherry case 1:
348 1.1 cherry printf("memstack_v( ");
349 1.1 cherry printf("t = %ld) \n", rchain->udesc.P7.t);
350 1.1 cherry break;
351 1.1 cherry case 2:
352 1.1 cherry printf("spillbase( ");
353 1.1 cherry printf("pspoff = %ld) \n", rchain->udesc.P7.t);
354 1.1 cherry break;
355 1.1 cherry case 3:
356 1.1 cherry printf("psp_sprel( ");
357 1.1 cherry printf("spoff = %ld) \n", rchain->udesc.P7.t);
358 1.1 cherry break;
359 1.1 cherry case 4:
360 1.1 cherry printf("rp_when( ");
361 1.1 cherry printf("t = %ld) \n", rchain->udesc.P7.t);
362 1.1 cherry break;
363 1.1 cherry case 5:
364 1.1 cherry printf("rp_psprel( ");
365 1.1 cherry printf("pspoff = %ld) \n", rchain->udesc.P7.t);
366 1.1 cherry break;
367 1.1 cherry case 6:
368 1.1 cherry printf("pfs_when( ");
369 1.1 cherry printf("t = %ld) \n", rchain->udesc.P7.t);
370 1.1 cherry break;
371 1.1 cherry case 7:
372 1.1 cherry printf("pfs_psprel( ");
373 1.1 cherry printf("pspoff = %ld) \n", rchain->udesc.P7.t);
374 1.1 cherry break;
375 1.1 cherry case 8:
376 1.1 cherry printf("preds_when( ");
377 1.1 cherry printf("t = %ld) \n", rchain->udesc.P7.t);
378 1.1 cherry break;
379 1.1 cherry case 9:
380 1.1 cherry printf("preds_psprel( ");
381 1.1 cherry printf("pspoff = %ld) \n", rchain->udesc.P7.t);
382 1.1 cherry break;
383 1.1 cherry case 10:
384 1.1 cherry printf("lc_when( ");
385 1.1 cherry printf("t = %ld) \n", rchain->udesc.P7.t);
386 1.1 cherry break;
387 1.1 cherry case 11:
388 1.1 cherry printf("lc_psprel( ");
389 1.1 cherry printf("pspoff = %ld) \n", rchain->udesc.P7.t);
390 1.1 cherry break;
391 1.1 cherry case 12:
392 1.1 cherry printf("unat_when( ");
393 1.1 cherry printf("t = %ld) \n", rchain->udesc.P7.t);
394 1.1 cherry break;
395 1.1 cherry case 13:
396 1.1 cherry printf("unat_psprel( ");
397 1.1 cherry printf("pspoff = %ld) \n", rchain->udesc.P7.t);
398 1.1 cherry break;
399 1.1 cherry case 14:
400 1.1 cherry printf("fpsr_when( ");
401 1.1 cherry printf("t = %ld) \n", rchain->udesc.P7.t);
402 1.1 cherry break;
403 1.1 cherry case 15:
404 1.1 cherry printf("fpsr_psprel( ");
405 1.1 cherry printf("pspoff = %ld) \n", rchain->udesc.P7.t);
406 1.1 cherry break;
407 1.1 cherry default:
408 1.1 cherry printf("unknown \n");
409 1.1 cherry }
410 1.1 cherry
411 1.1 cherry break;
412 1.1 cherry
413 1.1 cherry case P8:
414 1.1 cherry printf("\t\tP8:");
415 1.1 cherry switch(rchain->udesc.P8.r) {
416 1.1 cherry case 1:
417 1.1 cherry printf("rp_sprel( ");
418 1.1 cherry printf("spoff = %ld) \n", rchain->udesc.P8.t);
419 1.1 cherry break;
420 1.1 cherry case 2:
421 1.1 cherry printf("pfs_sprel( ");
422 1.1 cherry printf("spoff = %ld) \n", rchain->udesc.P8.t);
423 1.1 cherry break;
424 1.1 cherry case 3:
425 1.1 cherry printf("preds_sprel( ");
426 1.1 cherry printf("spoff = %ld) \n", rchain->udesc.P8.t);
427 1.1 cherry break;
428 1.1 cherry case 4:
429 1.1 cherry printf("lc_sprel( ");
430 1.1 cherry printf("spoff = %ld) \n", rchain->udesc.P8.t);
431 1.1 cherry break;
432 1.1 cherry case 5:
433 1.1 cherry printf("unat_sprel( ");
434 1.1 cherry printf("spoff = %ld) \n", rchain->udesc.P8.t);
435 1.1 cherry break;
436 1.1 cherry case 6:
437 1.1 cherry printf("fpsr_sprel( ");
438 1.1 cherry printf("spoff = %ld) \n", rchain->udesc.P8.t);
439 1.1 cherry break;
440 1.1 cherry case 7:
441 1.1 cherry printf("bsp_when( ");
442 1.1 cherry printf("t = %ld) \n", rchain->udesc.P8.t);
443 1.1 cherry break;
444 1.1 cherry case 8:
445 1.1 cherry printf("bsp_psprel( ");
446 1.1 cherry printf("pspoff = %ld) \n", rchain->udesc.P8.t);
447 1.1 cherry break;
448 1.1 cherry case 9:
449 1.1 cherry printf("bsp_sprel( ");
450 1.1 cherry printf("spoff = %ld) \n", rchain->udesc.P8.t);
451 1.1 cherry break;
452 1.1 cherry case 10:
453 1.1 cherry printf("bspstore_when( ");
454 1.1 cherry printf("t = %ld) \n", rchain->udesc.P8.t);
455 1.1 cherry break;
456 1.1 cherry case 11:
457 1.1 cherry printf("bspstore_psprel( ");
458 1.1 cherry printf("pspoff = %ld) \n", rchain->udesc.P8.t);
459 1.1 cherry break;
460 1.1 cherry case 12:
461 1.1 cherry printf("bspstore_sprel( ");
462 1.1 cherry printf("spoff = %ld) \n", rchain->udesc.P8.t);
463 1.1 cherry break;
464 1.1 cherry case 13:
465 1.1 cherry printf("rnat_when( ");
466 1.1 cherry printf("t = %ld) \n", rchain->udesc.P8.t);
467 1.1 cherry break;
468 1.1 cherry case 14:
469 1.1 cherry printf("rnat_psprel( ");
470 1.1 cherry printf("pspoff = %ld) \n", rchain->udesc.P8.t);
471 1.1 cherry break;
472 1.1 cherry case 15:
473 1.1 cherry printf("rnat_sprel( ");
474 1.1 cherry printf("spoff = %ld) \n", rchain->udesc.P8.t);
475 1.1 cherry break;
476 1.1 cherry case 16:
477 1.1 cherry printf("priunat_when_gr( ");
478 1.1 cherry printf("t = %ld) \n", rchain->udesc.P8.t);
479 1.1 cherry break;
480 1.1 cherry case 17:
481 1.1 cherry printf("priunat_psprel( ");
482 1.1 cherry printf("pspoff = %ld) \n", rchain->udesc.P8.t);
483 1.1 cherry break;
484 1.1 cherry case 18:
485 1.1 cherry printf("priunat_sprel( ");
486 1.1 cherry printf("spoff = %ld) \n", rchain->udesc.P8.t);
487 1.1 cherry break;
488 1.1 cherry case 19:
489 1.1 cherry printf("priunat_when_mem( ");
490 1.1 cherry printf("t = %ld) \n", rchain->udesc.P8.t);
491 1.1 cherry break;
492 1.1 cherry
493 1.1 cherry default:
494 1.1 cherry printf("unknown \n");
495 1.1 cherry }
496 1.1 cherry
497 1.1 cherry break;
498 1.1 cherry
499 1.1 cherry case P9:
500 1.1 cherry printf("\t\tP9:");
501 1.1 cherry printf("(grmask = %x, gr = %d) \n",
502 1.1 cherry rchain->udesc.P9.grmask, rchain->udesc.P9.gr);
503 1.1 cherry break;
504 1.1 cherry
505 1.1 cherry case P10:
506 1.1 cherry printf("\t\tP10:");
507 1.1 cherry printf("(abi: ");
508 1.1 cherry switch(rchain->udesc.P10.abi) {
509 1.1 cherry case 0:
510 1.1 cherry printf("Unix SVR4) \n");
511 1.1 cherry break;
512 1.1 cherry case 1:
513 1.1 cherry printf("HP-UX) \n");
514 1.1 cherry break;
515 1.1 cherry default:
516 1.1 cherry printf("Other) \n");
517 1.1 cherry }
518 1.1 cherry break;
519 1.1 cherry
520 1.1 cherry case B1:
521 1.1 cherry printf("\t\tB1:");
522 1.1 cherry if(rchain->udesc.B1.r)
523 1.1 cherry printf("copy_state( ");
524 1.1 cherry else
525 1.1 cherry printf("label_state( ");
526 1.1 cherry printf("label = %d) \n", rchain->udesc.B1.label);
527 1.1 cherry
528 1.1 cherry break;
529 1.1 cherry
530 1.1 cherry case B2:
531 1.1 cherry printf("\t\tB2:");
532 1.1 cherry printf("(ecount = %d, t = %ld)\n",
533 1.1 cherry rchain->udesc.B2.ecount, rchain->udesc.B2.t);
534 1.1 cherry
535 1.1 cherry break;
536 1.1 cherry
537 1.1 cherry case B3:
538 1.1 cherry printf("\t\tB3:");
539 1.1 cherry printf("(t = %ld, ecount = %ld) \n",
540 1.1 cherry rchain->udesc.B3.t, rchain->udesc.B3.ecount);
541 1.1 cherry
542 1.1 cherry break;
543 1.1 cherry
544 1.1 cherry case B4:
545 1.1 cherry printf("\t\tB4:");
546 1.1 cherry if(rchain->udesc.B4.r)
547 1.1 cherry printf("copy_state( ");
548 1.1 cherry else
549 1.1 cherry printf("label_state( ");
550 1.1 cherry
551 1.1 cherry printf("label = %ld) \n", rchain->udesc.B4.label);
552 1.1 cherry
553 1.1 cherry break;
554 1.1 cherry
555 1.1 cherry
556 1.1 cherry case X1:
557 1.1 cherry printf("\tX1:\n ");
558 1.1 cherry break;
559 1.1 cherry
560 1.1 cherry case X2:
561 1.1 cherry printf("\tX2:\n");
562 1.1 cherry break;
563 1.1 cherry
564 1.1 cherry case X3:
565 1.1 cherry printf("\tX3:\n");
566 1.1 cherry break;
567 1.1 cherry
568 1.1 cherry case X4:
569 1.1 cherry printf("\tX4:\n");
570 1.1 cherry break;
571 1.1 cherry default:
572 1.1 cherry printf("\tunknow: \n");
573 1.1 cherry }
574 1.1 cherry
575 1.1 cherry }
576 1.1 cherry
577 1.8 dholland /*
578 1.8 dholland * State record stuff..... based on section 11. and Appendix A. of the
579 1.8 dholland * "Itanium Software Conventions and Runtime Architecture Guide"
580 1.1 cherry */
581 1.1 cherry
582 1.1 cherry
583 1.8 dholland /*
584 1.8 dholland * Global variables:
585 1.1 cherry * 1. Two arrays of staterecords: recordstack[], recordstackcopy[]
586 1.1 cherry * XXX: Since we don't use malloc, we have two arbitrary sized arrays
587 1.1 cherry * providing guaranteed memory from the BSS. See the TODO file
588 1.1 cherry * for more details.
589 1.1 cherry * 2. Two head variables to hold the member index: unwind_rsp,unwind_rscp
590 1.1 cherry */
591 1.1 cherry
592 1.1 cherry struct staterecord recordstack[MAXSTATERECS];
593 1.1 cherry struct staterecord recordstackcopy[MAXSTATERECS];
594 1.1 cherry struct staterecord current_state;
595 1.1 cherry struct staterecord *unwind_rsp, *unwind_rscp;
596 1.1 cherry
597 1.1 cherry
598 1.8 dholland /* Base of spill area in memory stack frame as a psp relative offset */
599 1.8 dholland uint64_t spill_base = 0;
600 1.1 cherry
601 1.8 dholland /*
602 1.8 dholland * Initialises a staterecord from a given template,
603 1.1 cherry * with default values as described by the Runtime Spec.
604 1.1 cherry */
605 1.1 cherry void
606 1.1 cherry initrecord(struct staterecord *target)
607 1.1 cherry {
608 1.1 cherry target->bsp.where = UNSAVED;
609 1.1 cherry target->bsp.when = 0;
610 1.1 cherry target->bsp.offset = INVALID;
611 1.1 cherry target->psp.where = UNSAVED;
612 1.1 cherry target->psp.when = 0;
613 1.1 cherry target->psp.offset = INVALID;
614 1.1 cherry target->rp.where = UNSAVED;
615 1.1 cherry target->rp.when = 0;
616 1.1 cherry target->rp.offset = INVALID;
617 1.1 cherry target->pfs.where = UNSAVED;
618 1.1 cherry target->pfs.when = 0;
619 1.1 cherry target->pfs.offset = INVALID;
620 1.1 cherry }
621 1.1 cherry
622 1.1 cherry
623 1.8 dholland /*
624 1.8 dholland * Modifies a staterecord structure by parsing
625 1.1 cherry * a single record chain structure.
626 1.1 cherry * regionoffset is the offset within a (prologue) region
627 1.1 cherry * where the stack unwinding began.
628 1.1 cherry */
629 1.8 dholland void
630 1.8 dholland modifyrecord(struct staterecord *srec, struct recordchain *rchain,
631 1.8 dholland uint64_t regionoffset)
632 1.1 cherry {
633 1.8 dholland /*
634 1.8 dholland * Default start save GR for prologue_save GRs.
635 1.8 dholland */
636 1.8 dholland uint64_t grno = 32;
637 1.1 cherry
638 1.1 cherry
639 1.1 cherry switch (rchain->type) {
640 1.1 cherry
641 1.1 cherry case R2:
642 1.8 dholland /*
643 1.8 dholland * R2, prologue_gr is the only region encoding
644 1.1 cherry * with register save info.
645 1.1 cherry */
646 1.1 cherry
647 1.1 cherry grno = rchain->udesc.R2.grsave;
648 1.1 cherry
649 1.1 cherry if (rchain->udesc.R2.mask & R2MASKRP) {
650 1.1 cherry srec->rp.when = 0;
651 1.1 cherry srec->rp.where = GRREL;
652 1.1 cherry srec->rp.offset = grno++;
653 1.1 cherry }
654 1.1 cherry
655 1.1 cherry if (rchain->udesc.R2.mask & R2MASKPFS) {
656 1.1 cherry srec->pfs.when = 0;
657 1.1 cherry srec->pfs.where = GRREL;
658 1.1 cherry srec->pfs.offset = grno++;
659 1.1 cherry }
660 1.1 cherry
661 1.1 cherry if (rchain->udesc.R2.mask & R2MASKPSP) {
662 1.1 cherry srec->psp.when = 0;
663 1.1 cherry srec->psp.where = GRREL;
664 1.1 cherry srec->psp.offset = grno++;
665 1.1 cherry }
666 1.1 cherry break;
667 1.1 cherry
668 1.1 cherry case P3:
669 1.1 cherry switch (rchain->udesc.P3.r) {
670 1.1 cherry case 0: /* psp_gr */
671 1.1 cherry if (srec->psp.when < regionoffset) {
672 1.1 cherry srec->psp.where = GRREL;
673 1.1 cherry srec->psp.offset = rchain->udesc.P3.grbr;
674 1.1 cherry }
675 1.1 cherry break;
676 1.1 cherry
677 1.1 cherry case 1: /* rp_gr */
678 1.1 cherry if (srec->rp.when < regionoffset) {
679 1.1 cherry srec->rp.where = GRREL;
680 1.1 cherry srec->rp.offset = rchain->udesc.P3.grbr;
681 1.1 cherry }
682 1.1 cherry break;
683 1.1 cherry
684 1.1 cherry case 2: /* pfs_gr */
685 1.1 cherry if (srec->pfs.when < regionoffset) {
686 1.1 cherry srec->pfs.where = GRREL;
687 1.1 cherry srec->pfs.offset = rchain->udesc.P3.grbr;
688 1.1 cherry }
689 1.1 cherry break;
690 1.1 cherry
691 1.1 cherry }
692 1.1 cherry break;
693 1.1 cherry
694 1.1 cherry
695 1.8 dholland /*
696 1.8 dholland * XXX: P4 spill_mask and P7: spill_base are for GRs, FRs, and BRs.
697 1.1 cherry * We're not particularly worried about those right now.
698 1.1 cherry */
699 1.1 cherry
700 1.1 cherry case P7:
701 1.1 cherry switch (rchain->udesc.P7.r) {
702 1.1 cherry
703 1.1 cherry case 0: /* mem_stack_f */
704 1.1 cherry if (srec->psp.offset != INVALID) printf("!!!saw mem_stack_f more than once. \n");
705 1.1 cherry srec->psp.when = rchain->udesc.P7.t;
706 1.1 cherry if (srec->psp.when < regionoffset) {
707 1.1 cherry srec->psp.where = IMMED;
708 1.1 cherry srec->psp.offset = rchain->udesc.P7.size; /* spsz.offset is "overloaded" */
709 1.1 cherry }
710 1.1 cherry break;
711 1.1 cherry
712 1.1 cherry case 1: /* mem_stack_v */
713 1.1 cherry srec->psp.when = rchain->udesc.P7.t;
714 1.1 cherry break;
715 1.1 cherry
716 1.1 cherry case 2: /* spill_base */
717 1.1 cherry spill_base = rchain->udesc.P7.t;
718 1.1 cherry break;
719 1.1 cherry
720 1.1 cherry case 3: /* psp_sprel */
721 1.1 cherry if (srec->psp.when < regionoffset) {
722 1.1 cherry srec->psp.where = SPREL;
723 1.1 cherry srec->psp.offset = rchain->udesc.P7.t;
724 1.1 cherry }
725 1.1 cherry break;
726 1.1 cherry
727 1.1 cherry case 4: /* rp_when */
728 1.1 cherry srec->rp.when = rchain->udesc.P7.t;
729 1.1 cherry /* XXX: Need to set to prologue_gr(grno) for the orphan case
730 1.1 cherry * ie; _gr/_psprel/_sprel not set and therefore default
731 1.1 cherry * to begin from the gr specified in prologue_gr.
732 1.1 cherry */
733 1.1 cherry break;
734 1.1 cherry
735 1.1 cherry case 5: /* rp_psprel */
736 1.1 cherry if (srec->rp.when < regionoffset) {
737 1.1 cherry srec->rp.where = PSPREL;
738 1.1 cherry srec->rp.offset = rchain->udesc.P7.t;
739 1.1 cherry }
740 1.1 cherry break;
741 1.1 cherry
742 1.1 cherry case 6: /* pfs_when */
743 1.1 cherry srec->pfs.when = rchain->udesc.P7.t;
744 1.1 cherry /* XXX: Need to set to prologue_gr(grno) for the orphan case
745 1.1 cherry * ie; _gr/_psprel/_sprel not set and therefore default
746 1.1 cherry * to begin from the gr specified in prologue_gr.
747 1.1 cherry */
748 1.1 cherry break;
749 1.1 cherry
750 1.1 cherry case 7: /* pfs_psprel */
751 1.1 cherry if (srec->pfs.when < regionoffset) {
752 1.1 cherry srec->pfs.where = PSPREL;
753 1.1 cherry srec->pfs.offset = rchain->udesc.P7.t;
754 1.1 cherry }
755 1.1 cherry break;
756 1.1 cherry
757 1.1 cherry }
758 1.1 cherry break;
759 1.1 cherry
760 1.1 cherry case P8:
761 1.1 cherry switch (rchain->udesc.P8.r) {
762 1.1 cherry case 1: /* rp_sprel */
763 1.1 cherry if (srec->rp.when < regionoffset) {
764 1.1 cherry srec->rp.where = SPREL;
765 1.1 cherry srec->rp.offset = rchain->udesc.P8.t;
766 1.1 cherry }
767 1.1 cherry break;
768 1.1 cherry case 2: /* pfs_sprel */
769 1.1 cherry if (srec->pfs.when < regionoffset) {
770 1.1 cherry srec->pfs.where = SPREL;
771 1.1 cherry srec->pfs.offset = rchain->udesc.P8.t;
772 1.1 cherry
773 1.1 cherry }
774 1.1 cherry break;
775 1.1 cherry }
776 1.1 cherry break;
777 1.1 cherry
778 1.1 cherry case B1:
779 1.1 cherry
780 1.1 cherry rchain->udesc.B1.r ? switchrecordstack(0) :
781 1.1 cherry clonerecordstack(0);
782 1.1 cherry break;
783 1.1 cherry
784 1.1 cherry case B2:
785 1.1 cherry if (regionoffset < rchain->udesc.B2.t) {
786 1.1 cherry poprecord(¤t_state, rchain->udesc.B2.ecount);
787 1.1 cherry }
788 1.1 cherry break;
789 1.1 cherry case B3:
790 1.1 cherry if (regionoffset < rchain->udesc.B3.t) {
791 1.1 cherry poprecord(¤t_state, rchain->udesc.B3.ecount);
792 1.1 cherry }
793 1.1 cherry break;
794 1.1 cherry case B4:
795 1.1 cherry rchain->udesc.B4.r ? switchrecordstack(0) :
796 1.1 cherry clonerecordstack(0);
797 1.1 cherry break;
798 1.1 cherry
799 1.1 cherry case X1:
800 1.1 cherry case X2:
801 1.1 cherry case X3:
802 1.1 cherry /* XXX: Todo */
803 1.1 cherry break;
804 1.1 cherry
805 1.1 cherry
806 1.1 cherry case R1:
807 1.1 cherry case R3:
808 1.1 cherry case P1:
809 1.1 cherry case P2:
810 1.1 cherry case P4:
811 1.1 cherry case P5:
812 1.1 cherry case P6:
813 1.1 cherry case P9:
814 1.1 cherry case P10:
815 1.1 cherry default:
816 1.1 cherry /* Ignore. */
817 1.1 cherry printf("XXX: Ignored. \n");
818 1.1 cherry }
819 1.1 cherry
820 1.1 cherry
821 1.1 cherry }
822 1.1 cherry
823 1.8 dholland void
824 1.8 dholland dump_staterecord(struct staterecord *srec)
825 1.1 cherry {
826 1.1 cherry printf("rp.where: ");
827 1.1 cherry switch(srec->rp.where) {
828 1.1 cherry case UNSAVED:
829 1.1 cherry printf("UNSAVED ");
830 1.1 cherry break;
831 1.1 cherry case BRREL:
832 1.1 cherry printf("BRREL ");
833 1.1 cherry break;
834 1.1 cherry case GRREL:
835 1.1 cherry printf("GRREL ");
836 1.1 cherry break;
837 1.1 cherry case SPREL:
838 1.1 cherry printf("SPREL ");
839 1.1 cherry break;
840 1.1 cherry case PSPREL:
841 1.1 cherry printf("PSPSREL ");
842 1.1 cherry break;
843 1.1 cherry default:
844 1.1 cherry printf("unknown ");
845 1.1 cherry }
846 1.1 cherry
847 1.1 cherry printf(", rp.when = %lu, ", srec->rp.when);
848 1.1 cherry printf("rp.offset = %lu \n", srec->rp.offset);
849 1.1 cherry
850 1.1 cherry
851 1.1 cherry printf("pfs.where: ");
852 1.1 cherry switch(srec->pfs.where) {
853 1.1 cherry case UNSAVED:
854 1.1 cherry printf("UNSAVED ");
855 1.1 cherry break;
856 1.1 cherry case BRREL:
857 1.1 cherry printf("BRREL ");
858 1.1 cherry break;
859 1.1 cherry case GRREL:
860 1.1 cherry printf("GRREL ");
861 1.1 cherry break;
862 1.1 cherry case SPREL:
863 1.1 cherry printf("SPREL ");
864 1.1 cherry break;
865 1.1 cherry case PSPREL:
866 1.1 cherry printf("PSPSREL ");
867 1.1 cherry break;
868 1.1 cherry default:
869 1.1 cherry printf("unknown ");
870 1.1 cherry }
871 1.1 cherry
872 1.1 cherry printf(", pfs.when = %lu, ", srec->pfs.when);
873 1.1 cherry printf("pfs.offset = %lu \n", srec->pfs.offset);
874 1.1 cherry }
875 1.1 cherry
876 1.1 cherry
877 1.8 dholland /*
878 1.8 dholland * Push a state record on the record stack.
879 1.8 dholland */
880 1.8 dholland void
881 1.8 dholland pushrecord(struct staterecord *srec)
882 1.1 cherry {
883 1.1 cherry if(unwind_rsp >= recordstack + MAXSTATERECS) {
884 1.1 cherry printf("Push exceeded array size!!! \n");
885 1.1 cherry return;
886 1.1 cherry }
887 1.1 cherry
888 1.1 cherry memcpy(unwind_rsp, srec, sizeof(struct staterecord));
889 1.1 cherry unwind_rsp++;
890 1.1 cherry
891 1.1 cherry }
892 1.1 cherry
893 1.8 dholland /*
894 1.8 dholland * Pop n state records off the record stack.
895 1.8 dholland */
896 1.8 dholland void
897 1.8 dholland poprecord(struct staterecord *srec, int n)
898 1.1 cherry {
899 1.1 cherry if(unwind_rsp == recordstack) {
900 1.1 cherry printf("Popped beyond end of Stack!!! \n");
901 1.1 cherry return;
902 1.1 cherry }
903 1.1 cherry unwind_rsp -= n;
904 1.1 cherry memcpy(srec, unwind_rsp, sizeof(struct staterecord));
905 1.1 cherry #ifdef DEBUG
906 1.4 cegger memset(unwind_rsp, 0, sizeof(struct staterecord) * n);
907 1.1 cherry #endif
908 1.1 cherry
909 1.1 cherry }
910 1.1 cherry
911 1.8 dholland /*
912 1.8 dholland * Clone the whole record stack upto this one.
913 1.8 dholland */
914 1.8 dholland void
915 1.8 dholland clonerecordstack(u_int label)
916 1.1 cherry {
917 1.1 cherry memcpy(recordstackcopy, recordstack,
918 1.1 cherry (unwind_rsp - recordstack) * sizeof(struct staterecord));
919 1.1 cherry unwind_rscp = unwind_rsp;
920 1.1 cherry }
921 1.1 cherry
922 1.8 dholland /*
923 1.8 dholland * Discard the current stack, and adopt a clone.
924 1.8 dholland */
925 1.8 dholland void
926 1.8 dholland switchrecordstack(u_int label)
927 1.1 cherry {
928 1.1 cherry memcpy((void *) recordstack, (void *) recordstackcopy,
929 1.1 cherry (unwind_rscp - recordstackcopy) * sizeof(struct staterecord));
930 1.1 cherry unwind_rsp = unwind_rscp;
931 1.1 cherry
932 1.1 cherry }
933 1.1 cherry
934 1.8 dholland /*
935 1.8 dholland * In the context of a procedure:
936 1.1 cherry * Parses through a record chain, building, pushing and/or popping staterecords,
937 1.1 cherry * or cloning/destroying stacks of staterecords as required.
938 1.1 cherry * Parameters are:
939 1.1 cherry * rchain: pointer to recordchain array.
940 1.1 cherry * procoffset: offset of point of interest, in slots, within procedure starting from slot 0
941 1.1 cherry * This routine obeys [1]
942 1.1 cherry */
943 1.8 dholland struct staterecord *
944 1.8 dholland buildrecordstack(struct recordchain *rchain, uint64_t procoffset)
945 1.1 cherry {
946 1.1 cherry uint64_t rlen = 0; /* Current region length, defaults to zero, if not specified */
947 1.1 cherry uint64_t roffset = 0; /* Accumulated region length */
948 1.1 cherry uint64_t rdepth = 0; /* Offset within current region */
949 1.2 thorpej bool rtype;
950 1.8 dholland int i;
951 1.1 cherry
952 1.8 dholland /* Start with bottom of staterecord stack. */
953 1.8 dholland unwind_rsp = recordstack;
954 1.1 cherry
955 1.1 cherry initrecord(¤t_state);
956 1.1 cherry
957 1.1 cherry for (i = 0;i < rec_cnt;i++) {
958 1.1 cherry
959 1.1 cherry switch (rchain[i].type) {
960 1.1 cherry case R1:
961 1.1 cherry rlen = rchain[i].udesc.R1.rlen;
962 1.8 dholland if (procoffset < roffset) {
963 1.8 dholland /*
964 1.8 dholland * Overshot Region containing
965 1.8 dholland * procoffset. Bail out.
966 1.8 dholland */
967 1.8 dholland goto out;
968 1.8 dholland }
969 1.1 cherry rdepth = procoffset - roffset;
970 1.1 cherry roffset += rlen;
971 1.1 cherry rtype = rchain[i].udesc.R1.r;
972 1.1 cherry if (!rtype) {
973 1.1 cherry pushrecord(¤t_state);
974 1.1 cherry }
975 1.1 cherry break;
976 1.1 cherry
977 1.1 cherry case R3:
978 1.1 cherry rlen = rchain[i].udesc.R3.rlen;
979 1.8 dholland if (procoffset < roffset) {
980 1.8 dholland /*
981 1.8 dholland * Overshot Region containing
982 1.8 dholland * procoffset. Bail out.
983 1.8 dholland */
984 1.8 dholland goto out;
985 1.8 dholland }
986 1.1 cherry rdepth = procoffset - roffset;
987 1.1 cherry roffset += rlen;
988 1.1 cherry rtype = rchain[i].udesc.R3.r;
989 1.1 cherry if (!rtype) {
990 1.1 cherry pushrecord(¤t_state);
991 1.1 cherry }
992 1.1 cherry break;
993 1.1 cherry
994 1.1 cherry case R2:
995 1.1 cherry rlen = rchain[i].udesc.R2.rlen;
996 1.8 dholland if (procoffset < roffset) {
997 1.8 dholland /*
998 1.8 dholland * Overshot Region containing
999 1.8 dholland * procoffset. Bail out.
1000 1.8 dholland */
1001 1.8 dholland goto out;
1002 1.8 dholland }
1003 1.1 cherry rdepth = procoffset - roffset;
1004 1.1 cherry roffset += rlen;
1005 1.3 thorpej rtype = false; /* prologue region */
1006 1.1 cherry pushrecord(¤t_state);
1007 1.1 cherry
1008 1.1 cherry /* R2 has save info. Continue down. */
1009 1.8 dholland /* FALLTHROUGH */
1010 1.1 cherry case P1:
1011 1.1 cherry case P2:
1012 1.1 cherry case P3:
1013 1.1 cherry case P4:
1014 1.1 cherry case P5:
1015 1.1 cherry case P6:
1016 1.1 cherry case P7:
1017 1.1 cherry case P8:
1018 1.1 cherry case P9:
1019 1.1 cherry case P10:
1020 1.1 cherry modifyrecord(¤t_state, &rchain[i], rdepth);
1021 1.1 cherry break;
1022 1.1 cherry
1023 1.1 cherry case B1:
1024 1.1 cherry case B2:
1025 1.1 cherry case B3:
1026 1.1 cherry case B4:
1027 1.1 cherry modifyrecord(¤t_state, &rchain[i], rlen - 1 - rdepth);
1028 1.1 cherry break;
1029 1.1 cherry
1030 1.1 cherry case X1:
1031 1.1 cherry case X2:
1032 1.1 cherry case X3:
1033 1.1 cherry case X4:
1034 1.1 cherry default:
1035 1.1 cherry printf("Error: Unknown descriptor type!!! \n");
1036 1.1 cherry
1037 1.1 cherry }
1038 1.1 cherry
1039 1.1 cherry #if UNWIND_DIAGNOSTIC
1040 1.1 cherry dump_staterecord(¤t_state);
1041 1.1 cherry #endif
1042 1.1 cherry
1043 1.1 cherry
1044 1.1 cherry }
1045 1.1 cherry
1046 1.1 cherry out:
1047 1.1 cherry
1048 1.1 cherry return ¤t_state;
1049 1.1 cherry }
1050 1.1 cherry
1051 1.8 dholland void
1052 1.8 dholland updateregs(struct unwind_frame *uwf, struct staterecord *srec, uint64_t procoffset)
1053 1.1 cherry {
1054 1.1 cherry /* XXX: Update uwf for regs other than rp and pfs*/
1055 1.1 cherry uint64_t roffset = 0;
1056 1.1 cherry
1057 1.1 cherry /* Uses shadow arrays to update uwf from srec in a loop. */
1058 1.1 cherry /* Count of number of regstate elements in struct staterecord */
1059 1.1 cherry int statecount = sizeof(struct staterecord)/sizeof(struct regstate);
1060 1.1 cherry /* Pointer to current regstate. */
1061 1.1 cherry struct regstate *stptr = (void *) srec;
1062 1.1 cherry /* Pointer to current unwind_frame element */
1063 1.1 cherry uint64_t *gr = (void *) uwf;
1064 1.1 cherry
1065 1.8 dholland int i;
1066 1.1 cherry
1067 1.8 dholland #ifdef UNWIND_DIAGNOSTIC
1068 1.8 dholland printf("updateregs(): \n");
1069 1.8 dholland printf("procoffset (slots) = %lu \n", procoffset);
1070 1.8 dholland #endif
1071 1.1 cherry
1072 1.1 cherry for(i = 0; i < statecount; i++) {
1073 1.1 cherry switch (stptr[i].where) {
1074 1.1 cherry case IMMED: /* currently only mem_stack_f */
1075 1.1 cherry if (stptr[i].when >= procoffset) break;
1076 1.1 cherry uwf->psp -= (stptr[i].offset << 4);
1077 1.1 cherry break;
1078 1.1 cherry
1079 1.1 cherry case GRREL:
1080 1.1 cherry if (stptr[i].when >= procoffset) break;
1081 1.1 cherry
1082 1.1 cherry roffset = stptr[i].offset;
1083 1.1 cherry if (roffset == 0) {
1084 1.1 cherry gr[i] = 0;
1085 1.1 cherry break;
1086 1.1 cherry }
1087 1.1 cherry
1088 1.1 cherry
1089 1.1 cherry if (roffset < 32) {
1090 1.1 cherry printf("GR%ld: static register save ??? \n", roffset);
1091 1.1 cherry break;
1092 1.1 cherry }
1093 1.1 cherry
1094 1.1 cherry /* Fetch from bsp + offset - 32 + Adjust for RNAT. */
1095 1.1 cherry roffset -= 32;
1096 1.1 cherry gr[i] = ia64_getrse_gr(uwf->bsp, roffset);
1097 1.1 cherry break;
1098 1.1 cherry
1099 1.1 cherry case SPREL:
1100 1.1 cherry if (stptr[i].when >= procoffset) break;
1101 1.1 cherry
1102 1.1 cherry /* Check if frame has been setup. */
1103 1.1 cherry if (srec->psp.offset == INVALID) {
1104 1.1 cherry printf("sprel used without setting up stackframe!!! \n");
1105 1.1 cherry break;
1106 1.1 cherry }
1107 1.1 cherry
1108 1.1 cherry roffset = stptr[i].offset;
1109 1.1 cherry
1110 1.1 cherry /* Fetch from sp + offset */
1111 1.1 cherry memcpy(&gr[i], (char *) uwf->sp + roffset * 4, sizeof(uint64_t));
1112 1.1 cherry break;
1113 1.1 cherry
1114 1.1 cherry
1115 1.1 cherry case PSPREL:
1116 1.1 cherry if (stptr[i].when >= procoffset) break;
1117 1.1 cherry
1118 1.1 cherry /* Check if frame has been setup. */
1119 1.1 cherry if (srec->psp.offset == INVALID) {
1120 1.1 cherry printf("psprel used without setting up stackframe!!! \n");
1121 1.1 cherry break;
1122 1.1 cherry }
1123 1.1 cherry
1124 1.1 cherry roffset = stptr[i].offset;
1125 1.1 cherry
1126 1.1 cherry /* Fetch from sp + offset */
1127 1.1 cherry memcpy(&gr[i], (char *) uwf->psp + 16 - (roffset * 4), sizeof(uint64_t));
1128 1.1 cherry break;
1129 1.1 cherry
1130 1.1 cherry case UNSAVED:
1131 1.1 cherry case BRREL:
1132 1.1 cherry default:
1133 1.1 cherry #ifdef UNWIND_DIAGNOSTIC
1134 1.1 cherry printf ("updateregs: reg[%d] is UNSAVED \n", i);
1135 1.1 cherry #endif
1136 1.1 cherry break;
1137 1.1 cherry /* XXX: Not implemented yet. */
1138 1.1 cherry }
1139 1.1 cherry
1140 1.1 cherry }
1141 1.1 cherry
1142 1.1 cherry }
1143 1.1 cherry
1144 1.1 cherry
1145 1.8 dholland /*
1146 1.8 dholland * Locates unwind table entry, given unwind table entry info.
1147 1.1 cherry * Expects the variables ia64_unwindtab, and ia64_unwindtablen
1148 1.1 cherry * to be set appropriately.
1149 1.1 cherry */
1150 1.1 cherry struct uwtable_ent *
1151 1.1 cherry get_unwind_table_entry(uint64_t iprel)
1152 1.1 cherry {
1153 1.1 cherry
1154 1.1 cherry extern uint64_t ia64_unwindtab, ia64_unwindtablen;
1155 1.1 cherry
1156 1.1 cherry struct uwtable_ent *uwt;
1157 1.8 dholland int tabent;
1158 1.1 cherry
1159 1.1 cherry
1160 1.1 cherry for(uwt = (struct uwtable_ent *) ia64_unwindtab, tabent = 0;
1161 1.1 cherry /* The Runtime spec tells me the table entries are sorted. */
1162 1.1 cherry uwt->end <= iprel && tabent < ia64_unwindtablen;
1163 1.1 cherry uwt++, tabent += sizeof(struct uwtable_ent));
1164 1.1 cherry
1165 1.1 cherry
1166 1.1 cherry if (!(uwt->start <= iprel && iprel < uwt->end)) {
1167 1.1 cherry #ifdef UNWIND_DIAGNOSTIC
1168 1.1 cherry printf("Entry not found \n");
1169 1.1 cherry printf("iprel = %lx \n", iprel);
1170 1.1 cherry printf("uwt->start = %lx \nuwt->end = %lx \n",
1171 1.1 cherry uwt->start, uwt->end);
1172 1.1 cherry printf("tabent = %d \n", tabent);
1173 1.1 cherry printf("ia64_unwindtablen = %ld \n",
1174 1.1 cherry ia64_unwindtablen);
1175 1.1 cherry #endif
1176 1.1 cherry return NULL;
1177 1.1 cherry }
1178 1.1 cherry
1179 1.1 cherry #ifdef UNWIND_DIAGNOSTIC
1180 1.1 cherry printf("uwt->start = %lx \nuwt->end = %lx \n"
1181 1.1 cherry "uwt->infoptr = %p\n", uwt->start, uwt->end, uwt->infoptr);
1182 1.1 cherry #endif
1183 1.1 cherry
1184 1.1 cherry return uwt;
1185 1.1 cherry }
1186 1.1 cherry
1187 1.1 cherry
1188 1.1 cherry /*
1189 1.1 cherry * Reads unwind table info and updates register values.
1190 1.1 cherry */
1191 1.1 cherry void
1192 1.1 cherry patchunwindframe(struct unwind_frame *uwf, uint64_t iprel, uint64_t relocoffset)
1193 1.1 cherry {
1194 1.1 cherry
1195 1.1 cherry extern struct recordchain strc[];
1196 1.1 cherry struct staterecord *srec;
1197 1.1 cherry struct uwtable_ent *uwt;
1198 1.1 cherry uint64_t infoptr, procoffset, slotoffset;
1199 1.1 cherry
1200 1.6 dholland #if 0 /* does not work - moved to assertion at the call site */
1201 1.1 cherry if (iprel < 0) {
1202 1.1 cherry panic("unwind ip out of range!!! \n");
1203 1.1 cherry return;
1204 1.1 cherry }
1205 1.6 dholland #endif
1206 1.1 cherry
1207 1.1 cherry uwt = get_unwind_table_entry(iprel);
1208 1.1 cherry
1209 1.1 cherry if (uwt == NULL) return;
1210 1.1 cherry
1211 1.1 cherry infoptr = (uint64_t) uwt->infoptr + relocoffset;
1212 1.1 cherry
1213 1.1 cherry if (infoptr > relocoffset) {
1214 1.1 cherry buildrecordchain(infoptr, NULL);
1215 1.8 dholland } else {
1216 1.8 dholland return;
1217 1.1 cherry }
1218 1.1 cherry
1219 1.1 cherry slotoffset = iprel & 3;
1220 1.1 cherry
1221 1.1 cherry /* procoffset in Number of _slots_ , _not_ a byte offset. */
1222 1.1 cherry
1223 1.1 cherry procoffset = (((iprel - slotoffset) - (uwt->start)) / 0x10 * 3) + slotoffset;
1224 1.1 cherry srec = buildrecordstack(strc, procoffset);
1225 1.1 cherry
1226 1.1 cherry updateregs(uwf, srec, procoffset);
1227 1.1 cherry }
1228