|
||||
File indexing completed on 2025-01-17 09:55:19
0001 /* Interface between the opcode library and its callers. 0002 0003 Copyright (C) 1999-2024 Free Software Foundation, Inc. 0004 0005 This program is free software; you can redistribute it and/or modify 0006 it under the terms of the GNU General Public License as published by 0007 the Free Software Foundation; either version 3, or (at your option) 0008 any later version. 0009 0010 This program is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 GNU General Public License for more details. 0014 0015 You should have received a copy of the GNU General Public License 0016 along with this program; if not, write to the Free Software 0017 Foundation, Inc., 51 Franklin Street - Fifth Floor, 0018 Boston, MA 02110-1301, USA. 0019 0020 Written by Cygnus Support, 1993. 0021 0022 The opcode library (libopcodes.a) provides instruction decoders for 0023 a large variety of instruction sets, callable with an identical 0024 interface, for making instruction-processing programs more independent 0025 of the instruction set being processed. */ 0026 0027 #ifndef DIS_ASM_H 0028 #define DIS_ASM_H 0029 0030 #ifdef __cplusplus 0031 extern "C" { 0032 #endif 0033 0034 #include <stdio.h> 0035 #include <string.h> 0036 #include "bfd.h" 0037 0038 enum dis_insn_type 0039 { 0040 dis_noninsn, /* Not a valid instruction. */ 0041 dis_nonbranch, /* Not a branch instruction. */ 0042 dis_branch, /* Unconditional branch. */ 0043 dis_condbranch, /* Conditional branch. */ 0044 dis_jsr, /* Jump to subroutine. */ 0045 dis_condjsr, /* Conditional jump to subroutine. */ 0046 dis_dref, /* Data reference instruction. */ 0047 dis_dref2 /* Two data references in instruction. */ 0048 }; 0049 0050 /* When printing styled disassembler output, this describes what style 0051 should be used. */ 0052 0053 enum disassembler_style 0054 { 0055 /* This is the default style, use this for any additional syntax 0056 (e.g. commas between operands, brackets, etc), or just as a default if 0057 no other style seems appropriate. */ 0058 dis_style_text, 0059 0060 /* Use this for all instruction mnemonics, or aliases for mnemonics. 0061 These should be things that correspond to real machine 0062 instructions. */ 0063 dis_style_mnemonic, 0064 0065 /* Some architectures include additional mnemonic like fields within the 0066 instruction operands, e.g. on aarch64 'add w16, w7, w1, lsl #2' where 0067 the 'lsl' is an additional piece of text that describes how the 0068 instruction should behave. This sub-mnemonic style can be used for 0069 these pieces of text. */ 0070 dis_style_sub_mnemonic, 0071 0072 /* For things that aren't real machine instructions, but rather 0073 assembler directives, e.g. .byte, etc. */ 0074 dis_style_assembler_directive, 0075 0076 /* Use this for any register names. This may or may-not include any 0077 register prefix, e.g. '$', '%', at the discretion of the target, 0078 though within each target the choice to include prefixes for not 0079 should be kept consistent. If the prefix is not printed with this 0080 style, then dis_style_text should be used. */ 0081 dis_style_register, 0082 0083 /* Use this for any constant values used within instructions or 0084 directives, unless the value is an absolute address, or an offset 0085 that will be added to an address (no matter where the address comes 0086 from) before use. This style may, or may-not be used for any 0087 prefix to the immediate value, e.g. '$', at the discretion of the 0088 target, though within each target the choice to include these 0089 prefixes should be kept consistent. */ 0090 dis_style_immediate, 0091 0092 /* The style for the numerical representation of an absolute address. 0093 Anything that is an address offset should use the immediate style. 0094 This style may, or may-not be used for any prefix to the immediate 0095 value, e.g. '$', at the discretion of the target, though within 0096 each target the choice to include these prefixes should be kept 0097 consistent. */ 0098 dis_style_address, 0099 0100 /* The style for any constant value within an instruction or directive 0101 that represents an offset that will be added to an address before 0102 use. This style may, or may-not be used for any prefix to the 0103 immediate value, e.g. '$', at the discretion of the target, though 0104 within each target the choice to include these prefixes should be 0105 kept consistent. */ 0106 dis_style_address_offset, 0107 0108 /* The style for a symbol's name. The numerical address of a symbol 0109 should use the address style above, this style is reserved for the 0110 name. */ 0111 dis_style_symbol, 0112 0113 /* The start of a comment that runs to the end of the line. Anything 0114 printed after a comment start might be styled differently, 0115 e.g. everything might be styled as a comment, regardless of the 0116 actual style used. The disassembler itself should not try to adjust 0117 the style emitted for comment content, e.g. an address emitted within 0118 a comment should still be given dis_style_address, in this way it is 0119 up to the user of the disassembler to decide how comments should be 0120 styled. */ 0121 dis_style_comment_start 0122 }; 0123 0124 typedef int (*fprintf_ftype) (void *, const char*, ...) ATTRIBUTE_FPTR_PRINTF_2; 0125 typedef int (*fprintf_styled_ftype) (void *, enum disassembler_style, const char*, ...) ATTRIBUTE_FPTR_PRINTF_3; 0126 0127 /* This struct is passed into the instruction decoding routine, 0128 and is passed back out into each callback. The various fields are used 0129 for conveying information from your main routine into your callbacks, 0130 for passing information into the instruction decoders (such as the 0131 addresses of the callback functions), or for passing information 0132 back from the instruction decoders to their callers. 0133 0134 It must be initialized before it is first passed; this can be done 0135 by hand, or using one of the initialization macros below. */ 0136 0137 typedef struct disassemble_info 0138 { 0139 fprintf_ftype fprintf_func; 0140 fprintf_styled_ftype fprintf_styled_func; 0141 void *stream; 0142 void *application_data; 0143 0144 /* Target description. We could replace this with a pointer to the bfd, 0145 but that would require one. There currently isn't any such requirement 0146 so to avoid introducing one we record these explicitly. */ 0147 /* The bfd_flavour. This can be bfd_target_unknown_flavour. */ 0148 enum bfd_flavour flavour; 0149 /* The bfd_arch value. */ 0150 enum bfd_architecture arch; 0151 /* The bfd_mach value. */ 0152 unsigned long mach; 0153 /* Endianness (for bi-endian cpus). Mono-endian cpus can ignore this. */ 0154 enum bfd_endian endian; 0155 /* Endianness of code, for mixed-endian situations such as ARM BE8. */ 0156 enum bfd_endian endian_code; 0157 0158 /* Some targets need information about the current section to accurately 0159 display insns. If this is NULL, the target disassembler function 0160 will have to make its best guess. */ 0161 asection *section; 0162 0163 /* An array of pointers to symbols either at the location being disassembled 0164 or at the start of the function being disassembled. The array is sorted 0165 so that the first symbol is intended to be the one used. The others are 0166 present for any misc. purposes. This is not set reliably, but if it is 0167 not NULL, it is correct. */ 0168 asymbol **symbols; 0169 /* Number of symbols in array. */ 0170 int num_symbols; 0171 0172 /* Symbol table provided for targets that want to look at it. This is 0173 used on Arm to find mapping symbols and determine Arm/Thumb code. */ 0174 asymbol **symtab; 0175 int symtab_pos; 0176 int symtab_size; 0177 0178 /* For use by the disassembler. 0179 The top 16 bits are reserved for public use (and are documented here). 0180 The bottom 16 bits are for the internal use of the disassembler. */ 0181 unsigned long flags; 0182 /* Set if the disassembler has determined that there are one or more 0183 relocations associated with the instruction being disassembled. */ 0184 #define INSN_HAS_RELOC (1u << 31) 0185 /* Set if the user has requested the disassembly of data as well as code. */ 0186 #define DISASSEMBLE_DATA (1u << 30) 0187 /* Set if the user has specifically set the machine type encoded in the 0188 mach field of this structure. */ 0189 #define USER_SPECIFIED_MACHINE_TYPE (1u << 29) 0190 /* Set if the user has requested wide output. */ 0191 #define WIDE_OUTPUT (1u << 28) 0192 0193 /* Dynamic relocations, if they have been loaded. */ 0194 arelent **dynrelbuf; 0195 long dynrelcount; 0196 0197 /* Use internally by the target specific disassembly code. */ 0198 void *private_data; 0199 0200 /* Function used to get bytes to disassemble. MEMADDR is the 0201 address of the stuff to be disassembled, MYADDR is the address to 0202 put the bytes in, and LENGTH is the number of bytes to read. 0203 INFO is a pointer to this struct. 0204 Returns an errno value or 0 for success. */ 0205 int (*read_memory_func) 0206 (bfd_vma memaddr, bfd_byte *myaddr, unsigned int length, 0207 struct disassemble_info *dinfo); 0208 0209 /* Function which should be called if we get an error that we can't 0210 recover from. STATUS is the errno value from read_memory_func and 0211 MEMADDR is the address that we were trying to read. INFO is a 0212 pointer to this struct. */ 0213 void (*memory_error_func) 0214 (int status, bfd_vma memaddr, struct disassemble_info *dinfo); 0215 0216 /* Function called to print ADDR. */ 0217 void (*print_address_func) 0218 (bfd_vma addr, struct disassemble_info *dinfo); 0219 0220 /* Function called to determine if there is a symbol at the given ADDR. 0221 If there is, the function returns 1, otherwise it returns 0. 0222 This is used by ports which support an overlay manager where 0223 the overlay number is held in the top part of an address. In 0224 some circumstances we want to include the overlay number in the 0225 address, (normally because there is a symbol associated with 0226 that address), but sometimes we want to mask out the overlay bits. */ 0227 asymbol * (*symbol_at_address_func) 0228 (bfd_vma addr, struct disassemble_info *dinfo); 0229 0230 /* Function called to check if a SYMBOL is can be displayed to the user. 0231 This is used by some ports that want to hide special symbols when 0232 displaying debugging outout. */ 0233 bool (*symbol_is_valid) 0234 (asymbol *, struct disassemble_info *dinfo); 0235 0236 /* These are for buffer_read_memory. */ 0237 bfd_byte *buffer; 0238 bfd_vma buffer_vma; 0239 size_t buffer_length; 0240 0241 /* This variable may be set by the instruction decoder. It suggests 0242 the number of bytes objdump should display on a single line. If 0243 the instruction decoder sets this, it should always set it to 0244 the same value in order to get reasonable looking output. */ 0245 int bytes_per_line; 0246 0247 /* The next two variables control the way objdump displays the raw data. */ 0248 /* For example, if bytes_per_line is 8 and bytes_per_chunk is 4, the */ 0249 /* output will look like this: 0250 00: 00000000 00000000 0251 with the chunks displayed according to "display_endian". */ 0252 int bytes_per_chunk; 0253 enum bfd_endian display_endian; 0254 0255 /* Number of octets per incremented target address 0256 Normally one, but some DSPs have byte sizes of 16 or 32 bits. */ 0257 unsigned int octets_per_byte; 0258 0259 /* The number of zeroes we want to see at the end of a section before we 0260 start skipping them. */ 0261 unsigned int skip_zeroes; 0262 0263 /* The number of zeroes to skip at the end of a section. If the number 0264 of zeroes at the end is between SKIP_ZEROES_AT_END and SKIP_ZEROES, 0265 they will be disassembled. If there are fewer than 0266 SKIP_ZEROES_AT_END, they will be skipped. This is a heuristic 0267 attempt to avoid disassembling zeroes inserted by section 0268 alignment. */ 0269 unsigned int skip_zeroes_at_end; 0270 0271 /* Whether the disassembler always needs the relocations. */ 0272 bool disassembler_needs_relocs; 0273 0274 /* Results from instruction decoders. Not all decoders yet support 0275 this information. This info is set each time an instruction is 0276 decoded, and is only valid for the last such instruction. 0277 0278 To determine whether this decoder supports this information, set 0279 insn_info_valid to 0, decode an instruction, then check it. */ 0280 0281 char insn_info_valid; /* Branch info has been set. */ 0282 char branch_delay_insns; /* How many sequential insn's will run before 0283 a branch takes effect. (0 = normal) */ 0284 char data_size; /* Size of data reference in insn, in bytes */ 0285 enum dis_insn_type insn_type; /* Type of instruction */ 0286 bfd_vma target; /* Target address of branch or dref, if known; 0287 zero if unknown. */ 0288 bfd_vma target2; /* Second target address for dref2 */ 0289 0290 /* Command line options specific to the target disassembler. */ 0291 const char *disassembler_options; 0292 0293 /* If non-zero then try not disassemble beyond this address, even if 0294 there are values left in the buffer. This address is the address 0295 of the nearest symbol forwards from the start of the disassembly, 0296 and it is assumed that it lies on the boundary between instructions. 0297 If an instruction spans this address then this is an error in the 0298 file being disassembled. */ 0299 bfd_vma stop_vma; 0300 0301 /* The end range of the current range being disassembled. This is required 0302 in order to notify the disassembler when it's currently handling a 0303 different range than it was before. This prevent unsafe optimizations when 0304 disassembling such as the way mapping symbols are found on AArch64. */ 0305 bfd_vma stop_offset; 0306 0307 /* Set to true if the disassembler applied styling to the output, 0308 otherwise, set to false. */ 0309 bool created_styled_output; 0310 } disassemble_info; 0311 0312 /* This struct is used to pass information about valid disassembler 0313 option arguments from the target to the generic GDB functions 0314 that set and display them. */ 0315 0316 typedef struct 0317 { 0318 /* Option argument name to use in descriptions. */ 0319 const char *name; 0320 0321 /* Vector of acceptable option argument values, NULL-terminated. 0322 NULL if any values are accepted. */ 0323 const char **values; 0324 } disasm_option_arg_t; 0325 0326 /* This struct is used to pass information about valid disassembler 0327 options, their descriptions and arguments from the target to the 0328 generic GDB functions that set and display them. Options are 0329 defined by tuples of vector entries at each index. */ 0330 0331 typedef struct 0332 { 0333 /* Vector of option names, NULL-terminated. */ 0334 const char **name; 0335 0336 /* Vector of option descriptions or NULL if none to be shown. */ 0337 const char **description; 0338 0339 /* Vector of option argument information pointers or NULL if no 0340 option accepts an argument. NULL entries denote individual 0341 options that accept no argument. */ 0342 const disasm_option_arg_t **arg; 0343 } disasm_options_t; 0344 0345 /* This struct is used to pass information about valid disassembler 0346 options and arguments from the target to the generic GDB functions 0347 that set and display them. */ 0348 0349 typedef struct 0350 { 0351 /* Valid disassembler options. Individual options that support 0352 an argument will refer to entries in the ARGS vector. */ 0353 disasm_options_t options; 0354 0355 /* Vector of acceptable option arguments, NULL-terminated. This 0356 collects all possible option argument choices, some of which 0357 may be shared by different options from the OPTIONS member. */ 0358 disasm_option_arg_t *args; 0359 } disasm_options_and_args_t; 0360 0361 /* Standard disassemblers. Disassemble one instruction at the given 0362 target address. Return number of octets processed. */ 0363 typedef int (*disassembler_ftype) (bfd_vma, disassemble_info *); 0364 0365 /* Disassemblers used out side of opcodes library. */ 0366 extern int print_insn_m32c (bfd_vma, disassemble_info *); 0367 extern int print_insn_mep (bfd_vma, disassemble_info *); 0368 extern int print_insn_s12z (bfd_vma, disassemble_info *); 0369 extern int print_insn_sh (bfd_vma, disassemble_info *); 0370 extern int print_insn_sparc (bfd_vma, disassemble_info *); 0371 extern int print_insn_rx (bfd_vma, disassemble_info *); 0372 extern int print_insn_rl78 (bfd_vma, disassemble_info *); 0373 extern int print_insn_rl78_g10 (bfd_vma, disassemble_info *); 0374 extern int print_insn_rl78_g13 (bfd_vma, disassemble_info *); 0375 extern int print_insn_rl78_g14 (bfd_vma, disassemble_info *); 0376 0377 extern disassembler_ftype arc_get_disassembler (bfd *); 0378 extern disassembler_ftype cris_get_disassembler (bfd *); 0379 0380 extern void print_aarch64_disassembler_options (FILE *); 0381 extern void print_i386_disassembler_options (FILE *); 0382 extern void print_mips_disassembler_options (FILE *); 0383 extern void print_nfp_disassembler_options (FILE *); 0384 extern void print_ppc_disassembler_options (FILE *); 0385 extern void print_riscv_disassembler_options (FILE *); 0386 extern void print_arm_disassembler_options (FILE *); 0387 extern void print_arc_disassembler_options (FILE *); 0388 extern void print_kvx_disassembler_options(FILE *); 0389 extern void print_s390_disassembler_options (FILE *); 0390 extern void print_wasm32_disassembler_options (FILE *); 0391 extern void print_loongarch_disassembler_options (FILE *); 0392 extern void print_bpf_disassembler_options (FILE *); 0393 extern bool aarch64_symbol_is_valid (asymbol *, struct disassemble_info *); 0394 extern bool arm_symbol_is_valid (asymbol *, struct disassemble_info *); 0395 extern bool csky_symbol_is_valid (asymbol *, struct disassemble_info *); 0396 extern bool riscv_symbol_is_valid (asymbol *, struct disassemble_info *); 0397 extern void disassemble_init_powerpc (struct disassemble_info *); 0398 extern void disassemble_init_s390 (struct disassemble_info *); 0399 extern void disassemble_init_wasm32 (struct disassemble_info *); 0400 extern void disassemble_init_nds32 (struct disassemble_info *); 0401 extern const disasm_options_and_args_t *disassembler_options_arc (void); 0402 extern const disasm_options_and_args_t *disassembler_options_arm (void); 0403 extern const disasm_options_and_args_t *disassembler_options_mips (void); 0404 extern const disasm_options_and_args_t *disassembler_options_powerpc (void); 0405 extern const disasm_options_and_args_t *disassembler_options_riscv (void); 0406 extern const disasm_options_and_args_t *disassembler_options_s390 (void); 0407 0408 /* Fetch the disassembler for a given architecture ARC, endianess (big 0409 endian if BIG is true), bfd_mach value MACH, and ABFD, if that support 0410 is available. ABFD may be NULL. */ 0411 extern disassembler_ftype disassembler (enum bfd_architecture arc, 0412 bool big, unsigned long mach, 0413 bfd *abfd); 0414 0415 /* Amend the disassemble_info structure as necessary for the target architecture. 0416 Should only be called after initialising the info->arch field. */ 0417 extern void disassemble_init_for_target (struct disassemble_info *); 0418 0419 /* Tidy any memory allocated by targets, such as info->private_data. */ 0420 extern void disassemble_free_target (struct disassemble_info *); 0421 0422 /* Set the basic disassembler print functions. */ 0423 extern void disassemble_set_printf (struct disassemble_info *, void *, 0424 fprintf_ftype, fprintf_styled_ftype); 0425 0426 /* Document any target specific options available from the disassembler. */ 0427 extern void disassembler_usage (FILE *); 0428 0429 /* Remove whitespace and consecutive commas. */ 0430 extern char *remove_whitespace_and_extra_commas (char *); 0431 0432 /* Like STRCMP, but treat ',' the same as '\0' so that we match 0433 strings like "foobar" against "foobar,xxyyzz,...". */ 0434 extern int disassembler_options_cmp (const char *, const char *); 0435 0436 /* A helper function for FOR_EACH_DISASSEMBLER_OPTION. */ 0437 static inline const char * 0438 next_disassembler_option (const char *options) 0439 { 0440 const char *opt = strchr (options, ','); 0441 if (opt != NULL) 0442 opt++; 0443 return opt; 0444 } 0445 0446 /* A macro for iterating over each comma separated option in OPTIONS. */ 0447 #define FOR_EACH_DISASSEMBLER_OPTION(OPT, OPTIONS) \ 0448 for ((OPT) = (OPTIONS); \ 0449 (OPT) != NULL; \ 0450 (OPT) = next_disassembler_option (OPT)) 0451 0452 0453 /* This block of definitions is for particular callers who read instructions 0454 into a buffer before calling the instruction decoder. */ 0455 0456 /* Here is a function which callers may wish to use for read_memory_func. 0457 It gets bytes from a buffer. */ 0458 extern int buffer_read_memory 0459 (bfd_vma, bfd_byte *, unsigned int, struct disassemble_info *); 0460 0461 /* This function goes with buffer_read_memory. 0462 It prints a message using info->fprintf_func and info->stream. */ 0463 extern void perror_memory (int, bfd_vma, struct disassemble_info *); 0464 0465 0466 /* Just print the address in hex. This is included for completeness even 0467 though both GDB and objdump provide their own (to print symbolic 0468 addresses). */ 0469 extern void generic_print_address 0470 (bfd_vma, struct disassemble_info *); 0471 0472 /* Always NULL. */ 0473 extern asymbol *generic_symbol_at_address 0474 (bfd_vma, struct disassemble_info *); 0475 0476 /* Always true. */ 0477 extern bool generic_symbol_is_valid 0478 (asymbol *, struct disassemble_info *); 0479 0480 /* Method to initialize a disassemble_info struct. This should be 0481 called by all applications creating such a struct. */ 0482 extern void init_disassemble_info (struct disassemble_info *dinfo, void *stream, 0483 fprintf_ftype fprintf_func, 0484 fprintf_styled_ftype fprintf_styled_func); 0485 0486 /* For compatibility with existing code. */ 0487 #define INIT_DISASSEMBLE_INFO(INFO, STREAM, FPRINTF_FUNC, FPRINTF_STYLED_FUNC) \ 0488 init_disassemble_info (&(INFO), (STREAM), (fprintf_ftype) (FPRINTF_FUNC), \ 0489 (fprintf_styled_ftype) (FPRINTF_STYLED_FUNC)) 0490 0491 #ifdef __cplusplus 0492 } 0493 #endif 0494 0495 #endif /* ! defined (DIS_ASM_H) */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |