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