Import changeset
[linux-flexiantxendom0-3.2.10.git] / arch / ia64 / kernel / unwind_i.h
1 /*
2  * Copyright (C) 2000 Hewlett-Packard Co
3  * Copyright (C) 2000 David Mosberger-Tang <davidm@hpl.hp.com>
4  *
5  * Kernel unwind support.
6  */
7
8 #define UNW_VER(x)              ((x) >> 48)
9 #define UNW_FLAG_MASK           0x0000ffff00000000
10 #define UNW_FLAG_OSMASK         0x0000f00000000000
11 #define UNW_FLAG_EHANDLER(x)    ((x) & 0x0000000100000000L)
12 #define UNW_FLAG_UHANDLER(x)    ((x) & 0x0000000200000000L)
13 #define UNW_LENGTH(x)           ((x) & 0x00000000ffffffffL)
14
15 enum unw_register_index {
16         /* primary unat: */
17         UNW_REG_PRI_UNAT_GR,
18         UNW_REG_PRI_UNAT_MEM,
19
20         /* register stack */
21         UNW_REG_BSP,                                    /* register stack pointer */
22         UNW_REG_BSPSTORE,
23         UNW_REG_PFS,                                    /* previous function state */
24         UNW_REG_RNAT,
25         /* memory stack */
26         UNW_REG_PSP,                                    /* previous memory stack pointer */
27         /* return pointer: */
28         UNW_REG_RP,
29
30         /* preserved registers: */
31         UNW_REG_R4, UNW_REG_R5, UNW_REG_R6, UNW_REG_R7,
32         UNW_REG_UNAT, UNW_REG_PR, UNW_REG_LC, UNW_REG_FPSR,
33         UNW_REG_B1, UNW_REG_B2, UNW_REG_B3, UNW_REG_B4, UNW_REG_B5,
34         UNW_REG_F2, UNW_REG_F3, UNW_REG_F4, UNW_REG_F5,
35         UNW_REG_F16, UNW_REG_F17, UNW_REG_F18, UNW_REG_F19,
36         UNW_REG_F20, UNW_REG_F21, UNW_REG_F22, UNW_REG_F23,
37         UNW_REG_F24, UNW_REG_F25, UNW_REG_F26, UNW_REG_F27,
38         UNW_REG_F28, UNW_REG_F29, UNW_REG_F30, UNW_REG_F31,
39         UNW_NUM_REGS
40 };
41
42 struct unw_info_block {
43         u64 header;
44         u64 desc[0];            /* unwind descriptors */
45         /* personality routine and language-specific data follow behind descriptors */
46 };
47
48 struct unw_table_entry {
49         u64 start_offset;
50         u64 end_offset;
51         u64 info_offset;
52 };
53
54 struct unw_table {
55         struct unw_table *next;         /* must be first member! */
56         const char *name;
57         unsigned long gp;               /* global pointer for this load-module */
58         unsigned long segment_base;     /* base for offsets in the unwind table entries */
59         unsigned long start;
60         unsigned long end;
61         struct unw_table_entry *array;
62         unsigned long length;
63 };
64
65 enum unw_where {
66         UNW_WHERE_NONE,                 /* register isn't saved at all */
67         UNW_WHERE_GR,                   /* register is saved in a general register */
68         UNW_WHERE_FR,                   /* register is saved in a floating-point register */
69         UNW_WHERE_BR,                   /* register is saved in a branch register */
70         UNW_WHERE_SPREL,                /* register is saved on memstack (sp-relative) */
71         UNW_WHERE_PSPREL,               /* register is saved on memstack (psp-relative) */
72         /*
73          * At the end of each prologue these locations get resolved to
74          * UNW_WHERE_PSPREL and UNW_WHERE_GR, respectively:
75          */
76         UNW_WHERE_SPILL_HOME,           /* register is saved in its spill home */
77         UNW_WHERE_GR_SAVE               /* register is saved in next general register */
78 };
79
80 #define UNW_WHEN_NEVER  0x7fffffff
81
82 struct unw_reg_info {
83         unsigned long val;              /* save location: register number or offset */
84         enum unw_where where;           /* where the register gets saved */
85         int when;                       /* when the register gets saved */
86 };
87
88 struct unw_state_record {
89         unsigned int first_region : 1;  /* is this the first region? */
90         unsigned int done : 1;          /* are we done scanning descriptors? */
91         unsigned int any_spills : 1;    /* got any register spills? */
92         unsigned int in_body : 1;       /* are we inside a body (as opposed to a prologue)? */
93         unsigned long flags;            /* see UNW_FLAG_* in unwind.h */
94
95         u8 *imask;                      /* imask of of spill_mask record or NULL */
96         unsigned long pr_val;           /* predicate values */
97         unsigned long pr_mask;          /* predicate mask */
98         long spill_offset;              /* psp-relative offset for spill base */
99         int region_start;
100         int region_len;
101         int epilogue_start;
102         int epilogue_count;
103         int when_target;
104
105         u8 gr_save_loc;                 /* next general register to use for saving a register */
106         u8 return_link_reg;             /* branch register in which the return link is passed */
107
108         struct unw_reg_state {
109                 struct unw_reg_state *next;
110                 unsigned long label;            /* label of this state record */
111                 struct unw_reg_info reg[UNW_NUM_REGS];
112         } curr, *stack, *reg_state_list;
113 };
114
115 enum unw_nat_type {
116         UNW_NAT_NONE,           /* NaT not represented */
117         UNW_NAT_VAL,            /* NaT represented by NaT value (fp reg) */
118         UNW_NAT_MEMSTK,         /* NaT value is in unat word at offset OFF  */
119         UNW_NAT_REGSTK          /* NaT is in rnat */
120 };
121
122 enum unw_insn_opcode {
123         UNW_INSN_ADD,                   /* s[dst] += val */
124         UNW_INSN_ADD_PSP,               /* s[dst] = (s.psp + val) */
125         UNW_INSN_ADD_SP,                /* s[dst] = (s.sp + val) */
126         UNW_INSN_MOVE,                  /* s[dst] = s[val] */
127         UNW_INSN_MOVE2,                 /* s[dst] = s[val]; s[dst+1] = s[val+1] */
128         UNW_INSN_MOVE_STACKED,          /* s[dst] = ia64_rse_skip(*s.bsp, val) */
129         UNW_INSN_SETNAT_MEMSTK,         /* s[dst+1].nat.type = MEMSTK;
130                                            s[dst+1].nat.off = *s.pri_unat - s[dst] */
131         UNW_INSN_SETNAT_TYPE,           /* s[dst+1].nat.type = val */
132         UNW_INSN_LOAD                   /* s[dst] = *s[val] */
133 };
134
135 struct unw_insn {
136         unsigned int opc        :  4;
137         unsigned int dst        :  9;
138         signed int val          : 19;
139 };
140
141 /*
142  * Preserved general static registers (r2-r5) give rise to two script
143  * instructions; everything else yields at most one instruction; at
144  * the end of the script, the psp gets popped, accounting for one more
145  * instruction.
146  */
147 #define UNW_MAX_SCRIPT_LEN      (UNW_NUM_REGS + 5)
148
149 struct unw_script {
150         unsigned long ip;               /* ip this script is for */
151         unsigned long pr_mask;          /* mask of predicates script depends on */
152         unsigned long pr_val;           /* predicate values this script is for */
153         rwlock_t lock;
154         unsigned int flags;             /* see UNW_FLAG_* in unwind.h */
155         unsigned short lru_chain;       /* used for least-recently-used chain */
156         unsigned short coll_chain;      /* used for hash collisions */
157         unsigned short hint;            /* hint for next script to try (or -1) */
158         unsigned short count;           /* number of instructions in script */
159         struct unw_insn insn[UNW_MAX_SCRIPT_LEN];
160 };