1
/* Interface between the opcode library and its callers.
3
Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005
4
Free Software Foundation, Inc.
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin Street - Fifth Floor,
19
Boston, MA 02110-1301, USA.
21
Written by Cygnus Support, 1993.
23
The opcode library (libopcodes.a) provides instruction decoders for
24
a large variety of instruction sets, callable with an identical
25
interface, for making instruction-processing programs more independent
26
of the instruction set being processed. */
43
typedef uint64_t bfd_vma;
44
typedef int64_t bfd_signed_vma;
45
typedef uint8_t bfd_byte;
46
typedef int bfd_boolean;
47
#define BFD_HOST_U_64_BIT unsigned long
48
#define BFD_HOST_64_BIT long
49
#define sprintf_vma(s,x) sprintf (s, "%0" PRIx64, x)
51
extern unsigned long bfd_getl64 (const bfd_byte *addr);
54
#define ATTRIBUTE_FPTR_PRINTF_2
55
#define ATTRIBUTE_UNUSED __attribute__((unused))
58
bfd_target_unknown_flavour,
59
bfd_target_aout_flavour,
60
bfd_target_coff_flavour,
61
bfd_target_ecoff_flavour,
62
bfd_target_elf_flavour,
63
bfd_target_ieee_flavour,
64
bfd_target_nlm_flavour,
65
bfd_target_oasys_flavour,
66
bfd_target_tekhex_flavour,
67
bfd_target_srec_flavour,
68
bfd_target_ihex_flavour,
69
bfd_target_som_flavour,
70
bfd_target_os9k_flavour,
71
bfd_target_versados_flavour,
72
bfd_target_msdos_flavour,
73
bfd_target_evax_flavour
76
enum bfd_endian { BFD_ENDIAN_BIG, BFD_ENDIAN_LITTLE, BFD_ENDIAN_UNKNOWN };
80
bfd_arch_unknown, /* File arch not known */
81
bfd_arch_obscure, /* Arch known, not one of these */
82
bfd_arch_m68k, /* Motorola 68xxx */
83
#define bfd_mach_m68000 1
84
#define bfd_mach_m68008 2
85
#define bfd_mach_m68010 3
86
#define bfd_mach_m68020 4
87
#define bfd_mach_m68030 5
88
#define bfd_mach_m68040 6
89
#define bfd_mach_m68060 7
90
#define bfd_mach_cpu32 8
91
#define bfd_mach_mcf5200 9
92
#define bfd_mach_mcf5206e 10
93
#define bfd_mach_mcf5307 11
94
#define bfd_mach_mcf5407 12
95
#define bfd_mach_mcf528x 13
96
#define bfd_mach_mcfv4e 14
97
#define bfd_mach_mcf521x 15
98
#define bfd_mach_mcf5249 16
99
#define bfd_mach_mcf547x 17
100
#define bfd_mach_mcf548x 18
101
bfd_arch_vax, /* DEC Vax */
102
bfd_arch_i960, /* Intel 960 */
103
/* The order of the following is important.
104
lower number indicates a machine type that
105
only accepts a subset of the instructions
106
available to machines with higher numbers.
107
The exception is the "ca", which is
108
incompatible with all other machines except
111
#define bfd_mach_i960_core 1
112
#define bfd_mach_i960_ka_sa 2
113
#define bfd_mach_i960_kb_sb 3
114
#define bfd_mach_i960_mc 4
115
#define bfd_mach_i960_xa 5
116
#define bfd_mach_i960_ca 6
117
#define bfd_mach_i960_jx 7
118
#define bfd_mach_i960_hx 8
120
bfd_arch_a29k, /* AMD 29000 */
121
bfd_arch_sparc, /* SPARC */
122
#define bfd_mach_sparc 1
123
/* The difference between v8plus and v9 is that v9 is a true 64 bit env. */
124
#define bfd_mach_sparc_sparclet 2
125
#define bfd_mach_sparc_sparclite 3
126
#define bfd_mach_sparc_v8plus 4
127
#define bfd_mach_sparc_v8plusa 5 /* with ultrasparc add'ns. */
128
#define bfd_mach_sparc_sparclite_le 6
129
#define bfd_mach_sparc_v9 7
130
#define bfd_mach_sparc_v9a 8 /* with ultrasparc add'ns. */
131
#define bfd_mach_sparc_v8plusb 9 /* with cheetah add'ns. */
132
#define bfd_mach_sparc_v9b 10 /* with cheetah add'ns. */
133
/* Nonzero if MACH has the v9 instruction set. */
134
#define bfd_mach_sparc_v9_p(mach) \
135
((mach) >= bfd_mach_sparc_v8plus && (mach) <= bfd_mach_sparc_v9b \
136
&& (mach) != bfd_mach_sparc_sparclite_le)
137
bfd_arch_mips, /* MIPS Rxxxx */
138
#define bfd_mach_mips3000 3000
139
#define bfd_mach_mips3900 3900
140
#define bfd_mach_mips4000 4000
141
#define bfd_mach_mips4010 4010
142
#define bfd_mach_mips4100 4100
143
#define bfd_mach_mips4300 4300
144
#define bfd_mach_mips4400 4400
145
#define bfd_mach_mips4600 4600
146
#define bfd_mach_mips4650 4650
147
#define bfd_mach_mips5000 5000
148
#define bfd_mach_mips6000 6000
149
#define bfd_mach_mips8000 8000
150
#define bfd_mach_mips10000 10000
151
#define bfd_mach_mips16 16
152
bfd_arch_i386, /* Intel 386 */
153
#define bfd_mach_i386_i386 0
154
#define bfd_mach_i386_i8086 1
155
#define bfd_mach_i386_i386_intel_syntax 2
156
#define bfd_mach_x86_64 3
157
#define bfd_mach_x86_64_intel_syntax 4
158
bfd_arch_we32k, /* AT&T WE32xxx */
159
bfd_arch_tahoe, /* CCI/Harris Tahoe */
160
bfd_arch_i860, /* Intel 860 */
161
bfd_arch_romp, /* IBM ROMP PC/RT */
162
bfd_arch_alliant, /* Alliant */
163
bfd_arch_convex, /* Convex */
164
bfd_arch_m88k, /* Motorola 88xxx */
165
bfd_arch_pyramid, /* Pyramid Technology */
166
bfd_arch_h8300, /* Hitachi H8/300 */
167
#define bfd_mach_h8300 1
168
#define bfd_mach_h8300h 2
169
#define bfd_mach_h8300s 3
170
bfd_arch_powerpc, /* PowerPC */
171
#define bfd_mach_ppc 0
172
#define bfd_mach_ppc64 1
173
#define bfd_mach_ppc_403 403
174
#define bfd_mach_ppc_403gc 4030
175
#define bfd_mach_ppc_505 505
176
#define bfd_mach_ppc_601 601
177
#define bfd_mach_ppc_602 602
178
#define bfd_mach_ppc_603 603
179
#define bfd_mach_ppc_ec603e 6031
180
#define bfd_mach_ppc_604 604
181
#define bfd_mach_ppc_620 620
182
#define bfd_mach_ppc_630 630
183
#define bfd_mach_ppc_750 750
184
#define bfd_mach_ppc_860 860
185
#define bfd_mach_ppc_a35 35
186
#define bfd_mach_ppc_rs64ii 642
187
#define bfd_mach_ppc_rs64iii 643
188
#define bfd_mach_ppc_7400 7400
189
bfd_arch_rs6000, /* IBM RS/6000 */
190
bfd_arch_hppa, /* HP PA RISC */
191
bfd_arch_d10v, /* Mitsubishi D10V */
192
bfd_arch_z8k, /* Zilog Z8000 */
193
#define bfd_mach_z8001 1
194
#define bfd_mach_z8002 2
195
bfd_arch_h8500, /* Hitachi H8/500 */
196
bfd_arch_sh, /* Hitachi SH */
197
#define bfd_mach_sh 1
198
#define bfd_mach_sh2 0x20
199
#define bfd_mach_sh_dsp 0x2d
200
#define bfd_mach_sh2a 0x2a
201
#define bfd_mach_sh2a_nofpu 0x2b
202
#define bfd_mach_sh2e 0x2e
203
#define bfd_mach_sh3 0x30
204
#define bfd_mach_sh3_nommu 0x31
205
#define bfd_mach_sh3_dsp 0x3d
206
#define bfd_mach_sh3e 0x3e
207
#define bfd_mach_sh4 0x40
208
#define bfd_mach_sh4_nofpu 0x41
209
#define bfd_mach_sh4_nommu_nofpu 0x42
210
#define bfd_mach_sh4a 0x4a
211
#define bfd_mach_sh4a_nofpu 0x4b
212
#define bfd_mach_sh4al_dsp 0x4d
213
#define bfd_mach_sh5 0x50
214
bfd_arch_alpha, /* Dec Alpha */
215
#define bfd_mach_alpha 1
216
bfd_arch_arm, /* Advanced Risc Machines ARM */
217
#define bfd_mach_arm_2 1
218
#define bfd_mach_arm_2a 2
219
#define bfd_mach_arm_3 3
220
#define bfd_mach_arm_3M 4
221
#define bfd_mach_arm_4 5
222
#define bfd_mach_arm_4T 6
223
bfd_arch_ns32k, /* National Semiconductors ns32000 */
224
bfd_arch_w65, /* WDC 65816 */
225
bfd_arch_tic30, /* Texas Instruments TMS320C30 */
226
bfd_arch_v850, /* NEC V850 */
227
#define bfd_mach_v850 0
228
bfd_arch_arc, /* Argonaut RISC Core */
229
#define bfd_mach_arc_base 0
230
bfd_arch_m32r, /* Mitsubishi M32R/D */
231
#define bfd_mach_m32r 0 /* backwards compatibility */
232
bfd_arch_mn10200, /* Matsushita MN10200 */
233
bfd_arch_mn10300, /* Matsushita MN10300 */
237
typedef struct symbol_cache_entry
247
typedef int (*fprintf_ftype) (void *, const char*, ...) ATTRIBUTE_FPTR_PRINTF_2;
250
dis_noninsn, /* Not a valid instruction */
251
dis_nonbranch, /* Not a branch instruction */
252
dis_branch, /* Unconditional branch */
253
dis_condbranch, /* Conditional branch */
254
dis_jsr, /* Jump to subroutine */
255
dis_condjsr, /* Conditional jump to subroutine */
256
dis_dref, /* Data reference instruction */
257
dis_dref2 /* Two data references in instruction */
260
/* This struct is passed into the instruction decoding routine,
261
and is passed back out into each callback. The various fields are used
262
for conveying information from your main routine into your callbacks,
263
for passing information into the instruction decoders (such as the
264
addresses of the callback functions), or for passing information
265
back from the instruction decoders to their callers.
267
It must be initialized before it is first passed; this can be done
268
by hand, or using one of the initialization macros below. */
270
typedef struct disassemble_info {
271
fprintf_ftype fprintf_func;
273
void *application_data;
275
/* Target description. We could replace this with a pointer to the bfd,
276
but that would require one. There currently isn't any such requirement
277
so to avoid introducing one we record these explicitly. */
278
/* The bfd_flavour. This can be bfd_target_unknown_flavour. */
279
enum bfd_flavour flavour;
280
/* The bfd_arch value. */
281
enum bfd_architecture arch;
282
/* The bfd_mach value. */
284
/* Endianness (for bi-endian cpus). Mono-endian cpus can ignore this. */
285
enum bfd_endian endian;
286
/* An arch/mach-specific bitmask of selected instruction subsets, mainly
287
for processors with run-time-switchable instruction sets. The default,
288
zero, means that there is no constraint. CGEN-based opcodes ports
289
may use ISA_foo masks. */
292
/* Some targets need information about the current section to accurately
293
display insns. If this is NULL, the target disassembler function
294
will have to make its best guess. */
297
/* An array of pointers to symbols either at the location being disassembled
298
or at the start of the function being disassembled. The array is sorted
299
so that the first symbol is intended to be the one used. The others are
300
present for any misc. purposes. This is not set reliably, but if it is
301
not NULL, it is correct. */
303
/* Number of symbols in array. */
306
/* For use by the disassembler.
307
The top 16 bits are reserved for public use (and are documented here).
308
The bottom 16 bits are for the internal use of the disassembler. */
310
#define INSN_HAS_RELOC 0x80000000
313
/* Function used to get bytes to disassemble. MEMADDR is the
314
address of the stuff to be disassembled, MYADDR is the address to
315
put the bytes in, and LENGTH is the number of bytes to read.
316
INFO is a pointer to this struct.
317
Returns an errno value or 0 for success. */
318
int (*read_memory_func)
319
(bfd_vma memaddr, bfd_byte *myaddr, unsigned int length,
320
struct disassemble_info *info);
322
/* Function which should be called if we get an error that we can't
323
recover from. STATUS is the errno value from read_memory_func and
324
MEMADDR is the address that we were trying to read. INFO is a
325
pointer to this struct. */
326
void (*memory_error_func)
327
(int status, bfd_vma memaddr, struct disassemble_info *info);
329
/* Function called to print ADDR. */
330
void (*print_address_func)
331
(bfd_vma addr, struct disassemble_info *info);
333
/* Function called to determine if there is a symbol at the given ADDR.
334
If there is, the function returns 1, otherwise it returns 0.
335
This is used by ports which support an overlay manager where
336
the overlay number is held in the top part of an address. In
337
some circumstances we want to include the overlay number in the
338
address, (normally because there is a symbol associated with
339
that address), but sometimes we want to mask out the overlay bits. */
340
int (* symbol_at_address_func)
341
(bfd_vma addr, struct disassemble_info * info);
343
/* Function called to check if a SYMBOL is can be displayed to the user.
344
This is used by some ports that want to hide special symbols when
345
displaying debugging outout. */
346
bfd_boolean (* symbol_is_valid)
347
(asymbol *, struct disassemble_info * info);
349
/* These are for buffer_read_memory. */
352
unsigned int buffer_length;
354
/* This variable may be set by the instruction decoder. It suggests
355
the number of bytes objdump should display on a single line. If
356
the instruction decoder sets this, it should always set it to
357
the same value in order to get reasonable looking output. */
360
/* The next two variables control the way objdump displays the raw data. */
361
/* For example, if bytes_per_line is 8 and bytes_per_chunk is 4, the */
362
/* output will look like this:
363
00: 00000000 00000000
364
with the chunks displayed according to "display_endian". */
366
enum bfd_endian display_endian;
368
/* Number of octets per incremented target address
369
Normally one, but some DSPs have byte sizes of 16 or 32 bits. */
370
unsigned int octets_per_byte;
372
/* The number of zeroes we want to see at the end of a section before we
373
start skipping them. */
374
unsigned int skip_zeroes;
376
/* The number of zeroes to skip at the end of a section. If the number
377
of zeroes at the end is between SKIP_ZEROES_AT_END and SKIP_ZEROES,
378
they will be disassembled. If there are fewer than
379
SKIP_ZEROES_AT_END, they will be skipped. This is a heuristic
380
attempt to avoid disassembling zeroes inserted by section
382
unsigned int skip_zeroes_at_end;
384
/* Whether the disassembler always needs the relocations. */
385
bfd_boolean disassembler_needs_relocs;
387
/* Results from instruction decoders. Not all decoders yet support
388
this information. This info is set each time an instruction is
389
decoded, and is only valid for the last such instruction.
391
To determine whether this decoder supports this information, set
392
insn_info_valid to 0, decode an instruction, then check it. */
394
char insn_info_valid; /* Branch info has been set. */
395
char branch_delay_insns; /* How many sequential insn's will run before
396
a branch takes effect. (0 = normal) */
397
char data_size; /* Size of data reference in insn, in bytes */
398
enum dis_insn_type insn_type; /* Type of instruction */
399
bfd_vma target; /* Target address of branch or dref, if known;
401
bfd_vma target2; /* Second target address for dref2 */
403
/* Command line options specific to the target disassembler. */
404
char * disassembler_options;
409
/* Standard disassemblers. Disassemble one instruction at the given
410
target address. Return number of octets processed. */
411
typedef int (*disassembler_ftype) (bfd_vma, disassemble_info *);
413
extern int print_insn_big_mips (bfd_vma, disassemble_info *);
414
extern int print_insn_little_mips (bfd_vma, disassemble_info *);
415
extern int print_insn_i386 (bfd_vma, disassemble_info *);
416
extern int print_insn_i386_att (bfd_vma, disassemble_info *);
417
extern int print_insn_i386_intel (bfd_vma, disassemble_info *);
418
extern int print_insn_ia64 (bfd_vma, disassemble_info *);
419
extern int print_insn_i370 (bfd_vma, disassemble_info *);
420
extern int print_insn_m68hc11 (bfd_vma, disassemble_info *);
421
extern int print_insn_m68hc12 (bfd_vma, disassemble_info *);
422
extern int print_insn_m68k (bfd_vma, disassemble_info *);
423
extern int print_insn_z80 (bfd_vma, disassemble_info *);
424
extern int print_insn_z8001 (bfd_vma, disassemble_info *);
425
extern int print_insn_z8002 (bfd_vma, disassemble_info *);
426
extern int print_insn_h8300 (bfd_vma, disassemble_info *);
427
extern int print_insn_h8300h (bfd_vma, disassemble_info *);
428
extern int print_insn_h8300s (bfd_vma, disassemble_info *);
429
extern int print_insn_h8500 (bfd_vma, disassemble_info *);
430
extern int print_insn_alpha (bfd_vma, disassemble_info *);
431
extern int print_insn_big_arm (bfd_vma, disassemble_info *);
432
extern int print_insn_little_arm (bfd_vma, disassemble_info *);
433
extern int print_insn_sparc (bfd_vma, disassemble_info *);
434
extern int print_insn_avr (bfd_vma, disassemble_info *);
435
extern int print_insn_bfin (bfd_vma, disassemble_info *);
436
extern int print_insn_d10v (bfd_vma, disassemble_info *);
437
extern int print_insn_d30v (bfd_vma, disassemble_info *);
438
extern int print_insn_dlx (bfd_vma, disassemble_info *);
439
extern int print_insn_fr30 (bfd_vma, disassemble_info *);
440
extern int print_insn_hppa (bfd_vma, disassemble_info *);
441
extern int print_insn_i860 (bfd_vma, disassemble_info *);
442
extern int print_insn_i960 (bfd_vma, disassemble_info *);
443
extern int print_insn_ip2k (bfd_vma, disassemble_info *);
444
extern int print_insn_m32r (bfd_vma, disassemble_info *);
445
extern int print_insn_m88k (bfd_vma, disassemble_info *);
446
extern int print_insn_maxq_little (bfd_vma, disassemble_info *);
447
extern int print_insn_maxq_big (bfd_vma, disassemble_info *);
448
extern int print_insn_mcore (bfd_vma, disassemble_info *);
449
extern int print_insn_mmix (bfd_vma, disassemble_info *);
450
extern int print_insn_mn10200 (bfd_vma, disassemble_info *);
451
extern int print_insn_mn10300 (bfd_vma, disassemble_info *);
452
extern int print_insn_mt (bfd_vma, disassemble_info *);
453
extern int print_insn_msp430 (bfd_vma, disassemble_info *);
454
extern int print_insn_ns32k (bfd_vma, disassemble_info *);
455
extern int print_insn_crx (bfd_vma, disassemble_info *);
456
extern int print_insn_openrisc (bfd_vma, disassemble_info *);
457
extern int print_insn_big_or32 (bfd_vma, disassemble_info *);
458
extern int print_insn_little_or32 (bfd_vma, disassemble_info *);
459
extern int print_insn_pdp11 (bfd_vma, disassemble_info *);
460
extern int print_insn_pj (bfd_vma, disassemble_info *);
461
extern int print_insn_big_powerpc (bfd_vma, disassemble_info *);
462
extern int print_insn_little_powerpc (bfd_vma, disassemble_info *);
463
extern int print_insn_rs6000 (bfd_vma, disassemble_info *);
464
extern int print_insn_s390 (bfd_vma, disassemble_info *);
465
extern int print_insn_sh (bfd_vma, disassemble_info *);
466
extern int print_insn_tic30 (bfd_vma, disassemble_info *);
467
extern int print_insn_tic4x (bfd_vma, disassemble_info *);
468
extern int print_insn_tic54x (bfd_vma, disassemble_info *);
469
extern int print_insn_tic80 (bfd_vma, disassemble_info *);
470
extern int print_insn_v850 (bfd_vma, disassemble_info *);
471
extern int print_insn_vax (bfd_vma, disassemble_info *);
472
extern int print_insn_w65 (bfd_vma, disassemble_info *);
473
extern int print_insn_xstormy16 (bfd_vma, disassemble_info *);
474
extern int print_insn_xtensa (bfd_vma, disassemble_info *);
475
extern int print_insn_sh64 (bfd_vma, disassemble_info *);
476
extern int print_insn_sh64x_media (bfd_vma, disassemble_info *);
477
extern int print_insn_frv (bfd_vma, disassemble_info *);
478
extern int print_insn_iq2000 (bfd_vma, disassemble_info *);
479
extern int print_insn_xc16x (bfd_vma, disassemble_info *);
480
extern int print_insn_m32c (bfd_vma, disassemble_info *);
482
extern disassembler_ftype arc_get_disassembler (void *);
483
//extern disassembler_ftype cris_get_disassembler (bfd *);
485
extern void print_mips_disassembler_options (FILE *);
486
extern void print_ppc_disassembler_options (FILE *);
487
extern void print_arm_disassembler_options (FILE *);
488
extern void parse_arm_disassembler_option (char *);
489
extern int get_arm_regname_num_options (void);
490
extern int set_arm_regname_option (int);
491
extern int get_arm_regnames (int, const char **, const char **, const char *const **);
492
extern bfd_boolean arm_symbol_is_valid (asymbol *, struct disassemble_info *);
494
/* Fetch the disassembler for a given BFD, if that support is available. */
495
//extern disassembler_ftype disassembler (bfd *);
497
/* Amend the disassemble_info structure as necessary for the target architecture.
498
Should only be called after initialising the info->arch field. */
499
extern void disassemble_init_for_target (struct disassemble_info * info);
501
/* Document any target specific options available from the disassembler. */
502
extern void disassembler_usage (FILE *);
505
/* This block of definitions is for particular callers who read instructions
506
into a buffer before calling the instruction decoder. */
508
/* Here is a function which callers may wish to use for read_memory_func.
509
It gets bytes from a buffer. */
510
extern int buffer_read_memory
511
(bfd_vma, bfd_byte *, unsigned int, struct disassemble_info *);
513
/* This function goes with buffer_read_memory.
514
It prints a message using info->fprintf_func and info->stream. */
515
extern void perror_memory (int, bfd_vma, struct disassemble_info *);
518
/* Just print the address in hex. This is included for completeness even
519
though both GDB and objdump provide their own (to print symbolic
521
extern void generic_print_address
522
(bfd_vma, struct disassemble_info *);
525
extern int generic_symbol_at_address
526
(bfd_vma, struct disassemble_info *);
528
/* Also always true. */
529
extern bfd_boolean generic_symbol_is_valid
530
(asymbol *, struct disassemble_info *);
532
/* Method to initialize a disassemble_info struct. This should be
533
called by all applications creating such a struct. */
534
extern void init_disassemble_info (struct disassemble_info *info, void *stream,
535
fprintf_ftype fprintf_func);
537
/* For compatibility with existing code. */
538
#define INIT_DISASSEMBLE_INFO(INFO, STREAM, FPRINTF_FUNC) \
539
init_disassemble_info (&(INFO), (STREAM), (fprintf_ftype) (FPRINTF_FUNC))
540
#define INIT_DISASSEMBLE_INFO_NO_ARCH(INFO, STREAM, FPRINTF_FUNC) \
541
init_disassemble_info (&(INFO), (STREAM), (fprintf_ftype) (FPRINTF_FUNC))
548
#endif /* ! defined (DIS_ASM_H) */