dis-asm.h revision 33965
1264377Sdes/* Interface between the opcode library and its callers.
2224638Sbrooks   Written by Cygnus Support, 1993.
357429Smarkm
457429Smarkm   The opcode library (libopcodes.a) provides instruction decoders for
557429Smarkm   a large variety of instruction sets, callable with an identical
657429Smarkm   interface, for making instruction-processing programs more independent
757429Smarkm   of the instruction set being processed.  */
860576Skris
965674Skris#ifndef DIS_ASM_H
1065674Skris#define DIS_ASM_H
1165674Skris
1265674Skris#include <stdio.h>
1365674Skris#include "bfd.h"
1457429Smarkm
1557429Smarkmtypedef int (*fprintf_ftype) PARAMS((FILE*, const char*, ...));
1657429Smarkm
17162856Sdesenum dis_insn_type {
1857429Smarkm  dis_noninsn,			/* Not a valid instruction */
19162856Sdes  dis_nonbranch,		/* Not a branch instruction */
20162856Sdes  dis_branch,			/* Unconditional branch */
21162856Sdes  dis_condbranch,		/* Conditional branch */
22181918Sdes  dis_jsr,			/* Jump to subroutine */
23262566Sdes  dis_condjsr,			/* Conditional jump to subroutine */
24162856Sdes  dis_dref,			/* Data reference instruction */
25162856Sdes  dis_dref2			/* Two data references in instruction */
26221420Sdes};
27221420Sdes
28264377Sdes/* This struct is passed into the instruction decoding routine,
29162856Sdes   and is passed back out into each callback.  The various fields are used
30162856Sdes   for conveying information from your main routine into your callbacks,
31162856Sdes   for passing information into the instruction decoders (such as the
32262566Sdes   addresses of the callback functions), or for passing information
33162856Sdes   back from the instruction decoders to their callers.
34262566Sdes
35262566Sdes   It must be initialized before it is first passed; this can be done
36262566Sdes   by hand, or using one of the initialization macros below.  */
37262566Sdes
38162856Sdestypedef struct disassemble_info {
39162856Sdes  fprintf_ftype fprintf_func;
40162856Sdes  FILE *stream;
41162856Sdes  PTR application_data;
42162856Sdes
43255767Sdes  /* Target description.  We could replace this with a pointer to the bfd,
44255767Sdes     but that would require one.  There currently isn't any such requirement
45255767Sdes     so to avoid introducing one we record these explicitly.  */
46162856Sdes  /* The bfd_flavour.  This can be bfd_target_unknown_flavour.  */
47162856Sdes  enum bfd_flavour flavour;
4857429Smarkm  /* The bfd_arch value.  */
4976262Sgreen  enum bfd_architecture arch;
5076262Sgreen  /* The bfd_mach value.  */
5176262Sgreen  unsigned long mach;
5276262Sgreen  /* Endianness (for bi-endian cpus).  Mono-endian cpus can ignore this.  */
53162856Sdes  enum bfd_endian endian;
5457429Smarkm  /* The symbol at the start of the function being disassembled.  This
5560576Skris     is not set reliably, but if it is not NULL, it is correct.  */
5676262Sgreen  asymbol *symbol;
57162856Sdes
5876262Sgreen  /* For use by the disassembler.
5976262Sgreen     The top 16 bits are reserved for public use (and are documented here).
60262566Sdes     The bottom 16 bits are for the internal use of the disassembler.  */
61192595Sdes  unsigned long flags;
6257429Smarkm  PTR private_data;
6357429Smarkm
6457429Smarkm  /* Function used to get bytes to disassemble.  MEMADDR is the
6557429Smarkm     address of the stuff to be disassembled, MYADDR is the address to
6657429Smarkm     put the bytes in, and LENGTH is the number of bytes to read.
6757429Smarkm     INFO is a pointer to this struct.
6857429Smarkm     Returns an errno value or 0 for success.  */
6957429Smarkm  int (*read_memory_func)
7057429Smarkm    PARAMS ((bfd_vma memaddr, bfd_byte *myaddr, int length,
7157429Smarkm	     struct disassemble_info *info));
7257429Smarkm
7357429Smarkm  /* Function which should be called if we get an error that we can't
7457429Smarkm     recover from.  STATUS is the errno value from read_memory_func and
7557429Smarkm     MEMADDR is the address that we were trying to read.  INFO is a
7657429Smarkm     pointer to this struct.  */
7757429Smarkm  void (*memory_error_func)
7898684Sdes    PARAMS ((int status, bfd_vma memaddr, struct disassemble_info *info));
7957429Smarkm
8057429Smarkm  /* Function called to print ADDR.  */
8157429Smarkm  void (*print_address_func)
8257429Smarkm    PARAMS ((bfd_vma addr, struct disassemble_info *info));
8357429Smarkm
8457429Smarkm  /* These are for buffer_read_memory.  */
8557429Smarkm  bfd_byte *buffer;
8657429Smarkm  bfd_vma buffer_vma;
8757429Smarkm  int buffer_length;
8857429Smarkm
8957429Smarkm  /* This variable may be set by the instruction decoder.  It suggests
9057429Smarkm      the number of bytes objdump should display on a single line.  If
9157429Smarkm      the instruction decoder sets this, it should always set it to
9257429Smarkm      the same value in order to get reasonable looking output.  */
9357429Smarkm  int bytes_per_line;
9457429Smarkm
9557429Smarkm  /* the next two variables control the way objdump displays the raw data */
9657429Smarkm  /* For example, if bytes_per_line is 8 and bytes_per_chunk is 4, the */
9757429Smarkm  /* output will look like this:
9857429Smarkm     00:   00000000 00000000
9957429Smarkm     with the chunks displayed according to "display_endian". */
10057429Smarkm  int bytes_per_chunk;
10198684Sdes  enum bfd_endian display_endian;
10257429Smarkm
10357429Smarkm  /* Results from instruction decoders.  Not all decoders yet support
10457429Smarkm     this information.  This info is set each time an instruction is
10557429Smarkm     decoded, and is only valid for the last such instruction.
10657429Smarkm
107157019Sdes     To determine whether this decoder supports this information, set
108157019Sdes     insn_info_valid to 0, decode an instruction, then check it.  */
109157019Sdes
110157019Sdes  char insn_info_valid;		/* Branch info has been set. */
11157429Smarkm  char branch_delay_insns;	/* How many sequential insn's will run before
11257429Smarkm				   a branch takes effect.  (0 = normal) */
11357429Smarkm  char data_size;		/* Size of data reference in insn, in bytes */
11476262Sgreen  enum dis_insn_type insn_type;	/* Type of instruction */
11557429Smarkm  bfd_vma target;		/* Target address of branch or dref, if known;
11657429Smarkm				   zero if unknown.  */
11757429Smarkm  bfd_vma target2;		/* Second target address for dref2 */
11857429Smarkm
119126277Sdes} disassemble_info;
12057429Smarkm
12157429Smarkm
12257429Smarkm/* Standard disassemblers.  Disassemble one instruction at the given
12357429Smarkm   target address.  Return number of bytes processed.  */
12457429Smarkmtypedef int (*disassembler_ftype)
12557429Smarkm     PARAMS((bfd_vma, disassemble_info *));
12657429Smarkm
12757429Smarkmextern int print_insn_big_mips		PARAMS ((bfd_vma, disassemble_info*));
12857429Smarkmextern int print_insn_little_mips	PARAMS ((bfd_vma, disassemble_info*));
12957429Smarkmextern int print_insn_i386		PARAMS ((bfd_vma, disassemble_info*));
130262566Sdesextern int print_insn_m68k		PARAMS ((bfd_vma, disassemble_info*));
131215116Sdesextern int print_insn_z8001		PARAMS ((bfd_vma, disassemble_info*));
132215116Sdesextern int print_insn_z8002		PARAMS ((bfd_vma, disassemble_info*));
13398684Sdesextern int print_insn_h8300		PARAMS ((bfd_vma, disassemble_info*));
13476262Sgreenextern int print_insn_h8300h		PARAMS ((bfd_vma, disassemble_info*));
13557429Smarkmextern int print_insn_h8300s		PARAMS ((bfd_vma, disassemble_info*));
136262566Sdesextern int print_insn_h8500		PARAMS ((bfd_vma, disassemble_info*));
13757429Smarkmextern int print_insn_alpha		PARAMS ((bfd_vma, disassemble_info*));
13857429Smarkmextern int print_insn_big_arm		PARAMS ((bfd_vma, disassemble_info*));
139126277Sdesextern int print_insn_little_arm	PARAMS ((bfd_vma, disassemble_info*));
14076262Sgreenextern int print_insn_sparc		PARAMS ((bfd_vma, disassemble_info*));
14176262Sgreenextern int print_insn_big_a29k		PARAMS ((bfd_vma, disassemble_info*));
14276262Sgreenextern int print_insn_little_a29k	PARAMS ((bfd_vma, disassemble_info*));
14376262Sgreenextern int print_insn_i960		PARAMS ((bfd_vma, disassemble_info*));
144204917Sdesextern int print_insn_sh		PARAMS ((bfd_vma, disassemble_info*));
14593698Sdesextern int print_insn_shl		PARAMS ((bfd_vma, disassemble_info*));
146124211Sdesextern int print_insn_hppa		PARAMS ((bfd_vma, disassemble_info*));
147124211Sdesextern int print_insn_m32r		PARAMS ((bfd_vma, disassemble_info*));
148128461Sdesextern int print_insn_m88k		PARAMS ((bfd_vma, disassemble_info*));
149215116Sdesextern int print_insn_mn10200		PARAMS ((bfd_vma, disassemble_info*));
150215116Sdesextern int print_insn_mn10300		PARAMS ((bfd_vma, disassemble_info*));
151157019Sdesextern int print_insn_ns32k		PARAMS ((bfd_vma, disassemble_info*));
152264377Sdesextern int print_insn_big_powerpc	PARAMS ((bfd_vma, disassemble_info*));
153262566Sdesextern int print_insn_little_powerpc	PARAMS ((bfd_vma, disassemble_info*));
154262566Sdesextern int print_insn_rs6000		PARAMS ((bfd_vma, disassemble_info*));
155262566Sdesextern int print_insn_w65		PARAMS ((bfd_vma, disassemble_info*));
156255767Sdesextern int print_insn_d10v		PARAMS ((bfd_vma, disassemble_info*));
157224638Sbrooks
158224638Sbrooks/* Fetch the disassembler for a given BFD, if that support is available.  */
159224638Sbrooksextern disassembler_ftype disassembler	PARAMS ((bfd *));
160224638Sbrooks
161255767Sdes
16257429Smarkm/* This block of definitions is for particular callers who read instructions
16357429Smarkm   into a buffer before calling the instruction decoder.  */
16457429Smarkm
16557429Smarkm/* Here is a function which callers may wish to use for read_memory_func.
16657429Smarkm   It gets bytes from a buffer.  */
16757429Smarkmextern int buffer_read_memory
16857429Smarkm  PARAMS ((bfd_vma, bfd_byte *, int, struct disassemble_info *));
16957429Smarkm
17057429Smarkm/* This function goes with buffer_read_memory.
17157429Smarkm   It prints a message using info->fprintf_func and info->stream.  */
172126277Sdesextern void perror_memory PARAMS ((int, bfd_vma, struct disassemble_info *));
173215116Sdes
174162856Sdes
17565674Skris/* Just print the address in hex.  This is included for completeness even
17657429Smarkm   though both GDB and objdump provide their own (to print symbolic
17757429Smarkm   addresses).  */
178124211Sdesextern void generic_print_address
17957429Smarkm  PARAMS ((bfd_vma, struct disassemble_info *));
18069591Sgreen
18169591Sgreen/* Macro to initialize a disassemble_info struct.  This should be called
18257429Smarkm   by all applications creating such a struct.  */
18376262Sgreen#define INIT_DISASSEMBLE_INFO(INFO, STREAM, FPRINTF_FUNC) \
18476262Sgreen  (INFO).flavour = bfd_target_unknown_flavour, \
18576262Sgreen  (INFO).arch = bfd_arch_unknown, \
18676262Sgreen  (INFO).mach = 0, \
18776262Sgreen  (INFO).endian = BFD_ENDIAN_UNKNOWN, \
18876262Sgreen  INIT_DISASSEMBLE_INFO_NO_ARCH(INFO, STREAM, FPRINTF_FUNC)
18976262Sgreen
190124211Sdes/* Call this macro to initialize only the internal variables for the
191124211Sdes   disassembler.  Architecture dependent things such as byte order, or machine
192124211Sdes   variant are not touched by this macro.  This makes things much easier for
193124211Sdes   GDB which must initialize these things seperatly.  */
194124211Sdes
195124211Sdes#define INIT_DISASSEMBLE_INFO_NO_ARCH(INFO, STREAM, FPRINTF_FUNC) \
196124211Sdes  (INFO).fprintf_func = (FPRINTF_FUNC), \
197124211Sdes  (INFO).stream = (STREAM), \
198124211Sdes  (INFO).symbol = NULL, \
19992559Sdes  (INFO).buffer = NULL, \
20098684Sdes  (INFO).buffer_vma = 0, \
20198684Sdes  (INFO).buffer_length = 0, \
20257429Smarkm  (INFO).read_memory_func = buffer_read_memory, \
203192595Sdes  (INFO).memory_error_func = perror_memory, \
204128460Sdes  (INFO).print_address_func = generic_print_address, \
20557429Smarkm  (INFO).flags = 0, \
20676262Sgreen  (INFO).bytes_per_line = 0, \
20757429Smarkm  (INFO).bytes_per_chunk = 0, \
20857429Smarkm  (INFO).display_endian = BFD_ENDIAN_UNKNOWN, \
20957429Smarkm  (INFO).insn_info_valid = 0
21060576Skris
21176262Sgreen#endif /* ! defined (DIS_ASM_H) */
21260576Skris