1*3d8817e4Smiod /* Interface between the opcode library and its callers. 2*3d8817e4Smiod 3*3d8817e4Smiod Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005 4*3d8817e4Smiod Free Software Foundation, Inc. 5*3d8817e4Smiod 6*3d8817e4Smiod This program is free software; you can redistribute it and/or modify 7*3d8817e4Smiod it under the terms of the GNU General Public License as published by 8*3d8817e4Smiod the Free Software Foundation; either version 2, or (at your option) 9*3d8817e4Smiod any later version. 10*3d8817e4Smiod 11*3d8817e4Smiod This program is distributed in the hope that it will be useful, 12*3d8817e4Smiod but WITHOUT ANY WARRANTY; without even the implied warranty of 13*3d8817e4Smiod MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*3d8817e4Smiod GNU General Public License for more details. 15*3d8817e4Smiod 16*3d8817e4Smiod You should have received a copy of the GNU General Public License 17*3d8817e4Smiod along with this program; if not, write to the Free Software 18*3d8817e4Smiod Foundation, Inc., 51 Franklin Street - Fifth Floor, 19*3d8817e4Smiod Boston, MA 02110-1301, USA. 20*3d8817e4Smiod 21*3d8817e4Smiod Written by Cygnus Support, 1993. 22*3d8817e4Smiod 23*3d8817e4Smiod The opcode library (libopcodes.a) provides instruction decoders for 24*3d8817e4Smiod a large variety of instruction sets, callable with an identical 25*3d8817e4Smiod interface, for making instruction-processing programs more independent 26*3d8817e4Smiod of the instruction set being processed. */ 27*3d8817e4Smiod 28*3d8817e4Smiod #ifndef DIS_ASM_H 29*3d8817e4Smiod #define DIS_ASM_H 30*3d8817e4Smiod 31*3d8817e4Smiod #ifdef __cplusplus 32*3d8817e4Smiod extern "C" { 33*3d8817e4Smiod #endif 34*3d8817e4Smiod 35*3d8817e4Smiod #include <stdio.h> 36*3d8817e4Smiod #include "bfd.h" 37*3d8817e4Smiod 38*3d8817e4Smiod typedef int (*fprintf_ftype) (void *, const char*, ...) ATTRIBUTE_FPTR_PRINTF_2; 39*3d8817e4Smiod 40*3d8817e4Smiod enum dis_insn_type { 41*3d8817e4Smiod dis_noninsn, /* Not a valid instruction */ 42*3d8817e4Smiod dis_nonbranch, /* Not a branch instruction */ 43*3d8817e4Smiod dis_branch, /* Unconditional branch */ 44*3d8817e4Smiod dis_condbranch, /* Conditional branch */ 45*3d8817e4Smiod dis_jsr, /* Jump to subroutine */ 46*3d8817e4Smiod dis_condjsr, /* Conditional jump to subroutine */ 47*3d8817e4Smiod dis_dref, /* Data reference instruction */ 48*3d8817e4Smiod dis_dref2 /* Two data references in instruction */ 49*3d8817e4Smiod }; 50*3d8817e4Smiod 51*3d8817e4Smiod /* This struct is passed into the instruction decoding routine, 52*3d8817e4Smiod and is passed back out into each callback. The various fields are used 53*3d8817e4Smiod for conveying information from your main routine into your callbacks, 54*3d8817e4Smiod for passing information into the instruction decoders (such as the 55*3d8817e4Smiod addresses of the callback functions), or for passing information 56*3d8817e4Smiod back from the instruction decoders to their callers. 57*3d8817e4Smiod 58*3d8817e4Smiod It must be initialized before it is first passed; this can be done 59*3d8817e4Smiod by hand, or using one of the initialization macros below. */ 60*3d8817e4Smiod 61*3d8817e4Smiod typedef struct disassemble_info { 62*3d8817e4Smiod fprintf_ftype fprintf_func; 63*3d8817e4Smiod void *stream; 64*3d8817e4Smiod void *application_data; 65*3d8817e4Smiod 66*3d8817e4Smiod /* Target description. We could replace this with a pointer to the bfd, 67*3d8817e4Smiod but that would require one. There currently isn't any such requirement 68*3d8817e4Smiod so to avoid introducing one we record these explicitly. */ 69*3d8817e4Smiod /* The bfd_flavour. This can be bfd_target_unknown_flavour. */ 70*3d8817e4Smiod enum bfd_flavour flavour; 71*3d8817e4Smiod /* The bfd_arch value. */ 72*3d8817e4Smiod enum bfd_architecture arch; 73*3d8817e4Smiod /* The bfd_mach value. */ 74*3d8817e4Smiod unsigned long mach; 75*3d8817e4Smiod /* Endianness (for bi-endian cpus). Mono-endian cpus can ignore this. */ 76*3d8817e4Smiod enum bfd_endian endian; 77*3d8817e4Smiod /* An arch/mach-specific bitmask of selected instruction subsets, mainly 78*3d8817e4Smiod for processors with run-time-switchable instruction sets. The default, 79*3d8817e4Smiod zero, means that there is no constraint. CGEN-based opcodes ports 80*3d8817e4Smiod may use ISA_foo masks. */ 81*3d8817e4Smiod void *insn_sets; 82*3d8817e4Smiod 83*3d8817e4Smiod /* Some targets need information about the current section to accurately 84*3d8817e4Smiod display insns. If this is NULL, the target disassembler function 85*3d8817e4Smiod will have to make its best guess. */ 86*3d8817e4Smiod asection *section; 87*3d8817e4Smiod 88*3d8817e4Smiod /* An array of pointers to symbols either at the location being disassembled 89*3d8817e4Smiod or at the start of the function being disassembled. The array is sorted 90*3d8817e4Smiod so that the first symbol is intended to be the one used. The others are 91*3d8817e4Smiod present for any misc. purposes. This is not set reliably, but if it is 92*3d8817e4Smiod not NULL, it is correct. */ 93*3d8817e4Smiod asymbol **symbols; 94*3d8817e4Smiod /* Number of symbols in array. */ 95*3d8817e4Smiod int num_symbols; 96*3d8817e4Smiod 97*3d8817e4Smiod /* For use by the disassembler. 98*3d8817e4Smiod The top 16 bits are reserved for public use (and are documented here). 99*3d8817e4Smiod The bottom 16 bits are for the internal use of the disassembler. */ 100*3d8817e4Smiod unsigned long flags; 101*3d8817e4Smiod #define INSN_HAS_RELOC 0x80000000 102*3d8817e4Smiod void *private_data; 103*3d8817e4Smiod 104*3d8817e4Smiod /* Function used to get bytes to disassemble. MEMADDR is the 105*3d8817e4Smiod address of the stuff to be disassembled, MYADDR is the address to 106*3d8817e4Smiod put the bytes in, and LENGTH is the number of bytes to read. 107*3d8817e4Smiod INFO is a pointer to this struct. 108*3d8817e4Smiod Returns an errno value or 0 for success. */ 109*3d8817e4Smiod int (*read_memory_func) 110*3d8817e4Smiod (bfd_vma memaddr, bfd_byte *myaddr, unsigned int length, 111*3d8817e4Smiod struct disassemble_info *info); 112*3d8817e4Smiod 113*3d8817e4Smiod /* Function which should be called if we get an error that we can't 114*3d8817e4Smiod recover from. STATUS is the errno value from read_memory_func and 115*3d8817e4Smiod MEMADDR is the address that we were trying to read. INFO is a 116*3d8817e4Smiod pointer to this struct. */ 117*3d8817e4Smiod void (*memory_error_func) 118*3d8817e4Smiod (int status, bfd_vma memaddr, struct disassemble_info *info); 119*3d8817e4Smiod 120*3d8817e4Smiod /* Function called to print ADDR. */ 121*3d8817e4Smiod void (*print_address_func) 122*3d8817e4Smiod (bfd_vma addr, struct disassemble_info *info); 123*3d8817e4Smiod 124*3d8817e4Smiod /* Function called to determine if there is a symbol at the given ADDR. 125*3d8817e4Smiod If there is, the function returns 1, otherwise it returns 0. 126*3d8817e4Smiod This is used by ports which support an overlay manager where 127*3d8817e4Smiod the overlay number is held in the top part of an address. In 128*3d8817e4Smiod some circumstances we want to include the overlay number in the 129*3d8817e4Smiod address, (normally because there is a symbol associated with 130*3d8817e4Smiod that address), but sometimes we want to mask out the overlay bits. */ 131*3d8817e4Smiod int (* symbol_at_address_func) 132*3d8817e4Smiod (bfd_vma addr, struct disassemble_info * info); 133*3d8817e4Smiod 134*3d8817e4Smiod /* Function called to check if a SYMBOL is can be displayed to the user. 135*3d8817e4Smiod This is used by some ports that want to hide special symbols when 136*3d8817e4Smiod displaying debugging outout. */ 137*3d8817e4Smiod bfd_boolean (* symbol_is_valid) 138*3d8817e4Smiod (asymbol *, struct disassemble_info * info); 139*3d8817e4Smiod 140*3d8817e4Smiod /* These are for buffer_read_memory. */ 141*3d8817e4Smiod bfd_byte *buffer; 142*3d8817e4Smiod bfd_vma buffer_vma; 143*3d8817e4Smiod unsigned int buffer_length; 144*3d8817e4Smiod 145*3d8817e4Smiod /* This variable may be set by the instruction decoder. It suggests 146*3d8817e4Smiod the number of bytes objdump should display on a single line. If 147*3d8817e4Smiod the instruction decoder sets this, it should always set it to 148*3d8817e4Smiod the same value in order to get reasonable looking output. */ 149*3d8817e4Smiod int bytes_per_line; 150*3d8817e4Smiod 151*3d8817e4Smiod /* The next two variables control the way objdump displays the raw data. */ 152*3d8817e4Smiod /* For example, if bytes_per_line is 8 and bytes_per_chunk is 4, the */ 153*3d8817e4Smiod /* output will look like this: 154*3d8817e4Smiod 00: 00000000 00000000 155*3d8817e4Smiod with the chunks displayed according to "display_endian". */ 156*3d8817e4Smiod int bytes_per_chunk; 157*3d8817e4Smiod enum bfd_endian display_endian; 158*3d8817e4Smiod 159*3d8817e4Smiod /* Number of octets per incremented target address 160*3d8817e4Smiod Normally one, but some DSPs have byte sizes of 16 or 32 bits. */ 161*3d8817e4Smiod unsigned int octets_per_byte; 162*3d8817e4Smiod 163*3d8817e4Smiod /* The number of zeroes we want to see at the end of a section before we 164*3d8817e4Smiod start skipping them. */ 165*3d8817e4Smiod unsigned int skip_zeroes; 166*3d8817e4Smiod 167*3d8817e4Smiod /* The number of zeroes to skip at the end of a section. If the number 168*3d8817e4Smiod of zeroes at the end is between SKIP_ZEROES_AT_END and SKIP_ZEROES, 169*3d8817e4Smiod they will be disassembled. If there are fewer than 170*3d8817e4Smiod SKIP_ZEROES_AT_END, they will be skipped. This is a heuristic 171*3d8817e4Smiod attempt to avoid disassembling zeroes inserted by section 172*3d8817e4Smiod alignment. */ 173*3d8817e4Smiod unsigned int skip_zeroes_at_end; 174*3d8817e4Smiod 175*3d8817e4Smiod /* Whether the disassembler always needs the relocations. */ 176*3d8817e4Smiod bfd_boolean disassembler_needs_relocs; 177*3d8817e4Smiod 178*3d8817e4Smiod /* Results from instruction decoders. Not all decoders yet support 179*3d8817e4Smiod this information. This info is set each time an instruction is 180*3d8817e4Smiod decoded, and is only valid for the last such instruction. 181*3d8817e4Smiod 182*3d8817e4Smiod To determine whether this decoder supports this information, set 183*3d8817e4Smiod insn_info_valid to 0, decode an instruction, then check it. */ 184*3d8817e4Smiod 185*3d8817e4Smiod char insn_info_valid; /* Branch info has been set. */ 186*3d8817e4Smiod char branch_delay_insns; /* How many sequential insn's will run before 187*3d8817e4Smiod a branch takes effect. (0 = normal) */ 188*3d8817e4Smiod char data_size; /* Size of data reference in insn, in bytes */ 189*3d8817e4Smiod enum dis_insn_type insn_type; /* Type of instruction */ 190*3d8817e4Smiod bfd_vma target; /* Target address of branch or dref, if known; 191*3d8817e4Smiod zero if unknown. */ 192*3d8817e4Smiod bfd_vma target2; /* Second target address for dref2 */ 193*3d8817e4Smiod 194*3d8817e4Smiod /* Command line options specific to the target disassembler. */ 195*3d8817e4Smiod char * disassembler_options; 196*3d8817e4Smiod 197*3d8817e4Smiod } disassemble_info; 198*3d8817e4Smiod 199*3d8817e4Smiod 200*3d8817e4Smiod /* Standard disassemblers. Disassemble one instruction at the given 201*3d8817e4Smiod target address. Return number of octets processed. */ 202*3d8817e4Smiod typedef int (*disassembler_ftype) (bfd_vma, disassemble_info *); 203*3d8817e4Smiod 204*3d8817e4Smiod extern int print_insn_big_mips (bfd_vma, disassemble_info *); 205*3d8817e4Smiod extern int print_insn_little_mips (bfd_vma, disassemble_info *); 206*3d8817e4Smiod extern int print_insn_i386 (bfd_vma, disassemble_info *); 207*3d8817e4Smiod extern int print_insn_i386_att (bfd_vma, disassemble_info *); 208*3d8817e4Smiod extern int print_insn_i386_intel (bfd_vma, disassemble_info *); 209*3d8817e4Smiod extern int print_insn_ia64 (bfd_vma, disassemble_info *); 210*3d8817e4Smiod extern int print_insn_i370 (bfd_vma, disassemble_info *); 211*3d8817e4Smiod extern int print_insn_m68hc11 (bfd_vma, disassemble_info *); 212*3d8817e4Smiod extern int print_insn_m68hc12 (bfd_vma, disassemble_info *); 213*3d8817e4Smiod extern int print_insn_m68k (bfd_vma, disassemble_info *); 214*3d8817e4Smiod extern int print_insn_z80 (bfd_vma, disassemble_info *); 215*3d8817e4Smiod extern int print_insn_z8001 (bfd_vma, disassemble_info *); 216*3d8817e4Smiod extern int print_insn_z8002 (bfd_vma, disassemble_info *); 217*3d8817e4Smiod extern int print_insn_h8300 (bfd_vma, disassemble_info *); 218*3d8817e4Smiod extern int print_insn_h8300h (bfd_vma, disassemble_info *); 219*3d8817e4Smiod extern int print_insn_h8300s (bfd_vma, disassemble_info *); 220*3d8817e4Smiod extern int print_insn_h8500 (bfd_vma, disassemble_info *); 221*3d8817e4Smiod extern int print_insn_alpha (bfd_vma, disassemble_info *); 222*3d8817e4Smiod extern int print_insn_big_arm (bfd_vma, disassemble_info *); 223*3d8817e4Smiod extern int print_insn_little_arm (bfd_vma, disassemble_info *); 224*3d8817e4Smiod extern int print_insn_sparc (bfd_vma, disassemble_info *); 225*3d8817e4Smiod extern int print_insn_avr (bfd_vma, disassemble_info *); 226*3d8817e4Smiod extern int print_insn_bfin (bfd_vma, disassemble_info *); 227*3d8817e4Smiod extern int print_insn_d10v (bfd_vma, disassemble_info *); 228*3d8817e4Smiod extern int print_insn_d30v (bfd_vma, disassemble_info *); 229*3d8817e4Smiod extern int print_insn_dlx (bfd_vma, disassemble_info *); 230*3d8817e4Smiod extern int print_insn_fr30 (bfd_vma, disassemble_info *); 231*3d8817e4Smiod extern int print_insn_hppa (bfd_vma, disassemble_info *); 232*3d8817e4Smiod extern int print_insn_i860 (bfd_vma, disassemble_info *); 233*3d8817e4Smiod extern int print_insn_i960 (bfd_vma, disassemble_info *); 234*3d8817e4Smiod extern int print_insn_ip2k (bfd_vma, disassemble_info *); 235*3d8817e4Smiod extern int print_insn_m32r (bfd_vma, disassemble_info *); 236*3d8817e4Smiod extern int print_insn_m88k (bfd_vma, disassemble_info *); 237*3d8817e4Smiod extern int print_insn_maxq_little (bfd_vma, disassemble_info *); 238*3d8817e4Smiod extern int print_insn_maxq_big (bfd_vma, disassemble_info *); 239*3d8817e4Smiod extern int print_insn_mcore (bfd_vma, disassemble_info *); 240*3d8817e4Smiod extern int print_insn_mmix (bfd_vma, disassemble_info *); 241*3d8817e4Smiod extern int print_insn_mn10200 (bfd_vma, disassemble_info *); 242*3d8817e4Smiod extern int print_insn_mn10300 (bfd_vma, disassemble_info *); 243*3d8817e4Smiod extern int print_insn_mt (bfd_vma, disassemble_info *); 244*3d8817e4Smiod extern int print_insn_msp430 (bfd_vma, disassemble_info *); 245*3d8817e4Smiod extern int print_insn_ns32k (bfd_vma, disassemble_info *); 246*3d8817e4Smiod extern int print_insn_crx (bfd_vma, disassemble_info *); 247*3d8817e4Smiod extern int print_insn_openrisc (bfd_vma, disassemble_info *); 248*3d8817e4Smiod extern int print_insn_big_or32 (bfd_vma, disassemble_info *); 249*3d8817e4Smiod extern int print_insn_little_or32 (bfd_vma, disassemble_info *); 250*3d8817e4Smiod extern int print_insn_pdp11 (bfd_vma, disassemble_info *); 251*3d8817e4Smiod extern int print_insn_pj (bfd_vma, disassemble_info *); 252*3d8817e4Smiod extern int print_insn_big_powerpc (bfd_vma, disassemble_info *); 253*3d8817e4Smiod extern int print_insn_little_powerpc (bfd_vma, disassemble_info *); 254*3d8817e4Smiod extern int print_insn_rs6000 (bfd_vma, disassemble_info *); 255*3d8817e4Smiod extern int print_insn_s390 (bfd_vma, disassemble_info *); 256*3d8817e4Smiod extern int print_insn_sh (bfd_vma, disassemble_info *); 257*3d8817e4Smiod extern int print_insn_tic30 (bfd_vma, disassemble_info *); 258*3d8817e4Smiod extern int print_insn_tic4x (bfd_vma, disassemble_info *); 259*3d8817e4Smiod extern int print_insn_tic54x (bfd_vma, disassemble_info *); 260*3d8817e4Smiod extern int print_insn_tic80 (bfd_vma, disassemble_info *); 261*3d8817e4Smiod extern int print_insn_v850 (bfd_vma, disassemble_info *); 262*3d8817e4Smiod extern int print_insn_vax (bfd_vma, disassemble_info *); 263*3d8817e4Smiod extern int print_insn_w65 (bfd_vma, disassemble_info *); 264*3d8817e4Smiod extern int print_insn_xstormy16 (bfd_vma, disassemble_info *); 265*3d8817e4Smiod extern int print_insn_xtensa (bfd_vma, disassemble_info *); 266*3d8817e4Smiod extern int print_insn_sh64 (bfd_vma, disassemble_info *); 267*3d8817e4Smiod extern int print_insn_sh64x_media (bfd_vma, disassemble_info *); 268*3d8817e4Smiod extern int print_insn_frv (bfd_vma, disassemble_info *); 269*3d8817e4Smiod extern int print_insn_iq2000 (bfd_vma, disassemble_info *); 270*3d8817e4Smiod extern int print_insn_xc16x (bfd_vma, disassemble_info *); 271*3d8817e4Smiod extern int print_insn_m32c (bfd_vma, disassemble_info *); 272*3d8817e4Smiod 273*3d8817e4Smiod extern disassembler_ftype arc_get_disassembler (void *); 274*3d8817e4Smiod extern disassembler_ftype cris_get_disassembler (bfd *); 275*3d8817e4Smiod 276*3d8817e4Smiod extern void print_mips_disassembler_options (FILE *); 277*3d8817e4Smiod extern void print_ppc_disassembler_options (FILE *); 278*3d8817e4Smiod extern void print_arm_disassembler_options (FILE *); 279*3d8817e4Smiod extern void parse_arm_disassembler_option (char *); 280*3d8817e4Smiod extern int get_arm_regname_num_options (void); 281*3d8817e4Smiod extern int set_arm_regname_option (int); 282*3d8817e4Smiod extern int get_arm_regnames (int, const char **, const char **, const char *const **); 283*3d8817e4Smiod extern bfd_boolean arm_symbol_is_valid (asymbol *, struct disassemble_info *); 284*3d8817e4Smiod 285*3d8817e4Smiod /* Fetch the disassembler for a given BFD, if that support is available. */ 286*3d8817e4Smiod extern disassembler_ftype disassembler (bfd *); 287*3d8817e4Smiod 288*3d8817e4Smiod /* Amend the disassemble_info structure as necessary for the target architecture. 289*3d8817e4Smiod Should only be called after initialising the info->arch field. */ 290*3d8817e4Smiod extern void disassemble_init_for_target (struct disassemble_info * info); 291*3d8817e4Smiod 292*3d8817e4Smiod /* Document any target specific options available from the disassembler. */ 293*3d8817e4Smiod extern void disassembler_usage (FILE *); 294*3d8817e4Smiod 295*3d8817e4Smiod 296*3d8817e4Smiod /* This block of definitions is for particular callers who read instructions 297*3d8817e4Smiod into a buffer before calling the instruction decoder. */ 298*3d8817e4Smiod 299*3d8817e4Smiod /* Here is a function which callers may wish to use for read_memory_func. 300*3d8817e4Smiod It gets bytes from a buffer. */ 301*3d8817e4Smiod extern int buffer_read_memory 302*3d8817e4Smiod (bfd_vma, bfd_byte *, unsigned int, struct disassemble_info *); 303*3d8817e4Smiod 304*3d8817e4Smiod /* This function goes with buffer_read_memory. 305*3d8817e4Smiod It prints a message using info->fprintf_func and info->stream. */ 306*3d8817e4Smiod extern void perror_memory (int, bfd_vma, struct disassemble_info *); 307*3d8817e4Smiod 308*3d8817e4Smiod 309*3d8817e4Smiod /* Just print the address in hex. This is included for completeness even 310*3d8817e4Smiod though both GDB and objdump provide their own (to print symbolic 311*3d8817e4Smiod addresses). */ 312*3d8817e4Smiod extern void generic_print_address 313*3d8817e4Smiod (bfd_vma, struct disassemble_info *); 314*3d8817e4Smiod 315*3d8817e4Smiod /* Always true. */ 316*3d8817e4Smiod extern int generic_symbol_at_address 317*3d8817e4Smiod (bfd_vma, struct disassemble_info *); 318*3d8817e4Smiod 319*3d8817e4Smiod /* Also always true. */ 320*3d8817e4Smiod extern bfd_boolean generic_symbol_is_valid 321*3d8817e4Smiod (asymbol *, struct disassemble_info *); 322*3d8817e4Smiod 323*3d8817e4Smiod /* Method to initialize a disassemble_info struct. This should be 324*3d8817e4Smiod called by all applications creating such a struct. */ 325*3d8817e4Smiod extern void init_disassemble_info (struct disassemble_info *info, void *stream, 326*3d8817e4Smiod fprintf_ftype fprintf_func); 327*3d8817e4Smiod 328*3d8817e4Smiod /* For compatibility with existing code. */ 329*3d8817e4Smiod #define INIT_DISASSEMBLE_INFO(INFO, STREAM, FPRINTF_FUNC) \ 330*3d8817e4Smiod init_disassemble_info (&(INFO), (STREAM), (fprintf_ftype) (FPRINTF_FUNC)) 331*3d8817e4Smiod #define INIT_DISASSEMBLE_INFO_NO_ARCH(INFO, STREAM, FPRINTF_FUNC) \ 332*3d8817e4Smiod init_disassemble_info (&(INFO), (STREAM), (fprintf_ftype) (FPRINTF_FUNC)) 333*3d8817e4Smiod 334*3d8817e4Smiod 335*3d8817e4Smiod #ifdef __cplusplus 336*3d8817e4Smiod } 337*3d8817e4Smiod #endif 338*3d8817e4Smiod 339*3d8817e4Smiod #endif /* ! defined (DIS_ASM_H) */ 340