Back to index

cell-binutils  2.17cvs20070401
dis-asm.h
Go to the documentation of this file.
00001 /* Interface between the opcode library and its callers.
00002 
00003    Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
00004    Free Software Foundation, Inc.
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2, or (at your option)
00009    any later version.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the Free Software
00018    Foundation, Inc., 51 Franklin Street - Fifth Floor,
00019    Boston, MA 02110-1301, USA.
00020 
00021    Written by Cygnus Support, 1993.
00022 
00023    The opcode library (libopcodes.a) provides instruction decoders for
00024    a large variety of instruction sets, callable with an identical
00025    interface, for making instruction-processing programs more independent
00026    of the instruction set being processed.  */
00027 
00028 #ifndef DIS_ASM_H
00029 #define DIS_ASM_H
00030 
00031 #ifdef __cplusplus
00032 extern "C" {
00033 #endif
00034 
00035 #include <stdio.h>
00036 #include "bfd.h"
00037 
00038   typedef int (*fprintf_ftype) (void *, const char*, ...) /*ATTRIBUTE_FPTR_PRINTF_2*/;
00039 
00040 enum dis_insn_type
00041 {
00042   dis_noninsn,                     /* Not a valid instruction */
00043   dis_nonbranch,            /* Not a branch instruction */
00044   dis_branch,               /* Unconditional branch */
00045   dis_condbranch,           /* Conditional branch */
00046   dis_jsr,                  /* Jump to subroutine */
00047   dis_condjsr,                     /* Conditional jump to subroutine */
00048   dis_dref,                 /* Data reference instruction */
00049   dis_dref2                 /* Two data references in instruction */
00050 };
00051 
00052 /* This struct is passed into the instruction decoding routine,
00053    and is passed back out into each callback.  The various fields are used
00054    for conveying information from your main routine into your callbacks,
00055    for passing information into the instruction decoders (such as the
00056    addresses of the callback functions), or for passing information
00057    back from the instruction decoders to their callers.
00058 
00059    It must be initialized before it is first passed; this can be done
00060    by hand, or using one of the initialization macros below.  */
00061 
00062 typedef struct disassemble_info
00063 {
00064   fprintf_ftype fprintf_func;
00065   void *stream;
00066   void *application_data;
00067 
00068   /* Target description.  We could replace this with a pointer to the bfd,
00069      but that would require one.  There currently isn't any such requirement
00070      so to avoid introducing one we record these explicitly.  */
00071   /* The bfd_flavour.  This can be bfd_target_unknown_flavour.  */
00072   enum bfd_flavour flavour;
00073   /* The bfd_arch value.  */
00074   enum bfd_architecture arch;
00075   /* The bfd_mach value.  */
00076   unsigned long mach;
00077   /* Endianness (for bi-endian cpus).  Mono-endian cpus can ignore this.  */
00078   enum bfd_endian endian;
00079   /* An arch/mach-specific bitmask of selected instruction subsets, mainly
00080      for processors with run-time-switchable instruction sets.  The default,
00081      zero, means that there is no constraint.  CGEN-based opcodes ports
00082      may use ISA_foo masks.  */
00083   void *insn_sets;
00084 
00085   /* Some targets need information about the current section to accurately
00086      display insns.  If this is NULL, the target disassembler function
00087      will have to make its best guess.  */
00088   asection *section;
00089 
00090   /* An array of pointers to symbols either at the location being disassembled
00091      or at the start of the function being disassembled.  The array is sorted
00092      so that the first symbol is intended to be the one used.  The others are
00093      present for any misc. purposes.  This is not set reliably, but if it is
00094      not NULL, it is correct.  */
00095   asymbol **symbols;
00096   /* Number of symbols in array.  */
00097   int num_symbols;
00098 
00099   /* Symbol table provided for targets that want to look at it.  This is
00100      used on Arm to find mapping symbols and determine Arm/Thumb code.  */
00101   asymbol **symtab;
00102   int symtab_pos;
00103   int symtab_size;
00104 
00105   /* For use by the disassembler.
00106      The top 16 bits are reserved for public use (and are documented here).
00107      The bottom 16 bits are for the internal use of the disassembler.  */
00108   unsigned long flags;
00109 #define INSN_HAS_RELOC      0x80000000
00110   void *private_data;
00111 
00112   /* Function used to get bytes to disassemble.  MEMADDR is the
00113      address of the stuff to be disassembled, MYADDR is the address to
00114      put the bytes in, and LENGTH is the number of bytes to read.
00115      INFO is a pointer to this struct.
00116      Returns an errno value or 0 for success.  */
00117   int (*read_memory_func)
00118     (bfd_vma memaddr, bfd_byte *myaddr, unsigned int length,
00119      struct disassemble_info *info);
00120 
00121   /* Function which should be called if we get an error that we can't
00122      recover from.  STATUS is the errno value from read_memory_func and
00123      MEMADDR is the address that we were trying to read.  INFO is a
00124      pointer to this struct.  */
00125   void (*memory_error_func)
00126     (int status, bfd_vma memaddr, struct disassemble_info *info);
00127 
00128   /* Function called to print ADDR.  */
00129   void (*print_address_func)
00130     (bfd_vma addr, struct disassemble_info *info);
00131 
00132   /* Function called to determine if there is a symbol at the given ADDR.
00133      If there is, the function returns 1, otherwise it returns 0.
00134      This is used by ports which support an overlay manager where
00135      the overlay number is held in the top part of an address.  In
00136      some circumstances we want to include the overlay number in the
00137      address, (normally because there is a symbol associated with
00138      that address), but sometimes we want to mask out the overlay bits.  */
00139   int (* symbol_at_address_func)
00140     (bfd_vma addr, struct disassemble_info * info);
00141 
00142   /* Function called to check if a SYMBOL is can be displayed to the user.
00143      This is used by some ports that want to hide special symbols when
00144      displaying debugging outout.  */
00145   bfd_boolean (* symbol_is_valid)
00146     (asymbol *, struct disassemble_info * info);
00147 
00148   /* These are for buffer_read_memory.  */
00149   bfd_byte *buffer;
00150   bfd_vma buffer_vma;
00151   unsigned int buffer_length;
00152 
00153   /* This variable may be set by the instruction decoder.  It suggests
00154       the number of bytes objdump should display on a single line.  If
00155       the instruction decoder sets this, it should always set it to
00156       the same value in order to get reasonable looking output.  */
00157   int bytes_per_line;
00158 
00159   /* The next two variables control the way objdump displays the raw data.  */
00160   /* For example, if bytes_per_line is 8 and bytes_per_chunk is 4, the */
00161   /* output will look like this:
00162      00:   00000000 00000000
00163      with the chunks displayed according to "display_endian". */
00164   int bytes_per_chunk;
00165   enum bfd_endian display_endian;
00166 
00167   /* Number of octets per incremented target address
00168      Normally one, but some DSPs have byte sizes of 16 or 32 bits.  */
00169   unsigned int octets_per_byte;
00170 
00171   /* The number of zeroes we want to see at the end of a section before we
00172      start skipping them.  */
00173   unsigned int skip_zeroes;
00174 
00175   /* The number of zeroes to skip at the end of a section.  If the number
00176      of zeroes at the end is between SKIP_ZEROES_AT_END and SKIP_ZEROES,
00177      they will be disassembled.  If there are fewer than
00178      SKIP_ZEROES_AT_END, they will be skipped.  This is a heuristic
00179      attempt to avoid disassembling zeroes inserted by section
00180      alignment.  */
00181   unsigned int skip_zeroes_at_end;
00182 
00183   /* Whether the disassembler always needs the relocations.  */
00184   bfd_boolean disassembler_needs_relocs;
00185 
00186   /* Results from instruction decoders.  Not all decoders yet support
00187      this information.  This info is set each time an instruction is
00188      decoded, and is only valid for the last such instruction.
00189 
00190      To determine whether this decoder supports this information, set
00191      insn_info_valid to 0, decode an instruction, then check it.  */
00192 
00193   char insn_info_valid;            /* Branch info has been set. */
00194   char branch_delay_insns;  /* How many sequential insn's will run before
00195                                a branch takes effect.  (0 = normal) */
00196   char data_size;           /* Size of data reference in insn, in bytes */
00197   enum dis_insn_type insn_type;    /* Type of instruction */
00198   bfd_vma target;           /* Target address of branch or dref, if known;
00199                                zero if unknown.  */
00200   bfd_vma target2;          /* Second target address for dref2 */
00201 
00202   /* Command line options specific to the target disassembler.  */
00203   char * disassembler_options;
00204 
00205 } disassemble_info;
00206 
00207 
00208 /* Standard disassemblers.  Disassemble one instruction at the given
00209    target address.  Return number of octets processed.  */
00210 typedef int (*disassembler_ftype) (bfd_vma, disassemble_info *);
00211 
00212 extern int print_insn_alpha        (bfd_vma, disassemble_info *);
00213 extern int print_insn_avr          (bfd_vma, disassemble_info *);
00214 extern int print_insn_bfin         (bfd_vma, disassemble_info *);
00215 extern int print_insn_big_arm             (bfd_vma, disassemble_info *);
00216 extern int print_insn_big_mips            (bfd_vma, disassemble_info *);
00217 extern int print_insn_big_or32            (bfd_vma, disassemble_info *);
00218 extern int print_insn_big_powerpc  (bfd_vma, disassemble_info *);
00219 extern int print_insn_big_score         (bfd_vma, disassemble_info *);
00220 extern int print_insn_crx               (bfd_vma, disassemble_info *);
00221 extern int print_insn_d10v         (bfd_vma, disassemble_info *);
00222 extern int print_insn_d30v         (bfd_vma, disassemble_info *);
00223 extern int print_insn_dlx          (bfd_vma, disassemble_info *);
00224 extern int print_insn_fr30         (bfd_vma, disassemble_info *);
00225 extern int print_insn_frv          (bfd_vma, disassemble_info *);
00226 extern int print_insn_h8300        (bfd_vma, disassemble_info *);
00227 extern int print_insn_h8300h              (bfd_vma, disassemble_info *);
00228 extern int print_insn_h8300s              (bfd_vma, disassemble_info *);
00229 extern int print_insn_h8500        (bfd_vma, disassemble_info *);
00230 extern int print_insn_hppa         (bfd_vma, disassemble_info *);
00231 extern int print_insn_i370         (bfd_vma, disassemble_info *);
00232 extern int print_insn_i386         (bfd_vma, disassemble_info *);
00233 extern int print_insn_i386_att            (bfd_vma, disassemble_info *);
00234 extern int print_insn_i386_intel   (bfd_vma, disassemble_info *);
00235 extern int print_insn_i860         (bfd_vma, disassemble_info *);
00236 extern int print_insn_i960         (bfd_vma, disassemble_info *);
00237 extern int print_insn_ia64         (bfd_vma, disassemble_info *);
00238 extern int print_insn_ip2k         (bfd_vma, disassemble_info *);
00239 extern int print_insn_iq2000              (bfd_vma, disassemble_info *);
00240 extern int print_insn_little_arm   (bfd_vma, disassemble_info *);
00241 extern int print_insn_little_mips  (bfd_vma, disassemble_info *);
00242 extern int print_insn_little_or32  (bfd_vma, disassemble_info *);
00243 extern int print_insn_little_powerpc      (bfd_vma, disassemble_info *);
00244 extern int print_insn_little_score      (bfd_vma, disassemble_info *); 
00245 extern int print_insn_m32c          (bfd_vma, disassemble_info *);
00246 extern int print_insn_m32r         (bfd_vma, disassemble_info *);
00247 extern int print_insn_m68hc11             (bfd_vma, disassemble_info *);
00248 extern int print_insn_m68hc12             (bfd_vma, disassemble_info *);
00249 extern int print_insn_m68k         (bfd_vma, disassemble_info *);
00250 extern int print_insn_m88k         (bfd_vma, disassemble_info *);
00251 extern int print_insn_maxq_big            (bfd_vma, disassemble_info *);
00252 extern int print_insn_maxq_little  (bfd_vma, disassemble_info *);
00253 extern int print_insn_mcore        (bfd_vma, disassemble_info *);
00254 extern int print_insn_mep          (bfd_vma, disassemble_info *);
00255 extern int print_insn_mmix         (bfd_vma, disassemble_info *);
00256 extern int print_insn_mn10200             (bfd_vma, disassemble_info *);
00257 extern int print_insn_mn10300             (bfd_vma, disassemble_info *);
00258 extern int print_insn_msp430              (bfd_vma, disassemble_info *);
00259 extern int print_insn_mt                (bfd_vma, disassemble_info *);
00260 extern int print_insn_ns32k        (bfd_vma, disassemble_info *);
00261 extern int print_insn_openrisc            (bfd_vma, disassemble_info *);
00262 extern int print_insn_pdp11        (bfd_vma, disassemble_info *);
00263 extern int print_insn_pj           (bfd_vma, disassemble_info *);
00264 extern int print_insn_rs6000              (bfd_vma, disassemble_info *);
00265 extern int print_insn_s390         (bfd_vma, disassemble_info *);
00266 extern int print_insn_sh           (bfd_vma, disassemble_info *);
00267 extern int print_insn_sh64         (bfd_vma, disassemble_info *);
00268 extern int print_insn_sh64x_media  (bfd_vma, disassemble_info *);
00269 extern int print_insn_sparc        (bfd_vma, disassemble_info *);
00270 extern int print_insn_spu          (bfd_vma, disassemble_info *);
00271 extern int print_insn_tic30        (bfd_vma, disassemble_info *);
00272 extern int print_insn_tic4x        (bfd_vma, disassemble_info *);
00273 extern int print_insn_tic54x              (bfd_vma, disassemble_info *);
00274 extern int print_insn_tic80        (bfd_vma, disassemble_info *);
00275 extern int print_insn_v850         (bfd_vma, disassemble_info *);
00276 extern int print_insn_vax          (bfd_vma, disassemble_info *);
00277 extern int print_insn_w65          (bfd_vma, disassemble_info *);
00278 extern int print_insn_xc16x        (bfd_vma, disassemble_info *);
00279 extern int print_insn_xstormy16           (bfd_vma, disassemble_info *);
00280 extern int print_insn_xtensa              (bfd_vma, disassemble_info *);
00281 extern int print_insn_z80          (bfd_vma, disassemble_info *);
00282 extern int print_insn_z8001        (bfd_vma, disassemble_info *);
00283 extern int print_insn_z8002        (bfd_vma, disassemble_info *);
00284 
00285 extern disassembler_ftype arc_get_disassembler (void *);
00286 extern disassembler_ftype cris_get_disassembler (bfd *);
00287 
00288 extern void print_i386_disassembler_options (FILE *);
00289 extern void print_mips_disassembler_options (FILE *);
00290 extern void print_ppc_disassembler_options (FILE *);
00291 extern void print_arm_disassembler_options (FILE *);
00292 extern void parse_arm_disassembler_option (char *);
00293 extern int  get_arm_regname_num_options (void);
00294 extern int  set_arm_regname_option (int);
00295 extern int  get_arm_regnames (int, const char **, const char **, const char *const **);
00296 extern bfd_boolean arm_symbol_is_valid (asymbol *, struct disassemble_info *);
00297 
00298 /* Fetch the disassembler for a given BFD, if that support is available.  */
00299 extern disassembler_ftype disassembler (bfd *);
00300 
00301 /* Amend the disassemble_info structure as necessary for the target architecture.
00302    Should only be called after initialising the info->arch field.  */
00303 extern void disassemble_init_for_target (struct disassemble_info * info);
00304 
00305 /* Document any target specific options available from the disassembler.  */
00306 extern void disassembler_usage (FILE *);
00307 
00308 
00309 /* This block of definitions is for particular callers who read instructions
00310    into a buffer before calling the instruction decoder.  */
00311 
00312 /* Here is a function which callers may wish to use for read_memory_func.
00313    It gets bytes from a buffer.  */
00314 extern int buffer_read_memory
00315   (bfd_vma, bfd_byte *, unsigned int, struct disassemble_info *);
00316 
00317 /* This function goes with buffer_read_memory.
00318    It prints a message using info->fprintf_func and info->stream.  */
00319 extern void perror_memory (int, bfd_vma, struct disassemble_info *);
00320 
00321 
00322 /* Just print the address in hex.  This is included for completeness even
00323    though both GDB and objdump provide their own (to print symbolic
00324    addresses).  */
00325 extern void generic_print_address
00326   (bfd_vma, struct disassemble_info *);
00327 
00328 /* Always true.  */
00329 extern int generic_symbol_at_address
00330   (bfd_vma, struct disassemble_info *);
00331 
00332 /* Also always true.  */
00333 extern bfd_boolean generic_symbol_is_valid
00334   (asymbol *, struct disassemble_info *);
00335 
00336 /* Method to initialize a disassemble_info struct.  This should be
00337    called by all applications creating such a struct.  */
00338 extern void init_disassemble_info (struct disassemble_info *info, void *stream,
00339                                fprintf_ftype fprintf_func);
00340 
00341 /* For compatibility with existing code.  */
00342 #define INIT_DISASSEMBLE_INFO(INFO, STREAM, FPRINTF_FUNC) \
00343   init_disassemble_info (&(INFO), (STREAM), (fprintf_ftype) (FPRINTF_FUNC))
00344 #define INIT_DISASSEMBLE_INFO_NO_ARCH(INFO, STREAM, FPRINTF_FUNC) \
00345   init_disassemble_info (&(INFO), (STREAM), (fprintf_ftype) (FPRINTF_FUNC))
00346 
00347 
00348 #ifdef __cplusplus
00349 }
00350 #endif
00351 
00352 #endif /* ! defined (DIS_ASM_H) */