2 Copyright (C) 2011-2024 Free Software Foundation, Inc.
4 Contributed by Andrew Waterman (andrew@sifive.com).
7 This file is part of the GNU opcodes library.
9 This library is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
14 It is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
17 License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; see the file COPYING3. If not,
21 see <http://www.gnu.org/licenses/>. */
24 #include "disassemble.h"
25 #include "libiberty.h"
26 #include "opcode/riscv.h"
29 #include "elf/riscv.h"
30 #include "elfxx-riscv.h"
35 /* The RISC-V disassembler produces styled output using
36 disassemble_info::fprintf_styled_func. This define prevents use of
37 disassemble_info::fprintf_func which is for unstyled output. */
38 #define fprintf_func please_use_fprintf_styled_func_instead
40 /* Current XLEN for the disassembler. */
41 static unsigned xlen
= 0;
43 /* Default ISA specification version (constant as of now). */
44 static enum riscv_spec_class default_isa_spec
= ISA_SPEC_CLASS_DRAFT
- 1;
46 /* Default privileged specification
47 (as specified by the ELF attributes or the `priv-spec' option). */
48 static enum riscv_spec_class default_priv_spec
= PRIV_SPEC_CLASS_NONE
;
50 static riscv_subset_list_t riscv_subsets
;
51 static riscv_parse_subset_t riscv_rps_dis
=
53 &riscv_subsets
, /* subset_list. */
54 opcodes_error_handler
,/* error_handler. */
56 &default_isa_spec
, /* isa_spec. */
57 false, /* check_unknown_prefixed_ext. */
60 struct riscv_private_data
64 bfd_vma hi_addr
[OP_MASK_RD
+ 1];
69 /* Used for mapping symbols. */
70 static int last_map_symbol
= -1;
71 static bfd_vma last_stop_offset
= 0;
72 static bfd_vma last_map_symbol_boundary
= 0;
73 static enum riscv_seg_mstate last_map_state
= MAP_NONE
;
74 static asection
*last_map_section
= NULL
;
76 /* Register names as used by the disassembler. */
77 static const char (*riscv_gpr_names
)[NRC
];
78 static const char (*riscv_fpr_names
)[NRC
];
80 /* If set, disassemble as most general instruction. */
81 static bool no_aliases
= false;
84 /* Set default RISC-V disassembler options. */
87 set_default_riscv_dis_options (void)
89 riscv_gpr_names
= riscv_gpr_names_abi
;
90 riscv_fpr_names
= riscv_fpr_names_abi
;
94 /* Parse RISC-V disassembler option (without arguments). */
97 parse_riscv_dis_option_without_args (const char *option
)
99 if (strcmp (option
, "no-aliases") == 0)
101 else if (strcmp (option
, "numeric") == 0)
103 riscv_gpr_names
= riscv_gpr_names_numeric
;
104 riscv_fpr_names
= riscv_fpr_names_numeric
;
111 /* Parse RISC-V disassembler option (possibly with arguments). */
114 parse_riscv_dis_option (const char *option
)
118 if (parse_riscv_dis_option_without_args (option
))
121 equal
= strchr (option
, '=');
124 /* The option without '=' should be defined above. */
125 opcodes_error_handler (_("unrecognized disassembler option: %s"), option
);
129 || *(equal
+ 1) == '\0')
131 /* Invalid options with '=', no option name before '=',
132 and no value after '='. */
133 opcodes_error_handler (_("unrecognized disassembler option with '=': %s"),
140 if (strcmp (option
, "priv-spec") == 0)
142 enum riscv_spec_class priv_spec
= PRIV_SPEC_CLASS_NONE
;
143 const char *name
= NULL
;
145 RISCV_GET_PRIV_SPEC_CLASS (value
, priv_spec
);
146 if (priv_spec
== PRIV_SPEC_CLASS_NONE
)
147 opcodes_error_handler (_("unknown privileged spec set by %s=%s"),
149 else if (default_priv_spec
== PRIV_SPEC_CLASS_NONE
)
150 default_priv_spec
= priv_spec
;
151 else if (default_priv_spec
!= priv_spec
)
153 RISCV_GET_PRIV_SPEC_NAME (name
, default_priv_spec
);
154 opcodes_error_handler (_("mis-matched privilege spec set by %s=%s, "
155 "the elf privilege attribute is %s"),
156 option
, value
, name
);
161 /* xgettext:c-format */
162 opcodes_error_handler (_("unrecognized disassembler option: %s"), option
);
166 /* Parse RISC-V disassembler options. */
169 parse_riscv_dis_options (const char *opts_in
)
171 char *opts
= xstrdup (opts_in
), *opt
= opts
, *opt_end
= opts
;
173 set_default_riscv_dis_options ();
175 for ( ; opt_end
!= NULL
; opt
= opt_end
+ 1)
177 if ((opt_end
= strchr (opt
, ',')) != NULL
)
179 parse_riscv_dis_option (opt
);
185 /* Print one argument from an array. */
188 arg_print (struct disassemble_info
*info
, unsigned long val
,
189 const char* const* array
, size_t size
)
191 const char *s
= val
>= size
|| array
[val
] == NULL
? "unknown" : array
[val
];
192 (*info
->fprintf_styled_func
) (info
->stream
, dis_style_text
, "%s", s
);
195 /* If we need to print an address, set its value and state. */
198 maybe_print_address (struct riscv_private_data
*pd
, int base_reg
, int offset
,
201 if (pd
->hi_addr
[base_reg
] != (bfd_vma
)-1)
203 pd
->print_addr
= (base_reg
!= 0 ? pd
->hi_addr
[base_reg
] : 0) + offset
;
204 pd
->hi_addr
[base_reg
] = -1;
206 else if (base_reg
== X_GP
&& pd
->has_gp
)
207 pd
->print_addr
= pd
->gp
+ offset
;
208 else if (base_reg
== X_TP
|| base_reg
== 0)
209 pd
->print_addr
= offset
;
211 return; /* Don't print the address. */
212 pd
->to_print_addr
= true;
214 /* Sign-extend a 32-bit value to a 64-bit value. */
216 pd
->print_addr
= (bfd_vma
)(int32_t) pd
->print_addr
;
218 /* Fit into a 32-bit value on RV32. */
220 pd
->print_addr
= (bfd_vma
)(uint32_t)pd
->print_addr
;
223 /* Get Zcmp reg_list field. */
226 print_reg_list (disassemble_info
*info
, insn_t l
)
228 bool numeric
= riscv_gpr_names
== riscv_gpr_names_numeric
;
229 unsigned reg_list
= (int)EXTRACT_OPERAND (REG_LIST
, l
);
230 unsigned r_start
= numeric
? X_S2
: X_S0
;
231 info
->fprintf_styled_func (info
->stream
, dis_style_register
,
232 "%s", riscv_gpr_names
[X_RA
]);
236 info
->fprintf_styled_func (info
->stream
, dis_style_text
, ",");
237 info
->fprintf_styled_func (info
->stream
, dis_style_register
,
238 "%s", riscv_gpr_names
[X_S0
]);
240 else if (reg_list
== 6 || (numeric
&& reg_list
> 6))
242 info
->fprintf_styled_func (info
->stream
, dis_style_text
, ",");
243 info
->fprintf_styled_func (info
->stream
, dis_style_register
,
244 "%s", riscv_gpr_names
[X_S0
]);
245 info
->fprintf_styled_func (info
->stream
, dis_style_text
, "-");
246 info
->fprintf_styled_func (info
->stream
, dis_style_register
,
247 "%s", riscv_gpr_names
[X_S1
]);
252 info
->fprintf_styled_func (info
->stream
, dis_style_text
, ",");
253 info
->fprintf_styled_func (info
->stream
, dis_style_register
,
254 "%s", riscv_gpr_names
[r_start
]);
255 info
->fprintf_styled_func (info
->stream
, dis_style_text
, "-");
256 info
->fprintf_styled_func (info
->stream
, dis_style_register
,
257 "%s", riscv_gpr_names
[X_S11
]);
259 else if (reg_list
== 7 && numeric
)
261 info
->fprintf_styled_func (info
->stream
, dis_style_text
, ",");
262 info
->fprintf_styled_func (info
->stream
, dis_style_register
,
263 "%s", riscv_gpr_names
[X_S2
]);
265 else if (reg_list
> 6)
267 info
->fprintf_styled_func (info
->stream
, dis_style_text
, ",");
268 info
->fprintf_styled_func (info
->stream
, dis_style_register
,
269 "%s", riscv_gpr_names
[r_start
]);
270 info
->fprintf_styled_func (info
->stream
, dis_style_text
, "-");
271 info
->fprintf_styled_func (info
->stream
, dis_style_register
,
272 "%s", riscv_gpr_names
[reg_list
+ 11]);
276 /* Get Zcmp sp adjustment immediate. */
279 riscv_get_spimm (insn_t l
)
281 int spimm
= riscv_get_sp_base(l
, *riscv_rps_dis
.xlen
);
282 spimm
+= EXTRACT_ZCMP_SPIMM (l
);
283 if (((l
^ MATCH_CM_PUSH
) & MASK_CM_PUSH
) == 0)
288 /* Print insn arguments for 32/64-bit code. */
291 print_insn_args (const char *oparg
, insn_t l
, bfd_vma pc
, disassemble_info
*info
)
293 struct riscv_private_data
*pd
= info
->private_data
;
294 int rs1
= (l
>> OP_SH_RS1
) & OP_MASK_RS1
;
295 int rd
= (l
>> OP_SH_RD
) & OP_MASK_RD
;
296 fprintf_styled_ftype print
= info
->fprintf_styled_func
;
297 const char *opargStart
;
300 print (info
->stream
, dis_style_text
, "\t");
302 for (; *oparg
!= '\0'; oparg
++)
310 case 's': /* RS1 x8-x15. */
311 case 'w': /* RS1 x8-x15. */
312 print (info
->stream
, dis_style_register
, "%s",
313 riscv_gpr_names
[EXTRACT_OPERAND (CRS1S
, l
) + 8]);
315 case 't': /* RS2 x8-x15. */
316 case 'x': /* RS2 x8-x15. */
317 print (info
->stream
, dis_style_register
, "%s",
318 riscv_gpr_names
[EXTRACT_OPERAND (CRS2S
, l
) + 8]);
320 case 'U': /* RS1, constrained to equal RD. */
321 print (info
->stream
, dis_style_register
,
322 "%s", riscv_gpr_names
[rd
]);
324 case 'c': /* RS1, constrained to equal sp. */
325 print (info
->stream
, dis_style_register
, "%s",
326 riscv_gpr_names
[X_SP
]);
329 print (info
->stream
, dis_style_register
, "%s",
330 riscv_gpr_names
[EXTRACT_OPERAND (CRS2
, l
)]);
334 if (((l
& MASK_C_ADDI
) == MATCH_C_ADDI
) && rd
!= 0)
335 maybe_print_address (pd
, rd
, EXTRACT_CITYPE_IMM (l
), 0);
336 if (info
->mach
== bfd_mach_riscv64
337 && ((l
& MASK_C_ADDIW
) == MATCH_C_ADDIW
) && rd
!= 0)
338 maybe_print_address (pd
, rd
, EXTRACT_CITYPE_IMM (l
), 1);
339 print (info
->stream
, dis_style_immediate
, "%d",
340 (int)EXTRACT_CITYPE_IMM (l
));
343 print (info
->stream
, dis_style_address_offset
, "%d",
344 (int)EXTRACT_CLTYPE_LW_IMM (l
));
347 print (info
->stream
, dis_style_address_offset
, "%d",
348 (int)EXTRACT_CLTYPE_LD_IMM (l
));
351 print (info
->stream
, dis_style_address_offset
, "%d",
352 (int)EXTRACT_CITYPE_LWSP_IMM (l
));
355 print (info
->stream
, dis_style_address_offset
, "%d",
356 (int)EXTRACT_CITYPE_LDSP_IMM (l
));
359 print (info
->stream
, dis_style_immediate
, "%d",
360 (int)EXTRACT_CIWTYPE_ADDI4SPN_IMM (l
));
363 print (info
->stream
, dis_style_immediate
, "%d",
364 (int)EXTRACT_CITYPE_ADDI16SP_IMM (l
));
367 print (info
->stream
, dis_style_address_offset
, "%d",
368 (int)EXTRACT_CSSTYPE_SWSP_IMM (l
));
371 print (info
->stream
, dis_style_address_offset
, "%d",
372 (int)EXTRACT_CSSTYPE_SDSP_IMM (l
));
375 info
->target
= EXTRACT_CBTYPE_IMM (l
) + pc
;
376 (*info
->print_address_func
) (info
->target
, info
);
379 info
->target
= EXTRACT_CJTYPE_IMM (l
) + pc
;
380 (*info
->print_address_func
) (info
->target
, info
);
383 print (info
->stream
, dis_style_immediate
, "0x%x",
384 (unsigned)(EXTRACT_CITYPE_IMM (l
) & (RISCV_BIGIMM_REACH
-1)));
387 print (info
->stream
, dis_style_immediate
, "0x%x",
388 (unsigned)EXTRACT_CITYPE_IMM (l
) & 0x3f);
391 print (info
->stream
, dis_style_immediate
, "0x%x",
392 (unsigned)EXTRACT_CITYPE_IMM (l
) & 0x1f);
394 case 'T': /* Floating-point RS2. */
395 print (info
->stream
, dis_style_register
, "%s",
396 riscv_fpr_names
[EXTRACT_OPERAND (CRS2
, l
)]);
398 case 'D': /* Floating-point RS2 x8-x15. */
399 print (info
->stream
, dis_style_register
, "%s",
400 riscv_fpr_names
[EXTRACT_OPERAND (CRS2S
, l
) + 8]);
410 print (info
->stream
, dis_style_register
, "%s",
411 riscv_vecr_names_numeric
[EXTRACT_OPERAND (VD
, l
)]);
414 if (!EXTRACT_OPERAND (VWD
, l
))
415 print (info
->stream
, dis_style_register
, "%s",
418 print (info
->stream
, dis_style_register
, "%s",
419 riscv_vecr_names_numeric
[EXTRACT_OPERAND (VD
, l
)]);
422 print (info
->stream
, dis_style_register
, "%s",
423 riscv_vecr_names_numeric
[EXTRACT_OPERAND (VS1
, l
)]);
426 case 'u': /* VS1 == VS2 already verified at this point. */
427 case 'v': /* VD == VS1 == VS2 already verified at this point. */
428 print (info
->stream
, dis_style_register
, "%s",
429 riscv_vecr_names_numeric
[EXTRACT_OPERAND (VS2
, l
)]);
432 print (info
->stream
, dis_style_register
, "%s",
433 riscv_vecr_names_numeric
[0]);
438 int imm
= (*oparg
== 'b') ? EXTRACT_RVV_VB_IMM (l
)
439 : EXTRACT_RVV_VC_IMM (l
);
440 unsigned int imm_vlmul
= EXTRACT_OPERAND (VLMUL
, imm
);
441 unsigned int imm_vsew
= EXTRACT_OPERAND (VSEW
, imm
);
442 unsigned int imm_vta
= EXTRACT_OPERAND (VTA
, imm
);
443 unsigned int imm_vma
= EXTRACT_OPERAND (VMA
, imm
);
444 unsigned int imm_vtype_res
= (imm
>> 8);
446 if (imm_vsew
< ARRAY_SIZE (riscv_vsew
)
447 && imm_vlmul
< ARRAY_SIZE (riscv_vlmul
)
448 && imm_vta
< ARRAY_SIZE (riscv_vta
)
449 && imm_vma
< ARRAY_SIZE (riscv_vma
)
451 && riscv_vsew
[imm_vsew
] != NULL
452 && riscv_vlmul
[imm_vlmul
] != NULL
)
453 print (info
->stream
, dis_style_text
, "%s,%s,%s,%s",
454 riscv_vsew
[imm_vsew
],
455 riscv_vlmul
[imm_vlmul
], riscv_vta
[imm_vta
],
458 print (info
->stream
, dis_style_immediate
, "%d", imm
);
462 print (info
->stream
, dis_style_immediate
, "%d",
463 (int)EXTRACT_RVV_VI_IMM (l
));
466 print (info
->stream
, dis_style_immediate
, "%d",
467 (int)EXTRACT_RVV_VI_UIMM (l
));
470 print (info
->stream
, dis_style_immediate
, "%d",
471 (int)EXTRACT_RVV_OFFSET (l
));
474 print (info
->stream
, dis_style_immediate
, "%d",
475 (int)EXTRACT_RVV_VI_UIMM6 (l
));
478 if (!EXTRACT_OPERAND (VMASK
, l
))
480 print (info
->stream
, dis_style_text
, ",");
481 print (info
->stream
, dis_style_register
, "%s",
482 riscv_vecm_names_numeric
[0]);
495 print (info
->stream
, dis_style_text
, "%c", *oparg
);
499 /* Only print constant 0 if it is the last argument. */
501 print (info
->stream
, dis_style_immediate
, "0");
505 if ((l
& MASK_JALR
) == MATCH_JALR
)
506 maybe_print_address (pd
, rs1
, EXTRACT_ITYPE_IMM (l
), 0);
507 print (info
->stream
, dis_style_register
, "%s", riscv_gpr_names
[rs1
]);
511 print (info
->stream
, dis_style_register
, "%s",
512 riscv_gpr_names
[EXTRACT_OPERAND (RS2
, l
)]);
516 print (info
->stream
, dis_style_immediate
, "0x%x",
517 (unsigned)EXTRACT_UTYPE_IMM (l
) >> RISCV_IMM_BITS
);
521 arg_print (info
, EXTRACT_OPERAND (RM
, l
),
522 riscv_rm
, ARRAY_SIZE (riscv_rm
));
526 arg_print (info
, EXTRACT_OPERAND (PRED
, l
),
527 riscv_pred_succ
, ARRAY_SIZE (riscv_pred_succ
));
531 arg_print (info
, EXTRACT_OPERAND (SUCC
, l
),
532 riscv_pred_succ
, ARRAY_SIZE (riscv_pred_succ
));
536 maybe_print_address (pd
, rs1
, EXTRACT_ITYPE_IMM (l
), 0);
539 if (((l
& MASK_ADDI
) == MATCH_ADDI
&& rs1
!= 0)
540 || (l
& MASK_JALR
) == MATCH_JALR
)
541 maybe_print_address (pd
, rs1
, EXTRACT_ITYPE_IMM (l
), 0);
542 if (info
->mach
== bfd_mach_riscv64
543 && ((l
& MASK_ADDIW
) == MATCH_ADDIW
) && rs1
!= 0)
544 maybe_print_address (pd
, rs1
, EXTRACT_ITYPE_IMM (l
), 1);
545 print (info
->stream
, dis_style_immediate
, "%d",
546 (int)EXTRACT_ITYPE_IMM (l
));
550 maybe_print_address (pd
, rs1
, EXTRACT_STYPE_IMM (l
), 0);
551 print (info
->stream
, dis_style_address_offset
, "%d",
552 (int)EXTRACT_STYPE_IMM (l
));
556 info
->target
= EXTRACT_JTYPE_IMM (l
) + pc
;
557 (*info
->print_address_func
) (info
->target
, info
);
561 info
->target
= EXTRACT_BTYPE_IMM (l
) + pc
;
562 (*info
->print_address_func
) (info
->target
, info
);
566 if ((l
& MASK_AUIPC
) == MATCH_AUIPC
)
567 pd
->hi_addr
[rd
] = pc
+ EXTRACT_UTYPE_IMM (l
);
568 else if ((l
& MASK_LUI
) == MATCH_LUI
)
569 pd
->hi_addr
[rd
] = EXTRACT_UTYPE_IMM (l
);
570 else if ((l
& MASK_C_LUI
) == MATCH_C_LUI
)
571 pd
->hi_addr
[rd
] = EXTRACT_CITYPE_LUI_IMM (l
);
572 print (info
->stream
, dis_style_register
, "%s", riscv_gpr_names
[rd
]);
576 print (info
->stream
, dis_style_immediate
, "0x%x",
577 EXTRACT_OPERAND (BS
, l
));
581 print (info
->stream
, dis_style_register
, "%s", riscv_gpr_names
[0]);
585 print (info
->stream
, dis_style_immediate
, "0x%x",
586 EXTRACT_OPERAND (SHAMT
, l
));
590 print (info
->stream
, dis_style_immediate
, "0x%x",
591 EXTRACT_OPERAND (SHAMTW
, l
));
596 print (info
->stream
, dis_style_register
, "%s", riscv_fpr_names
[rs1
]);
600 print (info
->stream
, dis_style_register
, "%s",
601 riscv_fpr_names
[EXTRACT_OPERAND (RS2
, l
)]);
605 print (info
->stream
, dis_style_register
, "%s", riscv_fpr_names
[rd
]);
609 print (info
->stream
, dis_style_register
, "%s",
610 riscv_fpr_names
[EXTRACT_OPERAND (RS3
, l
)]);
615 static const char *riscv_csr_hash
[4096]; /* Total 2^12 CSRs. */
616 static bool init_csr
= false;
617 unsigned int csr
= EXTRACT_OPERAND (CSR
, l
);
622 for (i
= 0; i
< 4096; i
++)
623 riscv_csr_hash
[i
] = NULL
;
625 /* Set to the newest privileged version. */
626 if (default_priv_spec
== PRIV_SPEC_CLASS_NONE
)
627 default_priv_spec
= PRIV_SPEC_CLASS_DRAFT
- 1;
629 #define DECLARE_CSR(name, num, class, define_version, abort_version) \
630 if (riscv_csr_hash[num] == NULL \
631 && ((define_version == PRIV_SPEC_CLASS_NONE \
632 && abort_version == PRIV_SPEC_CLASS_NONE) \
633 || (default_priv_spec >= define_version \
634 && default_priv_spec < abort_version))) \
635 riscv_csr_hash[num] = #name;
636 #define DECLARE_CSR_ALIAS(name, num, class, define_version, abort_version) \
637 DECLARE_CSR (name, num, class, define_version, abort_version)
638 #include "opcode/riscv-opc.h"
642 if (riscv_csr_hash
[csr
] != NULL
)
643 if (riscv_subset_supports (&riscv_rps_dis
, "xtheadvector")
644 && (csr
== CSR_VSTART
649 || csr
== CSR_VLENB
))
650 print (info
->stream
, dis_style_register
, "%s",
651 concat ("th.", riscv_csr_hash
[csr
], NULL
));
653 print (info
->stream
, dis_style_register
, "%s",
654 riscv_csr_hash
[csr
]);
656 print (info
->stream
, dis_style_immediate
, "0x%x", csr
);
661 print (info
->stream
, dis_style_immediate
, "0x%x",
662 EXTRACT_OPERAND (RNUM
, l
));
666 print (info
->stream
, dis_style_immediate
, "%d", rs1
);
669 case 'W': /* Various operands for standard z extensions. */
676 print (info
->stream
, dis_style_address_offset
, "%d",
677 (int) EXTRACT_STYPE_IMM (l
));
680 goto undefined_modifier
;
687 if (riscv_fli_symval
[rs1
])
688 print (info
->stream
, dis_style_text
, "%s",
689 riscv_fli_symval
[rs1
]);
691 print (info
->stream
, dis_style_immediate
, "%a",
692 riscv_fli_numval
[rs1
]);
695 goto undefined_modifier
;
698 case 'c': /* Zcb extension 16 bits length instruction fields. */
702 print (info
->stream
, dis_style_immediate
, "%d",
703 (int)EXTRACT_ZCB_BYTE_UIMM (l
));
706 print (info
->stream
, dis_style_immediate
, "%d",
707 (int)EXTRACT_ZCB_HALFWORD_UIMM (l
));
710 print_reg_list (info
, l
);
713 print (info
->stream
, dis_style_immediate
, "%d",
714 riscv_get_spimm (l
));
717 goto undefined_modifier
;
721 goto undefined_modifier
;
725 case 'X': /* Vendor-specific operands. */
728 case 't': /* Vendor-specific (T-head) operands. */
738 goto undefined_modifier
;
740 int imm
= (*oparg
== 'b') ? EXTRACT_RVV_VB_IMM (l
)
741 : EXTRACT_RVV_VC_IMM (l
);
742 unsigned int imm_vediv
= EXTRACT_OPERAND (XTHEADVEDIV
, imm
);
743 unsigned int imm_vlmul
= EXTRACT_OPERAND (XTHEADVLMUL
, imm
);
744 unsigned int imm_vsew
= EXTRACT_OPERAND (XTHEADVSEW
, imm
);
745 unsigned int imm_vtype_res
746 = EXTRACT_OPERAND (XTHEADVTYPE_RES
, imm
);
747 if (imm_vsew
< ARRAY_SIZE (riscv_vsew
)
748 && imm_vlmul
< ARRAY_SIZE (riscv_th_vlen
)
749 && imm_vediv
< ARRAY_SIZE (riscv_th_vediv
)
751 print (info
->stream
, dis_style_text
, "%s,%s,%s",
752 riscv_vsew
[imm_vsew
], riscv_th_vlen
[imm_vlmul
],
753 riscv_th_vediv
[imm_vediv
]);
755 print (info
->stream
, dis_style_immediate
, "%d", imm
);
757 case 'l': /* Integer immediate, literal. */
759 while (*oparg
&& *oparg
!= ',')
761 print (info
->stream
, dis_style_immediate
, "%c", *oparg
);
766 case 's': /* Integer immediate, 'XsN@S' ... N-bit signed immediate at bit S. */
769 case 'u': /* Integer immediate, 'XuN@S' ... N-bit unsigned immediate at bit S. */
773 n
= strtol (oparg
+ 1, (char **)&oparg
, 10);
775 goto undefined_modifier
;
776 s
= strtol (oparg
+ 1, (char **)&oparg
, 10);
780 print (info
->stream
, dis_style_immediate
, "%lu",
781 (unsigned long)EXTRACT_U_IMM (n
, s
, l
));
783 print (info
->stream
, dis_style_immediate
, "%li",
784 (signed long)EXTRACT_S_IMM (n
, s
, l
));
787 goto undefined_modifier
;
791 case 'c': /* Vendor-specific (CORE-V) operands. */
795 print (info
->stream
, dis_style_immediate
, "%d",
796 ((int) EXTRACT_CV_IS2_UIMM5 (l
)));
799 print (info
->stream
, dis_style_immediate
, "%d",
800 ((int) EXTRACT_CV_IS3_UIMM5 (l
)));
803 print (info
->stream
, dis_style_immediate
, "%d",
804 ((int) EXTRACT_CV_BI_IMM5 (l
)));
807 goto undefined_modifier
;
810 case 's': /* Vendor-specific (SiFive) operands. */
813 /* SiFive vector coprocessor interface. */
815 print (info
->stream
, dis_style_register
, "0x%x",
816 (unsigned) EXTRACT_OPERAND (RD
, l
));
819 print (info
->stream
, dis_style_register
, "0x%x",
820 (unsigned) EXTRACT_OPERAND (RS2
, l
));
826 print (info
->stream
, dis_style_register
, "0x%x",
827 (unsigned) EXTRACT_OPERAND (XSO2
, l
));
830 print (info
->stream
, dis_style_register
, "0x%x",
831 (unsigned) EXTRACT_OPERAND (XSO1
, l
));
838 goto undefined_modifier
;
844 /* xgettext:c-format */
845 print (info
->stream
, dis_style_text
,
846 _("# internal error, undefined modifier (%c)"),
853 /* Print the RISC-V instruction at address MEMADDR in debugged memory,
854 on using INFO. Returns length of the instruction, in bytes.
855 BIGENDIAN must be 1 if this is big-endian code, 0 if
856 this is little-endian code. */
859 riscv_disassemble_insn (bfd_vma memaddr
,
861 const bfd_byte
*packet
,
862 disassemble_info
*info
)
864 const struct riscv_opcode
*op
;
865 static bool init
= false;
866 static const struct riscv_opcode
*riscv_hash
[OP_MASK_OP
+ 1];
867 struct riscv_private_data
*pd
= info
->private_data
;
871 #define OP_HASH_IDX(i) ((i) & (riscv_insn_length (i) == 2 ? 0x3 : OP_MASK_OP))
873 /* Build a hash table to shorten the search time. */
876 for (op
= riscv_opcodes
; op
->name
; op
++)
877 if (!riscv_hash
[OP_HASH_IDX (op
->match
)])
878 riscv_hash
[OP_HASH_IDX (op
->match
)] = op
;
883 insnlen
= riscv_insn_length (word
);
885 /* RISC-V instructions are always little-endian. */
886 info
->endian_code
= BFD_ENDIAN_LITTLE
;
888 info
->bytes_per_chunk
= insnlen
% 4 == 0 ? 4 : 2;
889 info
->bytes_per_line
= 8;
890 /* We don't support constant pools, so this must be code. */
891 info
->display_endian
= info
->endian_code
;
892 info
->insn_info_valid
= 1;
893 info
->branch_delay_insns
= 0;
895 info
->insn_type
= dis_nonbranch
;
899 op
= riscv_hash
[OP_HASH_IDX (word
)];
902 /* If XLEN is not known, get its value from the ELF class. */
903 if (info
->mach
== bfd_mach_riscv64
)
905 else if (info
->mach
== bfd_mach_riscv32
)
907 else if (info
->section
!= NULL
)
909 Elf_Internal_Ehdr
*ehdr
= elf_elfheader (info
->section
->owner
);
910 xlen
= ehdr
->e_ident
[EI_CLASS
] == ELFCLASS64
? 64 : 32;
913 /* If arch has the Zfinx extension, replace FPR with GPR. */
914 if (riscv_subset_supports (&riscv_rps_dis
, "zfinx"))
915 riscv_fpr_names
= riscv_gpr_names
;
917 riscv_fpr_names
= riscv_gpr_names
== riscv_gpr_names_abi
?
918 riscv_fpr_names_abi
: riscv_fpr_names_numeric
;
920 for (; op
->name
; op
++)
922 /* Ignore macro insns. */
923 if (op
->pinfo
== INSN_MACRO
)
925 /* Does the opcode match? */
926 if (! (op
->match_func
) (op
, word
))
928 /* Is this a pseudo-instruction and may we print it as such? */
929 if (no_aliases
&& (op
->pinfo
& INSN_ALIAS
))
931 /* Is this instruction restricted to a certain value of XLEN? */
932 if ((op
->xlen_requirement
!= 0) && (op
->xlen_requirement
!= xlen
))
934 /* Is this instruction supported by the current architecture? */
935 if (!riscv_multi_subset_supports (&riscv_rps_dis
, op
->insn_class
))
939 (*info
->fprintf_styled_func
) (info
->stream
, dis_style_mnemonic
,
941 print_insn_args (op
->args
, word
, memaddr
, info
);
943 /* Try to disassemble multi-instruction addressing sequences. */
944 if (pd
->to_print_addr
)
946 info
->target
= pd
->print_addr
;
947 (*info
->fprintf_styled_func
)
948 (info
->stream
, dis_style_comment_start
, " # ");
949 (*info
->print_address_func
) (info
->target
, info
);
950 pd
->to_print_addr
= false;
953 /* Finish filling out insn_info fields. */
954 switch (op
->pinfo
& INSN_TYPE
)
957 info
->insn_type
= dis_branch
;
959 case INSN_CONDBRANCH
:
960 info
->insn_type
= dis_condbranch
;
963 info
->insn_type
= dis_jsr
;
966 info
->insn_type
= dis_dref
;
972 if (op
->pinfo
& INSN_DATA_SIZE
)
974 int size
= ((op
->pinfo
& INSN_DATA_SIZE
)
975 >> INSN_DATA_SIZE_SHIFT
);
976 info
->data_size
= 1 << (size
- 1);
983 /* We did not find a match, so just print the instruction bits in
984 the shape of an assembler .insn directive. */
985 info
->insn_type
= dis_noninsn
;
986 (*info
->fprintf_styled_func
)
987 (info
->stream
, dis_style_assembler_directive
, ".insn");
988 (*info
->fprintf_styled_func
) (info
->stream
, dis_style_text
, "\t");
989 (*info
->fprintf_styled_func
) (info
->stream
, dis_style_immediate
,
991 (*info
->fprintf_styled_func
) (info
->stream
, dis_style_text
, ", ");
992 (*info
->fprintf_styled_func
) (info
->stream
, dis_style_immediate
, "0x");
993 for (i
= insnlen
, printed
= false; i
>= 2; )
996 word
= bfd_get_bits (packet
+ i
, 16, false);
997 if (!word
&& !printed
)
1000 (*info
->fprintf_styled_func
) (info
->stream
, dis_style_immediate
,
1001 "%04x", (unsigned int) word
);
1008 /* If we find the suitable mapping symbol update the STATE.
1009 Otherwise, do nothing. */
1012 riscv_update_map_state (int n
,
1013 enum riscv_seg_mstate
*state
,
1014 struct disassemble_info
*info
)
1018 /* If the symbol is in a different section, ignore it. */
1019 if (info
->section
!= NULL
1020 && info
->section
!= info
->symtab
[n
]->section
)
1023 name
= bfd_asymbol_name(info
->symtab
[n
]);
1024 if (strcmp (name
, "$x") == 0)
1026 else if (strcmp (name
, "$d") == 0)
1028 else if (strncmp (name
, "$xrv", 4) == 0)
1031 riscv_release_subset_list (&riscv_subsets
);
1033 /* ISA mapping string may be numbered, suffixed with '.n'. Do not
1034 consider this as part of the ISA string. */
1035 char *suffix
= strchr (name
, '.');
1038 int suffix_index
= (int)(suffix
- name
);
1039 char *name_substr
= xmalloc (suffix_index
+ 1);
1040 strncpy (name_substr
, name
, suffix_index
);
1041 name_substr
[suffix_index
] = '\0';
1042 riscv_parse_subset (&riscv_rps_dis
, name_substr
+ 2);
1046 riscv_parse_subset (&riscv_rps_dis
, name
+ 2);
1050 /* Return true if we find the suitable mapping symbol.
1051 Otherwise, return false. */
1054 riscv_is_valid_mapping_symbol (int n
,
1055 struct disassemble_info
*info
)
1059 /* If the symbol is in a different section, ignore it. */
1060 if (info
->section
!= NULL
1061 && info
->section
!= info
->symtab
[n
]->section
)
1064 name
= bfd_asymbol_name(info
->symtab
[n
]);
1065 return riscv_elf_is_mapping_symbols (name
);
1068 /* Check the sorted symbol table (sorted by the symbol value), find the
1069 suitable mapping symbols. */
1071 static enum riscv_seg_mstate
1072 riscv_search_mapping_symbol (bfd_vma memaddr
,
1073 struct disassemble_info
*info
)
1075 enum riscv_seg_mstate mstate
;
1076 bool from_last_map_symbol
;
1081 /* Return the last map state if the address is still within the range of the
1082 last mapping symbol. */
1083 if (last_map_section
== info
->section
1084 && (memaddr
< last_map_symbol_boundary
))
1085 return last_map_state
;
1087 last_map_section
= info
->section
;
1089 /* Decide whether to print the data or instruction by default, in case
1090 we can not find the corresponding mapping symbols. */
1093 && info
->section
->flags
& SEC_CODE
)
1097 if (info
->symtab_size
== 0
1098 || bfd_asymbol_flavour (*info
->symtab
) != bfd_target_elf_flavour
)
1101 /* Reset the last_map_symbol if we start to dump a new section. */
1103 last_map_symbol
= -1;
1105 /* If the last stop offset is different from the current one, then
1106 don't use the last_map_symbol to search. We usually reset the
1107 info->stop_offset when handling a new section. */
1108 from_last_map_symbol
= (last_map_symbol
>= 0
1109 && info
->stop_offset
== last_stop_offset
);
1111 /* Start scanning from wherever we finished last time, or the start
1113 n
= from_last_map_symbol
? last_map_symbol
: info
->symtab_pos
+ 1;
1115 /* Find the suitable mapping symbol to dump. */
1116 for (; n
< info
->symtab_size
; n
++)
1118 bfd_vma addr
= bfd_asymbol_value (info
->symtab
[n
]);
1119 /* We have searched all possible symbols in the range. */
1122 if (riscv_is_valid_mapping_symbol (n
, info
))
1126 /* Do not stop searching, in case there are some mapping
1127 symbols have the same value, but have different names.
1128 Use the last one. */
1132 /* We can not find the suitable mapping symbol above. Therefore, we
1133 look forwards and try to find it again, but don't go past the start
1134 of the section. Otherwise a data section without mapping symbols
1135 can pick up a text mapping symbol of a preceeding section. */
1138 n
= from_last_map_symbol
? last_map_symbol
: info
->symtab_pos
;
1142 bfd_vma addr
= bfd_asymbol_value (info
->symtab
[n
]);
1143 /* We have searched all possible symbols in the range. */
1144 if (addr
< (info
->section
? info
->section
->vma
: 0))
1146 /* Stop searching once we find the closed mapping symbol. */
1147 if (riscv_is_valid_mapping_symbol (n
, info
))
1158 riscv_update_map_state (symbol
, &mstate
, info
);
1160 /* Find the next mapping symbol to determine the boundary of this mapping
1163 bool found_next
= false;
1164 /* Try to found next mapping symbol. */
1165 for (n
= symbol
+ 1; n
< info
->symtab_size
; n
++)
1167 if (info
->symtab
[symbol
]->section
!= info
->symtab
[n
]->section
)
1170 bfd_vma addr
= bfd_asymbol_value (info
->symtab
[n
]);
1171 const char *sym_name
= bfd_asymbol_name(info
->symtab
[n
]);
1172 if (sym_name
[0] == '$' && (sym_name
[1] == 'x' || sym_name
[1] == 'd'))
1174 /* The next mapping symbol has been found, and it represents the
1175 boundary of this mapping symbol. */
1177 last_map_symbol_boundary
= addr
;
1182 /* No further mapping symbol has been found, indicating that the boundary
1183 of the current mapping symbol is the end of this section. */
1185 last_map_symbol_boundary
= info
->section
->vma
+ info
->section
->size
;
1188 /* Save the information for next use. */
1189 last_map_symbol
= symbol
;
1190 last_stop_offset
= info
->stop_offset
;
1195 /* Decide which data size we should print. */
1198 riscv_data_length (bfd_vma memaddr
,
1199 disassemble_info
*info
)
1205 if (info
->symtab_size
!= 0
1206 && bfd_asymbol_flavour (*info
->symtab
) == bfd_target_elf_flavour
1207 && last_map_symbol
>= 0)
1210 enum riscv_seg_mstate m
= MAP_NONE
;
1211 for (n
= last_map_symbol
+ 1; n
< info
->symtab_size
; n
++)
1213 bfd_vma addr
= bfd_asymbol_value (info
->symtab
[n
]);
1215 && riscv_is_valid_mapping_symbol (n
, info
))
1217 if (addr
- memaddr
< length
)
1218 length
= addr
- memaddr
;
1220 riscv_update_map_state (n
, &m
, info
);
1227 /* Do not set the length which exceeds the section size. */
1228 bfd_vma offset
= info
->section
->vma
+ info
->section
->size
;
1230 length
= (offset
< length
) ? offset
: length
;
1232 length
= length
== 3 ? 2 : length
;
1236 /* Dump the data contents. */
1239 riscv_disassemble_data (bfd_vma memaddr ATTRIBUTE_UNUSED
,
1241 const bfd_byte
*packet ATTRIBUTE_UNUSED
,
1242 disassemble_info
*info
)
1244 info
->display_endian
= info
->endian
;
1246 switch (info
->bytes_per_chunk
)
1249 info
->bytes_per_line
= 6;
1250 (*info
->fprintf_styled_func
)
1251 (info
->stream
, dis_style_assembler_directive
, ".byte");
1252 (*info
->fprintf_styled_func
) (info
->stream
, dis_style_text
, "\t");
1253 (*info
->fprintf_styled_func
) (info
->stream
, dis_style_immediate
,
1254 "0x%02x", (unsigned)data
);
1257 info
->bytes_per_line
= 8;
1258 (*info
->fprintf_styled_func
)
1259 (info
->stream
, dis_style_assembler_directive
, ".short");
1260 (*info
->fprintf_styled_func
) (info
->stream
, dis_style_text
, "\t");
1261 (*info
->fprintf_styled_func
)
1262 (info
->stream
, dis_style_immediate
, "0x%04x", (unsigned) data
);
1265 info
->bytes_per_line
= 8;
1266 (*info
->fprintf_styled_func
)
1267 (info
->stream
, dis_style_assembler_directive
, ".word");
1268 (*info
->fprintf_styled_func
) (info
->stream
, dis_style_text
, "\t");
1269 (*info
->fprintf_styled_func
)
1270 (info
->stream
, dis_style_immediate
, "0x%08lx",
1271 (unsigned long) data
);
1274 info
->bytes_per_line
= 8;
1275 (*info
->fprintf_styled_func
)
1276 (info
->stream
, dis_style_assembler_directive
, ".dword");
1277 (*info
->fprintf_styled_func
) (info
->stream
, dis_style_text
, "\t");
1278 (*info
->fprintf_styled_func
)
1279 (info
->stream
, dis_style_immediate
, "0x%016llx",
1280 (unsigned long long) data
);
1285 return info
->bytes_per_chunk
;
1289 riscv_init_disasm_info (struct disassemble_info
*info
)
1293 struct riscv_private_data
*pd
=
1294 xcalloc (1, sizeof (struct riscv_private_data
));
1297 for (i
= 0; i
< (int) ARRAY_SIZE (pd
->hi_addr
); i
++)
1298 pd
->hi_addr
[i
] = -1;
1299 pd
->to_print_addr
= false;
1302 for (i
= 0; i
< info
->symtab_size
; i
++)
1304 asymbol
*sym
= info
->symtab
[i
];
1305 if (strcmp (bfd_asymbol_name (sym
), RISCV_GP_SYMBOL
) == 0)
1307 pd
->gp
= bfd_asymbol_value (sym
);
1312 info
->private_data
= pd
;
1317 print_insn_riscv (bfd_vma memaddr
, struct disassemble_info
*info
)
1319 bfd_byte packet
[RISCV_MAX_INSN_LEN
];
1323 enum riscv_seg_mstate mstate
;
1324 int (*riscv_disassembler
) (bfd_vma
, insn_t
, const bfd_byte
*,
1325 struct disassemble_info
*);
1327 if (info
->disassembler_options
!= NULL
)
1329 parse_riscv_dis_options (info
->disassembler_options
);
1330 /* Avoid repeatedly parsing the options. */
1331 info
->disassembler_options
= NULL
;
1333 else if (riscv_gpr_names
== NULL
)
1334 set_default_riscv_dis_options ();
1336 if (info
->private_data
== NULL
&& !riscv_init_disasm_info (info
))
1339 mstate
= riscv_search_mapping_symbol (memaddr
, info
);
1340 /* Save the last mapping state. */
1341 last_map_state
= mstate
;
1343 /* Set the size to dump. */
1344 if (mstate
== MAP_DATA
1345 && (info
->flags
& DISASSEMBLE_DATA
) == 0)
1347 dump_size
= riscv_data_length (memaddr
, info
);
1348 info
->bytes_per_chunk
= dump_size
;
1349 riscv_disassembler
= riscv_disassemble_data
;
1353 /* Get the first 2-bytes to check the lenghth of instruction. */
1354 status
= (*info
->read_memory_func
) (memaddr
, packet
, 2, info
);
1357 (*info
->memory_error_func
) (status
, memaddr
, info
);
1360 insn
= (insn_t
) bfd_getl16 (packet
);
1361 dump_size
= riscv_insn_length (insn
);
1362 riscv_disassembler
= riscv_disassemble_insn
;
1365 /* Fetch the instruction to dump. */
1366 status
= (*info
->read_memory_func
) (memaddr
, packet
, dump_size
, info
);
1369 (*info
->memory_error_func
) (status
, memaddr
, info
);
1372 insn
= (insn_t
) bfd_get_bits (packet
, dump_size
* 8, false);
1374 return (*riscv_disassembler
) (memaddr
, insn
, packet
, info
);
1378 riscv_get_disassembler (bfd
*abfd
)
1380 const char *default_arch
= "rv64gc";
1382 if (abfd
&& bfd_get_flavour (abfd
) == bfd_target_elf_flavour
)
1384 const char *sec_name
= get_elf_backend_data (abfd
)->obj_attrs_section
;
1385 if (bfd_get_section_by_name (abfd
, sec_name
) != NULL
)
1387 obj_attribute
*attr
= elf_known_obj_attributes_proc (abfd
);
1388 unsigned int Tag_a
= Tag_RISCV_priv_spec
;
1389 unsigned int Tag_b
= Tag_RISCV_priv_spec_minor
;
1390 unsigned int Tag_c
= Tag_RISCV_priv_spec_revision
;
1391 riscv_get_priv_spec_class_from_numbers (attr
[Tag_a
].i
,
1394 &default_priv_spec
);
1395 default_arch
= attr
[Tag_RISCV_arch
].s
;
1399 riscv_release_subset_list (&riscv_subsets
);
1400 riscv_parse_subset (&riscv_rps_dis
, default_arch
);
1401 return print_insn_riscv
;
1404 /* Prevent use of the fake labels that are generated as part of the DWARF
1405 and for relaxable relocations in the assembler. */
1408 riscv_symbol_is_valid (asymbol
* sym
,
1409 struct disassemble_info
* info ATTRIBUTE_UNUSED
)
1416 name
= bfd_asymbol_name (sym
);
1418 return (strcmp (name
, RISCV_FAKE_LABEL_NAME
) != 0
1419 && !riscv_elf_is_mapping_symbols (name
));
1423 /* Indices into option argument vector for options accepting an argument.
1424 Use RISCV_OPTION_ARG_NONE for options accepting no argument. */
1428 RISCV_OPTION_ARG_NONE
= -1,
1429 RISCV_OPTION_ARG_PRIV_SPEC
,
1431 RISCV_OPTION_ARG_COUNT
1432 } riscv_option_arg_t
;
1434 /* Valid RISCV disassembler options. */
1439 const char *description
;
1440 riscv_option_arg_t arg
;
1444 N_("Print numeric register names, rather than ABI names."),
1445 RISCV_OPTION_ARG_NONE
},
1447 N_("Disassemble only into canonical instructions."),
1448 RISCV_OPTION_ARG_NONE
},
1450 N_("Print the CSR according to the chosen privilege spec."),
1451 RISCV_OPTION_ARG_PRIV_SPEC
}
1454 /* Build the structure representing valid RISCV disassembler options.
1455 This is done dynamically for maintenance ease purpose; a static
1456 initializer would be unreadable. */
1458 const disasm_options_and_args_t
*
1459 disassembler_options_riscv (void)
1461 static disasm_options_and_args_t
*opts_and_args
;
1463 if (opts_and_args
== NULL
)
1465 size_t num_options
= ARRAY_SIZE (riscv_options
);
1466 size_t num_args
= RISCV_OPTION_ARG_COUNT
;
1467 disasm_option_arg_t
*args
;
1468 disasm_options_t
*opts
;
1469 size_t i
, priv_spec_count
;
1471 args
= XNEWVEC (disasm_option_arg_t
, num_args
+ 1);
1473 args
[RISCV_OPTION_ARG_PRIV_SPEC
].name
= "SPEC";
1474 priv_spec_count
= PRIV_SPEC_CLASS_DRAFT
- PRIV_SPEC_CLASS_NONE
- 1;
1475 args
[RISCV_OPTION_ARG_PRIV_SPEC
].values
1476 = XNEWVEC (const char *, priv_spec_count
+ 1);
1477 for (i
= 0; i
< priv_spec_count
; i
++)
1478 args
[RISCV_OPTION_ARG_PRIV_SPEC
].values
[i
]
1479 = riscv_priv_specs
[i
].name
;
1480 /* The array we return must be NULL terminated. */
1481 args
[RISCV_OPTION_ARG_PRIV_SPEC
].values
[i
] = NULL
;
1483 /* The array we return must be NULL terminated. */
1484 args
[num_args
].name
= NULL
;
1485 args
[num_args
].values
= NULL
;
1487 opts_and_args
= XNEW (disasm_options_and_args_t
);
1488 opts_and_args
->args
= args
;
1490 opts
= &opts_and_args
->options
;
1491 opts
->name
= XNEWVEC (const char *, num_options
+ 1);
1492 opts
->description
= XNEWVEC (const char *, num_options
+ 1);
1493 opts
->arg
= XNEWVEC (const disasm_option_arg_t
*, num_options
+ 1);
1494 for (i
= 0; i
< num_options
; i
++)
1496 opts
->name
[i
] = riscv_options
[i
].name
;
1497 opts
->description
[i
] = _(riscv_options
[i
].description
);
1498 if (riscv_options
[i
].arg
!= RISCV_OPTION_ARG_NONE
)
1499 opts
->arg
[i
] = &args
[riscv_options
[i
].arg
];
1501 opts
->arg
[i
] = NULL
;
1503 /* The array we return must be NULL terminated. */
1504 opts
->name
[i
] = NULL
;
1505 opts
->description
[i
] = NULL
;
1506 opts
->arg
[i
] = NULL
;
1509 return opts_and_args
;
1513 print_riscv_disassembler_options (FILE *stream
)
1515 const disasm_options_and_args_t
*opts_and_args
;
1516 const disasm_option_arg_t
*args
;
1517 const disasm_options_t
*opts
;
1522 opts_and_args
= disassembler_options_riscv ();
1523 opts
= &opts_and_args
->options
;
1524 args
= opts_and_args
->args
;
1526 fprintf (stream
, _("\n\
1527 The following RISC-V specific disassembler options are supported for use\n\
1528 with the -M switch (multiple options should be separated by commas):\n"));
1529 fprintf (stream
, "\n");
1531 /* Compute the length of the longest option name. */
1532 for (i
= 0; opts
->name
[i
] != NULL
; i
++)
1534 size_t len
= strlen (opts
->name
[i
]);
1536 if (opts
->arg
[i
] != NULL
)
1537 len
+= strlen (opts
->arg
[i
]->name
);
1542 for (i
= 0, max_len
++; opts
->name
[i
] != NULL
; i
++)
1544 fprintf (stream
, " %s", opts
->name
[i
]);
1545 if (opts
->arg
[i
] != NULL
)
1546 fprintf (stream
, "%s", opts
->arg
[i
]->name
);
1547 if (opts
->description
[i
] != NULL
)
1549 size_t len
= strlen (opts
->name
[i
]);
1551 if (opts
->arg
!= NULL
&& opts
->arg
[i
] != NULL
)
1552 len
+= strlen (opts
->arg
[i
]->name
);
1553 fprintf (stream
, "%*c %s", (int) (max_len
- len
), ' ',
1554 opts
->description
[i
]);
1556 fprintf (stream
, "\n");
1559 for (i
= 0; args
[i
].name
!= NULL
; i
++)
1561 if (args
[i
].values
== NULL
)
1563 fprintf (stream
, _("\n\
1564 For the options above, the following values are supported for \"%s\":\n "),
1566 for (j
= 0; args
[i
].values
[j
] != NULL
; j
++)
1567 fprintf (stream
, " %s", args
[i
].values
[j
]);
1568 fprintf (stream
, _("\n"));
1571 fprintf (stream
, _("\n"));
1574 void disassemble_free_riscv (struct disassemble_info
*info ATTRIBUTE_UNUSED
)
1576 riscv_release_subset_list (&riscv_subsets
);