Gregs.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. /* libunwind - a platform-independent unwind library
  2. Copyright (C) 2001-2005 Hewlett-Packard Co
  3. Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
  4. This file is part of libunwind.
  5. Permission is hereby granted, free of charge, to any person obtaining
  6. a copy of this software and associated documentation files (the
  7. "Software"), to deal in the Software without restriction, including
  8. without limitation the rights to use, copy, modify, merge, publish,
  9. distribute, sublicense, and/or sell copies of the Software, and to
  10. permit persons to whom the Software is furnished to do so, subject to
  11. the following conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  18. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  19. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  20. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  21. #include "offsets.h"
  22. #include "regs.h"
  23. #include "unwind_i.h"
  24. static inline ia64_loc_t
  25. linux_scratch_loc (struct cursor *c, unw_regnum_t reg, uint8_t *nat_bitnr)
  26. {
  27. #if !defined(UNW_LOCAL_ONLY) || defined(__linux)
  28. unw_word_t addr = c->sigcontext_addr, flags, tmp_addr;
  29. int i;
  30. if (ia64_get_abi_marker (c) == ABI_MARKER_LINUX_SIGTRAMP
  31. || ia64_get_abi_marker (c) == ABI_MARKER_OLD_LINUX_SIGTRAMP)
  32. {
  33. switch (reg)
  34. {
  35. case UNW_IA64_NAT + 2 ... UNW_IA64_NAT + 3:
  36. case UNW_IA64_NAT + 8 ... UNW_IA64_NAT + 31:
  37. /* Linux sigcontext contains the NaT bit of scratch register
  38. N in bit position N of the sc_nat member. */
  39. *nat_bitnr = (reg - UNW_IA64_NAT);
  40. addr += LINUX_SC_NAT_OFF;
  41. break;
  42. case UNW_IA64_GR + 2 ... UNW_IA64_GR + 3:
  43. case UNW_IA64_GR + 8 ... UNW_IA64_GR + 31:
  44. addr += LINUX_SC_GR_OFF + 8 * (reg - UNW_IA64_GR);
  45. break;
  46. case UNW_IA64_FR + 6 ... UNW_IA64_FR + 15:
  47. addr += LINUX_SC_FR_OFF + 16 * (reg - UNW_IA64_FR);
  48. return IA64_LOC_ADDR (addr, IA64_LOC_TYPE_FP);
  49. case UNW_IA64_FR + 32 ... UNW_IA64_FR + 127:
  50. if (ia64_get (c, IA64_LOC_ADDR (addr + LINUX_SC_FLAGS_OFF, 0),
  51. &flags) < 0)
  52. return IA64_NULL_LOC;
  53. if (!(flags & IA64_SC_FLAG_FPH_VALID))
  54. {
  55. /* initialize fph partition: */
  56. tmp_addr = addr + LINUX_SC_FR_OFF + 32*16;
  57. for (i = 32; i < 128; ++i, tmp_addr += 16)
  58. if (ia64_putfp (c, IA64_LOC_ADDR (tmp_addr, 0),
  59. unw.read_only.f0) < 0)
  60. return IA64_NULL_LOC;
  61. /* mark fph partition as valid: */
  62. if (ia64_put (c, IA64_LOC_ADDR (addr + LINUX_SC_FLAGS_OFF, 0),
  63. flags | IA64_SC_FLAG_FPH_VALID) < 0)
  64. return IA64_NULL_LOC;
  65. }
  66. addr += LINUX_SC_FR_OFF + 16 * (reg - UNW_IA64_FR);
  67. return IA64_LOC_ADDR (addr, IA64_LOC_TYPE_FP);
  68. case UNW_IA64_BR + 0: addr += LINUX_SC_BR_OFF + 0; break;
  69. case UNW_IA64_BR + 6: addr += LINUX_SC_BR_OFF + 6*8; break;
  70. case UNW_IA64_BR + 7: addr += LINUX_SC_BR_OFF + 7*8; break;
  71. case UNW_IA64_AR_RSC: addr += LINUX_SC_AR_RSC_OFF; break;
  72. case UNW_IA64_AR_CSD: addr += LINUX_SC_AR_CSD_OFF; break;
  73. case UNW_IA64_AR_SSD: addr += LINUX_SC_AR_SSD_OFF; break;
  74. case UNW_IA64_AR_CCV: addr += LINUX_SC_AR_CCV; break;
  75. default:
  76. if (unw_is_fpreg (reg))
  77. return IA64_FPREG_LOC (c, reg);
  78. else
  79. return IA64_REG_LOC (c, reg);
  80. }
  81. return IA64_LOC_ADDR (addr, 0);
  82. }
  83. else
  84. {
  85. int is_nat = 0;
  86. if ((unsigned) (reg - UNW_IA64_NAT) < 128)
  87. {
  88. is_nat = 1;
  89. reg -= (UNW_IA64_NAT - UNW_IA64_GR);
  90. }
  91. if (ia64_get_abi_marker (c) == ABI_MARKER_LINUX_INTERRUPT)
  92. {
  93. switch (reg)
  94. {
  95. case UNW_IA64_BR + 6 ... UNW_IA64_BR + 7:
  96. addr += LINUX_PT_B6_OFF + 8 * (reg - (UNW_IA64_BR + 6));
  97. break;
  98. case UNW_IA64_AR_CSD: addr += LINUX_PT_CSD_OFF; break;
  99. case UNW_IA64_AR_SSD: addr += LINUX_PT_SSD_OFF; break;
  100. case UNW_IA64_GR + 8 ... UNW_IA64_GR + 11:
  101. addr += LINUX_PT_R8_OFF + 8 * (reg - (UNW_IA64_GR + 8));
  102. break;
  103. case UNW_IA64_IP: addr += LINUX_PT_IIP_OFF; break;
  104. case UNW_IA64_CFM: addr += LINUX_PT_IFS_OFF; break;
  105. case UNW_IA64_AR_UNAT: addr += LINUX_PT_UNAT_OFF; break;
  106. case UNW_IA64_AR_PFS: addr += LINUX_PT_PFS_OFF; break;
  107. case UNW_IA64_AR_RSC: addr += LINUX_PT_RSC_OFF; break;
  108. case UNW_IA64_AR_RNAT: addr += LINUX_PT_RNAT_OFF; break;
  109. case UNW_IA64_AR_BSPSTORE: addr += LINUX_PT_BSPSTORE_OFF; break;
  110. case UNW_IA64_PR: addr += LINUX_PT_PR_OFF; break;
  111. case UNW_IA64_BR + 0: addr += LINUX_PT_B0_OFF; break;
  112. case UNW_IA64_GR + 1:
  113. /* The saved r1 value is valid only in the frame in which
  114. it was saved; for everything else we need to look up
  115. the appropriate gp value. */
  116. if (c->sigcontext_addr != c->sp + 0x10)
  117. return IA64_NULL_LOC;
  118. addr += LINUX_PT_R1_OFF;
  119. break;
  120. case UNW_IA64_GR + 12: addr += LINUX_PT_R12_OFF; break;
  121. case UNW_IA64_GR + 13: addr += LINUX_PT_R13_OFF; break;
  122. case UNW_IA64_AR_FPSR: addr += LINUX_PT_FPSR_OFF; break;
  123. case UNW_IA64_GR + 15: addr += LINUX_PT_R15_OFF; break;
  124. case UNW_IA64_GR + 14: addr += LINUX_PT_R14_OFF; break;
  125. case UNW_IA64_GR + 2: addr += LINUX_PT_R2_OFF; break;
  126. case UNW_IA64_GR + 3: addr += LINUX_PT_R3_OFF; break;
  127. case UNW_IA64_GR + 16 ... UNW_IA64_GR + 31:
  128. addr += LINUX_PT_R16_OFF + 8 * (reg - (UNW_IA64_GR + 16));
  129. break;
  130. case UNW_IA64_AR_CCV: addr += LINUX_PT_CCV_OFF; break;
  131. case UNW_IA64_FR + 6 ... UNW_IA64_FR + 11:
  132. addr += LINUX_PT_F6_OFF + 16 * (reg - (UNW_IA64_FR + 6));
  133. return IA64_LOC_ADDR (addr, IA64_LOC_TYPE_FP);
  134. default:
  135. if (unw_is_fpreg (reg))
  136. return IA64_FPREG_LOC (c, reg);
  137. else
  138. return IA64_REG_LOC (c, reg);
  139. }
  140. }
  141. else if (ia64_get_abi_marker (c) == ABI_MARKER_OLD_LINUX_INTERRUPT)
  142. {
  143. switch (reg)
  144. {
  145. case UNW_IA64_GR + 1:
  146. /* The saved r1 value is valid only in the frame in which
  147. it was saved; for everything else we need to look up
  148. the appropriate gp value. */
  149. if (c->sigcontext_addr != c->sp + 0x10)
  150. return IA64_NULL_LOC;
  151. addr += LINUX_OLD_PT_R1_OFF;
  152. break;
  153. case UNW_IA64_GR + 2 ... UNW_IA64_GR + 3:
  154. addr += LINUX_OLD_PT_R2_OFF + 8 * (reg - (UNW_IA64_GR + 2));
  155. break;
  156. case UNW_IA64_GR + 8 ... UNW_IA64_GR + 11:
  157. addr += LINUX_OLD_PT_R8_OFF + 8 * (reg - (UNW_IA64_GR + 8));
  158. break;
  159. case UNW_IA64_GR + 16 ... UNW_IA64_GR + 31:
  160. addr += LINUX_OLD_PT_R16_OFF + 8 * (reg - (UNW_IA64_GR + 16));
  161. break;
  162. case UNW_IA64_FR + 6 ... UNW_IA64_FR + 9:
  163. addr += LINUX_OLD_PT_F6_OFF + 16 * (reg - (UNW_IA64_FR + 6));
  164. return IA64_LOC_ADDR (addr, IA64_LOC_TYPE_FP);
  165. case UNW_IA64_BR + 0: addr += LINUX_OLD_PT_B0_OFF; break;
  166. case UNW_IA64_BR + 6: addr += LINUX_OLD_PT_B6_OFF; break;
  167. case UNW_IA64_BR + 7: addr += LINUX_OLD_PT_B7_OFF; break;
  168. case UNW_IA64_AR_RSC: addr += LINUX_OLD_PT_RSC_OFF; break;
  169. case UNW_IA64_AR_CCV: addr += LINUX_OLD_PT_CCV_OFF; break;
  170. default:
  171. if (unw_is_fpreg (reg))
  172. return IA64_FPREG_LOC (c, reg);
  173. else
  174. return IA64_REG_LOC (c, reg);
  175. }
  176. }
  177. if (is_nat)
  178. {
  179. /* For Linux pt-regs structure, bit number is determined by
  180. the UNaT slot number (as determined by st8.spill) and the
  181. bits are saved wherever the (primary) UNaT was saved. */
  182. *nat_bitnr = ia64_unat_slot_num (addr);
  183. return c->loc[IA64_REG_PRI_UNAT_MEM];
  184. }
  185. return IA64_LOC_ADDR (addr, 0);
  186. }
  187. #endif
  188. return IA64_NULL_LOC;
  189. }
  190. static inline ia64_loc_t
  191. hpux_scratch_loc (struct cursor *c, unw_regnum_t reg, uint8_t *nat_bitnr)
  192. {
  193. #if !defined(UNW_LOCAL_ONLY) || defined(__hpux)
  194. return IA64_LOC_UC_REG (reg, c->sigcontext_addr);
  195. #else
  196. return IA64_NULL_LOC;
  197. #endif
  198. }
  199. HIDDEN ia64_loc_t
  200. ia64_scratch_loc (struct cursor *c, unw_regnum_t reg, uint8_t *nat_bitnr)
  201. {
  202. if (c->sigcontext_addr)
  203. {
  204. if (ia64_get_abi (c) == ABI_LINUX)
  205. return linux_scratch_loc (c, reg, nat_bitnr);
  206. else if (ia64_get_abi (c) == ABI_HPUX)
  207. return hpux_scratch_loc (c, reg, nat_bitnr);
  208. else
  209. return IA64_NULL_LOC;
  210. }
  211. else
  212. return IA64_REG_LOC (c, reg);
  213. }
  214. static inline int
  215. update_nat (struct cursor *c, ia64_loc_t nat_loc, unw_word_t mask,
  216. unw_word_t *valp, int write)
  217. {
  218. unw_word_t nat_word;
  219. int ret;
  220. ret = ia64_get (c, nat_loc, &nat_word);
  221. if (ret < 0)
  222. return ret;
  223. if (write)
  224. {
  225. if (*valp)
  226. nat_word |= mask;
  227. else
  228. nat_word &= ~mask;
  229. ret = ia64_put (c, nat_loc, nat_word);
  230. }
  231. else
  232. *valp = (nat_word & mask) != 0;
  233. return ret;
  234. }
  235. static int
  236. access_nat (struct cursor *c,
  237. ia64_loc_t nat_loc, ia64_loc_t reg_loc, uint8_t nat_bitnr,
  238. unw_word_t *valp, int write)
  239. {
  240. unw_word_t mask = 0;
  241. unw_fpreg_t tmp;
  242. int ret;
  243. if (IA64_IS_FP_LOC (reg_loc))
  244. {
  245. /* NaT bit is saved as a NaTVal. This happens when a general
  246. register is saved to a floating-point register. */
  247. if (write)
  248. {
  249. if (*valp)
  250. {
  251. if (ia64_is_big_endian (c))
  252. ret = ia64_putfp (c, reg_loc, unw.nat_val_be);
  253. else
  254. ret = ia64_putfp (c, reg_loc, unw.nat_val_le);
  255. }
  256. else
  257. {
  258. unw_word_t *src, *dst;
  259. unw_fpreg_t tmp;
  260. ret = ia64_getfp (c, reg_loc, &tmp);
  261. if (ret < 0)
  262. return ret;
  263. /* Reset the exponent to 0x1003e so that the significand
  264. will be interpreted as an integer value. */
  265. src = (unw_word_t *) &unw.int_val_be;
  266. dst = (unw_word_t *) &tmp;
  267. if (!ia64_is_big_endian (c))
  268. ++src, ++dst;
  269. *dst = *src;
  270. ret = ia64_putfp (c, reg_loc, tmp);
  271. }
  272. }
  273. else
  274. {
  275. ret = ia64_getfp (c, reg_loc, &tmp);
  276. if (ret < 0)
  277. return ret;
  278. if (ia64_is_big_endian (c))
  279. *valp = (memcmp (&tmp, &unw.nat_val_be, sizeof (tmp)) == 0);
  280. else
  281. *valp = (memcmp (&tmp, &unw.nat_val_le, sizeof (tmp)) == 0);
  282. }
  283. return ret;
  284. }
  285. if ((IA64_IS_REG_LOC (nat_loc)
  286. && (unsigned) (IA64_GET_REG (nat_loc) - UNW_IA64_NAT) < 128)
  287. || IA64_IS_UC_LOC (reg_loc))
  288. {
  289. if (write)
  290. return ia64_put (c, nat_loc, *valp);
  291. else
  292. return ia64_get (c, nat_loc, valp);
  293. }
  294. if (IA64_IS_NULL_LOC (nat_loc))
  295. {
  296. /* NaT bit is not saved. This happens if a general register is
  297. saved to a branch register. Since the NaT bit gets lost, we
  298. need to drop it here, too. Note that if the NaT bit had been
  299. set when the save occurred, it would have caused a NaT
  300. consumption fault. */
  301. if (write)
  302. {
  303. if (*valp)
  304. return -UNW_EBADREG; /* can't set NaT bit */
  305. }
  306. else
  307. *valp = 0;
  308. return 0;
  309. }
  310. mask = (unw_word_t) 1 << nat_bitnr;
  311. return update_nat (c, nat_loc, mask, valp, write);
  312. }
  313. HIDDEN int
  314. tdep_access_reg (struct cursor *c, unw_regnum_t reg, unw_word_t *valp,
  315. int write)
  316. {
  317. ia64_loc_t loc, reg_loc, nat_loc;
  318. unw_word_t mask, val;
  319. uint8_t nat_bitnr;
  320. int ret;
  321. switch (reg)
  322. {
  323. /* frame registers: */
  324. case UNW_IA64_BSP:
  325. if (write)
  326. c->bsp = *valp;
  327. else
  328. *valp = c->bsp;
  329. return 0;
  330. case UNW_REG_SP:
  331. if (write)
  332. c->sp = *valp;
  333. else
  334. *valp = c->sp;
  335. return 0;
  336. case UNW_REG_IP:
  337. if (write)
  338. {
  339. c->ip = *valp; /* also update the IP cache */
  340. if (c->pi_valid && (*valp < c->pi.start_ip || *valp >= c->pi.end_ip))
  341. c->pi_valid = 0; /* new IP outside of current proc */
  342. }
  343. loc = c->loc[IA64_REG_IP];
  344. break;
  345. /* preserved registers: */
  346. case UNW_IA64_GR + 4 ... UNW_IA64_GR + 7:
  347. loc = c->loc[IA64_REG_R4 + (reg - (UNW_IA64_GR + 4))];
  348. break;
  349. case UNW_IA64_NAT + 4 ... UNW_IA64_NAT + 7:
  350. loc = c->loc[IA64_REG_NAT4 + (reg - (UNW_IA64_NAT + 4))];
  351. reg_loc = c->loc[IA64_REG_R4 + (reg - (UNW_IA64_NAT + 4))];
  352. nat_bitnr = c->nat_bitnr[reg - (UNW_IA64_NAT + 4)];
  353. return access_nat (c, loc, reg_loc, nat_bitnr, valp, write);
  354. case UNW_IA64_AR_BSP: loc = c->loc[IA64_REG_BSP]; break;
  355. case UNW_IA64_AR_BSPSTORE: loc = c->loc[IA64_REG_BSPSTORE]; break;
  356. case UNW_IA64_AR_PFS: loc = c->loc[IA64_REG_PFS]; break;
  357. case UNW_IA64_AR_RNAT: loc = c->loc[IA64_REG_RNAT]; break;
  358. case UNW_IA64_AR_UNAT: loc = c->loc[IA64_REG_UNAT]; break;
  359. case UNW_IA64_AR_LC: loc = c->loc[IA64_REG_LC]; break;
  360. case UNW_IA64_AR_FPSR: loc = c->loc[IA64_REG_FPSR]; break;
  361. case UNW_IA64_BR + 1: loc = c->loc[IA64_REG_B1]; break;
  362. case UNW_IA64_BR + 2: loc = c->loc[IA64_REG_B2]; break;
  363. case UNW_IA64_BR + 3: loc = c->loc[IA64_REG_B3]; break;
  364. case UNW_IA64_BR + 4: loc = c->loc[IA64_REG_B4]; break;
  365. case UNW_IA64_BR + 5: loc = c->loc[IA64_REG_B5]; break;
  366. case UNW_IA64_CFM:
  367. if (write)
  368. c->cfm = *valp; /* also update the CFM cache */
  369. loc = c->cfm_loc;
  370. break;
  371. case UNW_IA64_PR:
  372. /*
  373. * Note: broad-side access to the predicates is NOT rotated
  374. * (i.e., it is done as if CFM.rrb.pr == 0.
  375. */
  376. if (write)
  377. {
  378. c->pr = *valp; /* update the predicate cache */
  379. return ia64_put (c, c->loc[IA64_REG_PR], *valp);
  380. }
  381. else
  382. return ia64_get (c, c->loc[IA64_REG_PR], valp);
  383. case UNW_IA64_GR + 32 ... UNW_IA64_GR + 127: /* stacked reg */
  384. reg = rotate_gr (c, reg - UNW_IA64_GR);
  385. if (reg < 0)
  386. return -UNW_EBADREG;
  387. ret = ia64_get_stacked (c, reg, &loc, NULL);
  388. if (ret < 0)
  389. return ret;
  390. break;
  391. case UNW_IA64_NAT + 32 ... UNW_IA64_NAT + 127: /* stacked reg */
  392. reg = rotate_gr (c, reg - UNW_IA64_NAT);
  393. if (reg < 0)
  394. return -UNW_EBADREG;
  395. ret = ia64_get_stacked (c, reg, &loc, &nat_loc);
  396. if (ret < 0)
  397. return ret;
  398. assert (!IA64_IS_REG_LOC (loc));
  399. mask = (unw_word_t) 1 << rse_slot_num (IA64_GET_ADDR (loc));
  400. return update_nat (c, nat_loc, mask, valp, write);
  401. case UNW_IA64_AR_EC:
  402. if ((ret = ia64_get (c, c->ec_loc, &val)) < 0)
  403. return ret;
  404. if (write)
  405. {
  406. val = ((val & ~((unw_word_t) 0x3f << 52)) | ((*valp & 0x3f) << 52));
  407. return ia64_put (c, c->ec_loc, val);
  408. }
  409. else
  410. {
  411. *valp = (val >> 52) & 0x3f;
  412. return 0;
  413. }
  414. /* scratch & special registers: */
  415. case UNW_IA64_GR + 0:
  416. if (write)
  417. return -UNW_EREADONLYREG;
  418. *valp = 0;
  419. return 0;
  420. case UNW_IA64_NAT + 0:
  421. if (write)
  422. return -UNW_EREADONLYREG;
  423. *valp = 0;
  424. return 0;
  425. case UNW_IA64_NAT + 1:
  426. case UNW_IA64_NAT + 2 ... UNW_IA64_NAT + 3:
  427. case UNW_IA64_NAT + 8 ... UNW_IA64_NAT + 31:
  428. loc = ia64_scratch_loc (c, reg, &nat_bitnr);
  429. if (IA64_IS_NULL_LOC (loc) && reg == UNW_IA64_NAT + 1)
  430. {
  431. /* access to GP */
  432. if (write)
  433. return -UNW_EREADONLYREG;
  434. *valp = 0;
  435. return 0;
  436. }
  437. if (!(IA64_IS_REG_LOC (loc) || IA64_IS_UC_LOC (loc)
  438. || IA64_IS_FP_LOC (loc)))
  439. /* We're dealing with a NaT bit stored in memory. */
  440. return update_nat(c, loc, (unw_word_t) 1 << nat_bitnr, valp, write);
  441. break;
  442. case UNW_IA64_GR + 15 ... UNW_IA64_GR + 18:
  443. mask = 1 << (reg - (UNW_IA64_GR + 15));
  444. if (write)
  445. {
  446. c->eh_args[reg - (UNW_IA64_GR + 15)] = *valp;
  447. c->eh_valid_mask |= mask;
  448. return 0;
  449. }
  450. else if ((c->eh_valid_mask & mask) != 0)
  451. {
  452. *valp = c->eh_args[reg - (UNW_IA64_GR + 15)];
  453. return 0;
  454. }
  455. else
  456. loc = ia64_scratch_loc (c, reg, NULL);
  457. break;
  458. case UNW_IA64_GR + 1: /* global pointer */
  459. case UNW_IA64_GR + 2 ... UNW_IA64_GR + 3:
  460. case UNW_IA64_GR + 8 ... UNW_IA64_GR + 14:
  461. case UNW_IA64_GR + 19 ... UNW_IA64_GR + 31:
  462. case UNW_IA64_BR + 0:
  463. case UNW_IA64_BR + 6:
  464. case UNW_IA64_BR + 7:
  465. case UNW_IA64_AR_RSC:
  466. case UNW_IA64_AR_CSD:
  467. case UNW_IA64_AR_SSD:
  468. case UNW_IA64_AR_CCV:
  469. loc = ia64_scratch_loc (c, reg, NULL);
  470. if (IA64_IS_NULL_LOC (loc) && reg == UNW_IA64_GR + 1)
  471. {
  472. /* access to GP */
  473. if (write)
  474. return -UNW_EREADONLYREG;
  475. /* ensure c->pi is up-to-date: */
  476. if ((ret = ia64_make_proc_info (c)) < 0)
  477. return ret;
  478. *valp = c->pi.gp;
  479. return 0;
  480. }
  481. break;
  482. default:
  483. Debug (1, "bad register number %d\n", reg);
  484. return -UNW_EBADREG;
  485. }
  486. if (write)
  487. return ia64_put (c, loc, *valp);
  488. else
  489. return ia64_get (c, loc, valp);
  490. }
  491. HIDDEN int
  492. tdep_access_fpreg (struct cursor *c, int reg, unw_fpreg_t *valp,
  493. int write)
  494. {
  495. ia64_loc_t loc;
  496. switch (reg)
  497. {
  498. case UNW_IA64_FR + 0:
  499. if (write)
  500. return -UNW_EREADONLYREG;
  501. *valp = unw.read_only.f0;
  502. return 0;
  503. case UNW_IA64_FR + 1:
  504. if (write)
  505. return -UNW_EREADONLYREG;
  506. if (ia64_is_big_endian (c))
  507. *valp = unw.read_only.f1_be;
  508. else
  509. *valp = unw.read_only.f1_le;
  510. return 0;
  511. case UNW_IA64_FR + 2: loc = c->loc[IA64_REG_F2]; break;
  512. case UNW_IA64_FR + 3: loc = c->loc[IA64_REG_F3]; break;
  513. case UNW_IA64_FR + 4: loc = c->loc[IA64_REG_F4]; break;
  514. case UNW_IA64_FR + 5: loc = c->loc[IA64_REG_F5]; break;
  515. case UNW_IA64_FR + 16 ... UNW_IA64_FR + 31:
  516. loc = c->loc[IA64_REG_F16 + (reg - (UNW_IA64_FR + 16))];
  517. break;
  518. case UNW_IA64_FR + 6 ... UNW_IA64_FR + 15:
  519. loc = ia64_scratch_loc (c, reg, NULL);
  520. break;
  521. case UNW_IA64_FR + 32 ... UNW_IA64_FR + 127:
  522. reg = rotate_fr (c, reg - UNW_IA64_FR) + UNW_IA64_FR;
  523. loc = ia64_scratch_loc (c, reg, NULL);
  524. break;
  525. default:
  526. Debug (1, "bad register number %d\n", reg);
  527. return -UNW_EBADREG;
  528. }
  529. if (write)
  530. return ia64_putfp (c, loc, *valp);
  531. else
  532. return ia64_getfp (c, loc, valp);
  533. }