Path: blob/master/arch/tile/include/asm/backtrace.h
10819 views
/*1* Copyright 2010 Tilera Corporation. All Rights Reserved.2*3* This program is free software; you can redistribute it and/or4* modify it under the terms of the GNU General Public License5* as published by the Free Software Foundation, version 2.6*7* This program is distributed in the hope that it will be useful, but8* WITHOUT ANY WARRANTY; without even the implied warranty of9* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or10* NON INFRINGEMENT. See the GNU General Public License for11* more details.12*/1314#ifndef _ASM_TILE_BACKTRACE_H15#define _ASM_TILE_BACKTRACE_H1617#include <linux/types.h>1819/* Reads 'size' bytes from 'address' and writes the data to 'result'.20* Returns true if successful, else false (e.g. memory not readable).21*/22typedef bool (*BacktraceMemoryReader)(void *result,23unsigned long address,24unsigned int size,25void *extra);2627typedef struct {28/* Current PC. */29unsigned long pc;3031/* Current stack pointer value. */32unsigned long sp;3334/* Current frame pointer value (i.e. caller's stack pointer) */35unsigned long fp;3637/* Internal use only: caller's PC for first frame. */38unsigned long initial_frame_caller_pc;3940/* Internal use only: callback to read memory. */41BacktraceMemoryReader read_memory_func;4243/* Internal use only: arbitrary argument to read_memory_func. */44void *read_memory_func_extra;4546} BacktraceIterator;474849typedef enum {5051/* We have no idea what the caller's pc is. */52PC_LOC_UNKNOWN,5354/* The caller's pc is currently in lr. */55PC_LOC_IN_LR,5657/* The caller's pc can be found by dereferencing the caller's sp. */58PC_LOC_ON_STACK5960} CallerPCLocation;616263typedef enum {6465/* We have no idea what the caller's sp is. */66SP_LOC_UNKNOWN,6768/* The caller's sp is currently in r52. */69SP_LOC_IN_R52,7071/* The caller's sp can be found by adding a certain constant72* to the current value of sp.73*/74SP_LOC_OFFSET7576} CallerSPLocation;777879/* Bit values ORed into CALLER_* values for info ops. */80enum {81/* Setting the low bit on any of these values means the info op82* applies only to one bundle ago.83*/84ONE_BUNDLE_AGO_FLAG = 1,8586/* Setting this bit on a CALLER_SP_* value means the PC is in LR.87* If not set, PC is on the stack.88*/89PC_IN_LR_FLAG = 2,9091/* This many of the low bits of a CALLER_SP_* value are for the92* flag bits above.93*/94NUM_INFO_OP_FLAGS = 2,9596/* We cannot have one in the memory pipe so this is the maximum. */97MAX_INFO_OPS_PER_BUNDLE = 298};99100101/* Internal constants used to define 'info' operands. */102enum {103/* 0 and 1 are reserved, as are all negative numbers. */104105CALLER_UNKNOWN_BASE = 2,106107CALLER_SP_IN_R52_BASE = 4,108109CALLER_SP_OFFSET_BASE = 8,110};111112113/* Current backtracer state describing where it thinks the caller is. */114typedef struct {115/*116* Public fields117*/118119/* How do we find the caller's PC? */120CallerPCLocation pc_location : 8;121122/* How do we find the caller's SP? */123CallerSPLocation sp_location : 8;124125/* If sp_location == SP_LOC_OFFSET, then caller_sp == sp +126* loc->sp_offset. Else this field is undefined.127*/128uint16_t sp_offset;129130/* In the most recently visited bundle a terminating bundle? */131bool at_terminating_bundle;132133/*134* Private fields135*/136137/* Will the forward scanner see someone clobbering sp138* (i.e. changing it with something other than addi sp, sp, N?)139*/140bool sp_clobber_follows;141142/* Operand to next "visible" info op (no more than one bundle past143* the next terminating bundle), or -32768 if none.144*/145int16_t next_info_operand;146147/* Is the info of in next_info_op in the very next bundle? */148bool is_next_info_operand_adjacent;149150} CallerLocation;151152extern void backtrace_init(BacktraceIterator *state,153BacktraceMemoryReader read_memory_func,154void *read_memory_func_extra,155unsigned long pc, unsigned long lr,156unsigned long sp, unsigned long r52);157158159extern bool backtrace_next(BacktraceIterator *state);160161#endif /* _ASM_TILE_BACKTRACE_H */162163164