backtrace.c 18 KB

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