dis-asm.h revision 77298
133965Sjdp/* Interface between the opcode library and its callers.
233965Sjdp   Written by Cygnus Support, 1993.
333965Sjdp
433965Sjdp   The opcode library (libopcodes.a) provides instruction decoders for
533965Sjdp   a large variety of instruction sets, callable with an identical
633965Sjdp   interface, for making instruction-processing programs more independent
733965Sjdp   of the instruction set being processed.  */
833965Sjdp
933965Sjdp#ifndef DIS_ASM_H
1033965Sjdp#define DIS_ASM_H
1133965Sjdp
1260484Sobrien#ifdef __cplusplus
1360484Sobrienextern "C" {
1460484Sobrien#endif
1560484Sobrien
1633965Sjdp#include <stdio.h>
1733965Sjdp#include "bfd.h"
1833965Sjdp
1960484Sobrientypedef int (*fprintf_ftype) PARAMS((PTR, const char*, ...));
2033965Sjdp
2133965Sjdpenum dis_insn_type {
2233965Sjdp  dis_noninsn,			/* Not a valid instruction */
2333965Sjdp  dis_nonbranch,		/* Not a branch instruction */
2433965Sjdp  dis_branch,			/* Unconditional branch */
2533965Sjdp  dis_condbranch,		/* Conditional branch */
2633965Sjdp  dis_jsr,			/* Jump to subroutine */
2733965Sjdp  dis_condjsr,			/* Conditional jump to subroutine */
2833965Sjdp  dis_dref,			/* Data reference instruction */
2933965Sjdp  dis_dref2			/* Two data references in instruction */
3033965Sjdp};
3133965Sjdp
3233965Sjdp/* This struct is passed into the instruction decoding routine,
3333965Sjdp   and is passed back out into each callback.  The various fields are used
3433965Sjdp   for conveying information from your main routine into your callbacks,
3533965Sjdp   for passing information into the instruction decoders (such as the
3633965Sjdp   addresses of the callback functions), or for passing information
3733965Sjdp   back from the instruction decoders to their callers.
3833965Sjdp
3933965Sjdp   It must be initialized before it is first passed; this can be done
4033965Sjdp   by hand, or using one of the initialization macros below.  */
4133965Sjdp
4233965Sjdptypedef struct disassemble_info {
4333965Sjdp  fprintf_ftype fprintf_func;
4460484Sobrien  PTR stream;
4533965Sjdp  PTR application_data;
4633965Sjdp
4733965Sjdp  /* Target description.  We could replace this with a pointer to the bfd,
4833965Sjdp     but that would require one.  There currently isn't any such requirement
4933965Sjdp     so to avoid introducing one we record these explicitly.  */
5033965Sjdp  /* The bfd_flavour.  This can be bfd_target_unknown_flavour.  */
5133965Sjdp  enum bfd_flavour flavour;
5233965Sjdp  /* The bfd_arch value.  */
5333965Sjdp  enum bfd_architecture arch;
5433965Sjdp  /* The bfd_mach value.  */
5533965Sjdp  unsigned long mach;
5633965Sjdp  /* Endianness (for bi-endian cpus).  Mono-endian cpus can ignore this.  */
5733965Sjdp  enum bfd_endian endian;
5833965Sjdp
5977298Sobrien  /* Some targets need information about the current section to accurately
6077298Sobrien     display insns.  If this is NULL, the target disassembler function
6177298Sobrien     will have to make its best guess.  */
6277298Sobrien  asection *section;
6377298Sobrien
6438889Sjdp  /* An array of pointers to symbols either at the location being disassembled
6538889Sjdp     or at the start of the function being disassembled.  The array is sorted
6638889Sjdp     so that the first symbol is intended to be the one used.  The others are
6738889Sjdp     present for any misc. purposes.  This is not set reliably, but if it is
6838889Sjdp     not NULL, it is correct.  */
6938889Sjdp  asymbol **symbols;
7038889Sjdp  /* Number of symbols in array.  */
7138889Sjdp  int num_symbols;
7238889Sjdp
7333965Sjdp  /* For use by the disassembler.
7433965Sjdp     The top 16 bits are reserved for public use (and are documented here).
7533965Sjdp     The bottom 16 bits are for the internal use of the disassembler.  */
7633965Sjdp  unsigned long flags;
7738889Sjdp#define INSN_HAS_RELOC	0x80000000
7833965Sjdp  PTR private_data;
7933965Sjdp
8033965Sjdp  /* Function used to get bytes to disassemble.  MEMADDR is the
8133965Sjdp     address of the stuff to be disassembled, MYADDR is the address to
8233965Sjdp     put the bytes in, and LENGTH is the number of bytes to read.
8333965Sjdp     INFO is a pointer to this struct.
8433965Sjdp     Returns an errno value or 0 for success.  */
8533965Sjdp  int (*read_memory_func)
8660484Sobrien    PARAMS ((bfd_vma memaddr, bfd_byte *myaddr, unsigned int length,
8733965Sjdp	     struct disassemble_info *info));
8833965Sjdp
8933965Sjdp  /* Function which should be called if we get an error that we can't
9033965Sjdp     recover from.  STATUS is the errno value from read_memory_func and
9133965Sjdp     MEMADDR is the address that we were trying to read.  INFO is a
9233965Sjdp     pointer to this struct.  */
9333965Sjdp  void (*memory_error_func)
9433965Sjdp    PARAMS ((int status, bfd_vma memaddr, struct disassemble_info *info));
9533965Sjdp
9633965Sjdp  /* Function called to print ADDR.  */
9733965Sjdp  void (*print_address_func)
9833965Sjdp    PARAMS ((bfd_vma addr, struct disassemble_info *info));
9933965Sjdp
10038889Sjdp  /* Function called to determine if there is a symbol at the given ADDR.
10138889Sjdp     If there is, the function returns 1, otherwise it returns 0.
10238889Sjdp     This is used by ports which support an overlay manager where
10338889Sjdp     the overlay number is held in the top part of an address.  In
10438889Sjdp     some circumstances we want to include the overlay number in the
10538889Sjdp     address, (normally because there is a symbol associated with
10638889Sjdp     that address), but sometimes we want to mask out the overlay bits.  */
10738889Sjdp  int (* symbol_at_address_func)
10838889Sjdp    PARAMS ((bfd_vma addr, struct disassemble_info * info));
10938889Sjdp
11033965Sjdp  /* These are for buffer_read_memory.  */
11133965Sjdp  bfd_byte *buffer;
11233965Sjdp  bfd_vma buffer_vma;
11360484Sobrien  unsigned int buffer_length;
11433965Sjdp
11533965Sjdp  /* This variable may be set by the instruction decoder.  It suggests
11633965Sjdp      the number of bytes objdump should display on a single line.  If
11733965Sjdp      the instruction decoder sets this, it should always set it to
11833965Sjdp      the same value in order to get reasonable looking output.  */
11933965Sjdp  int bytes_per_line;
12033965Sjdp
12133965Sjdp  /* the next two variables control the way objdump displays the raw data */
12233965Sjdp  /* For example, if bytes_per_line is 8 and bytes_per_chunk is 4, the */
12333965Sjdp  /* output will look like this:
12433965Sjdp     00:   00000000 00000000
12533965Sjdp     with the chunks displayed according to "display_endian". */
12633965Sjdp  int bytes_per_chunk;
12733965Sjdp  enum bfd_endian display_endian;
12833965Sjdp
12960484Sobrien  /* Number of octets per incremented target address
13060484Sobrien     Normally one, but some DSPs have byte sizes of 16 or 32 bits
13160484Sobrien   */
13260484Sobrien  unsigned int octets_per_byte;
13360484Sobrien
13433965Sjdp  /* Results from instruction decoders.  Not all decoders yet support
13533965Sjdp     this information.  This info is set each time an instruction is
13633965Sjdp     decoded, and is only valid for the last such instruction.
13733965Sjdp
13833965Sjdp     To determine whether this decoder supports this information, set
13933965Sjdp     insn_info_valid to 0, decode an instruction, then check it.  */
14033965Sjdp
14133965Sjdp  char insn_info_valid;		/* Branch info has been set. */
14233965Sjdp  char branch_delay_insns;	/* How many sequential insn's will run before
14333965Sjdp				   a branch takes effect.  (0 = normal) */
14433965Sjdp  char data_size;		/* Size of data reference in insn, in bytes */
14533965Sjdp  enum dis_insn_type insn_type;	/* Type of instruction */
14633965Sjdp  bfd_vma target;		/* Target address of branch or dref, if known;
14733965Sjdp				   zero if unknown.  */
14833965Sjdp  bfd_vma target2;		/* Second target address for dref2 */
14933965Sjdp
15060484Sobrien  /* Command line options specific to the target disassembler.  */
15160484Sobrien  char * disassembler_options;
15260484Sobrien
15333965Sjdp} disassemble_info;
15433965Sjdp
15533965Sjdp
15633965Sjdp/* Standard disassemblers.  Disassemble one instruction at the given
15733965Sjdp   target address.  Return number of bytes processed.  */
15833965Sjdptypedef int (*disassembler_ftype)
15933965Sjdp     PARAMS((bfd_vma, disassemble_info *));
16033965Sjdp
16133965Sjdpextern int print_insn_big_mips		PARAMS ((bfd_vma, disassemble_info*));
16233965Sjdpextern int print_insn_little_mips	PARAMS ((bfd_vma, disassemble_info*));
16360484Sobrienextern int print_insn_i386_att		PARAMS ((bfd_vma, disassemble_info*));
16460484Sobrienextern int print_insn_i386_intel	PARAMS ((bfd_vma, disassemble_info*));
16577298Sobrienextern int print_insn_ia64		PARAMS ((bfd_vma, disassemble_info*));
16660484Sobrienextern int print_insn_i370		PARAMS ((bfd_vma, disassemble_info*));
16777298Sobrienextern int print_insn_m68hc11		PARAMS ((bfd_vma, disassemble_info*));
16877298Sobrienextern int print_insn_m68hc12		PARAMS ((bfd_vma, disassemble_info*));
16933965Sjdpextern int print_insn_m68k		PARAMS ((bfd_vma, disassemble_info*));
17033965Sjdpextern int print_insn_z8001		PARAMS ((bfd_vma, disassemble_info*));
17133965Sjdpextern int print_insn_z8002		PARAMS ((bfd_vma, disassemble_info*));
17233965Sjdpextern int print_insn_h8300		PARAMS ((bfd_vma, disassemble_info*));
17333965Sjdpextern int print_insn_h8300h		PARAMS ((bfd_vma, disassemble_info*));
17433965Sjdpextern int print_insn_h8300s		PARAMS ((bfd_vma, disassemble_info*));
17533965Sjdpextern int print_insn_h8500		PARAMS ((bfd_vma, disassemble_info*));
17633965Sjdpextern int print_insn_alpha		PARAMS ((bfd_vma, disassemble_info*));
17777298Sobrienextern disassembler_ftype arc_get_disassembler PARAMS ((void *));
17833965Sjdpextern int print_insn_big_arm		PARAMS ((bfd_vma, disassemble_info*));
17933965Sjdpextern int print_insn_little_arm	PARAMS ((bfd_vma, disassemble_info*));
18033965Sjdpextern int print_insn_sparc		PARAMS ((bfd_vma, disassemble_info*));
18133965Sjdpextern int print_insn_big_a29k		PARAMS ((bfd_vma, disassemble_info*));
18233965Sjdpextern int print_insn_little_a29k	PARAMS ((bfd_vma, disassemble_info*));
18377298Sobrienextern int print_insn_i860		PARAMS ((bfd_vma, disassemble_info*));
18433965Sjdpextern int print_insn_i960		PARAMS ((bfd_vma, disassemble_info*));
18533965Sjdpextern int print_insn_sh		PARAMS ((bfd_vma, disassemble_info*));
18633965Sjdpextern int print_insn_shl		PARAMS ((bfd_vma, disassemble_info*));
18733965Sjdpextern int print_insn_hppa		PARAMS ((bfd_vma, disassemble_info*));
18860484Sobrienextern int print_insn_fr30		PARAMS ((bfd_vma, disassemble_info*));
18933965Sjdpextern int print_insn_m32r		PARAMS ((bfd_vma, disassemble_info*));
19033965Sjdpextern int print_insn_m88k		PARAMS ((bfd_vma, disassemble_info*));
19160484Sobrienextern int print_insn_mcore		PARAMS ((bfd_vma, disassemble_info*));
19233965Sjdpextern int print_insn_mn10200		PARAMS ((bfd_vma, disassemble_info*));
19333965Sjdpextern int print_insn_mn10300		PARAMS ((bfd_vma, disassemble_info*));
19433965Sjdpextern int print_insn_ns32k		PARAMS ((bfd_vma, disassemble_info*));
19533965Sjdpextern int print_insn_big_powerpc	PARAMS ((bfd_vma, disassemble_info*));
19633965Sjdpextern int print_insn_little_powerpc	PARAMS ((bfd_vma, disassemble_info*));
19733965Sjdpextern int print_insn_rs6000		PARAMS ((bfd_vma, disassemble_info*));
19833965Sjdpextern int print_insn_w65		PARAMS ((bfd_vma, disassemble_info*));
19977298Sobrienextern disassembler_ftype cris_get_disassembler PARAMS ((bfd *));
20033965Sjdpextern int print_insn_d10v		PARAMS ((bfd_vma, disassemble_info*));
20160484Sobrienextern int print_insn_d30v		PARAMS ((bfd_vma, disassemble_info*));
20238889Sjdpextern int print_insn_v850		PARAMS ((bfd_vma, disassemble_info*));
20338889Sjdpextern int print_insn_tic30		PARAMS ((bfd_vma, disassemble_info*));
20460484Sobrienextern int print_insn_vax		PARAMS ((bfd_vma, disassemble_info*));
20577298Sobrienextern int print_insn_tic54x		PARAMS ((bfd_vma, disassemble_info*));
20660484Sobrienextern int print_insn_tic80		PARAMS ((bfd_vma, disassemble_info*));
20760484Sobrienextern int print_insn_pj		PARAMS ((bfd_vma, disassemble_info*));
20860484Sobrienextern int print_insn_avr		PARAMS ((bfd_vma, disassemble_info*));
20933965Sjdp
21060484Sobrienextern void print_arm_disassembler_options PARAMS ((FILE *));
21160484Sobrienextern void parse_arm_disassembler_option  PARAMS ((char *));
21260484Sobrienextern int  get_arm_regname_num_options    PARAMS ((void));
21360484Sobrienextern int  set_arm_regname_option         PARAMS ((int));
21460484Sobrienextern int  get_arm_regnames               PARAMS ((int, const char **, const char **, const char ***));
21560484Sobrien
21633965Sjdp/* Fetch the disassembler for a given BFD, if that support is available.  */
21733965Sjdpextern disassembler_ftype disassembler	PARAMS ((bfd *));
21833965Sjdp
21960484Sobrien/* Document any target specific options available from the disassembler.  */
22060484Sobrienextern void disassembler_usage          PARAMS ((FILE *));
22160484Sobrien
22233965Sjdp
22333965Sjdp/* This block of definitions is for particular callers who read instructions
22433965Sjdp   into a buffer before calling the instruction decoder.  */
22533965Sjdp
22633965Sjdp/* Here is a function which callers may wish to use for read_memory_func.
22733965Sjdp   It gets bytes from a buffer.  */
22833965Sjdpextern int buffer_read_memory
22960484Sobrien  PARAMS ((bfd_vma, bfd_byte *, unsigned int, struct disassemble_info *));
23033965Sjdp
23133965Sjdp/* This function goes with buffer_read_memory.
23233965Sjdp   It prints a message using info->fprintf_func and info->stream.  */
23333965Sjdpextern void perror_memory PARAMS ((int, bfd_vma, struct disassemble_info *));
23433965Sjdp
23533965Sjdp
23633965Sjdp/* Just print the address in hex.  This is included for completeness even
23733965Sjdp   though both GDB and objdump provide their own (to print symbolic
23833965Sjdp   addresses).  */
23933965Sjdpextern void generic_print_address
24033965Sjdp  PARAMS ((bfd_vma, struct disassemble_info *));
24133965Sjdp
24238889Sjdp/* Always true.  */
24338889Sjdpextern int generic_symbol_at_address
24438889Sjdp  PARAMS ((bfd_vma, struct disassemble_info *));
24538889Sjdp
24633965Sjdp/* Macro to initialize a disassemble_info struct.  This should be called
24733965Sjdp   by all applications creating such a struct.  */
24833965Sjdp#define INIT_DISASSEMBLE_INFO(INFO, STREAM, FPRINTF_FUNC) \
24933965Sjdp  (INFO).flavour = bfd_target_unknown_flavour, \
25033965Sjdp  (INFO).arch = bfd_arch_unknown, \
25133965Sjdp  (INFO).mach = 0, \
25233965Sjdp  (INFO).endian = BFD_ENDIAN_UNKNOWN, \
25360484Sobrien  (INFO).octets_per_byte = 1, \
25433965Sjdp  INIT_DISASSEMBLE_INFO_NO_ARCH(INFO, STREAM, FPRINTF_FUNC)
25533965Sjdp
25633965Sjdp/* Call this macro to initialize only the internal variables for the
25733965Sjdp   disassembler.  Architecture dependent things such as byte order, or machine
25833965Sjdp   variant are not touched by this macro.  This makes things much easier for
25977298Sobrien   GDB which must initialize these things separately.  */
26033965Sjdp
26133965Sjdp#define INIT_DISASSEMBLE_INFO_NO_ARCH(INFO, STREAM, FPRINTF_FUNC) \
26260484Sobrien  (INFO).fprintf_func = (fprintf_ftype)(FPRINTF_FUNC), \
26360484Sobrien  (INFO).stream = (PTR)(STREAM), \
26477298Sobrien  (INFO).section = NULL, \
26538889Sjdp  (INFO).symbols = NULL, \
26638889Sjdp  (INFO).num_symbols = 0, \
26777298Sobrien  (INFO).private_data = NULL, \
26833965Sjdp  (INFO).buffer = NULL, \
26933965Sjdp  (INFO).buffer_vma = 0, \
27033965Sjdp  (INFO).buffer_length = 0, \
27133965Sjdp  (INFO).read_memory_func = buffer_read_memory, \
27233965Sjdp  (INFO).memory_error_func = perror_memory, \
27333965Sjdp  (INFO).print_address_func = generic_print_address, \
27438889Sjdp  (INFO).symbol_at_address_func = generic_symbol_at_address, \
27533965Sjdp  (INFO).flags = 0, \
27633965Sjdp  (INFO).bytes_per_line = 0, \
27733965Sjdp  (INFO).bytes_per_chunk = 0, \
27833965Sjdp  (INFO).display_endian = BFD_ENDIAN_UNKNOWN, \
27933965Sjdp  (INFO).insn_info_valid = 0
28033965Sjdp
28160484Sobrien#ifdef __cplusplus
28260484Sobrien};
28360484Sobrien#endif
28460484Sobrien
28533965Sjdp#endif /* ! defined (DIS_ASM_H) */
286