backtrace.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. /*
  2. * Copyright 2011 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/string.h>
  16. #include <asm/backtrace.h>
  17. #include <asm/tile-desc.h>
  18. #include <arch/abi.h>
  19. #ifdef __tilegx__
  20. #define TILE_MAX_INSTRUCTIONS_PER_BUNDLE TILEGX_MAX_INSTRUCTIONS_PER_BUNDLE
  21. #define tile_decoded_instruction tilegx_decoded_instruction
  22. #define tile_mnemonic tilegx_mnemonic
  23. #define parse_insn_tile parse_insn_tilegx
  24. #define TILE_OPC_IRET TILEGX_OPC_IRET
  25. #define TILE_OPC_ADDI TILEGX_OPC_ADDI
  26. #define TILE_OPC_ADDLI TILEGX_OPC_ADDLI
  27. #define TILE_OPC_INFO TILEGX_OPC_INFO
  28. #define TILE_OPC_INFOL TILEGX_OPC_INFOL
  29. #define TILE_OPC_JRP TILEGX_OPC_JRP
  30. #define TILE_OPC_MOVE TILEGX_OPC_MOVE
  31. #define OPCODE_STORE TILEGX_OPC_ST
  32. typedef long long bt_int_reg_t;
  33. #else
  34. #define TILE_MAX_INSTRUCTIONS_PER_BUNDLE TILEPRO_MAX_INSTRUCTIONS_PER_BUNDLE
  35. #define tile_decoded_instruction tilepro_decoded_instruction
  36. #define tile_mnemonic tilepro_mnemonic
  37. #define parse_insn_tile parse_insn_tilepro
  38. #define TILE_OPC_IRET TILEPRO_OPC_IRET
  39. #define TILE_OPC_ADDI TILEPRO_OPC_ADDI
  40. #define TILE_OPC_ADDLI TILEPRO_OPC_ADDLI
  41. #define TILE_OPC_INFO TILEPRO_OPC_INFO
  42. #define TILE_OPC_INFOL TILEPRO_OPC_INFOL
  43. #define TILE_OPC_JRP TILEPRO_OPC_JRP
  44. #define TILE_OPC_MOVE TILEPRO_OPC_MOVE
  45. #define OPCODE_STORE TILEPRO_OPC_SW
  46. typedef int bt_int_reg_t;
  47. #endif
  48. /* A decoded bundle used for backtracer analysis. */
  49. struct BacktraceBundle {
  50. tile_bundle_bits bits;
  51. int num_insns;
  52. struct tile_decoded_instruction
  53. insns[TILE_MAX_INSTRUCTIONS_PER_BUNDLE];
  54. };
  55. /* Locates an instruction inside the given bundle that
  56. * has the specified mnemonic, and whose first 'num_operands_to_match'
  57. * operands exactly match those in 'operand_values'.
  58. */
  59. static const struct tile_decoded_instruction *find_matching_insn(
  60. const struct BacktraceBundle *bundle,
  61. tile_mnemonic mnemonic,
  62. const int *operand_values,
  63. int num_operands_to_match)
  64. {
  65. int i, j;
  66. bool match;
  67. for (i = 0; i < bundle->num_insns; i++) {
  68. const struct tile_decoded_instruction *insn =
  69. &bundle->insns[i];
  70. if (insn->opcode->mnemonic != mnemonic)
  71. continue;
  72. match = true;
  73. for (j = 0; j < num_operands_to_match; j++) {
  74. if (operand_values[j] != insn->operand_values[j]) {
  75. match = false;
  76. break;
  77. }
  78. }
  79. if (match)
  80. return insn;
  81. }
  82. return NULL;
  83. }
  84. /* Does this bundle contain an 'iret' instruction? */
  85. static inline bool bt_has_iret(const struct BacktraceBundle *bundle)
  86. {
  87. return find_matching_insn(bundle, TILE_OPC_IRET, NULL, 0) != NULL;
  88. }
  89. /* Does this bundle contain an 'addi sp, sp, OFFSET' or
  90. * 'addli sp, sp, OFFSET' instruction, and if so, what is OFFSET?
  91. */
  92. static bool bt_has_addi_sp(const struct BacktraceBundle *bundle, int *adjust)
  93. {
  94. static const int vals[2] = { TREG_SP, TREG_SP };
  95. const struct tile_decoded_instruction *insn =
  96. find_matching_insn(bundle, TILE_OPC_ADDI, vals, 2);
  97. if (insn == NULL)
  98. insn = find_matching_insn(bundle, TILE_OPC_ADDLI, vals, 2);
  99. #ifdef __tilegx__
  100. if (insn == NULL)
  101. insn = find_matching_insn(bundle, TILEGX_OPC_ADDXLI, vals, 2);
  102. if (insn == NULL)
  103. insn = find_matching_insn(bundle, TILEGX_OPC_ADDXI, vals, 2);
  104. #endif
  105. if (insn == NULL)
  106. return false;
  107. *adjust = insn->operand_values[2];
  108. return true;
  109. }
  110. /* Does this bundle contain any 'info OP' or 'infol OP'
  111. * instruction, and if so, what are their OP? Note that OP is interpreted
  112. * as an unsigned value by this code since that's what the caller wants.
  113. * Returns the number of info ops found.
  114. */
  115. static int bt_get_info_ops(const struct BacktraceBundle *bundle,
  116. int operands[MAX_INFO_OPS_PER_BUNDLE])
  117. {
  118. int num_ops = 0;
  119. int i;
  120. for (i = 0; i < bundle->num_insns; i++) {
  121. const struct tile_decoded_instruction *insn =
  122. &bundle->insns[i];
  123. if (insn->opcode->mnemonic == TILE_OPC_INFO ||
  124. insn->opcode->mnemonic == TILE_OPC_INFOL) {
  125. operands[num_ops++] = insn->operand_values[0];
  126. }
  127. }
  128. return num_ops;
  129. }
  130. /* Does this bundle contain a jrp instruction, and if so, to which
  131. * register is it jumping?
  132. */
  133. static bool bt_has_jrp(const struct BacktraceBundle *bundle, int *target_reg)
  134. {
  135. const struct tile_decoded_instruction *insn =
  136. find_matching_insn(bundle, TILE_OPC_JRP, NULL, 0);
  137. if (insn == NULL)
  138. return false;
  139. *target_reg = insn->operand_values[0];
  140. return true;
  141. }
  142. /* Does this bundle modify the specified register in any way? */
  143. static bool bt_modifies_reg(const struct BacktraceBundle *bundle, int reg)
  144. {
  145. int i, j;
  146. for (i = 0; i < bundle->num_insns; i++) {
  147. const struct tile_decoded_instruction *insn =
  148. &bundle->insns[i];
  149. if (insn->opcode->implicitly_written_register == reg)
  150. return true;
  151. for (j = 0; j < insn->opcode->num_operands; j++)
  152. if (insn->operands[j]->is_dest_reg &&
  153. insn->operand_values[j] == reg)
  154. return true;
  155. }
  156. return false;
  157. }
  158. /* Does this bundle modify sp? */
  159. static inline bool bt_modifies_sp(const struct BacktraceBundle *bundle)
  160. {
  161. return bt_modifies_reg(bundle, TREG_SP);
  162. }
  163. /* Does this bundle modify lr? */
  164. static inline bool bt_modifies_lr(const struct BacktraceBundle *bundle)
  165. {
  166. return bt_modifies_reg(bundle, TREG_LR);
  167. }
  168. /* Does this bundle contain the instruction 'move fp, sp'? */
  169. static inline bool bt_has_move_r52_sp(const struct BacktraceBundle *bundle)
  170. {
  171. static const int vals[2] = { 52, TREG_SP };
  172. return find_matching_insn(bundle, TILE_OPC_MOVE, vals, 2) != NULL;
  173. }
  174. /* Does this bundle contain a store of lr to sp? */
  175. static inline bool bt_has_sw_sp_lr(const struct BacktraceBundle *bundle)
  176. {
  177. static const int vals[2] = { TREG_SP, TREG_LR };
  178. return find_matching_insn(bundle, OPCODE_STORE, vals, 2) != NULL;
  179. }
  180. #ifdef __tilegx__
  181. /* Track moveli values placed into registers. */
  182. static inline void bt_update_moveli(const struct BacktraceBundle *bundle,
  183. int moveli_args[])
  184. {
  185. int i;
  186. for (i = 0; i < bundle->num_insns; i++) {
  187. const struct tile_decoded_instruction *insn =
  188. &bundle->insns[i];
  189. if (insn->opcode->mnemonic == TILEGX_OPC_MOVELI) {
  190. int reg = insn->operand_values[0];
  191. moveli_args[reg] = insn->operand_values[1];
  192. }
  193. }
  194. }
  195. /* Does this bundle contain an 'add sp, sp, reg' instruction
  196. * from a register that we saw a moveli into, and if so, what
  197. * is the value in the register?
  198. */
  199. static bool bt_has_add_sp(const struct BacktraceBundle *bundle, int *adjust,
  200. int moveli_args[])
  201. {
  202. static const int vals[2] = { TREG_SP, TREG_SP };
  203. const struct tile_decoded_instruction *insn =
  204. find_matching_insn(bundle, TILEGX_OPC_ADDX, vals, 2);
  205. if (insn) {
  206. int reg = insn->operand_values[2];
  207. if (moveli_args[reg]) {
  208. *adjust = moveli_args[reg];
  209. return true;
  210. }
  211. }
  212. return false;
  213. }
  214. #endif
  215. /* Locates the caller's PC and SP for a program starting at the
  216. * given address.
  217. */
  218. static void find_caller_pc_and_caller_sp(CallerLocation *location,
  219. const unsigned long start_pc,
  220. BacktraceMemoryReader read_memory_func,
  221. void *read_memory_func_extra)
  222. {
  223. /* Have we explicitly decided what the sp is,
  224. * rather than just the default?
  225. */
  226. bool sp_determined = false;
  227. /* Has any bundle seen so far modified lr? */
  228. bool lr_modified = false;
  229. /* Have we seen a move from sp to fp? */
  230. bool sp_moved_to_r52 = false;
  231. /* Have we seen a terminating bundle? */
  232. bool seen_terminating_bundle = false;
  233. /* Cut down on round-trip reading overhead by reading several
  234. * bundles at a time.
  235. */
  236. tile_bundle_bits prefetched_bundles[32];
  237. int num_bundles_prefetched = 0;
  238. int next_bundle = 0;
  239. unsigned long pc;
  240. #ifdef __tilegx__
  241. /* Naively try to track moveli values to support addx for -m32. */
  242. int moveli_args[TILEGX_NUM_REGISTERS] = { 0 };
  243. #endif
  244. /* Default to assuming that the caller's sp is the current sp.
  245. * This is necessary to handle the case where we start backtracing
  246. * right at the end of the epilog.
  247. */
  248. location->sp_location = SP_LOC_OFFSET;
  249. location->sp_offset = 0;
  250. /* Default to having no idea where the caller PC is. */
  251. location->pc_location = PC_LOC_UNKNOWN;
  252. /* Don't even try if the PC is not aligned. */
  253. if (start_pc % TILE_BUNDLE_ALIGNMENT_IN_BYTES != 0)
  254. return;
  255. for (pc = start_pc;; pc += sizeof(tile_bundle_bits)) {
  256. struct BacktraceBundle bundle;
  257. int num_info_ops, info_operands[MAX_INFO_OPS_PER_BUNDLE];
  258. int one_ago, jrp_reg;
  259. bool has_jrp;
  260. if (next_bundle >= num_bundles_prefetched) {
  261. /* Prefetch some bytes, but don't cross a page
  262. * boundary since that might cause a read failure we
  263. * don't care about if we only need the first few
  264. * bytes. Note: we don't care what the actual page
  265. * size is; using the minimum possible page size will
  266. * prevent any problems.
  267. */
  268. unsigned int bytes_to_prefetch = 4096 - (pc & 4095);
  269. if (bytes_to_prefetch > sizeof prefetched_bundles)
  270. bytes_to_prefetch = sizeof prefetched_bundles;
  271. if (!read_memory_func(prefetched_bundles, pc,
  272. bytes_to_prefetch,
  273. read_memory_func_extra)) {
  274. if (pc == start_pc) {
  275. /* The program probably called a bad
  276. * address, such as a NULL pointer.
  277. * So treat this as if we are at the
  278. * start of the function prolog so the
  279. * backtrace will show how we got here.
  280. */
  281. location->pc_location = PC_LOC_IN_LR;
  282. return;
  283. }
  284. /* Unreadable address. Give up. */
  285. break;
  286. }
  287. next_bundle = 0;
  288. num_bundles_prefetched =
  289. bytes_to_prefetch / sizeof(tile_bundle_bits);
  290. }
  291. /* Decode the next bundle. */
  292. bundle.bits = prefetched_bundles[next_bundle++];
  293. bundle.num_insns =
  294. parse_insn_tile(bundle.bits, pc, bundle.insns);
  295. num_info_ops = bt_get_info_ops(&bundle, info_operands);
  296. /* First look at any one_ago info ops if they are interesting,
  297. * since they should shadow any non-one-ago info ops.
  298. */
  299. for (one_ago = (pc != start_pc) ? 1 : 0;
  300. one_ago >= 0; one_ago--) {
  301. int i;
  302. for (i = 0; i < num_info_ops; i++) {
  303. int info_operand = info_operands[i];
  304. if (info_operand < CALLER_UNKNOWN_BASE) {
  305. /* Weird; reserved value, ignore it. */
  306. continue;
  307. }
  308. /* Skip info ops which are not in the
  309. * "one_ago" mode we want right now.
  310. */
  311. if (((info_operand & ONE_BUNDLE_AGO_FLAG) != 0)
  312. != (one_ago != 0))
  313. continue;
  314. /* Clear the flag to make later checking
  315. * easier. */
  316. info_operand &= ~ONE_BUNDLE_AGO_FLAG;
  317. /* Default to looking at PC_IN_LR_FLAG. */
  318. if (info_operand & PC_IN_LR_FLAG)
  319. location->pc_location =
  320. PC_LOC_IN_LR;
  321. else
  322. location->pc_location =
  323. PC_LOC_ON_STACK;
  324. switch (info_operand) {
  325. case CALLER_UNKNOWN_BASE:
  326. location->pc_location = PC_LOC_UNKNOWN;
  327. location->sp_location = SP_LOC_UNKNOWN;
  328. return;
  329. case CALLER_SP_IN_R52_BASE:
  330. case CALLER_SP_IN_R52_BASE | PC_IN_LR_FLAG:
  331. location->sp_location = SP_LOC_IN_R52;
  332. return;
  333. default:
  334. {
  335. const unsigned int val = info_operand
  336. - CALLER_SP_OFFSET_BASE;
  337. const unsigned int sp_offset =
  338. (val >> NUM_INFO_OP_FLAGS) * 8;
  339. if (sp_offset < 32768) {
  340. /* This is a properly encoded
  341. * SP offset. */
  342. location->sp_location =
  343. SP_LOC_OFFSET;
  344. location->sp_offset =
  345. sp_offset;
  346. return;
  347. } else {
  348. /* This looked like an SP
  349. * offset, but it's outside
  350. * the legal range, so this
  351. * must be an unrecognized
  352. * info operand. Ignore it.
  353. */
  354. }
  355. }
  356. break;
  357. }
  358. }
  359. }
  360. if (seen_terminating_bundle) {
  361. /* We saw a terminating bundle during the previous
  362. * iteration, so we were only looking for an info op.
  363. */
  364. break;
  365. }
  366. if (bundle.bits == 0) {
  367. /* Wacky terminating bundle. Stop looping, and hope
  368. * we've already seen enough to find the caller.
  369. */
  370. break;
  371. }
  372. /*
  373. * Try to determine caller's SP.
  374. */
  375. if (!sp_determined) {
  376. int adjust;
  377. if (bt_has_addi_sp(&bundle, &adjust)
  378. #ifdef __tilegx__
  379. || bt_has_add_sp(&bundle, &adjust, moveli_args)
  380. #endif
  381. ) {
  382. location->sp_location = SP_LOC_OFFSET;
  383. if (adjust <= 0) {
  384. /* We are in prolog about to adjust
  385. * SP. */
  386. location->sp_offset = 0;
  387. } else {
  388. /* We are in epilog restoring SP. */
  389. location->sp_offset = adjust;
  390. }
  391. sp_determined = true;
  392. } else {
  393. if (bt_has_move_r52_sp(&bundle)) {
  394. /* Maybe in prolog, creating an
  395. * alloca-style frame. But maybe in
  396. * the middle of a fixed-size frame
  397. * clobbering r52 with SP.
  398. */
  399. sp_moved_to_r52 = true;
  400. }
  401. if (bt_modifies_sp(&bundle)) {
  402. if (sp_moved_to_r52) {
  403. /* We saw SP get saved into
  404. * r52 earlier (or now), which
  405. * must have been in the
  406. * prolog, so we now know that
  407. * SP is still holding the
  408. * caller's sp value.
  409. */
  410. location->sp_location =
  411. SP_LOC_OFFSET;
  412. location->sp_offset = 0;
  413. } else {
  414. /* Someone must have saved
  415. * aside the caller's SP value
  416. * into r52, so r52 holds the
  417. * current value.
  418. */
  419. location->sp_location =
  420. SP_LOC_IN_R52;
  421. }
  422. sp_determined = true;
  423. }
  424. }
  425. #ifdef __tilegx__
  426. /* Track moveli arguments for -m32 mode. */
  427. bt_update_moveli(&bundle, moveli_args);
  428. #endif
  429. }
  430. if (bt_has_iret(&bundle)) {
  431. /* This is a terminating bundle. */
  432. seen_terminating_bundle = true;
  433. continue;
  434. }
  435. /*
  436. * Try to determine caller's PC.
  437. */
  438. jrp_reg = -1;
  439. has_jrp = bt_has_jrp(&bundle, &jrp_reg);
  440. if (has_jrp)
  441. seen_terminating_bundle = true;
  442. if (location->pc_location == PC_LOC_UNKNOWN) {
  443. if (has_jrp) {
  444. if (jrp_reg == TREG_LR && !lr_modified) {
  445. /* Looks like a leaf function, or else
  446. * lr is already restored. */
  447. location->pc_location =
  448. PC_LOC_IN_LR;
  449. } else {
  450. location->pc_location =
  451. PC_LOC_ON_STACK;
  452. }
  453. } else if (bt_has_sw_sp_lr(&bundle)) {
  454. /* In prolog, spilling initial lr to stack. */
  455. location->pc_location = PC_LOC_IN_LR;
  456. } else if (bt_modifies_lr(&bundle)) {
  457. lr_modified = true;
  458. }
  459. }
  460. }
  461. }
  462. /* Initializes a backtracer to start from the given location.
  463. *
  464. * If the frame pointer cannot be determined it is set to -1.
  465. *
  466. * state: The state to be filled in.
  467. * read_memory_func: A callback that reads memory.
  468. * read_memory_func_extra: An arbitrary argument to read_memory_func.
  469. * pc: The current PC.
  470. * lr: The current value of the 'lr' register.
  471. * sp: The current value of the 'sp' register.
  472. * r52: The current value of the 'r52' register.
  473. */
  474. void backtrace_init(BacktraceIterator *state,
  475. BacktraceMemoryReader read_memory_func,
  476. void *read_memory_func_extra,
  477. unsigned long pc, unsigned long lr,
  478. unsigned long sp, unsigned long r52)
  479. {
  480. CallerLocation location;
  481. unsigned long fp, initial_frame_caller_pc;
  482. /* Find out where we are in the initial frame. */
  483. find_caller_pc_and_caller_sp(&location, pc,
  484. read_memory_func, read_memory_func_extra);
  485. switch (location.sp_location) {
  486. case SP_LOC_UNKNOWN:
  487. /* Give up. */
  488. fp = -1;
  489. break;
  490. case SP_LOC_IN_R52:
  491. fp = r52;
  492. break;
  493. case SP_LOC_OFFSET:
  494. fp = sp + location.sp_offset;
  495. break;
  496. default:
  497. /* Give up. */
  498. fp = -1;
  499. break;
  500. }
  501. /* If the frame pointer is not aligned to the basic word size
  502. * something terrible happened and we should mark it as invalid.
  503. */
  504. if (fp % sizeof(bt_int_reg_t) != 0)
  505. fp = -1;
  506. /* -1 means "don't know initial_frame_caller_pc". */
  507. initial_frame_caller_pc = -1;
  508. switch (location.pc_location) {
  509. case PC_LOC_UNKNOWN:
  510. /* Give up. */
  511. fp = -1;
  512. break;
  513. case PC_LOC_IN_LR:
  514. if (lr == 0 || lr % TILE_BUNDLE_ALIGNMENT_IN_BYTES != 0) {
  515. /* Give up. */
  516. fp = -1;
  517. } else {
  518. initial_frame_caller_pc = lr;
  519. }
  520. break;
  521. case PC_LOC_ON_STACK:
  522. /* Leave initial_frame_caller_pc as -1,
  523. * meaning check the stack.
  524. */
  525. break;
  526. default:
  527. /* Give up. */
  528. fp = -1;
  529. break;
  530. }
  531. state->pc = pc;
  532. state->sp = sp;
  533. state->fp = fp;
  534. state->initial_frame_caller_pc = initial_frame_caller_pc;
  535. state->read_memory_func = read_memory_func;
  536. state->read_memory_func_extra = read_memory_func_extra;
  537. }
  538. /* Handle the case where the register holds more bits than the VA. */
  539. static bool valid_addr_reg(bt_int_reg_t reg)
  540. {
  541. return ((unsigned long)reg == reg);
  542. }
  543. /* Advances the backtracing state to the calling frame, returning
  544. * true iff successful.
  545. */
  546. bool backtrace_next(BacktraceIterator *state)
  547. {
  548. unsigned long next_fp, next_pc;
  549. bt_int_reg_t next_frame[2];
  550. if (state->fp == -1) {
  551. /* No parent frame. */
  552. return false;
  553. }
  554. /* Try to read the frame linkage data chaining to the next function. */
  555. if (!state->read_memory_func(&next_frame, state->fp, sizeof next_frame,
  556. state->read_memory_func_extra)) {
  557. return false;
  558. }
  559. next_fp = next_frame[1];
  560. if (!valid_addr_reg(next_frame[1]) ||
  561. next_fp % sizeof(bt_int_reg_t) != 0) {
  562. /* Caller's frame pointer is suspect, so give up. */
  563. return false;
  564. }
  565. if (state->initial_frame_caller_pc != -1) {
  566. /* We must be in the initial stack frame and already know the
  567. * caller PC.
  568. */
  569. next_pc = state->initial_frame_caller_pc;
  570. /* Force reading stack next time, in case we were in the
  571. * initial frame. We don't do this above just to paranoidly
  572. * avoid changing the struct at all when we return false.
  573. */
  574. state->initial_frame_caller_pc = -1;
  575. } else {
  576. /* Get the caller PC from the frame linkage area. */
  577. next_pc = next_frame[0];
  578. if (!valid_addr_reg(next_frame[0]) || next_pc == 0 ||
  579. next_pc % TILE_BUNDLE_ALIGNMENT_IN_BYTES != 0) {
  580. /* The PC is suspect, so give up. */
  581. return false;
  582. }
  583. }
  584. /* Update state to become the caller's stack frame. */
  585. state->pc = next_pc;
  586. state->sp = state->fp;
  587. state->fp = next_fp;
  588. return true;
  589. }