1
/* libunwind - a platform-independent unwind library
2
Copyright (C) 2001-2004 Hewlett-Packard Co
3
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
5
This file is part of libunwind.
7
Permission is hereby granted, free of charge, to any person obtaining
8
a copy of this software and associated documentation files (the
9
"Software"), to deal in the Software without restriction, including
10
without limitation the rights to use, copy, modify, merge, publish,
11
distribute, sublicense, and/or sell copies of the Software, and to
12
permit persons to whom the Software is furnished to do so, subject to
13
the following conditions:
15
The above copyright notice and this permission notice shall be
16
included in all copies or substantial portions of the Software.
18
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
33
/* forward declaration: */
34
static int create_state_record_for (struct cursor *c,
35
struct ia64_state_record *sr,
38
typedef unsigned long unw_word;
40
#define alloc_reg_state() (mempool_alloc (&unw.reg_state_pool))
41
#define free_reg_state(rs) (mempool_free (&unw.reg_state_pool, rs))
42
#define alloc_labeled_state() (mempool_alloc (&unw.labeled_state_pool))
43
#define free_labeled_state(s) (mempool_free (&unw.labeled_state_pool, s))
45
/* Routines to manipulate the state stack. */
48
push (struct ia64_state_record *sr)
50
struct ia64_reg_state *rs;
52
rs = alloc_reg_state ();
55
print_error ("libunwind: cannot stack reg state!\n");
58
memcpy (rs, &sr->curr, sizeof (*rs));
63
pop (struct ia64_state_record *sr)
65
struct ia64_reg_state *rs = sr->curr.next;
69
print_error ("libunwind: stack underflow!\n");
72
memcpy (&sr->curr, rs, sizeof (*rs));
76
/* Make a copy of the state stack. Non-recursive to avoid stack overflows. */
77
static struct ia64_reg_state *
78
dup_state_stack (struct ia64_reg_state *rs)
80
struct ia64_reg_state *copy, *prev = NULL, *first = NULL;
84
copy = alloc_reg_state ();
87
print_error ("unwind.dup_state_stack: out of memory\n");
90
memcpy (copy, rs, sizeof (*copy));
101
/* Free all stacked register states (but not RS itself). */
103
free_state_stack (struct ia64_reg_state *rs)
105
struct ia64_reg_state *p, *next;
107
for (p = rs->next; p != NULL; p = next)
115
/* Unwind decoder routines */
117
static enum ia64_pregnum __attribute__ ((const))
118
decode_abreg (unsigned char abreg, int memory)
123
return IA64_REG_R4 + (abreg - 0x04);
125
return IA64_REG_F2 + (abreg - 0x22);
127
return IA64_REG_F16 + (abreg - 0x30);
129
return IA64_REG_B1 + (abreg - 0x41);
135
return memory ? IA64_REG_PRI_UNAT_MEM : IA64_REG_PRI_UNAT_GR;
141
return IA64_REG_BSPSTORE;
143
return IA64_REG_RNAT;
145
return IA64_REG_UNAT;
147
return IA64_REG_FPSR;
155
dprintf ("libunwind: bad abreg=0x%x\n", abreg);
160
set_reg (struct ia64_reg_info *reg, enum ia64_where where, int when,
165
if (reg->when == IA64_WHEN_NEVER)
170
alloc_spill_area (unsigned long *offp, unsigned long regsize,
171
struct ia64_reg_info *lo, struct ia64_reg_info *hi)
173
struct ia64_reg_info *reg;
175
for (reg = hi; reg >= lo; --reg)
177
if (reg->where == IA64_WHERE_SPILL_HOME)
179
reg->where = IA64_WHERE_PSPREL;
187
spill_next_when (struct ia64_reg_info **regp, struct ia64_reg_info *lim,
190
struct ia64_reg_info *reg;
192
for (reg = *regp; reg <= lim; ++reg)
194
if (reg->where == IA64_WHERE_SPILL_HOME)
201
dprintf ("libunwind: excess spill!\n");
205
finish_prologue (struct ia64_state_record *sr)
207
struct ia64_reg_info *reg;
211
/* First, resolve implicit register save locations (see Section
212
"11.4.2.3 Rules for Using Unwind Descriptors", rule 3). */
213
for (i = 0; i < (int) NELEMS (unw.save_order); ++i)
215
reg = sr->curr.reg + unw.save_order[i];
216
if (reg->where == IA64_WHERE_GR_SAVE)
218
reg->where = IA64_WHERE_GR;
219
reg->val = sr->gr_save_loc++;
223
/* Next, compute when the fp, general, and branch registers get
224
saved. This must come before alloc_spill_area() because we need
225
to know which registers are spilled to their home locations. */
229
unsigned char kind, mask = 0, *cp = sr->imask;
231
static const unsigned char limit[3] =
233
IA64_REG_F31, IA64_REG_R7, IA64_REG_B5
235
struct ia64_reg_info *(regs[3]);
237
regs[0] = sr->curr.reg + IA64_REG_F2;
238
regs[1] = sr->curr.reg + IA64_REG_R4;
239
regs[2] = sr->curr.reg + IA64_REG_B1;
241
for (t = 0; (int) t < sr->region_len; ++t)
245
kind = (mask >> 2 * (3 - (t & 3))) & 3;
247
spill_next_when (®s[kind - 1], sr->curr.reg + limit[kind - 1],
248
sr->region_start + t);
252
/* Next, lay out the memory stack spill area. */
256
off = sr->spill_offset;
257
alloc_spill_area (&off, 16, sr->curr.reg + IA64_REG_F2,
258
sr->curr.reg + IA64_REG_F31);
259
alloc_spill_area (&off, 8, sr->curr.reg + IA64_REG_B1,
260
sr->curr.reg + IA64_REG_B5);
261
alloc_spill_area (&off, 8, sr->curr.reg + IA64_REG_R4,
262
sr->curr.reg + IA64_REG_R7);
266
/* Region header descriptors. */
269
desc_prologue (int body, unw_word rlen, unsigned char mask,
270
unsigned char grsave, struct ia64_state_record *sr)
274
if (!(sr->in_body || sr->first_region))
275
finish_prologue (sr);
276
sr->first_region = 0;
278
/* check if we're done: */
279
if (sr->when_target < sr->region_start + sr->region_len)
285
region_start = sr->region_start + sr->region_len;
287
for (i = 0; i < sr->epilogue_count; ++i)
289
sr->epilogue_count = 0;
290
sr->when_sp_restored = IA64_WHEN_NEVER;
292
sr->region_start = region_start;
293
sr->region_len = rlen;
301
for (i = 0; i < 4; ++i)
304
set_reg (sr->curr.reg + unw.save_order[i], IA64_WHERE_GR,
305
sr->region_start + sr->region_len - 1, grsave++);
308
sr->gr_save_loc = grsave;
311
sr->spill_offset = 0x10; /* default to psp+16 */
315
/* Prologue descriptors. */
318
desc_abi (unsigned char abi, unsigned char context,
319
struct ia64_state_record *sr)
321
sr->abi_marker = (abi << 8) | context;
325
desc_br_gr (unsigned char brmask, unsigned char gr,
326
struct ia64_state_record *sr)
330
for (i = 0; i < 5; ++i)
333
set_reg (sr->curr.reg + IA64_REG_B1 + i, IA64_WHERE_GR,
334
sr->region_start + sr->region_len - 1, gr++);
340
desc_br_mem (unsigned char brmask, struct ia64_state_record *sr)
344
for (i = 0; i < 5; ++i)
348
set_reg (sr->curr.reg + IA64_REG_B1 + i, IA64_WHERE_SPILL_HOME,
349
sr->region_start + sr->region_len - 1, 0);
357
desc_frgr_mem (unsigned char grmask, unw_word frmask,
358
struct ia64_state_record *sr)
362
for (i = 0; i < 4; ++i)
364
if ((grmask & 1) != 0)
366
set_reg (sr->curr.reg + IA64_REG_R4 + i, IA64_WHERE_SPILL_HOME,
367
sr->region_start + sr->region_len - 1, 0);
372
for (i = 0; i < 20; ++i)
374
if ((frmask & 1) != 0)
376
int base = (i < 4) ? IA64_REG_F2 : IA64_REG_F16 - 4;
377
set_reg (sr->curr.reg + base + i, IA64_WHERE_SPILL_HOME,
378
sr->region_start + sr->region_len - 1, 0);
386
desc_fr_mem (unsigned char frmask, struct ia64_state_record *sr)
390
for (i = 0; i < 4; ++i)
392
if ((frmask & 1) != 0)
394
set_reg (sr->curr.reg + IA64_REG_F2 + i, IA64_WHERE_SPILL_HOME,
395
sr->region_start + sr->region_len - 1, 0);
403
desc_gr_gr (unsigned char grmask, unsigned char gr,
404
struct ia64_state_record *sr)
408
for (i = 0; i < 4; ++i)
410
if ((grmask & 1) != 0)
411
set_reg (sr->curr.reg + IA64_REG_R4 + i, IA64_WHERE_GR,
412
sr->region_start + sr->region_len - 1, gr++);
418
desc_gr_mem (unsigned char grmask, struct ia64_state_record *sr)
422
for (i = 0; i < 4; ++i)
424
if ((grmask & 1) != 0)
426
set_reg (sr->curr.reg + IA64_REG_R4 + i, IA64_WHERE_SPILL_HOME,
427
sr->region_start + sr->region_len - 1, 0);
435
desc_mem_stack_f (unw_word t, unw_word size, struct ia64_state_record *sr)
437
set_reg (sr->curr.reg + IA64_REG_PSP, IA64_WHERE_NONE,
438
sr->region_start + MIN ((int) t, sr->region_len - 1), 16 * size);
442
desc_mem_stack_v (unw_word t, struct ia64_state_record *sr)
444
sr->curr.reg[IA64_REG_PSP].when =
445
sr->region_start + MIN ((int) t, sr->region_len - 1);
449
desc_reg_gr (unsigned char reg, unsigned char dst,
450
struct ia64_state_record *sr)
452
set_reg (sr->curr.reg + reg, IA64_WHERE_GR,
453
sr->region_start + sr->region_len - 1, dst);
457
desc_reg_psprel (unsigned char reg, unw_word pspoff,
458
struct ia64_state_record *sr)
460
set_reg (sr->curr.reg + reg, IA64_WHERE_PSPREL,
461
sr->region_start + sr->region_len - 1, 0x10 - 4 * pspoff);
465
desc_reg_sprel (unsigned char reg, unw_word spoff,
466
struct ia64_state_record *sr)
468
set_reg (sr->curr.reg + reg, IA64_WHERE_SPREL,
469
sr->region_start + sr->region_len - 1, 4 * spoff);
473
desc_rp_br (unsigned char dst, struct ia64_state_record *sr)
475
sr->return_link_reg = dst;
479
desc_reg_when (unsigned char regnum, unw_word t, struct ia64_state_record *sr)
481
struct ia64_reg_info *reg = sr->curr.reg + regnum;
483
if (reg->where == IA64_WHERE_NONE)
484
reg->where = IA64_WHERE_GR_SAVE;
485
reg->when = sr->region_start + MIN ((int) t, sr->region_len - 1);
489
desc_spill_base (unw_word pspoff, struct ia64_state_record *sr)
491
sr->spill_offset = 0x10 - 4 * pspoff;
494
static inline unsigned char *
495
desc_spill_mask (unsigned char *imaskp, struct ia64_state_record *sr)
498
return imaskp + (2 * sr->region_len + 7) / 8;
501
/* Body descriptors. */
504
desc_epilogue (unw_word t, unw_word ecount, struct ia64_state_record *sr)
506
sr->when_sp_restored = sr->region_start + sr->region_len - 1 - t;
507
sr->epilogue_count = ecount + 1;
511
desc_copy_state (unw_word label, struct ia64_state_record *sr)
513
struct ia64_labeled_state *ls;
515
for (ls = sr->labeled_states; ls; ls = ls->next)
517
if (ls->label == label)
519
free_state_stack (&sr->curr);
520
memcpy (&sr->curr, &ls->saved_state, sizeof (sr->curr));
521
sr->curr.next = dup_state_stack (ls->saved_state.next);
525
print_error ("libunwind: failed to find labeled state\n");
529
desc_label_state (unw_word label, struct ia64_state_record *sr)
531
struct ia64_labeled_state *ls;
533
ls = alloc_labeled_state ();
536
print_error ("unwind.desc_label_state(): out of memory\n");
540
memcpy (&ls->saved_state, &sr->curr, sizeof (ls->saved_state));
541
ls->saved_state.next = dup_state_stack (sr->curr.next);
543
/* insert into list of labeled states: */
544
ls->next = sr->labeled_states;
545
sr->labeled_states = ls;
548
/* General descriptors. */
551
desc_is_active (unsigned char qp, unw_word t, struct ia64_state_record *sr)
553
if (sr->when_target <= sr->region_start + MIN ((int) t, sr->region_len - 1))
557
if ((sr->pr_val & ((unw_word_t) 1 << qp)) == 0)
559
sr->pr_mask |= ((unw_word_t) 1 << qp);
565
desc_restore_p (unsigned char qp, unw_word t, unsigned char abreg,
566
struct ia64_state_record *sr)
568
struct ia64_reg_info *r;
570
if (!desc_is_active (qp, t, sr))
573
r = sr->curr.reg + decode_abreg (abreg, 0);
574
r->where = IA64_WHERE_NONE;
575
r->when = IA64_WHEN_NEVER;
580
desc_spill_reg_p (unsigned char qp, unw_word t, unsigned char abreg,
581
unsigned char x, unsigned char ytreg,
582
struct ia64_state_record *sr)
584
enum ia64_where where = IA64_WHERE_GR;
585
struct ia64_reg_info *r;
587
if (!desc_is_active (qp, t, sr))
591
where = IA64_WHERE_BR;
592
else if (ytreg & 0x80)
593
where = IA64_WHERE_FR;
595
r = sr->curr.reg + decode_abreg (abreg, 0);
597
r->when = sr->region_start + MIN ((int) t, sr->region_len - 1);
598
r->val = (ytreg & 0x7f);
602
desc_spill_psprel_p (unsigned char qp, unw_word t, unsigned char abreg,
603
unw_word pspoff, struct ia64_state_record *sr)
605
struct ia64_reg_info *r;
607
if (!desc_is_active (qp, t, sr))
610
r = sr->curr.reg + decode_abreg (abreg, 1);
611
r->where = IA64_WHERE_PSPREL;
612
r->when = sr->region_start + MIN ((int) t, sr->region_len - 1);
613
r->val = 0x10 - 4 * pspoff;
617
desc_spill_sprel_p (unsigned char qp, unw_word t, unsigned char abreg,
618
unw_word spoff, struct ia64_state_record *sr)
620
struct ia64_reg_info *r;
622
if (!desc_is_active (qp, t, sr))
625
r = sr->curr.reg + decode_abreg (abreg, 1);
626
r->where = IA64_WHERE_SPREL;
627
r->when = sr->region_start + MIN ((int) t, sr->region_len - 1);
631
#define UNW_DEC_BAD_CODE(code) \
632
print_error ("libunwind: unknown code encountered\n")
634
/* Register names. */
635
#define UNW_REG_BSP IA64_REG_BSP
636
#define UNW_REG_BSPSTORE IA64_REG_BSPSTORE
637
#define UNW_REG_FPSR IA64_REG_FPSR
638
#define UNW_REG_LC IA64_REG_LC
639
#define UNW_REG_PFS IA64_REG_PFS
640
#define UNW_REG_PR IA64_REG_PR
641
#define UNW_REG_RNAT IA64_REG_RNAT
642
#define UNW_REG_PSP IA64_REG_PSP
643
#define UNW_REG_RP IA64_REG_IP
644
#define UNW_REG_UNAT IA64_REG_UNAT
646
/* Region headers. */
647
#define UNW_DEC_PROLOGUE_GR(fmt,r,m,gr,arg) desc_prologue(0,r,m,gr,arg)
648
#define UNW_DEC_PROLOGUE(fmt,b,r,arg) desc_prologue(b,r,0,32,arg)
650
/* Prologue descriptors. */
651
#define UNW_DEC_ABI(fmt,a,c,arg) desc_abi(a,c,arg)
652
#define UNW_DEC_BR_GR(fmt,b,g,arg) desc_br_gr(b,g,arg)
653
#define UNW_DEC_BR_MEM(fmt,b,arg) desc_br_mem(b,arg)
654
#define UNW_DEC_FRGR_MEM(fmt,g,f,arg) desc_frgr_mem(g,f,arg)
655
#define UNW_DEC_FR_MEM(fmt,f,arg) desc_fr_mem(f,arg)
656
#define UNW_DEC_GR_GR(fmt,m,g,arg) desc_gr_gr(m,g,arg)
657
#define UNW_DEC_GR_MEM(fmt,m,arg) desc_gr_mem(m,arg)
658
#define UNW_DEC_MEM_STACK_F(fmt,t,s,arg) desc_mem_stack_f(t,s,arg)
659
#define UNW_DEC_MEM_STACK_V(fmt,t,arg) desc_mem_stack_v(t,arg)
660
#define UNW_DEC_REG_GR(fmt,r,d,arg) desc_reg_gr(r,d,arg)
661
#define UNW_DEC_REG_PSPREL(fmt,r,o,arg) desc_reg_psprel(r,o,arg)
662
#define UNW_DEC_REG_SPREL(fmt,r,o,arg) desc_reg_sprel(r,o,arg)
663
#define UNW_DEC_REG_WHEN(fmt,r,t,arg) desc_reg_when(r,t,arg)
664
#define UNW_DEC_PRIUNAT_WHEN_GR(fmt,t,arg) \
665
desc_reg_when(IA64_REG_PRI_UNAT_GR,t,arg)
666
#define UNW_DEC_PRIUNAT_WHEN_MEM(fmt,t,arg) \
667
desc_reg_when(IA64_REG_PRI_UNAT_MEM,t,arg)
668
#define UNW_DEC_PRIUNAT_GR(fmt,r,arg) \
669
desc_reg_gr(IA64_REG_PRI_UNAT_GR,r,arg)
670
#define UNW_DEC_PRIUNAT_PSPREL(fmt,o,arg) \
671
desc_reg_psprel(IA64_REG_PRI_UNAT_MEM,o,arg)
672
#define UNW_DEC_PRIUNAT_SPREL(fmt,o,arg) \
673
desc_reg_sprel(IA64_REG_PRI_UNAT_MEM,o,arg)
674
#define UNW_DEC_RP_BR(fmt,d,arg) desc_rp_br(d,arg)
675
#define UNW_DEC_SPILL_BASE(fmt,o,arg) desc_spill_base(o,arg)
676
#define UNW_DEC_SPILL_MASK(fmt,m,arg) (m = desc_spill_mask(m,arg))
678
/* Body descriptors. */
679
#define UNW_DEC_EPILOGUE(fmt,t,c,arg) desc_epilogue(t,c,arg)
680
#define UNW_DEC_COPY_STATE(fmt,l,arg) desc_copy_state(l,arg)
681
#define UNW_DEC_LABEL_STATE(fmt,l,arg) desc_label_state(l,arg)
683
/* General unwind descriptors. */
684
#define UNW_DEC_SPILL_REG_P(f,p,t,a,x,y,arg) desc_spill_reg_p(p,t,a,x,y,arg)
685
#define UNW_DEC_SPILL_REG(f,t,a,x,y,arg) desc_spill_reg_p(0,t,a,x,y,arg)
686
#define UNW_DEC_SPILL_PSPREL_P(f,p,t,a,o,arg) \
687
desc_spill_psprel_p(p,t,a,o,arg)
688
#define UNW_DEC_SPILL_PSPREL(f,t,a,o,arg) \
689
desc_spill_psprel_p(0,t,a,o,arg)
690
#define UNW_DEC_SPILL_SPREL_P(f,p,t,a,o,arg) desc_spill_sprel_p(p,t,a,o,arg)
691
#define UNW_DEC_SPILL_SPREL(f,t,a,o,arg) desc_spill_sprel_p(0,t,a,o,arg)
692
#define UNW_DEC_RESTORE_P(f,p,t,a,arg) desc_restore_p(p,t,a,arg)
693
#define UNW_DEC_RESTORE(f,t,a,arg) desc_restore_p(0,t,a,arg)
695
#include "unwind_decoder.h"
697
/* parse dynamic unwind info */
699
static struct ia64_reg_info *
700
lookup_preg (int regnum, int memory, struct ia64_state_record *sr)
706
case UNW_IA64_AR_BSP: preg = IA64_REG_BSP; break;
707
case UNW_IA64_AR_BSPSTORE: preg = IA64_REG_BSPSTORE; break;
708
case UNW_IA64_AR_FPSR: preg = IA64_REG_FPSR; break;
709
case UNW_IA64_AR_LC: preg = IA64_REG_LC; break;
710
case UNW_IA64_AR_PFS: preg = IA64_REG_PFS; break;
711
case UNW_IA64_AR_RNAT: preg = IA64_REG_RNAT; break;
712
case UNW_IA64_AR_UNAT: preg = IA64_REG_UNAT; break;
713
case UNW_IA64_BR + 0: preg = IA64_REG_IP; break;
714
case UNW_IA64_PR: preg = IA64_REG_PR; break;
715
case UNW_IA64_SP: preg = IA64_REG_PSP; break;
719
preg = IA64_REG_PRI_UNAT_MEM;
721
preg = IA64_REG_PRI_UNAT_GR;
724
case UNW_IA64_GR + 4 ... UNW_IA64_GR + 7:
725
preg = IA64_REG_R4 + (regnum - (UNW_IA64_GR + 4));
728
case UNW_IA64_BR + 1 ... UNW_IA64_BR + 5:
729
preg = IA64_REG_B1 + (regnum - UNW_IA64_BR);
732
case UNW_IA64_FR + 2 ... UNW_IA64_FR + 5:
733
preg = IA64_REG_F2 + (regnum - (UNW_IA64_FR + 2));
736
case UNW_IA64_FR + 16 ... UNW_IA64_FR + 31:
737
preg = IA64_REG_F16 + (regnum - (UNW_IA64_FR + 16));
741
dprintf ("%s: invalid register number %d\n", __FUNCTION__, regnum);
744
return sr->curr.reg + preg;
747
/* An alias directive inside a region of length RLEN is interpreted to
748
mean that the region behaves exactly like the first RLEN
749
instructions at the aliased IP. RLEN=0 implies that the current
750
state matches exactly that of the aliased IP. */
753
desc_alias (unw_dyn_op_t *op, struct cursor *c, struct ia64_state_record *sr)
755
struct ia64_state_record orig_sr = *sr;
756
int i, ret, when, rlen = sr->region_len;
759
when = MIN(sr->when_target, rlen - 1);
760
new_ip = op->val + ((when / 3) * 16 + (when % 3));
762
if ((ret = ia64_fetch_proc_info (c, new_ip, 1)) < 0)
765
if ((ret = create_state_record_for (c, sr, new_ip)) < 0)
768
sr->first_region = orig_sr.first_region;
770
sr->any_spills |= orig_sr.any_spills;
771
sr->in_body = orig_sr.in_body;
772
sr->region_start = orig_sr.region_start;
773
sr->region_len = orig_sr.region_len;
774
if (sr->when_sp_restored != IA64_WHEN_NEVER)
775
sr->when_sp_restored = op->when + MIN (orig_sr.when_sp_restored, rlen - 1);
776
sr->epilogue_count = orig_sr.epilogue_count;
777
sr->when_target = orig_sr.when_target;
779
for (i = 0; i < IA64_NUM_PREGS; ++i)
780
if (sr->curr.reg[i].when != IA64_WHEN_NEVER)
781
sr->curr.reg[i].when = op->when + MIN (sr->curr.reg[i].when, rlen - 1);
783
ia64_free_state_record (sr);
784
sr->labeled_states = orig_sr.labeled_states;
785
sr->curr.next = orig_sr.curr.next;
790
parse_dynamic (struct cursor *c, struct ia64_state_record *sr)
792
unw_dyn_info_t *di = c->pi.unwind_info;
793
unw_dyn_proc_info_t *proc = &di->u.pi;
794
unw_dyn_region_info_t *r;
795
struct ia64_reg_info *ri;
796
enum ia64_where where;
803
for (r = proc->regions; r; r = r->next)
810
Debug (1, "negative region length allowed in last region only!");
814
/* hack old region info to set the start where we need it: */
815
sr->region_start = (di->end_ip - di->start_ip) / 0x10 * 3 - len;
818
/* all regions are treated as prologue regions: */
819
desc_prologue (0, len, 0, 0, sr);
824
for (op = r->op; op < r->op + r->op_count; ++op)
830
if (!desc_is_active (qp, when, sr))
833
when = sr->region_start + MIN ((int) when, sr->region_len - 1);
837
case UNW_DYN_SAVE_REG:
839
if ((unsigned) (val - UNW_IA64_GR) < 128)
840
where = IA64_WHERE_GR;
841
else if ((unsigned) (val - UNW_IA64_FR) < 128)
842
where = IA64_WHERE_FR;
843
else if ((unsigned) (val - UNW_IA64_BR) < 8)
844
where = IA64_WHERE_BR;
847
dprintf ("%s: can't save to register number %d\n",
848
__FUNCTION__, (int) op->reg);
853
ri = lookup_preg (op->reg, memory, sr);
861
case UNW_DYN_SPILL_FP_REL:
863
where = IA64_WHERE_PSPREL;
865
goto update_reg_info;
867
case UNW_DYN_SPILL_SP_REL:
869
where = IA64_WHERE_SPREL;
870
goto update_reg_info;
873
if (op->reg == UNW_IA64_SP)
877
dprintf ("%s: frame-size %ld not an integer "
879
__FUNCTION__, (long) op->val);
882
desc_mem_stack_f (when, -((int64_t) val / 16), sr);
886
dprintf ("%s: can only ADD to stack-pointer\n",
892
case UNW_DYN_POP_FRAMES:
893
sr->when_sp_restored = when;
894
sr->epilogue_count = op->val;
897
case UNW_DYN_LABEL_STATE:
898
desc_label_state (op->val, sr);
901
case UNW_DYN_COPY_STATE:
902
desc_copy_state (op->val, sr);
906
if ((ret = desc_alias (op, c, sr)) < 0)
921
ia64_fetch_proc_info (struct cursor *c, unw_word_t ip, int need_unwind_info)
923
int ret, dynamic = 1;
925
if (c->pi_valid && !need_unwind_info)
928
/* check dynamic info first --- it overrides everything else */
929
ret = unwi_find_dynamic_proc_info (c->as, ip, &c->pi, need_unwind_info,
931
if (ret == -UNW_ENOINFO)
934
ret = ia64_find_proc_info (c, ip, need_unwind_info);
938
c->pi_is_dynamic = dynamic;
943
put_unwind_info (struct cursor *c, unw_proc_info_t *pi)
948
if (c->pi_is_dynamic)
949
unwi_put_dynamic_unwind_info (c->as, pi, c->as_arg);
951
ia64_put_unwind_info (c, pi);
955
create_state_record_for (struct cursor *c, struct ia64_state_record *sr,
958
unw_word_t predicates = c->pr;
959
struct ia64_reg_info *r;
960
uint8_t *dp, *desc_end;
963
assert (c->pi_valid);
965
/* build state record */
966
memset (sr, 0, sizeof (*sr));
967
for (r = sr->curr.reg; r < sr->curr.reg + IA64_NUM_PREGS; ++r)
968
r->when = IA64_WHEN_NEVER;
969
sr->pr_val = predicates;
970
sr->first_region = 1;
972
if (!c->pi.unwind_info)
974
/* No info, return default unwinder (leaf proc, no mem stack, no
975
saved regs), rp in b0, pfs in ar.pfs. */
976
Debug (1, "no unwind info for ip=0x%lx (gp=%lx)\n",
977
(long) ip, (long) c->pi.gp);
978
sr->curr.reg[IA64_REG_IP].where = IA64_WHERE_BR;
979
sr->curr.reg[IA64_REG_IP].when = -1;
980
sr->curr.reg[IA64_REG_IP].val = 0;
984
sr->when_target = (3 * ((ip & ~(unw_word_t) 0xf) - c->pi.start_ip) / 16
987
switch (c->pi.format)
989
case UNW_INFO_FORMAT_TABLE:
990
case UNW_INFO_FORMAT_REMOTE_TABLE:
991
dp = c->pi.unwind_info;
992
desc_end = dp + c->pi.unwind_info_size;
993
while (!sr->done && dp < desc_end)
994
dp = unw_decode (dp, sr->in_body, sr);
998
case UNW_INFO_FORMAT_DYNAMIC:
999
ret = parse_dynamic (c, sr);
1006
put_unwind_info (c, &c->pi);
1011
if (sr->when_target > sr->when_sp_restored)
1013
/* sp has been restored and all values on the memory stack below
1014
psp also have been restored. */
1015
sr->curr.reg[IA64_REG_PSP].val = 0;
1016
sr->curr.reg[IA64_REG_PSP].where = IA64_WHERE_NONE;
1017
sr->curr.reg[IA64_REG_PSP].when = IA64_WHEN_NEVER;
1018
for (r = sr->curr.reg; r < sr->curr.reg + IA64_NUM_PREGS; ++r)
1019
if ((r->where == IA64_WHERE_PSPREL && r->val <= 0x10)
1020
|| r->where == IA64_WHERE_SPREL)
1023
r->where = IA64_WHERE_NONE;
1024
r->when = IA64_WHEN_NEVER;
1028
/* If RP did't get saved, generate entry for the return link
1030
if (sr->curr.reg[IA64_REG_IP].when >= sr->when_target)
1032
sr->curr.reg[IA64_REG_IP].where = IA64_WHERE_BR;
1033
sr->curr.reg[IA64_REG_IP].when = -1;
1034
sr->curr.reg[IA64_REG_IP].val = sr->return_link_reg;
1037
if (sr->when_target > sr->curr.reg[IA64_REG_BSP].when
1038
&& sr->when_target > sr->curr.reg[IA64_REG_BSPSTORE].when
1039
&& sr->when_target > sr->curr.reg[IA64_REG_RNAT].when)
1041
Debug (8, "func 0x%lx may switch the register-backing-store\n",
1043
c->pi.flags |= UNW_PI_FLAG_IA64_RBS_SWITCH;
1047
if (unwi_debug_level > 0)
1049
dprintf ("libunwind: state record for func 0x%lx, t=%u (flags=0x%lx):\n",
1050
(long) c->pi.start_ip, sr->when_target, (long) c->pi.flags);
1051
for (r = sr->curr.reg; r < sr->curr.reg + IA64_NUM_PREGS; ++r)
1053
if (r->where != IA64_WHERE_NONE || r->when != IA64_WHEN_NEVER)
1055
dprintf (" %s <- ", unw.preg_name[r - sr->curr.reg]);
1059
dprintf ("r%lu", (long) r->val);
1062
dprintf ("f%lu", (long) r->val);
1065
dprintf ("b%lu", (long) r->val);
1067
case IA64_WHERE_SPREL:
1068
dprintf ("[sp+0x%lx]", (long) r->val);
1070
case IA64_WHERE_PSPREL:
1071
dprintf ("[psp+0x%lx]", (long) r->val);
1073
case IA64_WHERE_NONE:
1074
dprintf ("%s+0x%lx",
1075
unw.preg_name[r - sr->curr.reg], (long) r->val);
1078
dprintf ("BADWHERE(%d)", r->where);
1081
dprintf ("\t\t%d\n", r->when);
1089
/* The proc-info must be valid for IP before this routine can be
1092
ia64_create_state_record (struct cursor *c, struct ia64_state_record *sr)
1094
return create_state_record_for (c, sr, c->ip);
1098
ia64_free_state_record (struct ia64_state_record *sr)
1100
struct ia64_labeled_state *ls, *next;
1102
/* free labeled register states & stack: */
1104
for (ls = sr->labeled_states; ls; ls = next)
1107
free_state_stack (&ls->saved_state);
1108
free_labeled_state (ls);
1110
free_state_stack (&sr->curr);
1116
ia64_make_proc_info (struct cursor *c)
1118
if (c->as->caching_policy == UNW_CACHE_NONE
1119
|| ia64_get_cached_proc_info (c) < 0)
1120
/* Lookup it up the slow way... */
1121
return ia64_fetch_proc_info (c, c->ip, 0);