• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* libunwind - a platform-independent unwind library
2    Copyright (C) 2002-2003, 2005 Hewlett-Packard Co
3 	Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
4 
5 This file is part of libunwind.
6 
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the
9 "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
14 
15 The above copyright notice and this permission notice shall be
16 included in all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
25 
26 #include <assert.h>
27 
28 #include "rse.h"
29 
30 #include "offsets.h"
31 #include "regs.h"
32 
33 PROTECTED int
unw_get_save_loc(unw_cursor_t * cursor,int reg,unw_save_loc_t * sloc)34 unw_get_save_loc (unw_cursor_t *cursor, int reg, unw_save_loc_t *sloc)
35 {
36   struct cursor *c = (struct cursor *) cursor;
37   ia64_loc_t loc, reg_loc;
38   uint8_t nat_bitnr;
39   int ret;
40 
41   loc = IA64_NULL_LOC;		/* default to "not saved" */
42 
43   switch (reg)
44     {
45       /* frame registers */
46     case UNW_IA64_BSP:
47     case UNW_REG_SP:
48     default:
49       break;
50 
51     case UNW_REG_IP:
52       loc = c->loc[IA64_REG_IP];
53       break;
54 
55       /* preserved registers: */
56     case UNW_IA64_GR + 4 ... UNW_IA64_GR + 7:
57       loc = c->loc[IA64_REG_R4 + (reg - (UNW_IA64_GR + 4))];
58       break;
59 
60     case UNW_IA64_NAT + 4 ... UNW_IA64_NAT + 7:
61       loc = c->loc[IA64_REG_NAT4 + (reg - (UNW_IA64_NAT + 4))];
62       reg_loc = c->loc[IA64_REG_R4 + (reg - (UNW_IA64_NAT + 4))];
63       nat_bitnr = c->nat_bitnr[reg - (UNW_IA64_NAT + 4)];
64       if (IA64_IS_FP_LOC (reg_loc))
65 	/* NaT bit saved as a NaTVal.  */
66 	loc = reg_loc;
67       break;
68 
69     case UNW_IA64_FR + 2: loc = c->loc[IA64_REG_F2]; break;
70     case UNW_IA64_FR + 3: loc = c->loc[IA64_REG_F3]; break;
71     case UNW_IA64_FR + 4: loc = c->loc[IA64_REG_F4]; break;
72     case UNW_IA64_FR + 5: loc = c->loc[IA64_REG_F5]; break;
73     case UNW_IA64_FR + 16 ... UNW_IA64_FR + 31:
74       loc = c->loc[IA64_REG_F16 + (reg - (UNW_IA64_FR + 16))];
75       break;
76 
77     case UNW_IA64_AR_BSP:	loc = c->loc[IA64_REG_BSP]; break;
78     case UNW_IA64_AR_BSPSTORE:	loc = c->loc[IA64_REG_BSPSTORE]; break;
79     case UNW_IA64_AR_PFS:	loc = c->loc[IA64_REG_PFS]; break;
80     case UNW_IA64_AR_RNAT:	loc = c->loc[IA64_REG_RNAT]; break;
81     case UNW_IA64_AR_UNAT:	loc = c->loc[IA64_REG_UNAT]; break;
82     case UNW_IA64_AR_LC:	loc = c->loc[IA64_REG_LC]; break;
83     case UNW_IA64_AR_FPSR:	loc = c->loc[IA64_REG_FPSR]; break;
84     case UNW_IA64_BR + 1:	loc = c->loc[IA64_REG_B1]; break;
85     case UNW_IA64_BR + 2:	loc = c->loc[IA64_REG_B2]; break;
86     case UNW_IA64_BR + 3:	loc = c->loc[IA64_REG_B3]; break;
87     case UNW_IA64_BR + 4:	loc = c->loc[IA64_REG_B4]; break;
88     case UNW_IA64_BR + 5:	loc = c->loc[IA64_REG_B5]; break;
89     case UNW_IA64_CFM:		loc = c->cfm_loc; break;
90     case UNW_IA64_PR:		loc = c->loc[IA64_REG_PR]; break;
91 
92     case UNW_IA64_GR + 32 ... UNW_IA64_GR + 127:	/* stacked reg */
93       reg = rotate_gr (c, reg - UNW_IA64_GR);
94       ret = ia64_get_stacked (c, reg, &loc, NULL);
95       if (ret < 0)
96 	return ret;
97       break;
98 
99     case UNW_IA64_NAT + 32 ... UNW_IA64_NAT + 127:	/* stacked reg */
100       reg = rotate_gr (c, reg - UNW_IA64_NAT);
101       ret = ia64_get_stacked (c, reg, NULL, &loc);
102       break;
103 
104     case UNW_IA64_AR_EC:
105       loc = c->cfm_loc;
106       break;
107 
108       /* scratch & special registers: */
109 
110     case UNW_IA64_GR + 0:
111     case UNW_IA64_GR + 1:				/* global pointer */
112     case UNW_IA64_NAT + 0:
113     case UNW_IA64_NAT + 1:				/* global pointer */
114     case UNW_IA64_FR + 0:
115     case UNW_IA64_FR + 1:
116       break;
117 
118     case UNW_IA64_NAT + 2 ... UNW_IA64_NAT + 3:
119     case UNW_IA64_NAT + 8 ... UNW_IA64_NAT + 31:
120       loc = ia64_scratch_loc (c, reg, &nat_bitnr);
121       break;
122 
123     case UNW_IA64_GR + 2 ... UNW_IA64_GR + 3:
124     case UNW_IA64_GR + 8 ... UNW_IA64_GR + 31:
125     case UNW_IA64_BR + 0:
126     case UNW_IA64_BR + 6:
127     case UNW_IA64_BR + 7:
128     case UNW_IA64_AR_RSC:
129     case UNW_IA64_AR_CSD:
130     case UNW_IA64_AR_SSD:
131     case UNW_IA64_AR_CCV:
132       loc = ia64_scratch_loc (c, reg, NULL);
133       break;
134 
135     case UNW_IA64_FR + 6 ... UNW_IA64_FR + 15:
136       loc = ia64_scratch_loc (c, reg, NULL);
137       break;
138 
139     case UNW_IA64_FR + 32 ... UNW_IA64_FR + 127:
140       reg = rotate_fr (c, reg - UNW_IA64_FR) + UNW_IA64_FR;
141       loc = ia64_scratch_loc (c, reg, NULL);
142       break;
143     }
144 
145   memset (sloc, 0, sizeof (*sloc));
146 
147   if (IA64_IS_NULL_LOC (loc))
148     {
149       sloc->type = UNW_SLT_NONE;
150       return 0;
151     }
152 
153 #if !defined(UNW_LOCAL_ONLY)
154   if (IA64_IS_REG_LOC (loc))
155     {
156       sloc->type = UNW_SLT_REG;
157       sloc->u.regnum = IA64_GET_REG (loc);
158       sloc->extra.nat_bitnr = nat_bitnr;
159     }
160   else
161 #endif
162     {
163       sloc->type = UNW_SLT_MEMORY;
164       sloc->u.addr = IA64_GET_ADDR (loc);
165       sloc->extra.nat_bitnr = nat_bitnr;
166     }
167   return 0;
168 }
169