Home | History | Annotate | Line # | Download | only in unwind
stackframe.h revision 1.1.2.2
      1  1.1.2.2  yamt /*	$NetBSD: stackframe.h,v 1.1.2.2 2006/04/11 11:53:43 yamt Exp $	*/
      2  1.1.2.2  yamt 
      3  1.1.2.2  yamt /*
      4  1.1.2.2  yamt  * Contributed to the NetBSD foundation by Cherry G. Mathew
      5  1.1.2.2  yamt  */
      6  1.1.2.2  yamt 
      7  1.1.2.2  yamt #define UNW_VER(x)           ((x) >> 48)
      8  1.1.2.2  yamt #define UNW_FLAG_MASK        0x0000ffff00000000L
      9  1.1.2.2  yamt #define UNW_FLAG_OSMASK      0x0000f00000000000L
     10  1.1.2.2  yamt #define UNW_FLAG_EHANDLER(x) ((x) & 0x0000000100000000L)
     11  1.1.2.2  yamt #define UNW_FLAG_UHANDLER(x) ((x) & 0x0000000200000000L)
     12  1.1.2.2  yamt #define UNW_LENGTH(x)        ((x) & 0x00000000ffffffffL)
     13  1.1.2.2  yamt 
     14  1.1.2.2  yamt /* Unwind table entry. */
     15  1.1.2.2  yamt struct uwtable_ent {
     16  1.1.2.2  yamt 	uint64_t start;
     17  1.1.2.2  yamt 	uint64_t end;
     18  1.1.2.2  yamt 	char *infoptr;
     19  1.1.2.2  yamt };
     20  1.1.2.2  yamt 
     21  1.1.2.2  yamt 
     22  1.1.2.2  yamt enum regrecord_type{
     23  1.1.2.2  yamt 	UNSAVED,	/* Register contents live ( and therefore untouched ). */
     24  1.1.2.2  yamt 	IMMED,		/* .offset field is the saved content. */
     25  1.1.2.2  yamt 	BRREL,		/* Register saved in one of the Branch Registers. */
     26  1.1.2.2  yamt 	GRREL,		/* Register saved in one of the Stacked GRs
     27  1.1.2.2  yamt 			 * regstate.offset contains GR number (usually >= 32)
     28  1.1.2.2  yamt 			 */
     29  1.1.2.2  yamt 	SPREL,		/* Register saved on the memory stack frame.
     30  1.1.2.2  yamt 			 * regstate.offset is in words; ie; location == (sp + 4 * spoff).
     31  1.1.2.2  yamt 			 */
     32  1.1.2.2  yamt 	PSPREL		/* Register saved on the memory stack frame but offseted via psp
     33  1.1.2.2  yamt 			 * regstate.offset is in words; ie; location == (psp + 16  4 * pspoff)
     34  1.1.2.2  yamt 			 */
     35  1.1.2.2  yamt };
     36  1.1.2.2  yamt 
     37  1.1.2.2  yamt 
     38  1.1.2.2  yamt struct regstate {
     39  1.1.2.2  yamt 	enum regrecord_type where;
     40  1.1.2.2  yamt 	uint64_t when;
     41  1.1.2.2  yamt 
     42  1.1.2.2  yamt #define INVALID -1UL	/* Indicates uninitialised offset value. */
     43  1.1.2.2  yamt 	uint64_t offset;
     44  1.1.2.2  yamt };
     45  1.1.2.2  yamt 
     46  1.1.2.2  yamt 
     47  1.1.2.2  yamt /* A staterecord contains the net state of
     48  1.1.2.2  yamt  * sequentially parsing unwind descriptors.
     49  1.1.2.2  yamt  * The entry state of the current prologue region
     50  1.1.2.2  yamt  * is the exit state of the previous region.
     51  1.1.2.2  yamt  * We record info about registers we care about
     52  1.1.2.2  yamt  * ie; just enough to re-construct an unwind frame,
     53  1.1.2.2  yamt  * and ignore the rest.
     54  1.1.2.2  yamt  * Initial state is where = UNSAVED for all .where fields.
     55  1.1.2.2  yamt  */
     56  1.1.2.2  yamt 
     57  1.1.2.2  yamt struct staterecord {
     58  1.1.2.2  yamt 	struct regstate bsp;
     59  1.1.2.2  yamt    	struct regstate psp;
     60  1.1.2.2  yamt  	struct regstate rp;
     61  1.1.2.2  yamt  	struct regstate pfs;
     62  1.1.2.2  yamt };
     63  1.1.2.2  yamt 
     64  1.1.2.2  yamt /* The unwind frame is a simpler version of the trap frame
     65  1.1.2.2  yamt  * and contains a subset of preserved registers, which are
     66  1.1.2.2  yamt  * usefull in unwinding an ia64 stack frame.
     67  1.1.2.2  yamt  * Keep this in sync with the staterecord. See: stackframe.c:updateregs()
     68  1.1.2.2  yamt  */
     69  1.1.2.2  yamt 
     70  1.1.2.2  yamt struct unwind_frame {
     71  1.1.2.2  yamt 	uint64_t		bsp;	/* Base of the RSE. !!! XXX: Stack Frame discontinuities */
     72  1.1.2.2  yamt 	uint64_t		psp;	/* Mem stack (variable size) base. */
     73  1.1.2.2  yamt 	uint64_t		rp;	/* Return Pointer */
     74  1.1.2.2  yamt 	uint64_t		pfs;	/* Previous Frame size info */
     75  1.1.2.2  yamt 
     76  1.1.2.2  yamt 	/* Don't mirror anything below this line with struct staterecord */
     77  1.1.2.2  yamt 	uint64_t		sp;
     78  1.1.2.2  yamt };
     79  1.1.2.2  yamt 
     80  1.1.2.2  yamt 
     81  1.1.2.2  yamt void buildrecordchain(uint64_t, struct recordchain *);
     82  1.1.2.2  yamt void initrecord(struct staterecord *);
     83  1.1.2.2  yamt void modifyrecord(struct staterecord *, struct recordchain *, uint64_t);
     84  1.1.2.2  yamt void pushrecord(struct staterecord *);
     85  1.1.2.2  yamt void poprecord(struct staterecord *, int);
     86  1.1.2.2  yamt void dump_staterecord(struct staterecord *);
     87  1.1.2.2  yamt void clonerecordstack(u_int);
     88  1.1.2.2  yamt void switchrecordstack(u_int);
     89  1.1.2.2  yamt 
     90  1.1.2.2  yamt struct uwtable_ent *
     91  1.1.2.2  yamt get_unwind_table_entry(uint64_t);
     92  1.1.2.2  yamt void
     93  1.1.2.2  yamt patchunwindframe(struct unwind_frame *, uint64_t, uint64_t);
     94  1.1.2.2  yamt void
     95  1.1.2.2  yamt updateregs(struct unwind_frame *uwf, struct staterecord *, uint64_t) ;
     96  1.1.2.2  yamt struct uwtable_ent * get_unwind_table_entry(uint64_t ip);
     97  1.1.2.2  yamt 
     98  1.1.2.2  yamt struct staterecord *
     99  1.1.2.2  yamt buildrecordstack(struct recordchain *, uint64_t);
    100  1.1.2.2  yamt void dump_recordchain(struct recordchain *);
    101  1.1.2.2  yamt 
    102  1.1.2.2  yamt /* Convenience macros to decompose CFM & ar.pfs. */
    103  1.1.2.2  yamt #define	IA64_CFM_SOF(x)		((x) & 0x7f)
    104  1.1.2.2  yamt #define	IA64_CFM_SOL(x)		(((x) >> 7) & 0x7f)
    105  1.1.2.2  yamt #define	IA64_CFM_SOR(x)		(((x) >> 14) & 0x0f)
    106  1.1.2.2  yamt #define	IA64_CFM_RRB_GR(x)	(((x) >> 18) & 0x7f)
    107  1.1.2.2  yamt #define	IA64_CFM_RRB_FR(x)	(((x) >> 25) & 0x7f)
    108  1.1.2.2  yamt #define	IA64_CFM_RRB_PR(x)	(((x) >> 32) & 0x3f)
    109  1.1.2.2  yamt 
    110  1.1.2.2  yamt #define IA64_RNATINDEX(x)	(((x) & 0x1f8) >> 3)
    111  1.1.2.2  yamt 
    112  1.1.2.2  yamt /* Obeys Table 6:2 RSE Operation Instructions and State Modification */
    113  1.1.2.2  yamt 
    114  1.1.2.2  yamt /* These functions adjust for RSE rnat saves to bsp in the forward and
    115  1.1.2.2  yamt  * reverse directions respectively.
    116  1.1.2.2  yamt  */
    117  1.1.2.2  yamt #define ia64_rnat_adjust ia64_bsp_adjust_call
    118  1.1.2.2  yamt 
    119  1.1.2.2  yamt static __inline uint64_t
    120  1.1.2.2  yamt ia64_bsp_adjust_call(uint64_t bsp, int sol)
    121  1.1.2.2  yamt {
    122  1.1.2.2  yamt 	bsp += ((sol + (IA64_RNATINDEX(bsp) + sol) / 63) << 3);
    123  1.1.2.2  yamt 	return bsp;
    124  1.1.2.2  yamt }
    125  1.1.2.2  yamt 
    126  1.1.2.2  yamt static __inline uint64_t
    127  1.1.2.2  yamt ia64_bsp_adjust_ret(uint64_t bsp, int sol)
    128  1.1.2.2  yamt {
    129  1.1.2.2  yamt 	bsp -= ((sol + (62 - IA64_RNATINDEX(bsp) + sol) / 63) << 3);
    130  1.1.2.2  yamt 	return bsp;
    131  1.1.2.2  yamt }
    132  1.1.2.2  yamt 
    133  1.1.2.2  yamt static __inline uint64_t
    134  1.1.2.2  yamt ia64_getrse_gr(uint64_t bsp, uint64_t gr)
    135  1.1.2.2  yamt {
    136  1.1.2.2  yamt 	bsp = ia64_bsp_adjust_call(bsp, gr);
    137  1.1.2.2  yamt 	return *(uint64_t *) bsp;
    138  1.1.2.2  yamt }
    139