1 /* Subroutines needed for unwinding IA-64 standard format stack frame
2 info for exception handling.
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006,
4 2009, 2011 Free Software Foundation, Inc.
5 Contributed by Andrew MacLeod <amacleod@cygnus.com>
6 Andrew Haley <aph@cygnus.com>
7 David Mosberger-Tang <davidm@hpl.hp.com>
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3, or (at your option)
16 GCC is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 Under Section 7 of GPL version 3, you are granted additional
22 permissions described in the GCC Runtime Library Exception, version
23 3.1, as published by the Free Software Foundation.
25 You should have received a copy of the GNU General Public License and
26 a copy of the GCC Runtime Library Exception along with this program;
27 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
28 <http://www.gnu.org/licenses/>. */
32 #include "coretypes.h"
35 #include "unwind-ia64.h"
36 #include "unwind-compat.h"
37 #include "ia64intrin.h"
39 /* This isn't thread safe, but nice for occasional tests. */
40 #undef ENABLE_MALLOC_CHECKING
42 #ifndef __USING_SJLJ_EXCEPTIONS__
44 enum unw_application_register
58 enum unw_register_index
65 UNW_REG_PSP
, /* previous memory stack pointer */
68 UNW_REG_BSP
, /* register stack pointer */
70 UNW_REG_PFS
, /* previous function state */
75 /* Special preserved registers. */
76 UNW_REG_UNAT
, UNW_REG_PR
, UNW_REG_LC
, UNW_REG_FPSR
,
78 /* Non-stacked general registers. */
80 UNW_REG_R4
= UNW_REG_R2
+ 2,
81 UNW_REG_R7
= UNW_REG_R2
+ 5,
82 UNW_REG_R31
= UNW_REG_R2
+ 29,
84 /* Non-stacked floating point registers. */
86 UNW_REG_F5
= UNW_REG_F2
+ 3,
87 UNW_REG_F16
= UNW_REG_F2
+ 14,
88 UNW_REG_F31
= UNW_REG_F2
+ 29,
90 /* Branch registers. */
91 UNW_REG_B0
, UNW_REG_B1
,
92 UNW_REG_B5
= UNW_REG_B1
+ 4,
99 UNW_WHERE_NONE
, /* register isn't saved at all */
100 UNW_WHERE_GR
, /* register is saved in a general register */
101 UNW_WHERE_FR
, /* register is saved in a floating-point register */
102 UNW_WHERE_BR
, /* register is saved in a branch register */
103 UNW_WHERE_SPREL
, /* register is saved on memstack (sp-relative) */
104 UNW_WHERE_PSPREL
, /* register is saved on memstack (psp-relative) */
106 /* At the end of each prologue these locations get resolved to
107 UNW_WHERE_PSPREL and UNW_WHERE_GR, respectively. */
108 UNW_WHERE_SPILL_HOME
, /* register is saved in its spill home */
109 UNW_WHERE_GR_SAVE
/* register is saved in next general register */
112 #define UNW_WHEN_NEVER 0x7fffffff
116 unsigned long val
; /* save location: register number or offset */
117 enum unw_where where
; /* where the register gets saved */
118 int when
; /* when the register gets saved */
121 struct unw_reg_state
{
122 struct unw_reg_state
*next
; /* next (outer) element on state stack */
123 struct unw_reg_info reg
[UNW_NUM_REGS
]; /* register save locations */
126 struct unw_labeled_state
{
127 struct unw_labeled_state
*next
; /* next labeled state (or NULL) */
128 unsigned long label
; /* label for this state */
129 struct unw_reg_state saved_state
;
132 typedef struct unw_state_record
134 unsigned int first_region
: 1; /* is this the first region? */
135 unsigned int done
: 1; /* are we done scanning descriptors? */
136 unsigned int any_spills
: 1; /* got any register spills? */
137 unsigned int in_body
: 1; /* are we inside a body? */
138 unsigned int no_reg_stack_frame
: 1; /* Don't adjust bsp for i&l regs */
139 unsigned char *imask
; /* imask of spill_mask record or NULL */
140 unsigned long pr_val
; /* predicate values */
141 unsigned long pr_mask
; /* predicate mask */
142 long spill_offset
; /* psp-relative offset for spill base */
149 unsigned char gr_save_loc
; /* next general register to use for saving */
150 unsigned char return_link_reg
; /* branch register for return link */
151 unsigned short unwabi
;
153 struct unw_labeled_state
*labeled_states
; /* list of all labeled states */
154 struct unw_reg_state curr
; /* current state */
156 _Unwind_Personality_Fn personality
;
158 } _Unwind_FrameState
;
162 UNW_NAT_NONE
, /* NaT not represented */
163 UNW_NAT_VAL
, /* NaT represented by NaT value (fp reg) */
164 UNW_NAT_MEMSTK
, /* NaT value is in unat word at offset OFF */
165 UNW_NAT_REGSTK
/* NaT is in rnat */
174 struct _Unwind_Context
176 /* Initial frame info. */
177 unsigned long rnat
; /* rse nat collection */
178 unsigned long regstk_top
; /* lowest address of rbs stored register
179 which uses context->rnat collection */
181 /* Current frame info. */
182 unsigned long bsp
; /* backing store pointer value
183 corresponding to psp. */
184 unsigned long sp
; /* stack pointer value */
185 unsigned long psp
; /* previous sp value */
186 unsigned long rp
; /* return pointer */
187 unsigned long pr
; /* predicate collection */
189 unsigned long region_start
; /* start of unwind region */
190 unsigned long gp
; /* global pointer value */
191 void *lsda
; /* language specific data area */
193 /* Preserved state. */
194 unsigned long *bsp_loc
; /* previous bsp save location
195 Appears to be write-only? */
196 unsigned long *bspstore_loc
;
197 unsigned long *pfs_loc
; /* Save location for pfs in current
198 (corr. to sp) frame. Target
199 contains cfm for caller. */
200 unsigned long *signal_pfs_loc
;/* Save location for pfs in current
201 signal frame. Target contains
203 unsigned long *pri_unat_loc
;
204 unsigned long *unat_loc
;
205 unsigned long *lc_loc
;
206 unsigned long *fpsr_loc
;
208 unsigned long eh_data
[4];
215 enum unw_nat_type type
: 3;
216 signed long off
: 61; /* NaT word is at loc+nat.off */
218 } ireg
[32 - 2]; /* Indexed by <register number> - 2 */
220 unsigned long *br_loc
[8];
221 void *fr_loc
[32 - 2];
223 /* ??? We initially point pri_unat_loc here. The entire NAT bit
225 unsigned long initial_unat
;
228 typedef unsigned long unw_word
;
230 /* Implicit register save order. See section 11.4.2.3 Rules for Using
231 Unwind Descriptors, rule 3. */
233 static unsigned char const save_order
[] =
235 UNW_REG_RP
, UNW_REG_PFS
, UNW_REG_PSP
, UNW_REG_PR
,
236 UNW_REG_UNAT
, UNW_REG_LC
, UNW_REG_FPSR
, UNW_REG_PRI_UNAT_GR
240 #define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
242 /* MASK is a bitmap describing the allocation state of emergency buffers,
243 with bit set indicating free. Return >= 0 if allocation is successful;
247 atomic_alloc (unsigned int *mask
)
249 unsigned int old
= *mask
, ret
, new;
257 new = __sync_val_compare_and_swap (mask
, old
, new);
263 return __builtin_ffs (ret
) - 1;
266 /* Similarly, free an emergency buffer. */
269 atomic_free (unsigned int *mask
, int bit
)
271 __sync_xor_and_fetch (mask
, 1 << bit
);
275 #define SIZE(X) (sizeof(X) / sizeof(*(X)))
276 #define MASK_FOR(X) ((2U << (SIZE (X) - 1)) - 1)
277 #define PTR_IN(X, P) ((P) >= (X) && (P) < (X) + SIZE (X))
279 static struct unw_reg_state emergency_reg_state
[32];
280 static unsigned int emergency_reg_state_free
= MASK_FOR (emergency_reg_state
);
282 static struct unw_labeled_state emergency_labeled_state
[8];
283 static unsigned int emergency_labeled_state_free
= MASK_FOR (emergency_labeled_state
);
285 #ifdef ENABLE_MALLOC_CHECKING
286 static int reg_state_alloced
;
287 static int labeled_state_alloced
;
290 /* Allocation and deallocation of structures. */
292 static struct unw_reg_state
*
293 alloc_reg_state (void)
295 struct unw_reg_state
*rs
;
297 #ifdef ENABLE_MALLOC_CHECKING
301 rs
= malloc (sizeof (struct unw_reg_state
));
304 int n
= atomic_alloc (&emergency_reg_state_free
);
306 rs
= &emergency_reg_state
[n
];
313 free_reg_state (struct unw_reg_state
*rs
)
315 #ifdef ENABLE_MALLOC_CHECKING
319 if (PTR_IN (emergency_reg_state
, rs
))
320 atomic_free (&emergency_reg_state_free
, rs
- emergency_reg_state
);
325 static struct unw_labeled_state
*
326 alloc_label_state (void)
328 struct unw_labeled_state
*ls
;
330 #ifdef ENABLE_MALLOC_CHECKING
331 labeled_state_alloced
++;
334 ls
= malloc(sizeof(struct unw_labeled_state
));
337 int n
= atomic_alloc (&emergency_labeled_state_free
);
339 ls
= &emergency_labeled_state
[n
];
346 free_label_state (struct unw_labeled_state
*ls
)
348 #ifdef ENABLE_MALLOC_CHECKING
349 labeled_state_alloced
--;
352 if (PTR_IN (emergency_labeled_state
, ls
))
353 atomic_free (&emergency_labeled_state_free
, emergency_labeled_state
- ls
);
358 /* Routines to manipulate the state stack. */
361 push (struct unw_state_record
*sr
)
363 struct unw_reg_state
*rs
= alloc_reg_state ();
364 memcpy (rs
, &sr
->curr
, sizeof (*rs
));
369 pop (struct unw_state_record
*sr
)
371 struct unw_reg_state
*rs
= sr
->curr
.next
;
375 memcpy (&sr
->curr
, rs
, sizeof(*rs
));
379 /* Make a copy of the state stack. Non-recursive to avoid stack overflows. */
381 static struct unw_reg_state
*
382 dup_state_stack (struct unw_reg_state
*rs
)
384 struct unw_reg_state
*copy
, *prev
= NULL
, *first
= NULL
;
388 copy
= alloc_reg_state ();
389 memcpy (copy
, rs
, sizeof(*copy
));
401 /* Free all stacked register states (but not RS itself). */
403 free_state_stack (struct unw_reg_state
*rs
)
405 struct unw_reg_state
*p
, *next
;
407 for (p
= rs
->next
; p
!= NULL
; p
= next
)
415 /* Free all labeled states. */
418 free_label_states (struct unw_labeled_state
*ls
)
420 struct unw_labeled_state
*next
;
422 for (; ls
; ls
= next
)
426 free_state_stack (&ls
->saved_state
);
427 free_label_state (ls
);
431 /* Unwind decoder routines */
433 static enum unw_register_index
__attribute__((const))
434 decode_abreg (unsigned char abreg
, int memory
)
438 #if TARGET_ABI_OPEN_VMS
439 /* OpenVMS Calling Standard specifies R3 - R31. */
440 case 0x03 ... 0x1f: return UNW_REG_R2
+ (abreg
- 0x02);
442 /* Standard Intel ABI specifies GR 4 - 7. */
443 case 0x04 ... 0x07: return UNW_REG_R4
+ (abreg
- 0x04);
445 case 0x22 ... 0x25: return UNW_REG_F2
+ (abreg
- 0x22);
446 case 0x30 ... 0x3f: return UNW_REG_F16
+ (abreg
- 0x30);
447 case 0x41 ... 0x45: return UNW_REG_B1
+ (abreg
- 0x41);
448 case 0x60: return UNW_REG_PR
;
449 case 0x61: return UNW_REG_PSP
;
450 case 0x62: return memory
? UNW_REG_PRI_UNAT_MEM
: UNW_REG_PRI_UNAT_GR
;
451 case 0x63: return UNW_REG_RP
;
452 case 0x64: return UNW_REG_BSP
;
453 case 0x65: return UNW_REG_BSPSTORE
;
454 case 0x66: return UNW_REG_RNAT
;
455 case 0x67: return UNW_REG_UNAT
;
456 case 0x68: return UNW_REG_FPSR
;
457 case 0x69: return UNW_REG_PFS
;
458 case 0x6a: return UNW_REG_LC
;
465 set_reg (struct unw_reg_info
*reg
, enum unw_where where
,
466 int when
, unsigned long val
)
470 if (reg
->when
== UNW_WHEN_NEVER
)
475 alloc_spill_area (unsigned long *offp
, unsigned long regsize
,
476 struct unw_reg_info
*lo
, struct unw_reg_info
*hi
)
478 struct unw_reg_info
*reg
;
480 for (reg
= hi
; reg
>= lo
; --reg
)
482 if (reg
->where
== UNW_WHERE_SPILL_HOME
)
484 reg
->where
= UNW_WHERE_PSPREL
;
492 spill_next_when (struct unw_reg_info
**regp
, struct unw_reg_info
*lim
,
495 struct unw_reg_info
*reg
;
497 for (reg
= *regp
; reg
<= lim
; ++reg
)
499 if (reg
->where
== UNW_WHERE_SPILL_HOME
)
511 finish_prologue (struct unw_state_record
*sr
)
513 struct unw_reg_info
*reg
;
517 /* First, resolve implicit register save locations
518 (see Section "11.4.2.3 Rules for Using Unwind Descriptors", rule 3). */
520 for (i
= 0; i
< (int) sizeof (save_order
); ++i
)
522 reg
= sr
->curr
.reg
+ save_order
[i
];
523 if (reg
->where
== UNW_WHERE_GR_SAVE
)
525 reg
->where
= UNW_WHERE_GR
;
526 reg
->val
= sr
->gr_save_loc
++;
530 /* Next, compute when the fp, general, and branch registers get saved.
531 This must come before alloc_spill_area() because we need to know
532 which registers are spilled to their home locations. */
535 static unsigned char const limit
[3] = {
536 UNW_REG_F31
, UNW_REG_R7
, UNW_REG_B5
539 unsigned char kind
, mask
= 0, *cp
= sr
->imask
;
541 struct unw_reg_info
*(regs
[3]);
543 regs
[0] = sr
->curr
.reg
+ UNW_REG_F2
;
544 regs
[1] = sr
->curr
.reg
+ UNW_REG_R4
;
545 regs
[2] = sr
->curr
.reg
+ UNW_REG_B1
;
547 for (t
= 0; t
< sr
->region_len
; ++t
)
551 kind
= (mask
>> 2*(3-(t
& 3))) & 3;
553 spill_next_when (®s
[kind
- 1], sr
->curr
.reg
+ limit
[kind
- 1],
554 sr
->region_start
+ t
);
558 /* Next, lay out the memory stack spill area. */
561 off
= sr
->spill_offset
;
562 alloc_spill_area (&off
, 16, sr
->curr
.reg
+ UNW_REG_F2
,
563 sr
->curr
.reg
+ UNW_REG_F31
);
564 alloc_spill_area (&off
, 8, sr
->curr
.reg
+ UNW_REG_B1
,
565 sr
->curr
.reg
+ UNW_REG_B5
);
566 alloc_spill_area (&off
, 8, sr
->curr
.reg
+ UNW_REG_R4
,
567 sr
->curr
.reg
+ UNW_REG_R7
);
572 * Region header descriptors.
576 desc_prologue (int body
, unw_word rlen
, unsigned char mask
,
577 unsigned char grsave
, struct unw_state_record
*sr
)
581 if (!(sr
->in_body
|| sr
->first_region
))
582 finish_prologue (sr
);
583 sr
->first_region
= 0;
585 /* Check if we're done. */
586 if (sr
->when_target
< sr
->region_start
+ sr
->region_len
)
592 for (i
= 0; i
< sr
->epilogue_count
; ++i
)
595 sr
->epilogue_count
= 0;
596 sr
->epilogue_start
= UNW_WHEN_NEVER
;
601 sr
->region_start
+= sr
->region_len
;
602 sr
->region_len
= rlen
;
607 for (i
= 0; i
< 4; ++i
)
610 set_reg (sr
->curr
.reg
+ save_order
[i
], UNW_WHERE_GR
,
611 sr
->region_start
+ sr
->region_len
- 1, grsave
++);
614 sr
->gr_save_loc
= grsave
;
617 sr
->spill_offset
= 0x10; /* default to psp+16 */
622 * Prologue descriptors.
626 desc_abi (unsigned char abi
,
627 unsigned char context
,
628 struct unw_state_record
*sr
)
630 sr
->unwabi
= (abi
<< 8) | context
;
634 desc_br_gr (unsigned char brmask
, unsigned char gr
,
635 struct unw_state_record
*sr
)
639 for (i
= 0; i
< 5; ++i
)
642 set_reg (sr
->curr
.reg
+ UNW_REG_B1
+ i
, UNW_WHERE_GR
,
643 sr
->region_start
+ sr
->region_len
- 1, gr
++);
649 desc_br_mem (unsigned char brmask
, struct unw_state_record
*sr
)
653 for (i
= 0; i
< 5; ++i
)
657 set_reg (sr
->curr
.reg
+ UNW_REG_B1
+ i
, UNW_WHERE_SPILL_HOME
,
658 sr
->region_start
+ sr
->region_len
- 1, 0);
666 desc_frgr_mem (unsigned char grmask
, unw_word frmask
,
667 struct unw_state_record
*sr
)
671 for (i
= 0; i
< 4; ++i
)
673 if ((grmask
& 1) != 0)
675 set_reg (sr
->curr
.reg
+ UNW_REG_R4
+ i
, UNW_WHERE_SPILL_HOME
,
676 sr
->region_start
+ sr
->region_len
- 1, 0);
681 for (i
= 0; i
< 20; ++i
)
683 if ((frmask
& 1) != 0)
685 enum unw_register_index base
= i
< 4 ? UNW_REG_F2
: UNW_REG_F16
- 4;
686 set_reg (sr
->curr
.reg
+ base
+ i
, UNW_WHERE_SPILL_HOME
,
687 sr
->region_start
+ sr
->region_len
- 1, 0);
695 desc_fr_mem (unsigned char frmask
, struct unw_state_record
*sr
)
699 for (i
= 0; i
< 4; ++i
)
701 if ((frmask
& 1) != 0)
703 set_reg (sr
->curr
.reg
+ UNW_REG_F2
+ i
, UNW_WHERE_SPILL_HOME
,
704 sr
->region_start
+ sr
->region_len
- 1, 0);
712 desc_gr_gr (unsigned char grmask
, unsigned char gr
,
713 struct unw_state_record
*sr
)
717 for (i
= 0; i
< 4; ++i
)
719 if ((grmask
& 1) != 0)
720 set_reg (sr
->curr
.reg
+ UNW_REG_R4
+ i
, UNW_WHERE_GR
,
721 sr
->region_start
+ sr
->region_len
- 1, gr
++);
727 desc_gr_mem (unsigned char grmask
, struct unw_state_record
*sr
)
731 for (i
= 0; i
< 4; ++i
)
733 if ((grmask
& 1) != 0)
735 set_reg (sr
->curr
.reg
+ UNW_REG_R4
+ i
, UNW_WHERE_SPILL_HOME
,
736 sr
->region_start
+ sr
->region_len
- 1, 0);
744 desc_mem_stack_f (unw_word t
, unw_word size
, struct unw_state_record
*sr
)
746 set_reg (sr
->curr
.reg
+ UNW_REG_PSP
, UNW_WHERE_NONE
,
747 sr
->region_start
+ MIN ((int)t
, sr
->region_len
- 1), 16*size
);
751 desc_mem_stack_v (unw_word t
, struct unw_state_record
*sr
)
753 sr
->curr
.reg
[UNW_REG_PSP
].when
754 = sr
->region_start
+ MIN ((int)t
, sr
->region_len
- 1);
758 desc_reg_gr (unsigned char reg
, unsigned char dst
, struct unw_state_record
*sr
)
760 set_reg (sr
->curr
.reg
+ reg
, UNW_WHERE_GR
,
761 sr
->region_start
+ sr
->region_len
- 1, dst
);
765 desc_reg_psprel (unsigned char reg
, unw_word pspoff
,
766 struct unw_state_record
*sr
)
768 set_reg (sr
->curr
.reg
+ reg
, UNW_WHERE_PSPREL
,
769 sr
->region_start
+ sr
->region_len
- 1,
774 desc_reg_sprel (unsigned char reg
, unw_word spoff
, struct unw_state_record
*sr
)
776 set_reg (sr
->curr
.reg
+ reg
, UNW_WHERE_SPREL
,
777 sr
->region_start
+ sr
->region_len
- 1,
782 desc_rp_br (unsigned char dst
, struct unw_state_record
*sr
)
784 sr
->return_link_reg
= dst
;
788 desc_reg_when (unsigned char regnum
, unw_word t
, struct unw_state_record
*sr
)
790 struct unw_reg_info
*reg
= sr
->curr
.reg
+ regnum
;
792 if (reg
->where
== UNW_WHERE_NONE
)
793 reg
->where
= UNW_WHERE_GR_SAVE
;
794 reg
->when
= sr
->region_start
+ MIN ((int)t
, sr
->region_len
- 1);
798 desc_spill_base (unw_word pspoff
, struct unw_state_record
*sr
)
800 sr
->spill_offset
= 0x10 - 4*pspoff
;
803 static inline unsigned char *
804 desc_spill_mask (unsigned char *imaskp
, struct unw_state_record
*sr
)
807 return imaskp
+ (2*sr
->region_len
+ 7)/8;
814 desc_epilogue (unw_word t
, unw_word ecount
, struct unw_state_record
*sr
)
816 sr
->epilogue_start
= sr
->region_start
+ sr
->region_len
- 1 - t
;
817 sr
->epilogue_count
= ecount
+ 1;
821 desc_copy_state (unw_word label
, struct unw_state_record
*sr
)
823 struct unw_labeled_state
*ls
;
825 for (ls
= sr
->labeled_states
; ls
; ls
= ls
->next
)
827 if (ls
->label
== label
)
829 free_state_stack (&sr
->curr
);
830 memcpy (&sr
->curr
, &ls
->saved_state
, sizeof (sr
->curr
));
831 sr
->curr
.next
= dup_state_stack (ls
->saved_state
.next
);
839 desc_label_state (unw_word label
, struct unw_state_record
*sr
)
841 struct unw_labeled_state
*ls
= alloc_label_state ();
844 memcpy (&ls
->saved_state
, &sr
->curr
, sizeof (ls
->saved_state
));
845 ls
->saved_state
.next
= dup_state_stack (sr
->curr
.next
);
847 /* Insert into list of labeled states. */
848 ls
->next
= sr
->labeled_states
;
849 sr
->labeled_states
= ls
;
853 * General descriptors.
857 desc_is_active (unsigned char qp
, unw_word t
, struct unw_state_record
*sr
)
859 if (sr
->when_target
<= sr
->region_start
+ MIN ((int)t
, sr
->region_len
- 1))
863 if ((sr
->pr_val
& (1UL << qp
)) == 0)
865 sr
->pr_mask
|= (1UL << qp
);
871 desc_restore_p (unsigned char qp
, unw_word t
, unsigned char abreg
,
872 struct unw_state_record
*sr
)
874 struct unw_reg_info
*r
;
876 if (! desc_is_active (qp
, t
, sr
))
879 r
= sr
->curr
.reg
+ decode_abreg (abreg
, 0);
880 r
->where
= UNW_WHERE_NONE
;
881 r
->when
= sr
->region_start
+ MIN ((int)t
, sr
->region_len
- 1);
886 desc_spill_reg_p (unsigned char qp
, unw_word t
, unsigned char abreg
,
887 unsigned char x
, unsigned char ytreg
,
888 struct unw_state_record
*sr
)
890 enum unw_where where
= UNW_WHERE_GR
;
891 struct unw_reg_info
*r
;
893 if (! desc_is_active (qp
, t
, sr
))
897 where
= UNW_WHERE_BR
;
898 else if (ytreg
& 0x80)
899 where
= UNW_WHERE_FR
;
901 r
= sr
->curr
.reg
+ decode_abreg (abreg
, 0);
903 r
->when
= sr
->region_start
+ MIN ((int)t
, sr
->region_len
- 1);
904 r
->val
= ytreg
& 0x7f;
908 desc_spill_psprel_p (unsigned char qp
, unw_word t
, unsigned char abreg
,
909 unw_word pspoff
, struct unw_state_record
*sr
)
911 struct unw_reg_info
*r
;
913 if (! desc_is_active (qp
, t
, sr
))
916 r
= sr
->curr
.reg
+ decode_abreg (abreg
, 1);
917 r
->where
= UNW_WHERE_PSPREL
;
918 r
->when
= sr
->region_start
+ MIN((int)t
, sr
->region_len
- 1);
919 r
->val
= 0x10 - 4*pspoff
;
923 desc_spill_sprel_p (unsigned char qp
, unw_word t
, unsigned char abreg
,
924 unw_word spoff
, struct unw_state_record
*sr
)
926 struct unw_reg_info
*r
;
928 if (! desc_is_active (qp
, t
, sr
))
931 r
= sr
->curr
.reg
+ decode_abreg (abreg
, 1);
932 r
->where
= UNW_WHERE_SPREL
;
933 r
->when
= sr
->region_start
+ MIN ((int)t
, sr
->region_len
- 1);
938 #define UNW_DEC_BAD_CODE(code) abort ();
940 /* Region headers. */
941 #define UNW_DEC_PROLOGUE_GR(fmt,r,m,gr,arg) desc_prologue(0,r,m,gr,arg)
942 #define UNW_DEC_PROLOGUE(fmt,b,r,arg) desc_prologue(b,r,0,32,arg)
944 /* Prologue descriptors. */
945 #define UNW_DEC_ABI(fmt,a,c,arg) desc_abi(a,c,arg)
946 #define UNW_DEC_BR_GR(fmt,b,g,arg) desc_br_gr(b,g,arg)
947 #define UNW_DEC_BR_MEM(fmt,b,arg) desc_br_mem(b,arg)
948 #define UNW_DEC_FRGR_MEM(fmt,g,f,arg) desc_frgr_mem(g,f,arg)
949 #define UNW_DEC_FR_MEM(fmt,f,arg) desc_fr_mem(f,arg)
950 #define UNW_DEC_GR_GR(fmt,m,g,arg) desc_gr_gr(m,g,arg)
951 #define UNW_DEC_GR_MEM(fmt,m,arg) desc_gr_mem(m,arg)
952 #define UNW_DEC_MEM_STACK_F(fmt,t,s,arg) desc_mem_stack_f(t,s,arg)
953 #define UNW_DEC_MEM_STACK_V(fmt,t,arg) desc_mem_stack_v(t,arg)
954 #define UNW_DEC_REG_GR(fmt,r,d,arg) desc_reg_gr(r,d,arg)
955 #define UNW_DEC_REG_PSPREL(fmt,r,o,arg) desc_reg_psprel(r,o,arg)
956 #define UNW_DEC_REG_SPREL(fmt,r,o,arg) desc_reg_sprel(r,o,arg)
957 #define UNW_DEC_REG_WHEN(fmt,r,t,arg) desc_reg_when(r,t,arg)
958 #define UNW_DEC_PRIUNAT_WHEN_GR(fmt,t,arg) desc_reg_when(UNW_REG_PRI_UNAT_GR,t,arg)
959 #define UNW_DEC_PRIUNAT_WHEN_MEM(fmt,t,arg) desc_reg_when(UNW_REG_PRI_UNAT_MEM,t,arg)
960 #define UNW_DEC_PRIUNAT_GR(fmt,r,arg) desc_reg_gr(UNW_REG_PRI_UNAT_GR,r,arg)
961 #define UNW_DEC_PRIUNAT_PSPREL(fmt,o,arg) desc_reg_psprel(UNW_REG_PRI_UNAT_MEM,o,arg)
962 #define UNW_DEC_PRIUNAT_SPREL(fmt,o,arg) desc_reg_sprel(UNW_REG_PRI_UNAT_MEM,o,arg)
963 #define UNW_DEC_RP_BR(fmt,d,arg) desc_rp_br(d,arg)
964 #define UNW_DEC_SPILL_BASE(fmt,o,arg) desc_spill_base(o,arg)
965 #define UNW_DEC_SPILL_MASK(fmt,m,arg) (m = desc_spill_mask(m,arg))
967 /* Body descriptors. */
968 #define UNW_DEC_EPILOGUE(fmt,t,c,arg) desc_epilogue(t,c,arg)
969 #define UNW_DEC_COPY_STATE(fmt,l,arg) desc_copy_state(l,arg)
970 #define UNW_DEC_LABEL_STATE(fmt,l,arg) desc_label_state(l,arg)
972 /* General unwind descriptors. */
973 #define UNW_DEC_SPILL_REG_P(f,p,t,a,x,y,arg) desc_spill_reg_p(p,t,a,x,y,arg)
974 #define UNW_DEC_SPILL_REG(f,t,a,x,y,arg) desc_spill_reg_p(0,t,a,x,y,arg)
975 #define UNW_DEC_SPILL_PSPREL_P(f,p,t,a,o,arg) desc_spill_psprel_p(p,t,a,o,arg)
976 #define UNW_DEC_SPILL_PSPREL(f,t,a,o,arg) desc_spill_psprel_p(0,t,a,o,arg)
977 #define UNW_DEC_SPILL_SPREL_P(f,p,t,a,o,arg) desc_spill_sprel_p(p,t,a,o,arg)
978 #define UNW_DEC_SPILL_SPREL(f,t,a,o,arg) desc_spill_sprel_p(0,t,a,o,arg)
979 #define UNW_DEC_RESTORE_P(f,p,t,a,arg) desc_restore_p(p,t,a,arg)
980 #define UNW_DEC_RESTORE(f,t,a,arg) desc_restore_p(0,t,a,arg)
984 * Generic IA-64 unwind info decoder.
986 * This file is used both by the Linux kernel and objdump. Please keep
987 * the copies of this file in sync.
989 * You need to customize the decoder by defining the following
990 * macros/constants before including this file:
993 * unw_word Unsigned integer type with at least 64 bits
1007 * Decoder action macros:
1008 * UNW_DEC_BAD_CODE(code)
1009 * UNW_DEC_ABI(fmt,abi,context,arg)
1010 * UNW_DEC_BR_GR(fmt,brmask,gr,arg)
1011 * UNW_DEC_BR_MEM(fmt,brmask,arg)
1012 * UNW_DEC_COPY_STATE(fmt,label,arg)
1013 * UNW_DEC_EPILOGUE(fmt,t,ecount,arg)
1014 * UNW_DEC_FRGR_MEM(fmt,grmask,frmask,arg)
1015 * UNW_DEC_FR_MEM(fmt,frmask,arg)
1016 * UNW_DEC_GR_GR(fmt,grmask,gr,arg)
1017 * UNW_DEC_GR_MEM(fmt,grmask,arg)
1018 * UNW_DEC_LABEL_STATE(fmt,label,arg)
1019 * UNW_DEC_MEM_STACK_F(fmt,t,size,arg)
1020 * UNW_DEC_MEM_STACK_V(fmt,t,arg)
1021 * UNW_DEC_PRIUNAT_GR(fmt,r,arg)
1022 * UNW_DEC_PRIUNAT_WHEN_GR(fmt,t,arg)
1023 * UNW_DEC_PRIUNAT_WHEN_MEM(fmt,t,arg)
1024 * UNW_DEC_PRIUNAT_WHEN_PSPREL(fmt,pspoff,arg)
1025 * UNW_DEC_PRIUNAT_WHEN_SPREL(fmt,spoff,arg)
1026 * UNW_DEC_PROLOGUE(fmt,body,rlen,arg)
1027 * UNW_DEC_PROLOGUE_GR(fmt,rlen,mask,grsave,arg)
1028 * UNW_DEC_REG_PSPREL(fmt,reg,pspoff,arg)
1029 * UNW_DEC_REG_REG(fmt,src,dst,arg)
1030 * UNW_DEC_REG_SPREL(fmt,reg,spoff,arg)
1031 * UNW_DEC_REG_WHEN(fmt,reg,t,arg)
1032 * UNW_DEC_RESTORE(fmt,t,abreg,arg)
1033 * UNW_DEC_RESTORE_P(fmt,qp,t,abreg,arg)
1034 * UNW_DEC_SPILL_BASE(fmt,pspoff,arg)
1035 * UNW_DEC_SPILL_MASK(fmt,imaskp,arg)
1036 * UNW_DEC_SPILL_PSPREL(fmt,t,abreg,pspoff,arg)
1037 * UNW_DEC_SPILL_PSPREL_P(fmt,qp,t,abreg,pspoff,arg)
1038 * UNW_DEC_SPILL_REG(fmt,t,abreg,x,ytreg,arg)
1039 * UNW_DEC_SPILL_REG_P(fmt,qp,t,abreg,x,ytreg,arg)
1040 * UNW_DEC_SPILL_SPREL(fmt,t,abreg,spoff,arg)
1041 * UNW_DEC_SPILL_SPREL_P(fmt,qp,t,abreg,pspoff,arg)
1045 unw_decode_uleb128 (unsigned char **dpp
)
1048 unw_word byte
, result
= 0;
1049 unsigned char *bp
= *dpp
;
1054 result
|= (byte
& 0x7f) << shift
;
1055 if ((byte
& 0x80) == 0)
1063 static unsigned char *
1064 unw_decode_x1 (unsigned char *dp
,
1065 unsigned char code
__attribute__((unused
)),
1068 unsigned char byte1
, abreg
;
1072 t
= unw_decode_uleb128 (&dp
);
1073 off
= unw_decode_uleb128 (&dp
);
1074 abreg
= (byte1
& 0x7f);
1076 UNW_DEC_SPILL_SPREL(X1
, t
, abreg
, off
, arg
);
1078 UNW_DEC_SPILL_PSPREL(X1
, t
, abreg
, off
, arg
);
1082 static unsigned char *
1083 unw_decode_x2 (unsigned char *dp
,
1084 unsigned char code
__attribute__((unused
)),
1087 unsigned char byte1
, byte2
, abreg
, x
, ytreg
;
1090 byte1
= *dp
++; byte2
= *dp
++;
1091 t
= unw_decode_uleb128 (&dp
);
1092 abreg
= (byte1
& 0x7f);
1094 x
= (byte1
>> 7) & 1;
1095 if ((byte1
& 0x80) == 0 && ytreg
== 0)
1096 UNW_DEC_RESTORE(X2
, t
, abreg
, arg
);
1098 UNW_DEC_SPILL_REG(X2
, t
, abreg
, x
, ytreg
, arg
);
1102 static unsigned char *
1103 unw_decode_x3 (unsigned char *dp
,
1104 unsigned char code
__attribute__((unused
)),
1107 unsigned char byte1
, byte2
, abreg
, qp
;
1110 byte1
= *dp
++; byte2
= *dp
++;
1111 t
= unw_decode_uleb128 (&dp
);
1112 off
= unw_decode_uleb128 (&dp
);
1114 qp
= (byte1
& 0x3f);
1115 abreg
= (byte2
& 0x7f);
1118 UNW_DEC_SPILL_SPREL_P(X3
, qp
, t
, abreg
, off
, arg
);
1120 UNW_DEC_SPILL_PSPREL_P(X3
, qp
, t
, abreg
, off
, arg
);
1124 static unsigned char *
1125 unw_decode_x4 (unsigned char *dp
,
1126 unsigned char code
__attribute__((unused
)),
1129 unsigned char byte1
, byte2
, byte3
, qp
, abreg
, x
, ytreg
;
1132 byte1
= *dp
++; byte2
= *dp
++; byte3
= *dp
++;
1133 t
= unw_decode_uleb128 (&dp
);
1135 qp
= (byte1
& 0x3f);
1136 abreg
= (byte2
& 0x7f);
1137 x
= (byte2
>> 7) & 1;
1140 if ((byte2
& 0x80) == 0 && byte3
== 0)
1141 UNW_DEC_RESTORE_P(X4
, qp
, t
, abreg
, arg
);
1143 UNW_DEC_SPILL_REG_P(X4
, qp
, t
, abreg
, x
, ytreg
, arg
);
1147 static unsigned char *
1148 unw_decode_r1 (unsigned char *dp
, unsigned char code
, void *arg
)
1150 int body
= (code
& 0x20) != 0;
1153 rlen
= (code
& 0x1f);
1154 UNW_DEC_PROLOGUE(R1
, body
, rlen
, arg
);
1158 static unsigned char *
1159 unw_decode_r2 (unsigned char *dp
, unsigned char code
, void *arg
)
1161 unsigned char byte1
, mask
, grsave
;
1166 mask
= ((code
& 0x7) << 1) | ((byte1
>> 7) & 1);
1167 grsave
= (byte1
& 0x7f);
1168 rlen
= unw_decode_uleb128 (&dp
);
1169 UNW_DEC_PROLOGUE_GR(R2
, rlen
, mask
, grsave
, arg
);
1173 static unsigned char *
1174 unw_decode_r3 (unsigned char *dp
, unsigned char code
, void *arg
)
1178 rlen
= unw_decode_uleb128 (&dp
);
1179 UNW_DEC_PROLOGUE(R3
, ((code
& 0x3) == 1), rlen
, arg
);
1183 static unsigned char *
1184 unw_decode_p1 (unsigned char *dp
, unsigned char code
, void *arg
)
1186 unsigned char brmask
= (code
& 0x1f);
1188 UNW_DEC_BR_MEM(P1
, brmask
, arg
);
1192 static unsigned char *
1193 unw_decode_p2_p5 (unsigned char *dp
, unsigned char code
, void *arg
)
1195 if ((code
& 0x10) == 0)
1197 unsigned char byte1
= *dp
++;
1199 UNW_DEC_BR_GR(P2
, ((code
& 0xf) << 1) | ((byte1
>> 7) & 1),
1200 (byte1
& 0x7f), arg
);
1202 else if ((code
& 0x08) == 0)
1204 unsigned char byte1
= *dp
++, r
, dst
;
1206 r
= ((code
& 0x7) << 1) | ((byte1
>> 7) & 1);
1207 dst
= (byte1
& 0x7f);
1210 case 0: UNW_DEC_REG_GR(P3
, UNW_REG_PSP
, dst
, arg
); break;
1211 case 1: UNW_DEC_REG_GR(P3
, UNW_REG_RP
, dst
, arg
); break;
1212 case 2: UNW_DEC_REG_GR(P3
, UNW_REG_PFS
, dst
, arg
); break;
1213 case 3: UNW_DEC_REG_GR(P3
, UNW_REG_PR
, dst
, arg
); break;
1214 case 4: UNW_DEC_REG_GR(P3
, UNW_REG_UNAT
, dst
, arg
); break;
1215 case 5: UNW_DEC_REG_GR(P3
, UNW_REG_LC
, dst
, arg
); break;
1216 case 6: UNW_DEC_RP_BR(P3
, dst
, arg
); break;
1217 case 7: UNW_DEC_REG_GR(P3
, UNW_REG_RNAT
, dst
, arg
); break;
1218 case 8: UNW_DEC_REG_GR(P3
, UNW_REG_BSP
, dst
, arg
); break;
1219 case 9: UNW_DEC_REG_GR(P3
, UNW_REG_BSPSTORE
, dst
, arg
); break;
1220 case 10: UNW_DEC_REG_GR(P3
, UNW_REG_FPSR
, dst
, arg
); break;
1221 case 11: UNW_DEC_PRIUNAT_GR(P3
, dst
, arg
); break;
1222 default: UNW_DEC_BAD_CODE(r
); break;
1225 else if ((code
& 0x7) == 0)
1226 UNW_DEC_SPILL_MASK(P4
, dp
, arg
);
1227 else if ((code
& 0x7) == 1)
1229 unw_word grmask
, frmask
, byte1
, byte2
, byte3
;
1231 byte1
= *dp
++; byte2
= *dp
++; byte3
= *dp
++;
1232 grmask
= ((byte1
>> 4) & 0xf);
1233 frmask
= ((byte1
& 0xf) << 16) | (byte2
<< 8) | byte3
;
1234 UNW_DEC_FRGR_MEM(P5
, grmask
, frmask
, arg
);
1237 UNW_DEC_BAD_CODE(code
);
1241 static unsigned char *
1242 unw_decode_p6 (unsigned char *dp
, unsigned char code
, void *arg
)
1244 int gregs
= (code
& 0x10) != 0;
1245 unsigned char mask
= (code
& 0x0f);
1248 UNW_DEC_GR_MEM(P6
, mask
, arg
);
1250 UNW_DEC_FR_MEM(P6
, mask
, arg
);
1254 static unsigned char *
1255 unw_decode_p7_p10 (unsigned char *dp
, unsigned char code
, void *arg
)
1257 unsigned char r
, byte1
, byte2
;
1260 if ((code
& 0x10) == 0)
1263 t
= unw_decode_uleb128 (&dp
);
1267 size
= unw_decode_uleb128 (&dp
);
1268 UNW_DEC_MEM_STACK_F(P7
, t
, size
, arg
);
1271 case 1: UNW_DEC_MEM_STACK_V(P7
, t
, arg
); break;
1272 case 2: UNW_DEC_SPILL_BASE(P7
, t
, arg
); break;
1273 case 3: UNW_DEC_REG_SPREL(P7
, UNW_REG_PSP
, t
, arg
); break;
1274 case 4: UNW_DEC_REG_WHEN(P7
, UNW_REG_RP
, t
, arg
); break;
1275 case 5: UNW_DEC_REG_PSPREL(P7
, UNW_REG_RP
, t
, arg
); break;
1276 case 6: UNW_DEC_REG_WHEN(P7
, UNW_REG_PFS
, t
, arg
); break;
1277 case 7: UNW_DEC_REG_PSPREL(P7
, UNW_REG_PFS
, t
, arg
); break;
1278 case 8: UNW_DEC_REG_WHEN(P7
, UNW_REG_PR
, t
, arg
); break;
1279 case 9: UNW_DEC_REG_PSPREL(P7
, UNW_REG_PR
, t
, arg
); break;
1280 case 10: UNW_DEC_REG_WHEN(P7
, UNW_REG_LC
, t
, arg
); break;
1281 case 11: UNW_DEC_REG_PSPREL(P7
, UNW_REG_LC
, t
, arg
); break;
1282 case 12: UNW_DEC_REG_WHEN(P7
, UNW_REG_UNAT
, t
, arg
); break;
1283 case 13: UNW_DEC_REG_PSPREL(P7
, UNW_REG_UNAT
, t
, arg
); break;
1284 case 14: UNW_DEC_REG_WHEN(P7
, UNW_REG_FPSR
, t
, arg
); break;
1285 case 15: UNW_DEC_REG_PSPREL(P7
, UNW_REG_FPSR
, t
, arg
); break;
1286 default: UNW_DEC_BAD_CODE(r
); break;
1296 t
= unw_decode_uleb128 (&dp
);
1299 case 1: UNW_DEC_REG_SPREL(P8
, UNW_REG_RP
, t
, arg
); break;
1300 case 2: UNW_DEC_REG_SPREL(P8
, UNW_REG_PFS
, t
, arg
); break;
1301 case 3: UNW_DEC_REG_SPREL(P8
, UNW_REG_PR
, t
, arg
); break;
1302 case 4: UNW_DEC_REG_SPREL(P8
, UNW_REG_LC
, t
, arg
); break;
1303 case 5: UNW_DEC_REG_SPREL(P8
, UNW_REG_UNAT
, t
, arg
); break;
1304 case 6: UNW_DEC_REG_SPREL(P8
, UNW_REG_FPSR
, t
, arg
); break;
1305 case 7: UNW_DEC_REG_WHEN(P8
, UNW_REG_BSP
, t
, arg
); break;
1306 case 8: UNW_DEC_REG_PSPREL(P8
, UNW_REG_BSP
, t
, arg
); break;
1307 case 9: UNW_DEC_REG_SPREL(P8
, UNW_REG_BSP
, t
, arg
); break;
1308 case 10: UNW_DEC_REG_WHEN(P8
, UNW_REG_BSPSTORE
, t
, arg
); break;
1309 case 11: UNW_DEC_REG_PSPREL(P8
, UNW_REG_BSPSTORE
, t
, arg
); break;
1310 case 12: UNW_DEC_REG_SPREL(P8
, UNW_REG_BSPSTORE
, t
, arg
); break;
1311 case 13: UNW_DEC_REG_WHEN(P8
, UNW_REG_RNAT
, t
, arg
); break;
1312 case 14: UNW_DEC_REG_PSPREL(P8
, UNW_REG_RNAT
, t
, arg
); break;
1313 case 15: UNW_DEC_REG_SPREL(P8
, UNW_REG_RNAT
, t
, arg
); break;
1314 case 16: UNW_DEC_PRIUNAT_WHEN_GR(P8
, t
, arg
); break;
1315 case 17: UNW_DEC_PRIUNAT_PSPREL(P8
, t
, arg
); break;
1316 case 18: UNW_DEC_PRIUNAT_SPREL(P8
, t
, arg
); break;
1317 case 19: UNW_DEC_PRIUNAT_WHEN_MEM(P8
, t
, arg
); break;
1318 default: UNW_DEC_BAD_CODE(r
); break;
1324 byte1
= *dp
++; byte2
= *dp
++;
1325 UNW_DEC_GR_GR(P9
, (byte1
& 0xf), (byte2
& 0x7f), arg
);
1329 byte1
= *dp
++; byte2
= *dp
++;
1330 UNW_DEC_ABI(P10
, byte1
, byte2
, arg
);
1334 return unw_decode_x1 (dp
, code
, arg
);
1337 return unw_decode_x2 (dp
, code
, arg
);
1340 return unw_decode_x3 (dp
, code
, arg
);
1343 return unw_decode_x4 (dp
, code
, arg
);
1346 UNW_DEC_BAD_CODE(code
);
1353 static unsigned char *
1354 unw_decode_b1 (unsigned char *dp
, unsigned char code
, void *arg
)
1356 unw_word label
= (code
& 0x1f);
1358 if ((code
& 0x20) != 0)
1359 UNW_DEC_COPY_STATE(B1
, label
, arg
);
1361 UNW_DEC_LABEL_STATE(B1
, label
, arg
);
1365 static unsigned char *
1366 unw_decode_b2 (unsigned char *dp
, unsigned char code
, void *arg
)
1370 t
= unw_decode_uleb128 (&dp
);
1371 UNW_DEC_EPILOGUE(B2
, t
, (code
& 0x1f), arg
);
1375 static unsigned char *
1376 unw_decode_b3_x4 (unsigned char *dp
, unsigned char code
, void *arg
)
1378 unw_word t
, ecount
, label
;
1380 if ((code
& 0x10) == 0)
1382 t
= unw_decode_uleb128 (&dp
);
1383 ecount
= unw_decode_uleb128 (&dp
);
1384 UNW_DEC_EPILOGUE(B3
, t
, ecount
, arg
);
1386 else if ((code
& 0x07) == 0)
1388 label
= unw_decode_uleb128 (&dp
);
1389 if ((code
& 0x08) != 0)
1390 UNW_DEC_COPY_STATE(B4
, label
, arg
);
1392 UNW_DEC_LABEL_STATE(B4
, label
, arg
);
1397 case 1: return unw_decode_x1 (dp
, code
, arg
);
1398 case 2: return unw_decode_x2 (dp
, code
, arg
);
1399 case 3: return unw_decode_x3 (dp
, code
, arg
);
1400 case 4: return unw_decode_x4 (dp
, code
, arg
);
1401 default: UNW_DEC_BAD_CODE(code
); break;
1406 typedef unsigned char *(*unw_decoder
) (unsigned char *, unsigned char, void *);
1408 static const unw_decoder unw_decode_table
[2][8] =
1410 /* prologue table: */
1412 unw_decode_r1
, /* 0 */
1416 unw_decode_p1
, /* 4 */
1422 unw_decode_r1
, /* 0 */
1426 unw_decode_b1
, /* 4 */
1434 * Decode one descriptor and return address of next descriptor.
1436 static inline unsigned char *
1437 unw_decode (unsigned char *dp
, int inside_body
, void *arg
)
1439 unw_decoder decoder
;
1443 decoder
= unw_decode_table
[inside_body
][code
>> 5];
1444 dp
= (*decoder
) (dp
, code
, arg
);
1449 /* RSE helper functions. */
1451 static inline unsigned long
1452 ia64_rse_slot_num (unsigned long *addr
)
1454 return (((unsigned long) addr
) >> 3) & 0x3f;
1457 /* Return TRUE if ADDR is the address of an RNAT slot. */
1458 static inline unsigned long
1459 ia64_rse_is_rnat_slot (unsigned long *addr
)
1461 return ia64_rse_slot_num (addr
) == 0x3f;
1464 /* Returns the address of the RNAT slot that covers the slot at
1465 address SLOT_ADDR. */
1466 static inline unsigned long *
1467 ia64_rse_rnat_addr (unsigned long *slot_addr
)
1469 return (unsigned long *) ((unsigned long) slot_addr
| (0x3f << 3));
1472 /* Calculate the number of registers in the dirty partition starting at
1473 BSPSTORE with a size of DIRTY bytes. This isn't simply DIRTY
1474 divided by eight because the 64th slot is used to store ar.rnat. */
1475 static inline unsigned long
1476 ia64_rse_num_regs (unsigned long *bspstore
, unsigned long *bsp
)
1478 unsigned long slots
= (bsp
- bspstore
);
1480 return slots
- (ia64_rse_slot_num (bspstore
) + slots
)/0x40;
1483 /* The inverse of the above: given bspstore and the number of
1484 registers, calculate ar.bsp. */
1485 static inline unsigned long *
1486 ia64_rse_skip_regs (unsigned long *addr
, long num_regs
)
1488 long delta
= ia64_rse_slot_num (addr
) + num_regs
;
1492 return addr
+ num_regs
+ delta
/0x3f;
1496 /* Copy register backing store from SRC to DST, LEN words
1497 (which include both saved registers and nat collections).
1498 DST_RNAT is a partial nat collection for DST. SRC and DST
1499 don't have to be equal modulo 64 slots, so it cannot be
1500 done with a simple memcpy as the nat collections will be
1501 at different relative offsets and need to be combined together. */
1503 ia64_copy_rbs (struct _Unwind_Context
*info
, unsigned long dst
,
1504 unsigned long src
, long len
, unsigned long dst_rnat
)
1507 unsigned long src_rnat
;
1508 unsigned long shift1
, shift2
;
1511 dst_rnat
&= (1UL << ((dst
>> 3) & 0x3f)) - 1;
1512 src_rnat
= src
>= info
->regstk_top
1513 ? info
->rnat
: *(unsigned long *) (src
| 0x1f8);
1514 src_rnat
&= ~((1UL << ((src
>> 3) & 0x3f)) - 1);
1515 /* Just to make sure. */
1516 src_rnat
&= ~(1UL << 63);
1517 shift1
= ((dst
- src
) >> 3) & 0x3f;
1518 if ((dst
& 0x1f8) < (src
& 0x1f8))
1520 shift2
= 0x3f - shift1
;
1521 if ((dst
& 0x1f8) >= (src
& 0x1f8))
1523 count
= ~dst
& 0x1f8;
1526 count
= ~src
& 0x1f8;
1530 src_rnat
= src
>= info
->regstk_top
1531 ? info
->rnat
: *(unsigned long *) (src
| 0x1f8);
1532 /* Just to make sure. */
1533 src_rnat
&= ~(1UL << 63);
1534 count
= shift2
<< 3;
1538 memcpy ((char *) dst
, (char *) src
, count
);
1542 dst_rnat
|= (src_rnat
<< shift1
) & ~(1UL << 63);
1545 *(long *) dst
= dst_rnat
;
1548 count
= shift1
<< 3;
1552 memcpy ((char *) dst
, (char *) src
, count
);
1556 dst_rnat
|= (src_rnat
>> shift2
);
1558 if ((dst
& 0x1f8) == 0x1f8)
1560 *(long *) dst
= dst_rnat
;
1564 /* Set info->regstk_top to lowest rbs address which will use
1565 info->rnat collection. */
1566 info
->regstk_top
= dst
& ~0x1ffUL
;
1567 info
->rnat
= dst_rnat
;
1570 /* Unwind accessors. */
1573 unw_access_gr (struct _Unwind_Context
*info
, int regnum
,
1574 unsigned long *val
, char *nat
, int write
)
1576 unsigned long *addr
, *nat_addr
= 0, nat_mask
= 0, dummy_nat
;
1577 struct unw_ireg
*ireg
;
1579 if ((unsigned) regnum
- 1 >= 127)
1584 nat_addr
= addr
= &dummy_nat
;
1587 else if (regnum
< 32)
1589 /* Access a non-stacked register. */
1590 ireg
= &info
->ireg
[regnum
- 2];
1594 nat_addr
= addr
+ ireg
->nat
.off
;
1595 switch (ireg
->nat
.type
)
1598 /* Simulate getf.sig/setf.sig. */
1603 /* Write NaTVal and be done with it. */
1610 else if (addr
[0] == 0 && addr
[1] == 0x1ffe)
1612 /* Return NaT and be done with it. */
1621 nat_addr
= &dummy_nat
;
1624 case UNW_NAT_MEMSTK
:
1625 nat_mask
= 1UL << ((long) addr
& 0x1f8)/8;
1628 case UNW_NAT_REGSTK
:
1629 if ((unsigned long) addr
>= info
->regstk_top
)
1630 nat_addr
= &info
->rnat
;
1632 nat_addr
= ia64_rse_rnat_addr (addr
);
1633 nat_mask
= 1UL << ia64_rse_slot_num (addr
);
1640 /* Access a stacked register. */
1641 addr
= ia64_rse_skip_regs ((unsigned long *) info
->bsp
, regnum
- 32);
1642 if ((unsigned long) addr
>= info
->regstk_top
)
1643 nat_addr
= &info
->rnat
;
1645 nat_addr
= ia64_rse_rnat_addr (addr
);
1646 nat_mask
= 1UL << ia64_rse_slot_num (addr
);
1653 *nat_addr
|= nat_mask
;
1655 *nat_addr
&= ~nat_mask
;
1660 *nat
= (*nat_addr
& nat_mask
) != 0;
1664 /* Get the value of register REG as saved in CONTEXT. */
1667 _Unwind_GetGR (struct _Unwind_Context
*context
, int index
)
1674 else if (index
>= 15 && index
<= 18)
1675 return context
->eh_data
[index
- 15];
1677 unw_access_gr (context
, index
, &ret
, &nat
, 0);
1682 /* Overwrite the saved value for register REG in CONTEXT with VAL. */
1685 _Unwind_SetGR (struct _Unwind_Context
*context
, int index
, _Unwind_Word val
)
1691 else if (index
>= 15 && index
<= 18)
1692 context
->eh_data
[index
- 15] = val
;
1694 unw_access_gr (context
, index
, &val
, &nat
, 1);
1697 /* Retrieve the return address for CONTEXT. */
1700 _Unwind_GetIP (struct _Unwind_Context
*context
)
1706 _Unwind_GetIPInfo (struct _Unwind_Context
*context
, int *ip_before_insn
)
1708 *ip_before_insn
= 0;
1712 /* Overwrite the return address for CONTEXT with VAL. */
1715 _Unwind_SetIP (struct _Unwind_Context
*context
, _Unwind_Ptr val
)
1721 _Unwind_GetLanguageSpecificData (struct _Unwind_Context
*context
)
1723 return context
->lsda
;
1727 _Unwind_GetRegionStart (struct _Unwind_Context
*context
)
1729 return context
->region_start
;
1733 _Unwind_FindEnclosingFunction (void *pc
)
1735 struct unw_table_entry
*entp
, ent
;
1736 unsigned long segment_base
, gp
;
1738 entp
= _Unwind_FindTableEntry (pc
, &segment_base
, &gp
, &ent
);
1742 return (void *)(segment_base
+ entp
->start_offset
);
1745 /* Get the value of the CFA as saved in CONTEXT. In GCC/Dwarf2 parlance,
1746 the CFA is the value of the stack pointer on entry; In IA-64 unwind
1747 parlance, this is the PSP. */
1750 _Unwind_GetCFA (struct _Unwind_Context
*context
)
1752 return (_Unwind_Ptr
) context
->psp
;
1755 /* Get the value of the Backing Store Pointer as saved in CONTEXT. */
1758 _Unwind_GetBSP (struct _Unwind_Context
*context
)
1760 return (_Unwind_Ptr
) context
->bsp
;
1763 #include "md-unwind-support.h"
1765 /* By default, assume personality routine interface compatibility with
1766 our expectations. */
1767 #ifndef MD_UNW_COMPATIBLE_PERSONALITY_P
1768 #define MD_UNW_COMPATIBLE_PERSONALITY_P(HEADER) 1
1772 static _Unwind_Reason_Code
1773 uw_frame_state_for (struct _Unwind_Context
*context
, _Unwind_FrameState
*fs
)
1775 struct unw_table_entry
*entp
, ent
;
1776 unsigned long *unw
, header
, length
;
1777 unsigned char *insn
, *insn_end
;
1778 unsigned long segment_base
;
1779 struct unw_reg_info
*r
;
1781 memset (fs
, 0, sizeof (*fs
));
1782 for (r
= fs
->curr
.reg
; r
< fs
->curr
.reg
+ UNW_NUM_REGS
; ++r
)
1783 r
->when
= UNW_WHEN_NEVER
;
1786 entp
= _Unwind_FindTableEntry ((void *) context
->rp
,
1787 &segment_base
, &context
->gp
, &ent
);
1790 /* Couldn't find unwind info for this function. Try an
1791 os-specific fallback mechanism. This will necessarily
1792 not provide a personality routine or LSDA. */
1793 #ifdef MD_FALLBACK_FRAME_STATE_FOR
1794 if (MD_FALLBACK_FRAME_STATE_FOR (context
, fs
) == _URC_NO_REASON
)
1795 return _URC_NO_REASON
;
1798 /* [SCRA 11.4.1] A leaf function with no memory stack, no exception
1799 handlers, and which keeps the return value in B0 does not need
1800 an unwind table entry.
1802 This can only happen in the frame after unwinding through a signal
1803 handler. Avoid infinite looping by requiring that B0 != RP.
1804 RP == 0 terminates the chain. */
1805 if (context
->br_loc
[0]
1806 && *context
->br_loc
[0] != context
->rp
1807 && context
->rp
!= 0)
1808 goto skip_unwind_info
;
1810 return _URC_END_OF_STACK
;
1813 context
->region_start
= entp
->start_offset
+ segment_base
;
1814 fs
->when_target
= ((context
->rp
& -16) - context
->region_start
) / 16 * 3
1815 + (context
->rp
& 15);
1817 unw
= (unsigned long *) (entp
->info_offset
+ segment_base
);
1819 length
= UNW_LENGTH (header
);
1821 /* Some operating systems use the personality routine slot in way not
1822 compatible with what we expect. For instance, OpenVMS uses this slot to
1823 designate "condition handlers" with very different arguments than what we
1824 would be providing. Such cases are typically identified from OS specific
1825 bits in the unwind information block header, and checked by the target
1826 MD_UNW_COMPATIBLE_PERSONALITY_P macro.
1828 We just pretend there is no personality from our standpoint in such
1829 situations, and expect GCC not to set the identifying bits itself so that
1830 compatible personalities for GCC compiled code are called.
1832 Of course, this raises the question of what combinations of native/GCC
1833 calls can be expected to behave properly exception handling-wise. We are
1834 not to provide a magic answer here, merely to prevent crashes assuming
1835 users know what they are doing.
1837 ??? Perhaps check UNW_VER / UNW_FLAG_OSMASK as well. */
1839 if (MD_UNW_COMPATIBLE_PERSONALITY_P (header
)
1840 && (UNW_FLAG_EHANDLER (header
) | UNW_FLAG_UHANDLER (header
)))
1843 *(_Unwind_Personality_Fn
*) (unw
[length
+ 1] + context
->gp
);
1844 context
->lsda
= unw
+ length
+ 2;
1847 insn
= (unsigned char *) (unw
+ 1);
1848 insn_end
= (unsigned char *) (unw
+ 1 + length
);
1849 while (!fs
->done
&& insn
< insn_end
)
1850 insn
= unw_decode (insn
, fs
->in_body
, fs
);
1852 free_label_states (fs
->labeled_states
);
1853 free_state_stack (&fs
->curr
);
1855 #ifdef ENABLE_MALLOC_CHECKING
1856 if (reg_state_alloced
|| labeled_state_alloced
)
1860 /* If we're in the epilogue, sp has been restored and all values
1861 on the memory stack below psp also have been restored. */
1862 if (fs
->when_target
> fs
->epilogue_start
)
1864 struct unw_reg_info
*r
;
1866 fs
->curr
.reg
[UNW_REG_PSP
].where
= UNW_WHERE_NONE
;
1867 fs
->curr
.reg
[UNW_REG_PSP
].val
= 0;
1868 for (r
= fs
->curr
.reg
; r
< fs
->curr
.reg
+ UNW_NUM_REGS
; ++r
)
1869 if ((r
->where
== UNW_WHERE_PSPREL
&& r
->val
<= 0x10)
1870 || r
->where
== UNW_WHERE_SPREL
)
1871 r
->where
= UNW_WHERE_NONE
;
1875 /* If RP didn't get saved, generate entry for the return link register. */
1876 if (fs
->curr
.reg
[UNW_REG_RP
].when
>= fs
->when_target
)
1878 fs
->curr
.reg
[UNW_REG_RP
].where
= UNW_WHERE_BR
;
1879 fs
->curr
.reg
[UNW_REG_RP
].when
= -1;
1880 fs
->curr
.reg
[UNW_REG_RP
].val
= fs
->return_link_reg
;
1883 /* There is a subtlety for the frame after unwinding through a signal
1884 handler: should we restore the cfm as usual or the pfs? We can't
1885 restore both because we use br.ret to resume execution of user code.
1886 For other frames the procedure is by definition non-leaf so the pfs
1887 is saved and restored and thus effectively dead in the body; only
1888 the cfm need therefore be restored.
1890 Here we have 2 cases:
1891 - either the pfs is saved and restored and thus effectively dead
1892 like in regular frames; then we do nothing special and restore
1894 - or the pfs is not saved and thus live; but in that case the
1895 procedure is necessarily leaf so the cfm is effectively dead
1896 and we restore the pfs. */
1897 if (context
->signal_pfs_loc
)
1899 if (fs
->curr
.reg
[UNW_REG_PFS
].when
>= fs
->when_target
)
1900 context
->pfs_loc
= context
->signal_pfs_loc
;
1901 context
->signal_pfs_loc
= NULL
;
1904 return _URC_NO_REASON
;
1908 uw_update_reg_address (struct _Unwind_Context
*context
,
1909 _Unwind_FrameState
*fs
,
1910 enum unw_register_index regno
)
1912 struct unw_reg_info
*r
= fs
->curr
.reg
+ regno
;
1916 if (r
->where
== UNW_WHERE_NONE
|| r
->when
>= fs
->when_target
)
1924 addr
= ia64_rse_skip_regs ((unsigned long *) context
->bsp
, rval
- 32);
1926 addr
= context
->ireg
[rval
- 2].loc
;
1929 static const unsigned long dummy
;
1930 addr
= (void *) &dummy
;
1937 if (rval
>= 2 && rval
< 32)
1938 addr
= context
->fr_loc
[rval
- 2];
1944 /* Note that while RVAL can only be 1-5 from normal descriptors,
1945 we can want to look at B0, B6 and B7 due to having manually unwound a
1948 addr
= context
->br_loc
[rval
];
1953 case UNW_WHERE_SPREL
:
1954 addr
= (void *)(context
->sp
+ rval
);
1957 case UNW_WHERE_PSPREL
:
1958 addr
= (void *)(context
->psp
+ rval
);
1967 case UNW_REG_R2
... UNW_REG_R31
:
1968 context
->ireg
[regno
- UNW_REG_R2
].loc
= addr
;
1974 context
->ireg
[regno
- UNW_REG_R2
].nat
.type
= UNW_NAT_MEMSTK
;
1975 context
->ireg
[regno
- UNW_REG_R2
].nat
.off
1976 = context
->pri_unat_loc
- (unsigned long *) addr
;
1980 context
->ireg
[regno
- UNW_REG_R2
].nat
1981 = context
->ireg
[rval
- 2].nat
;
1985 context
->ireg
[regno
- UNW_REG_R2
].nat
.type
= UNW_NAT_NONE
;
1986 context
->ireg
[regno
- UNW_REG_R2
].nat
.off
= 0;
1993 context
->ireg
[regno
- UNW_REG_R2
].nat
.type
= UNW_NAT_VAL
;
1994 context
->ireg
[regno
- UNW_REG_R2
].nat
.off
= 0;
1998 context
->ireg
[regno
- UNW_REG_R2
].nat
.type
= UNW_NAT_NONE
;
1999 context
->ireg
[regno
- UNW_REG_R2
].nat
.off
= 0;
2002 case UNW_WHERE_PSPREL
:
2003 case UNW_WHERE_SPREL
:
2004 context
->ireg
[regno
- UNW_REG_R2
].nat
.type
= UNW_NAT_MEMSTK
;
2005 context
->ireg
[regno
- UNW_REG_R2
].nat
.off
2006 = context
->pri_unat_loc
- (unsigned long *) addr
;
2014 case UNW_REG_F2
... UNW_REG_F31
:
2015 context
->fr_loc
[regno
- UNW_REG_F2
] = addr
;
2018 case UNW_REG_B1
... UNW_REG_B5
:
2019 context
->br_loc
[regno
- UNW_REG_B0
] = addr
;
2023 context
->bsp_loc
= addr
;
2025 case UNW_REG_BSPSTORE
:
2026 context
->bspstore_loc
= addr
;
2029 context
->pfs_loc
= addr
;
2032 context
->rp
= *(unsigned long *)addr
;
2035 context
->unat_loc
= addr
;
2038 context
->pr
= *(unsigned long *) addr
;
2041 context
->lc_loc
= addr
;
2044 context
->fpsr_loc
= addr
;
2048 context
->psp
= *(unsigned long *)addr
;
2057 uw_update_context (struct _Unwind_Context
*context
, _Unwind_FrameState
*fs
)
2061 #ifdef MD_HANDLE_UNWABI
2062 MD_HANDLE_UNWABI (context
, fs
);
2065 context
->sp
= context
->psp
;
2067 /* First, set PSP. Subsequent instructions may depend on this value. */
2068 if (fs
->when_target
> fs
->curr
.reg
[UNW_REG_PSP
].when
)
2070 if (fs
->curr
.reg
[UNW_REG_PSP
].where
== UNW_WHERE_NONE
)
2071 context
->psp
= context
->psp
+ fs
->curr
.reg
[UNW_REG_PSP
].val
;
2073 uw_update_reg_address (context
, fs
, UNW_REG_PSP
);
2076 /* Determine the location of the primary UNaT. */
2079 if (fs
->when_target
< fs
->curr
.reg
[UNW_REG_PRI_UNAT_GR
].when
)
2080 i
= UNW_REG_PRI_UNAT_MEM
;
2081 else if (fs
->when_target
< fs
->curr
.reg
[UNW_REG_PRI_UNAT_MEM
].when
)
2082 i
= UNW_REG_PRI_UNAT_GR
;
2083 else if (fs
->curr
.reg
[UNW_REG_PRI_UNAT_MEM
].when
2084 > fs
->curr
.reg
[UNW_REG_PRI_UNAT_GR
].when
)
2085 i
= UNW_REG_PRI_UNAT_MEM
;
2087 i
= UNW_REG_PRI_UNAT_GR
;
2088 uw_update_reg_address (context
, fs
, i
);
2091 /* Compute the addresses of all registers saved in this frame. */
2092 for (i
= UNW_REG_BSP
; i
< UNW_NUM_REGS
; ++i
)
2093 uw_update_reg_address (context
, fs
, i
);
2095 /* Unwind BSP for the local registers allocated this frame. */
2096 /* ??? What to do with stored BSP or BSPSTORE registers. */
2097 /* We assert that we are either at a call site, or we have
2098 just unwound through a signal frame. In either case
2099 pfs_loc is valid. */
2100 if (!(fs
-> no_reg_stack_frame
))
2102 unsigned long pfs
= *context
->pfs_loc
;
2103 unsigned long sol
= (pfs
>> 7) & 0x7f;
2104 context
->bsp
= (unsigned long)
2105 ia64_rse_skip_regs ((unsigned long *) context
->bsp
, -sol
);
2110 uw_advance_context (struct _Unwind_Context
*context
, _Unwind_FrameState
*fs
)
2112 uw_update_context (context
, fs
);
2115 /* Fill in CONTEXT for top-of-stack. The only valid registers at this
2116 level will be the return address and the CFA. Note that CFA = SP+16. */
2118 #define uw_init_context(CONTEXT) \
2120 /* ??? There is a whole lot o code in uw_install_context that \
2121 tries to avoid spilling the entire machine state here. We \
2122 should try to make that work again. */ \
2123 __builtin_unwind_init(); \
2124 uw_init_context_1 (CONTEXT, __builtin_ia64_bsp ()); \
2127 static void __attribute__((noinline
))
2128 uw_init_context_1 (struct _Unwind_Context
*context
, void *bsp
)
2130 void *rp
= __builtin_extract_return_addr (__builtin_return_address (0));
2131 /* Set psp to the caller's stack pointer. */
2132 void *psp
= __builtin_dwarf_cfa () - 16;
2133 _Unwind_FrameState fs
;
2134 unsigned long rnat
, tmp1
, tmp2
;
2136 /* Flush the register stack to memory so that we can access it.
2137 Get rse nat collection for the last incomplete rbs chunk of
2138 registers at the same time. For this RSE needs to be turned
2139 into the mandatory only mode. */
2140 asm ("mov.m %1 = ar.rsc;;\n\t"
2141 "and %2 = 0x1c, %1;;\n\t"
2142 "mov.m ar.rsc = %2;;\n\t"
2144 "mov.m %0 = ar.rnat;;\n\t"
2145 "mov.m ar.rsc = %1\n\t"
2146 : "=r" (rnat
), "=r" (tmp1
), "=r" (tmp2
));
2148 memset (context
, 0, sizeof (struct _Unwind_Context
));
2149 context
->bsp
= (unsigned long) bsp
;
2150 /* Set context->regstk_top to lowest rbs address which will use
2151 context->rnat collection. */
2152 context
->regstk_top
= context
->bsp
& ~0x1ffULL
;
2153 context
->rnat
= rnat
;
2154 context
->psp
= (unsigned long) psp
;
2155 context
->rp
= (unsigned long) rp
;
2156 asm ("mov %0 = sp" : "=r" (context
->sp
));
2157 asm ("mov %0 = pr" : "=r" (context
->pr
));
2158 context
->pri_unat_loc
= &context
->initial_unat
; /* ??? */
2160 if (uw_frame_state_for (context
, &fs
) != _URC_NO_REASON
)
2163 uw_update_context (context
, &fs
);
2166 /* Install (i.e. longjmp to) the contents of TARGET. */
2168 static void __attribute__((noreturn
))
2169 uw_install_context (struct _Unwind_Context
*current
__attribute__((unused
)),
2170 struct _Unwind_Context
*target
)
2172 unsigned long ireg_buf
[4], ireg_nat
= 0, ireg_pr
= 0;
2175 /* Copy integer register data from the target context to a
2176 temporary buffer. Do this so that we can frob AR.UNAT
2177 to get the NaT bits for these registers set properly. */
2178 for (i
= 4; i
<= 7; ++i
)
2181 void *t
= target
->ireg
[i
- 2].loc
;
2184 unw_access_gr (target
, i
, &ireg_buf
[i
- 4], &nat
, 0);
2185 ireg_nat
|= (long)nat
<< (((size_t)&ireg_buf
[i
- 4] >> 3) & 0x3f);
2191 /* The value in uc_bsp that we've computed is that for the
2192 target function. The value that we install below will be
2193 adjusted by the BR.RET instruction based on the contents
2194 of AR.PFS. So we must unadjust that here. */
2195 target
->bsp
= (unsigned long)
2196 ia64_rse_skip_regs ((unsigned long *)target
->bsp
,
2197 (*target
->pfs_loc
>> 7) & 0x7f);
2199 if (target
->bsp
< target
->regstk_top
)
2200 target
->rnat
= *ia64_rse_rnat_addr ((unsigned long *) target
->bsp
);
2202 /* Provide assembly with the offsets into the _Unwind_Context. */
2203 asm volatile ("uc_rnat = %0"
2204 : : "i"(offsetof (struct _Unwind_Context
, rnat
)));
2205 asm volatile ("uc_bsp = %0"
2206 : : "i"(offsetof (struct _Unwind_Context
, bsp
)));
2207 asm volatile ("uc_psp = %0"
2208 : : "i"(offsetof (struct _Unwind_Context
, psp
)));
2209 asm volatile ("uc_rp = %0"
2210 : : "i"(offsetof (struct _Unwind_Context
, rp
)));
2211 asm volatile ("uc_pr = %0"
2212 : : "i"(offsetof (struct _Unwind_Context
, pr
)));
2213 asm volatile ("uc_gp = %0"
2214 : : "i"(offsetof (struct _Unwind_Context
, gp
)));
2215 asm volatile ("uc_pfs_loc = %0"
2216 : : "i"(offsetof (struct _Unwind_Context
, pfs_loc
)));
2217 asm volatile ("uc_unat_loc = %0"
2218 : : "i"(offsetof (struct _Unwind_Context
, unat_loc
)));
2219 asm volatile ("uc_lc_loc = %0"
2220 : : "i"(offsetof (struct _Unwind_Context
, lc_loc
)));
2221 asm volatile ("uc_fpsr_loc = %0"
2222 : : "i"(offsetof (struct _Unwind_Context
, fpsr_loc
)));
2223 asm volatile ("uc_eh_data = %0"
2224 : : "i"(offsetof (struct _Unwind_Context
, eh_data
)));
2225 asm volatile ("uc_br_loc = %0"
2226 : : "i"(offsetof (struct _Unwind_Context
, br_loc
)));
2227 asm volatile ("uc_fr_loc = %0"
2228 : : "i"(offsetof (struct _Unwind_Context
, fr_loc
)));
2231 /* Load up call-saved non-window integer registers from ireg_buf. */
2232 "add r20 = 8, %1 \n\t"
2233 "mov ar.unat = %2 \n\t"
2234 "mov pr = %3, 0x3c0 \n\t"
2236 "(p6) ld8.fill r4 = [%1] \n\t"
2237 "(p7) ld8.fill r5 = [r20] \n\t"
2238 "add r21 = uc_br_loc + 16, %0 \n\t"
2239 "adds %1 = 16, %1 \n\t"
2240 "adds r20 = 16, r20 \n\t"
2242 "(p8) ld8.fill r6 = [%1] \n\t"
2243 "(p9) ld8.fill r7 = [r20] \n\t"
2244 "add r20 = uc_br_loc + 8, %0 \n\t"
2246 /* Load up call-saved branch registers. */
2247 "ld8 r22 = [r20], 16 \n\t"
2248 "ld8 r23 = [r21], 16 \n\t"
2250 "ld8 r24 = [r20], 16 \n\t"
2251 "ld8 r25 = [r21], uc_fr_loc - (uc_br_loc + 32)\n\t"
2253 "ld8 r26 = [r20], uc_fr_loc + 8 - (uc_br_loc + 40)\n\t"
2254 "ld8 r27 = [r21], 24 \n\t"
2255 "cmp.ne p6, p0 = r0, r22 \n\t"
2257 "ld8 r28 = [r20], 8 \n\t"
2258 "(p6) ld8 r22 = [r22] \n\t"
2259 "cmp.ne p7, p0 = r0, r23 \n\t"
2261 "(p7) ld8 r23 = [r23] \n\t"
2262 "cmp.ne p8, p0 = r0, r24 \n\t"
2264 "(p8) ld8 r24 = [r24] \n\t"
2265 "(p6) mov b1 = r22 \n\t"
2266 "cmp.ne p9, p0 = r0, r25 \n\t"
2268 "(p9) ld8 r25 = [r25] \n\t"
2269 "(p7) mov b2 = r23 \n\t"
2270 "cmp.ne p6, p0 = r0, r26 \n\t"
2272 "(p6) ld8 r26 = [r26] \n\t"
2273 "(p8) mov b3 = r24 \n\t"
2274 "cmp.ne p7, p0 = r0, r27 \n\t"
2276 /* Load up call-saved fp registers. */
2277 "(p7) ldf.fill f2 = [r27] \n\t"
2278 "(p9) mov b4 = r25 \n\t"
2279 "cmp.ne p8, p0 = r0, r28 \n\t"
2281 "(p8) ldf.fill f3 = [r28] \n\t"
2282 "(p6) mov b5 = r26 \n\t"
2284 "ld8 r29 = [r20], 16*8 - 4*8 \n\t"
2285 "ld8 r30 = [r21], 17*8 - 5*8 \n\t"
2287 "ld8 r22 = [r20], 16 \n\t"
2288 "ld8 r23 = [r21], 16 \n\t"
2290 "ld8 r24 = [r20], 16 \n\t"
2291 "ld8 r25 = [r21] \n\t"
2292 "cmp.ne p6, p0 = r0, r29 \n\t"
2294 "ld8 r26 = [r20], 8 \n\t"
2295 "(p6) ldf.fill f4 = [r29] \n\t"
2296 "cmp.ne p7, p0 = r0, r30 \n\t"
2298 "ld8 r27 = [r20], 8 \n\t"
2299 "(p7) ldf.fill f5 = [r30] \n\t"
2300 "cmp.ne p6, p0 = r0, r22 \n\t"
2302 "ld8 r28 = [r20], 8 \n\t"
2303 "(p6) ldf.fill f16 = [r22] \n\t"
2304 "cmp.ne p7, p0 = r0, r23 \n\t"
2306 "ld8 r29 = [r20], 8 \n\t"
2307 "(p7) ldf.fill f17 = [r23] \n\t"
2308 "cmp.ne p6, p0 = r0, r24 \n\t"
2310 "ld8 r22 = [r20], 8 \n\t"
2311 "(p6) ldf.fill f18 = [r24] \n\t"
2312 "cmp.ne p7, p0 = r0, r25 \n\t"
2314 "ld8 r23 = [r20], 8 \n\t"
2315 "(p7) ldf.fill f19 = [r25] \n\t"
2316 "cmp.ne p6, p0 = r0, r26 \n\t"
2318 "ld8 r24 = [r20], 8 \n\t"
2319 "(p6) ldf.fill f20 = [r26] \n\t"
2320 "cmp.ne p7, p0 = r0, r27 \n\t"
2322 "ld8 r25 = [r20], 8 \n\t"
2323 "(p7) ldf.fill f21 = [r27] \n\t"
2324 "cmp.ne p6, p0 = r0, r28 \n\t"
2326 "ld8 r26 = [r20], 8 \n\t"
2327 "(p6) ldf.fill f22 = [r28] \n\t"
2328 "cmp.ne p7, p0 = r0, r29 \n\t"
2330 "ld8 r27 = [r20], 8 \n\t"
2332 "ld8 r28 = [r20], 8 \n\t"
2333 "(p7) ldf.fill f23 = [r29] \n\t"
2334 "cmp.ne p6, p0 = r0, r22 \n\t"
2336 "ld8 r29 = [r20], 8 \n\t"
2337 "(p6) ldf.fill f24 = [r22] \n\t"
2338 "cmp.ne p7, p0 = r0, r23 \n\t"
2340 "(p7) ldf.fill f25 = [r23] \n\t"
2341 "cmp.ne p6, p0 = r0, r24 \n\t"
2342 "cmp.ne p7, p0 = r0, r25 \n\t"
2344 "(p6) ldf.fill f26 = [r24] \n\t"
2345 "(p7) ldf.fill f27 = [r25] \n\t"
2346 "cmp.ne p6, p0 = r0, r26 \n\t"
2348 "(p6) ldf.fill f28 = [r26] \n\t"
2349 "cmp.ne p7, p0 = r0, r27 \n\t"
2350 "cmp.ne p6, p0 = r0, r28 \n\t"
2352 "(p7) ldf.fill f29 = [r27] \n\t"
2353 "(p6) ldf.fill f30 = [r28] \n\t"
2354 "cmp.ne p7, p0 = r0, r29 \n\t"
2356 "(p7) ldf.fill f31 = [r29] \n\t"
2357 "add r20 = uc_rnat, %0 \n\t"
2358 "add r21 = uc_bsp, %0 \n\t"
2360 /* Load the balance of the thread state from the context. */
2361 "ld8 r22 = [r20], uc_psp - uc_rnat \n\t"
2362 "ld8 r23 = [r21], uc_gp - uc_bsp \n\t"
2364 "ld8 r24 = [r20], uc_pfs_loc - uc_psp \n\t"
2365 "ld8 r1 = [r21], uc_rp - uc_gp \n\t"
2367 "ld8 r25 = [r20], uc_unat_loc - uc_pfs_loc\n\t"
2368 "ld8 r26 = [r21], uc_pr - uc_rp \n\t"
2370 "ld8 r27 = [r20], uc_lc_loc - uc_unat_loc\n\t"
2371 "ld8 r28 = [r21], uc_fpsr_loc - uc_pr \n\t"
2373 "ld8 r29 = [r20], uc_eh_data - uc_lc_loc\n\t"
2374 "ld8 r30 = [r21], uc_eh_data + 8 - uc_fpsr_loc\n\t"
2376 /* Load data for the exception handler. */
2377 "ld8 r15 = [r20], 16 \n\t"
2378 "ld8 r16 = [r21], 16 \n\t"
2380 "ld8 r17 = [r20] \n\t"
2381 "ld8 r18 = [r21] \n\t"
2383 /* Install the balance of the thread state loaded above. */
2384 "cmp.ne p6, p0 = r0, r25 \n\t"
2385 "cmp.ne p7, p0 = r0, r27 \n\t"
2387 "(p6) ld8 r25 = [r25] \n\t"
2388 "(p7) ld8 r27 = [r27] \n\t"
2390 "(p7) mov.m ar.unat = r27 \n\t"
2391 "(p6) mov.i ar.pfs = r25 \n\t"
2392 "cmp.ne p9, p0 = r0, r29 \n\t"
2394 "(p9) ld8 r29 = [r29] \n\t"
2395 "cmp.ne p6, p0 = r0, r30 \n\t"
2397 "(p6) ld8 r30 = [r30] \n\t"
2398 /* Don't clobber p6-p9, which are in use at present. */
2399 "mov pr = r28, ~0x3c0 \n\t"
2400 "(p9) mov.i ar.lc = r29 \n\t"
2402 "mov.m r25 = ar.rsc \n\t"
2403 "(p6) mov.m ar.fpsr = r30 \n\t"
2405 "and r29 = 0x1c, r25 \n\t"
2408 "mov.m ar.rsc = r29 \n\t"
2410 /* This must be done before setting AR.BSPSTORE, otherwise
2411 AR.BSP will be initialized with a random displacement
2412 below the value we want, based on the current number of
2413 dirty stacked registers. */
2417 "mov.m ar.bspstore = r23 \n\t"
2419 "mov.m ar.rnat = r22 \n\t"
2421 "mov.m ar.rsc = r25 \n\t"
2423 "br.ret.sptk.few b0"
2424 : : "r"(target
), "r"(ireg_buf
), "r"(ireg_nat
), "r"(ireg_pr
)
2425 : "r15", "r16", "r17", "r18", "r20", "r21", "r22",
2426 "r23", "r24", "r25", "r26", "r27", "r28", "r29",
2432 static inline _Unwind_Ptr
2433 uw_identify_context (struct _Unwind_Context
*context
)
2435 return _Unwind_GetIP (context
);
2438 #include "unwind.inc"
2440 #if defined (USE_GAS_SYMVER) && defined (SHARED) && defined (USE_LIBUNWIND_EXCEPTIONS)
2441 alias (_Unwind_Backtrace
);
2442 alias (_Unwind_DeleteException
);
2443 alias (_Unwind_FindEnclosingFunction
);
2444 alias (_Unwind_ForcedUnwind
);
2445 alias (_Unwind_GetBSP
);
2446 alias (_Unwind_GetCFA
);
2447 alias (_Unwind_GetGR
);
2448 alias (_Unwind_GetIP
);
2449 alias (_Unwind_GetLanguageSpecificData
);
2450 alias (_Unwind_GetRegionStart
);
2451 alias (_Unwind_RaiseException
);
2452 alias (_Unwind_Resume
);
2453 alias (_Unwind_Resume_or_Rethrow
);
2454 alias (_Unwind_SetGR
);
2455 alias (_Unwind_SetIP
);