backtrace.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * Copyright 2010 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. #ifndef _ASM_TILE_BACKTRACE_H
  15. #define _ASM_TILE_BACKTRACE_H
  16. #include <linux/types.h>
  17. /* Reads 'size' bytes from 'address' and writes the data to 'result'.
  18. * Returns true if successful, else false (e.g. memory not readable).
  19. */
  20. typedef bool (*BacktraceMemoryReader)(void *result,
  21. unsigned long address,
  22. unsigned int size,
  23. void *extra);
  24. typedef struct {
  25. /* Current PC. */
  26. unsigned long pc;
  27. /* Current stack pointer value. */
  28. unsigned long sp;
  29. /* Current frame pointer value (i.e. caller's stack pointer) */
  30. unsigned long fp;
  31. /* Internal use only: caller's PC for first frame. */
  32. unsigned long initial_frame_caller_pc;
  33. /* Internal use only: callback to read memory. */
  34. BacktraceMemoryReader read_memory_func;
  35. /* Internal use only: arbitrary argument to read_memory_func. */
  36. void *read_memory_func_extra;
  37. } BacktraceIterator;
  38. typedef enum {
  39. /* We have no idea what the caller's pc is. */
  40. PC_LOC_UNKNOWN,
  41. /* The caller's pc is currently in lr. */
  42. PC_LOC_IN_LR,
  43. /* The caller's pc can be found by dereferencing the caller's sp. */
  44. PC_LOC_ON_STACK
  45. } CallerPCLocation;
  46. typedef enum {
  47. /* We have no idea what the caller's sp is. */
  48. SP_LOC_UNKNOWN,
  49. /* The caller's sp is currently in r52. */
  50. SP_LOC_IN_R52,
  51. /* The caller's sp can be found by adding a certain constant
  52. * to the current value of sp.
  53. */
  54. SP_LOC_OFFSET
  55. } CallerSPLocation;
  56. /* Bit values ORed into CALLER_* values for info ops. */
  57. enum {
  58. /* Setting the low bit on any of these values means the info op
  59. * applies only to one bundle ago.
  60. */
  61. ONE_BUNDLE_AGO_FLAG = 1,
  62. /* Setting this bit on a CALLER_SP_* value means the PC is in LR.
  63. * If not set, PC is on the stack.
  64. */
  65. PC_IN_LR_FLAG = 2,
  66. /* This many of the low bits of a CALLER_SP_* value are for the
  67. * flag bits above.
  68. */
  69. NUM_INFO_OP_FLAGS = 2,
  70. /* We cannot have one in the memory pipe so this is the maximum. */
  71. MAX_INFO_OPS_PER_BUNDLE = 2
  72. };
  73. /* Internal constants used to define 'info' operands. */
  74. enum {
  75. /* 0 and 1 are reserved, as are all negative numbers. */
  76. CALLER_UNKNOWN_BASE = 2,
  77. CALLER_SP_IN_R52_BASE = 4,
  78. CALLER_SP_OFFSET_BASE = 8,
  79. };
  80. /* Current backtracer state describing where it thinks the caller is. */
  81. typedef struct {
  82. /*
  83. * Public fields
  84. */
  85. /* How do we find the caller's PC? */
  86. CallerPCLocation pc_location : 8;
  87. /* How do we find the caller's SP? */
  88. CallerSPLocation sp_location : 8;
  89. /* If sp_location == SP_LOC_OFFSET, then caller_sp == sp +
  90. * loc->sp_offset. Else this field is undefined.
  91. */
  92. uint16_t sp_offset;
  93. /* In the most recently visited bundle a terminating bundle? */
  94. bool at_terminating_bundle;
  95. /*
  96. * Private fields
  97. */
  98. /* Will the forward scanner see someone clobbering sp
  99. * (i.e. changing it with something other than addi sp, sp, N?)
  100. */
  101. bool sp_clobber_follows;
  102. /* Operand to next "visible" info op (no more than one bundle past
  103. * the next terminating bundle), or -32768 if none.
  104. */
  105. int16_t next_info_operand;
  106. /* Is the info of in next_info_op in the very next bundle? */
  107. bool is_next_info_operand_adjacent;
  108. } CallerLocation;
  109. extern void backtrace_init(BacktraceIterator *state,
  110. BacktraceMemoryReader read_memory_func,
  111. void *read_memory_func_extra,
  112. unsigned long pc, unsigned long lr,
  113. unsigned long sp, unsigned long r52);
  114. extern bool backtrace_next(BacktraceIterator *state);
  115. #endif /* _ASM_TILE_BACKTRACE_H */