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