dis-asm.h 15 KB

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