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