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