133965Sjdp/* Interface between the opcode library and its callers. 278828Sobrien 3218822Sdim Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 4218822Sdim Free Software Foundation, Inc. 5218822Sdim 678828Sobrien This program is free software; you can redistribute it and/or modify 778828Sobrien it under the terms of the GNU General Public License as published by 878828Sobrien the Free Software Foundation; either version 2, or (at your option) 978828Sobrien any later version. 1078828Sobrien 1178828Sobrien This program is distributed in the hope that it will be useful, 1278828Sobrien but WITHOUT ANY WARRANTY; without even the implied warranty of 1378828Sobrien MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1478828Sobrien GNU General Public License for more details. 1578828Sobrien 1678828Sobrien You should have received a copy of the GNU General Public License 1778828Sobrien along with this program; if not, write to the Free Software 18218822Sdim Foundation, Inc., 51 Franklin Street - Fifth Floor, 19218822Sdim Boston, MA 02110-1301, USA. 20218822Sdim 2133965Sjdp Written by Cygnus Support, 1993. 2233965Sjdp 2333965Sjdp The opcode library (libopcodes.a) provides instruction decoders for 2433965Sjdp a large variety of instruction sets, callable with an identical 2533965Sjdp interface, for making instruction-processing programs more independent 2633965Sjdp of the instruction set being processed. */ 2733965Sjdp 2833965Sjdp#ifndef DIS_ASM_H 2933965Sjdp#define DIS_ASM_H 3033965Sjdp 3160484Sobrien#ifdef __cplusplus 3260484Sobrienextern "C" { 3360484Sobrien#endif 3460484Sobrien 3533965Sjdp#include <stdio.h> 3633965Sjdp#include "bfd.h" 3733965Sjdp 38218822Sdim typedef int (*fprintf_ftype) (void *, const char*, ...) /*ATTRIBUTE_FPTR_PRINTF_2*/; 3933965Sjdp 40218822Sdimenum dis_insn_type 41218822Sdim{ 4233965Sjdp dis_noninsn, /* Not a valid instruction */ 4333965Sjdp dis_nonbranch, /* Not a branch instruction */ 4433965Sjdp dis_branch, /* Unconditional branch */ 4533965Sjdp dis_condbranch, /* Conditional branch */ 4633965Sjdp dis_jsr, /* Jump to subroutine */ 4733965Sjdp dis_condjsr, /* Conditional jump to subroutine */ 4833965Sjdp dis_dref, /* Data reference instruction */ 4933965Sjdp dis_dref2 /* Two data references in instruction */ 5033965Sjdp}; 5133965Sjdp 52218822Sdim/* This struct is passed into the instruction decoding routine, 5333965Sjdp and is passed back out into each callback. The various fields are used 5433965Sjdp for conveying information from your main routine into your callbacks, 5533965Sjdp for passing information into the instruction decoders (such as the 5633965Sjdp addresses of the callback functions), or for passing information 5733965Sjdp back from the instruction decoders to their callers. 5833965Sjdp 5933965Sjdp It must be initialized before it is first passed; this can be done 6033965Sjdp by hand, or using one of the initialization macros below. */ 6133965Sjdp 62218822Sdimtypedef struct disassemble_info 63218822Sdim{ 6433965Sjdp fprintf_ftype fprintf_func; 65130561Sobrien void *stream; 66130561Sobrien void *application_data; 6733965Sjdp 6833965Sjdp /* Target description. We could replace this with a pointer to the bfd, 6933965Sjdp but that would require one. There currently isn't any such requirement 7033965Sjdp so to avoid introducing one we record these explicitly. */ 7133965Sjdp /* The bfd_flavour. This can be bfd_target_unknown_flavour. */ 7233965Sjdp enum bfd_flavour flavour; 7333965Sjdp /* The bfd_arch value. */ 7433965Sjdp enum bfd_architecture arch; 7533965Sjdp /* The bfd_mach value. */ 7633965Sjdp unsigned long mach; 7733965Sjdp /* Endianness (for bi-endian cpus). Mono-endian cpus can ignore this. */ 7833965Sjdp enum bfd_endian endian; 7991041Sobrien /* An arch/mach-specific bitmask of selected instruction subsets, mainly 8091041Sobrien for processors with run-time-switchable instruction sets. The default, 8191041Sobrien zero, means that there is no constraint. CGEN-based opcodes ports 8291041Sobrien may use ISA_foo masks. */ 83218822Sdim void *insn_sets; 8433965Sjdp 8577298Sobrien /* Some targets need information about the current section to accurately 8677298Sobrien display insns. If this is NULL, the target disassembler function 8777298Sobrien will have to make its best guess. */ 8877298Sobrien asection *section; 8977298Sobrien 9038889Sjdp /* An array of pointers to symbols either at the location being disassembled 9138889Sjdp or at the start of the function being disassembled. The array is sorted 9238889Sjdp so that the first symbol is intended to be the one used. The others are 9338889Sjdp present for any misc. purposes. This is not set reliably, but if it is 9438889Sjdp not NULL, it is correct. */ 9538889Sjdp asymbol **symbols; 9638889Sjdp /* Number of symbols in array. */ 9738889Sjdp int num_symbols; 9838889Sjdp 99218822Sdim /* Symbol table provided for targets that want to look at it. This is 100218822Sdim used on Arm to find mapping symbols and determine Arm/Thumb code. */ 101218822Sdim asymbol **symtab; 102218822Sdim int symtab_pos; 103218822Sdim int symtab_size; 104218822Sdim 10533965Sjdp /* For use by the disassembler. 10633965Sjdp The top 16 bits are reserved for public use (and are documented here). 10733965Sjdp The bottom 16 bits are for the internal use of the disassembler. */ 10833965Sjdp unsigned long flags; 10938889Sjdp#define INSN_HAS_RELOC 0x80000000 110130561Sobrien void *private_data; 11133965Sjdp 11233965Sjdp /* Function used to get bytes to disassemble. MEMADDR is the 11333965Sjdp address of the stuff to be disassembled, MYADDR is the address to 11433965Sjdp put the bytes in, and LENGTH is the number of bytes to read. 11533965Sjdp INFO is a pointer to this struct. 11633965Sjdp Returns an errno value or 0 for success. */ 11733965Sjdp int (*read_memory_func) 118130561Sobrien (bfd_vma memaddr, bfd_byte *myaddr, unsigned int length, 119130561Sobrien struct disassemble_info *info); 12033965Sjdp 12133965Sjdp /* Function which should be called if we get an error that we can't 12233965Sjdp recover from. STATUS is the errno value from read_memory_func and 12333965Sjdp MEMADDR is the address that we were trying to read. INFO is a 12433965Sjdp pointer to this struct. */ 12533965Sjdp void (*memory_error_func) 126130561Sobrien (int status, bfd_vma memaddr, struct disassemble_info *info); 12733965Sjdp 12833965Sjdp /* Function called to print ADDR. */ 12933965Sjdp void (*print_address_func) 130130561Sobrien (bfd_vma addr, struct disassemble_info *info); 13133965Sjdp 13238889Sjdp /* Function called to determine if there is a symbol at the given ADDR. 13338889Sjdp If there is, the function returns 1, otherwise it returns 0. 13438889Sjdp This is used by ports which support an overlay manager where 13538889Sjdp the overlay number is held in the top part of an address. In 13638889Sjdp some circumstances we want to include the overlay number in the 13738889Sjdp address, (normally because there is a symbol associated with 13838889Sjdp that address), but sometimes we want to mask out the overlay bits. */ 13938889Sjdp int (* symbol_at_address_func) 140130561Sobrien (bfd_vma addr, struct disassemble_info * info); 14138889Sjdp 142130561Sobrien /* Function called to check if a SYMBOL is can be displayed to the user. 143130561Sobrien This is used by some ports that want to hide special symbols when 144130561Sobrien displaying debugging outout. */ 145130561Sobrien bfd_boolean (* symbol_is_valid) 146130561Sobrien (asymbol *, struct disassemble_info * info); 147218822Sdim 14833965Sjdp /* These are for buffer_read_memory. */ 14933965Sjdp bfd_byte *buffer; 15033965Sjdp bfd_vma buffer_vma; 15160484Sobrien unsigned int buffer_length; 15233965Sjdp 15333965Sjdp /* This variable may be set by the instruction decoder. It suggests 15433965Sjdp the number of bytes objdump should display on a single line. If 15533965Sjdp the instruction decoder sets this, it should always set it to 15633965Sjdp the same value in order to get reasonable looking output. */ 15733965Sjdp int bytes_per_line; 15833965Sjdp 159130561Sobrien /* The next two variables control the way objdump displays the raw data. */ 16033965Sjdp /* For example, if bytes_per_line is 8 and bytes_per_chunk is 4, the */ 16133965Sjdp /* output will look like this: 16233965Sjdp 00: 00000000 00000000 16333965Sjdp with the chunks displayed according to "display_endian". */ 16433965Sjdp int bytes_per_chunk; 16533965Sjdp enum bfd_endian display_endian; 16633965Sjdp 167218822Sdim /* Number of octets per incremented target address 16889857Sobrien Normally one, but some DSPs have byte sizes of 16 or 32 bits. */ 16960484Sobrien unsigned int octets_per_byte; 17060484Sobrien 171218822Sdim /* The number of zeroes we want to see at the end of a section before we 172218822Sdim start skipping them. */ 173218822Sdim unsigned int skip_zeroes; 174218822Sdim 175218822Sdim /* The number of zeroes to skip at the end of a section. If the number 176218822Sdim of zeroes at the end is between SKIP_ZEROES_AT_END and SKIP_ZEROES, 177218822Sdim they will be disassembled. If there are fewer than 178218822Sdim SKIP_ZEROES_AT_END, they will be skipped. This is a heuristic 179218822Sdim attempt to avoid disassembling zeroes inserted by section 180218822Sdim alignment. */ 181218822Sdim unsigned int skip_zeroes_at_end; 182218822Sdim 183218822Sdim /* Whether the disassembler always needs the relocations. */ 184218822Sdim bfd_boolean disassembler_needs_relocs; 185218822Sdim 18633965Sjdp /* Results from instruction decoders. Not all decoders yet support 18733965Sjdp this information. This info is set each time an instruction is 18833965Sjdp decoded, and is only valid for the last such instruction. 18933965Sjdp 19033965Sjdp To determine whether this decoder supports this information, set 19133965Sjdp insn_info_valid to 0, decode an instruction, then check it. */ 19233965Sjdp 19333965Sjdp char insn_info_valid; /* Branch info has been set. */ 19433965Sjdp char branch_delay_insns; /* How many sequential insn's will run before 19533965Sjdp a branch takes effect. (0 = normal) */ 19633965Sjdp char data_size; /* Size of data reference in insn, in bytes */ 19733965Sjdp enum dis_insn_type insn_type; /* Type of instruction */ 19833965Sjdp bfd_vma target; /* Target address of branch or dref, if known; 19933965Sjdp zero if unknown. */ 20033965Sjdp bfd_vma target2; /* Second target address for dref2 */ 20133965Sjdp 20260484Sobrien /* Command line options specific to the target disassembler. */ 20360484Sobrien char * disassembler_options; 20460484Sobrien 20533965Sjdp} disassemble_info; 20633965Sjdp 20733965Sjdp 20833965Sjdp/* Standard disassemblers. Disassemble one instruction at the given 20989857Sobrien target address. Return number of octets processed. */ 210130561Sobrientypedef int (*disassembler_ftype) (bfd_vma, disassemble_info *); 21133965Sjdp 212130561Sobrienextern int print_insn_alpha (bfd_vma, disassemble_info *); 213218822Sdimextern int print_insn_avr (bfd_vma, disassemble_info *); 214218822Sdimextern int print_insn_bfin (bfd_vma, disassemble_info *); 215130561Sobrienextern int print_insn_big_arm (bfd_vma, disassemble_info *); 216218822Sdimextern int print_insn_big_mips (bfd_vma, disassemble_info *); 217218822Sdimextern int print_insn_big_or32 (bfd_vma, disassemble_info *); 218218822Sdimextern int print_insn_big_powerpc (bfd_vma, disassemble_info *); 219218822Sdimextern int print_insn_big_score (bfd_vma, disassemble_info *); 220218822Sdimextern int print_insn_cr16 (bfd_vma, disassemble_info *); 221218822Sdimextern int print_insn_crx (bfd_vma, disassemble_info *); 222130561Sobrienextern int print_insn_d10v (bfd_vma, disassemble_info *); 223130561Sobrienextern int print_insn_d30v (bfd_vma, disassemble_info *); 224130561Sobrienextern int print_insn_dlx (bfd_vma, disassemble_info *); 225130561Sobrienextern int print_insn_fr30 (bfd_vma, disassemble_info *); 226218822Sdimextern int print_insn_frv (bfd_vma, disassemble_info *); 227218822Sdimextern int print_insn_h8300 (bfd_vma, disassemble_info *); 228218822Sdimextern int print_insn_h8300h (bfd_vma, disassemble_info *); 229218822Sdimextern int print_insn_h8300s (bfd_vma, disassemble_info *); 230218822Sdimextern int print_insn_h8500 (bfd_vma, disassemble_info *); 231130561Sobrienextern int print_insn_hppa (bfd_vma, disassemble_info *); 232218822Sdimextern int print_insn_i370 (bfd_vma, disassemble_info *); 233218822Sdimextern int print_insn_i386 (bfd_vma, disassemble_info *); 234218822Sdimextern int print_insn_i386_att (bfd_vma, disassemble_info *); 235218822Sdimextern int print_insn_i386_intel (bfd_vma, disassemble_info *); 236130561Sobrienextern int print_insn_i860 (bfd_vma, disassemble_info *); 237130561Sobrienextern int print_insn_i960 (bfd_vma, disassemble_info *); 238218822Sdimextern int print_insn_ia64 (bfd_vma, disassemble_info *); 239130561Sobrienextern int print_insn_ip2k (bfd_vma, disassemble_info *); 240218822Sdimextern int print_insn_iq2000 (bfd_vma, disassemble_info *); 241218822Sdimextern int print_insn_little_arm (bfd_vma, disassemble_info *); 242218822Sdimextern int print_insn_little_mips (bfd_vma, disassemble_info *); 243218822Sdimextern int print_insn_little_or32 (bfd_vma, disassemble_info *); 244218822Sdimextern int print_insn_little_powerpc (bfd_vma, disassemble_info *); 245218822Sdimextern int print_insn_little_score (bfd_vma, disassemble_info *); 246218822Sdimextern int print_insn_m32c (bfd_vma, disassemble_info *); 247130561Sobrienextern int print_insn_m32r (bfd_vma, disassemble_info *); 248218822Sdimextern int print_insn_m68hc11 (bfd_vma, disassemble_info *); 249218822Sdimextern int print_insn_m68hc12 (bfd_vma, disassemble_info *); 250218822Sdimextern int print_insn_m68k (bfd_vma, disassemble_info *); 251130561Sobrienextern int print_insn_m88k (bfd_vma, disassemble_info *); 252218822Sdimextern int print_insn_maxq_big (bfd_vma, disassemble_info *); 253218822Sdimextern int print_insn_maxq_little (bfd_vma, disassemble_info *); 254130561Sobrienextern int print_insn_mcore (bfd_vma, disassemble_info *); 255218822Sdimextern int print_insn_mep (bfd_vma, disassemble_info *); 256130561Sobrienextern int print_insn_mmix (bfd_vma, disassemble_info *); 257130561Sobrienextern int print_insn_mn10200 (bfd_vma, disassemble_info *); 258130561Sobrienextern int print_insn_mn10300 (bfd_vma, disassemble_info *); 259130561Sobrienextern int print_insn_msp430 (bfd_vma, disassemble_info *); 260218822Sdimextern int print_insn_mt (bfd_vma, disassemble_info *); 261130561Sobrienextern int print_insn_ns32k (bfd_vma, disassemble_info *); 262130561Sobrienextern int print_insn_openrisc (bfd_vma, disassemble_info *); 263130561Sobrienextern int print_insn_pdp11 (bfd_vma, disassemble_info *); 264130561Sobrienextern int print_insn_pj (bfd_vma, disassemble_info *); 265130561Sobrienextern int print_insn_rs6000 (bfd_vma, disassemble_info *); 266218822Sdimextern int print_insn_s390 (bfd_vma, disassemble_info *); 267130561Sobrienextern int print_insn_sh (bfd_vma, disassemble_info *); 268218822Sdimextern int print_insn_sh64 (bfd_vma, disassemble_info *); 269218822Sdimextern int print_insn_sh64x_media (bfd_vma, disassemble_info *); 270218822Sdimextern int print_insn_sparc (bfd_vma, disassemble_info *); 271218822Sdimextern int print_insn_spu (bfd_vma, disassemble_info *); 272130561Sobrienextern int print_insn_tic30 (bfd_vma, disassemble_info *); 273130561Sobrienextern int print_insn_tic4x (bfd_vma, disassemble_info *); 274130561Sobrienextern int print_insn_tic54x (bfd_vma, disassemble_info *); 275130561Sobrienextern int print_insn_tic80 (bfd_vma, disassemble_info *); 276130561Sobrienextern int print_insn_v850 (bfd_vma, disassemble_info *); 277130561Sobrienextern int print_insn_vax (bfd_vma, disassemble_info *); 278130561Sobrienextern int print_insn_w65 (bfd_vma, disassemble_info *); 279218822Sdimextern int print_insn_xc16x (bfd_vma, disassemble_info *); 280130561Sobrienextern int print_insn_xstormy16 (bfd_vma, disassemble_info *); 281130561Sobrienextern int print_insn_xtensa (bfd_vma, disassemble_info *); 282218822Sdimextern int print_insn_z80 (bfd_vma, disassemble_info *); 283218822Sdimextern int print_insn_z8001 (bfd_vma, disassemble_info *); 284218822Sdimextern int print_insn_z8002 (bfd_vma, disassemble_info *); 28533965Sjdp 286130561Sobrienextern disassembler_ftype arc_get_disassembler (void *); 287130561Sobrienextern disassembler_ftype cris_get_disassembler (bfd *); 28889857Sobrien 289218822Sdimextern void print_i386_disassembler_options (FILE *); 290130561Sobrienextern void print_mips_disassembler_options (FILE *); 291130561Sobrienextern void print_ppc_disassembler_options (FILE *); 292130561Sobrienextern void print_arm_disassembler_options (FILE *); 293130561Sobrienextern void parse_arm_disassembler_option (char *); 294218822Sdimextern int get_arm_regname_num_options (void); 295218822Sdimextern int set_arm_regname_option (int); 296218822Sdimextern int get_arm_regnames (int, const char **, const char **, const char *const **); 297130561Sobrienextern bfd_boolean arm_symbol_is_valid (asymbol *, struct disassemble_info *); 29860484Sobrien 29933965Sjdp/* Fetch the disassembler for a given BFD, if that support is available. */ 300130561Sobrienextern disassembler_ftype disassembler (bfd *); 30133965Sjdp 302130561Sobrien/* Amend the disassemble_info structure as necessary for the target architecture. 303130561Sobrien Should only be called after initialising the info->arch field. */ 304130561Sobrienextern void disassemble_init_for_target (struct disassemble_info * info); 305130561Sobrien 30660484Sobrien/* Document any target specific options available from the disassembler. */ 307130561Sobrienextern void disassembler_usage (FILE *); 30860484Sobrien 30933965Sjdp 31033965Sjdp/* This block of definitions is for particular callers who read instructions 31133965Sjdp into a buffer before calling the instruction decoder. */ 31233965Sjdp 31333965Sjdp/* Here is a function which callers may wish to use for read_memory_func. 31433965Sjdp It gets bytes from a buffer. */ 31533965Sjdpextern int buffer_read_memory 316130561Sobrien (bfd_vma, bfd_byte *, unsigned int, struct disassemble_info *); 31733965Sjdp 31833965Sjdp/* This function goes with buffer_read_memory. 31933965Sjdp It prints a message using info->fprintf_func and info->stream. */ 320130561Sobrienextern void perror_memory (int, bfd_vma, struct disassemble_info *); 32133965Sjdp 32233965Sjdp 32333965Sjdp/* Just print the address in hex. This is included for completeness even 32433965Sjdp though both GDB and objdump provide their own (to print symbolic 32533965Sjdp addresses). */ 32633965Sjdpextern void generic_print_address 327130561Sobrien (bfd_vma, struct disassemble_info *); 32833965Sjdp 32938889Sjdp/* Always true. */ 33038889Sjdpextern int generic_symbol_at_address 331130561Sobrien (bfd_vma, struct disassemble_info *); 33238889Sjdp 333218822Sdim/* Also always true. */ 334130561Sobrienextern bfd_boolean generic_symbol_is_valid 335130561Sobrien (asymbol *, struct disassemble_info *); 336218822Sdim 337130561Sobrien/* Method to initialize a disassemble_info struct. This should be 338130561Sobrien called by all applications creating such a struct. */ 339130561Sobrienextern void init_disassemble_info (struct disassemble_info *info, void *stream, 340130561Sobrien fprintf_ftype fprintf_func); 341130561Sobrien 342130561Sobrien/* For compatibility with existing code. */ 34333965Sjdp#define INIT_DISASSEMBLE_INFO(INFO, STREAM, FPRINTF_FUNC) \ 344130561Sobrien init_disassemble_info (&(INFO), (STREAM), (fprintf_ftype) (FPRINTF_FUNC)) 345130561Sobrien#define INIT_DISASSEMBLE_INFO_NO_ARCH(INFO, STREAM, FPRINTF_FUNC) \ 346130561Sobrien init_disassemble_info (&(INFO), (STREAM), (fprintf_ftype) (FPRINTF_FUNC)) 34733965Sjdp 34833965Sjdp 34960484Sobrien#ifdef __cplusplus 350104834Sobrien} 35160484Sobrien#endif 35260484Sobrien 35333965Sjdp#endif /* ! defined (DIS_ASM_H) */ 354