| 1 | /* PowerPC traceback table support for BFD. | 
|---|
| 2 | Copyright 1993, 1998, 1999, 2000, 2001, 2002 | 
|---|
| 3 | Free Software Foundation, Inc. | 
|---|
| 4 |  | 
|---|
| 5 | This file is part of BFD, the Binary File Descriptor library. | 
|---|
| 6 |  | 
|---|
| 7 | This program is free software; you can redistribute it and/or modify | 
|---|
| 8 | it under the terms of the GNU General Public License as published by | 
|---|
| 9 | the Free Software Foundation; either version 2 of the License, or | 
|---|
| 10 | (at your option) any later version. | 
|---|
| 11 |  | 
|---|
| 12 | This program is distributed in the hope that it will be useful, | 
|---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 15 | GNU General Public License for more details. | 
|---|
| 16 |  | 
|---|
| 17 | You should have received a copy of the GNU General Public License | 
|---|
| 18 | along with this program; if not, write to the Free Software | 
|---|
| 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */ | 
|---|
| 20 |  | 
|---|
| 21 | /* Originally written by Ira Ruben, 06/28/93 */ | 
|---|
| 22 |  | 
|---|
| 23 | /*  This is a compiler independent representation of the AIX Version 3 traceback table (in | 
|---|
| 24 | sys/debug.h), which occurs, usually, one per procedure (routine). The table is marked by | 
|---|
| 25 | a multiple of 4 32-bit word of zeroes in the instruction space. The traceback table is | 
|---|
| 26 | also referred to as "procedure-end table". | 
|---|
| 27 |  | 
|---|
| 28 | The AIX traceback table representation on which this header is based is defined as a | 
|---|
| 29 | series of bit field struct specifications. Bit fields are compiler dependent! Thus, | 
|---|
| 30 | the definitions presented here follow the original header and the existing documentation | 
|---|
| 31 | (such as it is), but define the fields as BIT MASKS and other macros. The mask names, | 
|---|
| 32 | however, where chosen as the original field names to give some compatibility with the | 
|---|
| 33 | original header and to agree with the documentation.  */ | 
|---|
| 34 |  | 
|---|
| 35 | #ifndef __TRACEBACK__ | 
|---|
| 36 | #define __TRACEBACK__ | 
|---|
| 37 |  | 
|---|
| 38 | #define TB_C 0U                 /* C */ | 
|---|
| 39 | #define TB_FORTRAN 1U           /* FORTRAN */ | 
|---|
| 40 | #define TB_PASCAL 2U            /* Pascal */ | 
|---|
| 41 | #define TB_ADA 3U               /* ADA */ | 
|---|
| 42 | #define TB_PL1 4U               /* PL1 */ | 
|---|
| 43 | #define TB_BASIC 5U             /* Basic */ | 
|---|
| 44 | #define TB_LISP 6U              /* Lisp */ | 
|---|
| 45 | #define TB_COBOL 7U             /* eCobol */ | 
|---|
| 46 | #define TB_MODULA2 8U           /* Modula2 */ | 
|---|
| 47 | #define TB_CPLUSPLUS 9U         /* C++ */ | 
|---|
| 48 | #define TB_RPG 10U              /* RPG */ | 
|---|
| 49 | #define TB_PL8 11U              /* PL8 */ | 
|---|
| 50 | #define TB_ASM 12U              /* Asm */ | 
|---|
| 51 |  | 
|---|
| 52 | /* flags 1 */ | 
|---|
| 53 |  | 
|---|
| 54 | #define TB_GLOBALLINK 0x80U     /* Routine is Global Linkage.  */ | 
|---|
| 55 | #define TB_is_eprol 0x40U       /* Out-of-line prolog or epilog routine.  */ | 
|---|
| 56 | #define TB_HAS_TBOFF 0x20U      /* tb_offset set (extension field).  */ | 
|---|
| 57 | #define TB_INT_PROC 0x10U       /* Internal leaf routine.  */ | 
|---|
| 58 | #define TB_HAS_CTL 0x08U        /* Has controlled automatic storage.  */ | 
|---|
| 59 | #define TB_TOCLESS 0X04U        /* Routine has no TOC.  */ | 
|---|
| 60 | #define TB_FP_PRESENT 0x02U     /* Routine has floating point ops.  */ | 
|---|
| 61 | #define TB_LOG_ABORT 0x01U      /* fp_present && log/abort compiler opt.  */ | 
|---|
| 62 |  | 
|---|
| 63 | /* flags 2 */ | 
|---|
| 64 |  | 
|---|
| 65 | #define TB_INT_HNDL 0x80U       /* Routine is an interrupt handler.  */ | 
|---|
| 66 | #define TB_NAME_PRESENT 0x40U   /* Name_len/name set (extension field).  */ | 
|---|
| 67 | #define TB_USES_ALLOCA 0x20U    /* Uses alloca() to allocate storage.  */ | 
|---|
| 68 | #define TB_CL_DIS_inv 0x1CU     /* On-condition directives (see below).  */ | 
|---|
| 69 | #define TB_SAVES_CR 0x02U       /* Routine saves the CR.  */ | 
|---|
| 70 | #define TB_SAVES_LR 0x01U       /* Routine saves the LR.  */ | 
|---|
| 71 |  | 
|---|
| 72 | /* cl_dis_inv "on condition" settings: */ | 
|---|
| 73 |  | 
|---|
| 74 | #define TB_CL_DIS_INV(x) (((x) & cl_dis_inv) >> 2U) | 
|---|
| 75 |  | 
|---|
| 76 | #define TB_WALK_ONCOND 0U       /* Walk stack without restoring state.  */ | 
|---|
| 77 | #define TB_DISCARD_ONCOND 1U    /* Walk stack and discard.  */ | 
|---|
| 78 | #define TB_INVOKE_ONCOND 2U     /* Invoke a specific system routine.  */ | 
|---|
| 79 |  | 
|---|
| 80 | /* flags 3 */ | 
|---|
| 81 |  | 
|---|
| 82 | #define TB_STORES_BC 0x80U      /* Routine saves frame ptr of caller.  */ | 
|---|
| 83 | #define TB_SPARE2 0X40U         /* Spare bit.  */ | 
|---|
| 84 | #define TB_FPR_SAVED 0x3fU      /* Number of FPRs saved (max of 32).  */ | 
|---|
| 85 | /* (Last reg saved is ALWAYS fpr31).  */ | 
|---|
| 86 |  | 
|---|
| 87 | #define TB_NUM_FPR_SAVED(x) ((x) & fpr_saved) | 
|---|
| 88 |  | 
|---|
| 89 | /* flags 4 */ | 
|---|
| 90 |  | 
|---|
| 91 | #define TB_HAS_VEC_INFO 0x80U   /* Routine uses vectors.  */ | 
|---|
| 92 | #define TB_SPARE3 0X40U         /* Spare bit.  */ | 
|---|
| 93 | #define TB_GPR_SAVED 0x3fU      /* Number of GPRs saved (max of 32).  */ | 
|---|
| 94 | /* (Last reg saved is ALWAYS gpr31).  */ | 
|---|
| 95 |  | 
|---|
| 96 | #define TB_NUM_GPR_SAVED(x) ((x) & gpr_saved) | 
|---|
| 97 |  | 
|---|
| 98 | /* flags 5 */ | 
|---|
| 99 |  | 
|---|
| 100 | #define TB_FLOATPARAMS 0xfeU    /* Number of floating point parameters.  */ | 
|---|
| 101 | #define TB_PARAMSONSTK 0X01U    /* All parameters are on the stack.  */ | 
|---|
| 102 |  | 
|---|
| 103 | #define TB_NUM_FLOATPARAMS(X) (((x) & floatparams) >> 1U) | 
|---|
| 104 |  | 
|---|
| 105 | /* traceback_table (fixed portion).  */ | 
|---|
| 106 |  | 
|---|
| 107 | struct traceback_table | 
|---|
| 108 | { | 
|---|
| 109 | /* Traceback table layout (fixed portion):  */ | 
|---|
| 110 |  | 
|---|
| 111 | unsigned char version;        /* Traceback format version.  */ | 
|---|
| 112 | unsigned char lang;           /* Language indicators:  */ | 
|---|
| 113 | unsigned char flags1;         /* Flag bits #1:  */ | 
|---|
| 114 | unsigned char flags2;         /* Flag bits #2:  */ | 
|---|
| 115 | unsigned char flags3;         /* Flag bits #3:  */ | 
|---|
| 116 | unsigned char flags4;         /* Flag bits #4:  */ | 
|---|
| 117 | unsigned char fixedparams;    /* Number of fixed point parameters.  */ | 
|---|
| 118 | unsigned char flags5;         /* Flag bits #5:  */ | 
|---|
| 119 | }; | 
|---|
| 120 |  | 
|---|
| 121 | /* traceback_table (optional) extensions.  */ | 
|---|
| 122 |  | 
|---|
| 123 | /* Optional portions exist independently in the order presented below, | 
|---|
| 124 | not as a structure or a union. Whether or not portions exist is | 
|---|
| 125 | determinable from bit-fields within the fixed portion above.  */ | 
|---|
| 126 |  | 
|---|
| 127 | /* The following is present only if fixedparams or floatparams are non | 
|---|
| 128 | zero and it immediately follows the fixed portion of the traceback | 
|---|
| 129 | table...  */ | 
|---|
| 130 |  | 
|---|
| 131 | /* Order and type encoding of parameters:  */ | 
|---|
| 132 | struct traceback_table_fixedparams | 
|---|
| 133 | { | 
|---|
| 134 | unsigned long paraminfo; | 
|---|
| 135 | }; | 
|---|
| 136 |  | 
|---|
| 137 | /* Left-justified bit-encoding as follows:  */ | 
|---|
| 138 | #define FIXED_PARAM 0           /* '0'  ==> fixed param (1 gpr or word).  */ | 
|---|
| 139 | #define SPFP_PARAM 2            /* '10' ==> single-precision float param.  */ | 
|---|
| 140 | #define DPFP_PARAM 3            /* '11' ==> double-precision float param.  */ | 
|---|
| 141 |  | 
|---|
| 142 | #define PARAM_ENCODING(x, bit) /* Yields xxx_PARAM as a function of "bit".  */          \ | 
|---|
| 143 | ((((x)&(1UL<<(31UL-(bit++))))==0UL) /* Values 0:31 (left-to-right). "bit" is */        \ | 
|---|
| 144 | ? FIXED_PARAM /* an L-value that's left incremented to */                              \ | 
|---|
| 145 | : ((((x)&(1UL<<(31UL-(bit++))))==0)/* the next bit position for the next */            \ | 
|---|
| 146 | ? SPFP_PARAM /* parameter.  This will be 1 or 2 bit */                                 \ | 
|---|
| 147 | : DPFP_PARAM)) /* positions later.  */ | 
|---|
| 148 |  | 
|---|
| 149 | /* The following is present only if has_tboff (in flags1) in fixed part is present...  */ | 
|---|
| 150 |  | 
|---|
| 151 | /* Offset from start of code to TracebackTbl.  */ | 
|---|
| 152 | struct traceback_table_tboff | 
|---|
| 153 | { | 
|---|
| 154 | unsigned long tb_offset; | 
|---|
| 155 | }; | 
|---|
| 156 |  | 
|---|
| 157 | /* The following is present only if int_hndl (in flags2) in fixed part is present ...  */ | 
|---|
| 158 |  | 
|---|
| 159 | /* What interrupts are handled by the routine.  */ | 
|---|
| 160 | struct traceback_table_interrupts | 
|---|
| 161 | { | 
|---|
| 162 | long hand_mask; | 
|---|
| 163 | }; | 
|---|
| 164 |  | 
|---|
| 165 | /* The following are present only if has_ctl (in flags1) in fixed part is present...  */ | 
|---|
| 166 |  | 
|---|
| 167 | /* Controlled automatic storage info:  */ | 
|---|
| 168 | struct traceback_table_anchors | 
|---|
| 169 | { | 
|---|
| 170 | unsigned long ctl_info;       /* Number of controlled automatic anchors.  */ | 
|---|
| 171 | long ctl_info_disp[1];        /* Array of stack displacements where each.  */ | 
|---|
| 172 | };                              /* Anchor is located (array STARTS here).  */ | 
|---|
| 173 |  | 
|---|
| 174 | /* The following are present only if name_present (in flags2) in fixed | 
|---|
| 175 | part is present...  */ | 
|---|
| 176 |  | 
|---|
| 177 | /* Routine name:  */ | 
|---|
| 178 | struct traceback_table_routine | 
|---|
| 179 | { | 
|---|
| 180 | unsigned short name_len;      /* Length of name that follows.  */ | 
|---|
| 181 | char name[1];                 /* Name starts here (NOT null terminated).  */ | 
|---|
| 182 | }; | 
|---|
| 183 |  | 
|---|
| 184 | /* The following are present only if uses_alloca (in flags2) in fixed | 
|---|
| 185 | part is present...  */ | 
|---|
| 186 |  | 
|---|
| 187 | /* Register auto storage when alloca() is used.  */ | 
|---|
| 188 | struct traceback_table_alloca | 
|---|
| 189 | { | 
|---|
| 190 | char alloca_reg; | 
|---|
| 191 | }; | 
|---|
| 192 |  | 
|---|
| 193 | /* The following are present only if has_vec_info (in flags4) in fixed | 
|---|
| 194 | part is present...  */ | 
|---|
| 195 |  | 
|---|
| 196 | /* Vector info:  */ | 
|---|
| 197 | struct traceback_table_vector | 
|---|
| 198 | { | 
|---|
| 199 | unsigned char vec_flags1;     /* Vec info bits #1:  */ | 
|---|
| 200 |  | 
|---|
| 201 | #define TB_VR_SAVED 0xFCU       /* Number of saved vector registers.  */ | 
|---|
| 202 | #define TB_SAVES_VRSAVE 0x02U   /* Saves VRsave.  */ | 
|---|
| 203 | #define TB_HAS_VARARGS 0x01U    /* Routine has a variable argument list.  */ | 
|---|
| 204 |  | 
|---|
| 205 | #define TB_NUM_VR_SAVED(x) (((x) & TB_VR_SAVED) >> 2U) | 
|---|
| 206 |  | 
|---|
| 207 | unsigned char vec_flags2;     /* Vec info bits #2:  */ | 
|---|
| 208 |  | 
|---|
| 209 | #define TB_VECTORPARAMS 0xfeU   /* Number of vector parameters.  */ | 
|---|
| 210 | #define TB_VEC_PRESENT 0x01U    /* Routine uses at least one vec instr.  */ | 
|---|
| 211 |  | 
|---|
| 212 | #define VECPARAMS(x) (((x) & TB_VECTORPARAMS) >> 1U) | 
|---|
| 213 | }; | 
|---|
| 214 |  | 
|---|
| 215 | #endif | 
|---|