1 /* tc-riscv.c -- RISC-V assembler
2 Copyright (C) 2011-2023 Free Software Foundation, Inc.
4 Contributed by Andrew Waterman (andrew@sifive.com).
7 This file is part of GAS.
9 GAS 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 GAS is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public 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/>. */
26 #include "safe-ctype.h"
29 #include "dwarf2dbg.h"
30 #include "dw2gencfi.h"
32 #include "bfd/elfxx-riscv.h"
33 #include "elf/riscv.h"
34 #include "opcode/riscv.h"
38 /* Information about an instruction, including its format, operands
42 /* The opcode's entry in riscv_opcodes. */
43 const struct riscv_opcode
*insn_mo
;
45 /* The encoded instruction bits
46 (first bits enough to extract instruction length on a long opcode). */
49 /* The long encoded instruction bits ([0] is non-zero on a long opcode). */
50 char insn_long_opcode
[RISCV_MAX_INSN_LEN
];
52 /* The frag that contains the instruction. */
55 /* The offset into FRAG of the first instruction byte. */
58 /* The relocs associated with the instruction, if any. */
62 /* All RISC-V CSR belong to one of these classes. */
68 CSR_CLASS_I_32
, /* rv32 only */
69 CSR_CLASS_F
, /* f-ext only */
70 CSR_CLASS_ZKR
, /* zkr only */
71 CSR_CLASS_V
, /* rvv only */
72 CSR_CLASS_DEBUG
, /* debug CSR */
73 CSR_CLASS_H
, /* hypervisor */
74 CSR_CLASS_H_32
, /* hypervisor, rv32 only */
75 CSR_CLASS_SMAIA
, /* Smaia */
76 CSR_CLASS_SMAIA_32
, /* Smaia, rv32 only */
77 CSR_CLASS_SMSTATEEN
, /* Smstateen only */
78 CSR_CLASS_SMSTATEEN_32
, /* Smstateen RV32 only */
79 CSR_CLASS_SSAIA
, /* Ssaia */
80 CSR_CLASS_SSAIA_AND_H
, /* Ssaia with H */
81 CSR_CLASS_SSAIA_32
, /* Ssaia, rv32 only */
82 CSR_CLASS_SSAIA_AND_H_32
, /* Ssaia with H, rv32 only */
83 CSR_CLASS_SSSTATEEN
, /* S[ms]stateen only */
84 CSR_CLASS_SSSTATEEN_AND_H
, /* S[ms]stateen only (with H) */
85 CSR_CLASS_SSSTATEEN_AND_H_32
, /* S[ms]stateen RV32 only (with H) */
86 CSR_CLASS_SSCOFPMF
, /* Sscofpmf only */
87 CSR_CLASS_SSCOFPMF_32
, /* Sscofpmf RV32 only */
88 CSR_CLASS_SSTC
, /* Sstc only */
89 CSR_CLASS_SSTC_AND_H
, /* Sstc only (with H) */
90 CSR_CLASS_SSTC_32
, /* Sstc RV32 only */
91 CSR_CLASS_SSTC_AND_H_32
, /* Sstc RV32 only (with H) */
94 /* This structure holds all restricted conditions for a CSR. */
95 struct riscv_csr_extra
97 /* Class to which this CSR belongs. Used to decide whether or
98 not this CSR is legal in the current -march context. */
99 enum riscv_csr_class csr_class
;
101 /* CSR may have differnet numbers in the previous priv spec. */
104 /* Record the CSR is defined/valid in which versions. */
105 enum riscv_spec_class define_version
;
107 /* Record the CSR is aborted/invalid from which versions. If it isn't
108 aborted in the current version, then it should be PRIV_SPEC_CLASS_DRAFT. */
109 enum riscv_spec_class abort_version
;
111 /* The CSR may have more than one setting. */
112 struct riscv_csr_extra
*next
;
115 /* This structure contains information about errors that occur within the
117 struct riscv_ip_error
119 /* General error message */
122 /* Statement that caused the error */
125 /* Missing extension that needs to be enabled */
126 const char* missing_ext
;
130 #define DEFAULT_ARCH "riscv64"
133 #ifndef DEFAULT_RISCV_ATTR
134 #define DEFAULT_RISCV_ATTR 0
137 /* Let riscv_after_parse_args set the default value according to xlen. */
138 #ifndef DEFAULT_RISCV_ARCH_WITH_EXT
139 #define DEFAULT_RISCV_ARCH_WITH_EXT NULL
142 /* Need to sync the version with RISC-V compiler. */
143 #ifndef DEFAULT_RISCV_ISA_SPEC
144 #define DEFAULT_RISCV_ISA_SPEC "20191213"
147 #ifndef DEFAULT_RISCV_PRIV_SPEC
148 #define DEFAULT_RISCV_PRIV_SPEC "1.11"
151 static const char default_arch
[] = DEFAULT_ARCH
;
152 static const char *default_arch_with_ext
= DEFAULT_RISCV_ARCH_WITH_EXT
;
153 static enum riscv_spec_class default_isa_spec
= ISA_SPEC_CLASS_NONE
;
154 static enum riscv_spec_class default_priv_spec
= PRIV_SPEC_CLASS_NONE
;
156 static unsigned xlen
= 0; /* The width of an x-register. */
157 static unsigned abi_xlen
= 0; /* The width of a pointer in the ABI. */
158 static bool rve_abi
= false;
161 FLOAT_ABI_DEFAULT
= -1,
167 static enum float_abi float_abi
= FLOAT_ABI_DEFAULT
;
169 #define LOAD_ADDRESS_INSN (abi_xlen == 64 ? "ld" : "lw")
170 #define ADD32_INSN (xlen == 64 ? "addiw" : "addi")
172 static unsigned elf_flags
= 0;
174 static bool probing_insn_operands
;
176 /* Set the default_isa_spec. Return 0 if the spec isn't supported.
177 Otherwise, return 1. */
180 riscv_set_default_isa_spec (const char *s
)
182 enum riscv_spec_class
class = ISA_SPEC_CLASS_NONE
;
183 RISCV_GET_ISA_SPEC_CLASS (s
, class);
184 if (class == ISA_SPEC_CLASS_NONE
)
186 as_bad ("unknown default ISA spec `%s' set by "
187 "-misa-spec or --with-isa-spec", s
);
191 default_isa_spec
= class;
195 /* Set the default_priv_spec. Find the privileged elf attributes when
196 the input string is NULL. Return 0 if the spec isn't supported.
197 Otherwise, return 1. */
200 riscv_set_default_priv_spec (const char *s
)
202 enum riscv_spec_class
class = PRIV_SPEC_CLASS_NONE
;
203 unsigned major
, minor
, revision
;
206 RISCV_GET_PRIV_SPEC_CLASS (s
, class);
207 if (class != PRIV_SPEC_CLASS_NONE
)
209 default_priv_spec
= class;
215 as_bad (_("unknown default privileged spec `%s' set by "
216 "-mpriv-spec or --with-priv-spec"), s
);
220 /* Set the default_priv_spec by the privileged elf attributes. */
221 attr
= elf_known_obj_attributes_proc (stdoutput
);
222 major
= (unsigned) attr
[Tag_RISCV_priv_spec
].i
;
223 minor
= (unsigned) attr
[Tag_RISCV_priv_spec_minor
].i
;
224 revision
= (unsigned) attr
[Tag_RISCV_priv_spec_revision
].i
;
225 /* Version 0.0.0 is the default value and meningless. */
226 if (major
== 0 && minor
== 0 && revision
== 0)
229 riscv_get_priv_spec_class_from_numbers (major
, minor
, revision
, &class);
230 if (class != PRIV_SPEC_CLASS_NONE
)
232 default_priv_spec
= class;
236 /* Still can not find the privileged spec class. */
237 as_bad (_("unknown default privileged spec `%d.%d.%d' set by "
238 "privileged elf attributes"), major
, minor
, revision
);
242 /* This is the set of options which the .option pseudo-op may modify. */
243 struct riscv_set_options
245 int pic
; /* Generate position-independent code. */
246 int rvc
; /* Generate RVC code. */
247 int relax
; /* Emit relocs the linker is allowed to relax. */
248 int arch_attr
; /* Emit architecture and privileged elf attributes. */
249 int csr_check
; /* Enable the CSR checking. */
252 static struct riscv_set_options riscv_opts
=
257 DEFAULT_RISCV_ATTR
, /* arch_attr */
261 /* Enable or disable the rvc flags for riscv_opts. Turn on the rvc flag
262 for elf_flags once we have enabled c extension. */
265 riscv_set_rvc (bool rvc_value
)
268 elf_flags
|= EF_RISCV_RVC
;
270 riscv_opts
.rvc
= rvc_value
;
273 /* Turn on the tso flag for elf_flags once we have enabled ztso extension. */
278 elf_flags
|= EF_RISCV_TSO
;
281 /* The linked list hanging off of .subsets_list records all enabled extensions,
282 which are parsed from the architecture string. The architecture string can
283 be set by the -march option, the elf architecture attributes, and the
284 --with-arch configure option. */
285 static riscv_parse_subset_t riscv_rps_as
=
287 NULL
, /* subset_list, we will set it later once
288 riscv_opts_stack is created or updated. */
289 as_bad
, /* error_handler. */
291 &default_isa_spec
, /* isa_spec. */
292 true, /* check_unknown_prefixed_ext. */
295 /* Update the architecture string in the subset_list. */
298 riscv_reset_subsets_list_arch_str (void)
300 riscv_subset_list_t
*subsets
= riscv_rps_as
.subset_list
;
301 if (subsets
->arch_str
!= NULL
)
302 free ((void *) subsets
->arch_str
);
303 subsets
->arch_str
= riscv_arch_str (xlen
, subsets
);
306 /* This structure is used to hold a stack of .option values. */
307 struct riscv_option_stack
309 struct riscv_option_stack
*next
;
310 struct riscv_set_options options
;
311 riscv_subset_list_t
*subset_list
;
314 static struct riscv_option_stack
*riscv_opts_stack
= NULL
;
316 /* Set which ISA and extensions are available. */
319 riscv_set_arch (const char *s
)
321 if (s
!= NULL
&& strcmp (s
, "") == 0)
323 as_bad (_("the architecture string of -march and elf architecture "
324 "attributes cannot be empty"));
328 if (riscv_rps_as
.subset_list
== NULL
)
330 riscv_rps_as
.subset_list
= XNEW (riscv_subset_list_t
);
331 riscv_rps_as
.subset_list
->head
= NULL
;
332 riscv_rps_as
.subset_list
->tail
= NULL
;
333 riscv_rps_as
.subset_list
->arch_str
= NULL
;
335 riscv_release_subset_list (riscv_rps_as
.subset_list
);
336 riscv_parse_subset (&riscv_rps_as
, s
);
337 riscv_reset_subsets_list_arch_str ();
339 riscv_set_rvc (false);
340 if (riscv_subset_supports (&riscv_rps_as
, "c"))
341 riscv_set_rvc (true);
343 if (riscv_subset_supports (&riscv_rps_as
, "ztso"))
347 /* Indicate -mabi option is explictly set. */
348 static bool explicit_mabi
= false;
350 /* Set the abi information. */
353 riscv_set_abi (unsigned new_xlen
, enum float_abi new_float_abi
, bool rve
)
356 float_abi
= new_float_abi
;
360 /* If the -mabi option isn't set, then set the abi according to the
361 ISA string. Otherwise, check if there is any conflict. */
364 riscv_set_abi_by_arch (void)
368 if (riscv_subset_supports (&riscv_rps_as
, "q"))
369 riscv_set_abi (xlen
, FLOAT_ABI_QUAD
, false);
370 else if (riscv_subset_supports (&riscv_rps_as
, "d"))
371 riscv_set_abi (xlen
, FLOAT_ABI_DOUBLE
, false);
372 else if (riscv_subset_supports (&riscv_rps_as
, "e"))
373 riscv_set_abi (xlen
, FLOAT_ABI_SOFT
, true);
375 riscv_set_abi (xlen
, FLOAT_ABI_SOFT
, false);
379 gas_assert (abi_xlen
!= 0 && xlen
!= 0 && float_abi
!= FLOAT_ABI_DEFAULT
);
381 as_bad ("can't have %d-bit ABI on %d-bit ISA", abi_xlen
, xlen
);
382 else if (abi_xlen
< xlen
)
383 as_bad ("%d-bit ABI not yet supported on %d-bit ISA", abi_xlen
, xlen
);
385 if (riscv_subset_supports (&riscv_rps_as
, "e") && !rve_abi
)
386 as_bad ("only the ilp32e ABI is supported for e extension");
388 if (float_abi
== FLOAT_ABI_SINGLE
389 && !riscv_subset_supports (&riscv_rps_as
, "f"))
390 as_bad ("ilp32f/lp64f ABI can't be used when f extension "
392 else if (float_abi
== FLOAT_ABI_DOUBLE
393 && !riscv_subset_supports (&riscv_rps_as
, "d"))
394 as_bad ("ilp32d/lp64d ABI can't be used when d extension "
396 else if (float_abi
== FLOAT_ABI_QUAD
397 && !riscv_subset_supports (&riscv_rps_as
, "q"))
398 as_bad ("ilp32q/lp64q ABI can't be used when q extension "
402 /* Update the EF_RISCV_FLOAT_ABI field of elf_flags. */
403 elf_flags
&= ~EF_RISCV_FLOAT_ABI
;
404 elf_flags
|= float_abi
<< 1;
407 elf_flags
|= EF_RISCV_RVE
;
410 /* Handle of the OPCODE hash table. */
411 static htab_t op_hash
= NULL
;
413 /* Handle of the type of .insn hash table. */
414 static htab_t insn_type_hash
= NULL
;
416 /* This array holds the chars that always start a comment. If the
417 pre-processor is disabled, these aren't very useful. */
418 const char comment_chars
[] = "#";
420 /* This array holds the chars that only start a comment at the beginning of
421 a line. If the line seems to have the form '# 123 filename'
422 .line and .file directives will appear in the pre-processed output
424 Note that input_file.c hand checks for '#' at the beginning of the
425 first line of the input file. This is because the compiler outputs
426 #NO_APP at the beginning of its output.
428 Also note that C style comments are always supported. */
429 const char line_comment_chars
[] = "#";
431 /* This array holds machine specific line separator characters. */
432 const char line_separator_chars
[] = ";";
434 /* Chars that can be used to separate mant from exp in floating point nums. */
435 const char EXP_CHARS
[] = "eE";
437 /* Chars that mean this number is a floating point constant.
438 As in 0f12.456 or 0d1.2345e12. */
439 const char FLT_CHARS
[] = "rRsSfFdDxXpPhH";
441 /* Indicate we are already assemble any instructions or not. */
442 static bool start_assemble
= false;
444 /* Indicate ELF attributes are explicitly set. */
445 static bool explicit_attr
= false;
447 /* Indicate CSR or priv instructions are explicitly used. */
448 static bool explicit_priv_attr
= false;
450 static char *expr_parse_end
;
452 /* Macros for encoding relaxation state for RVC branches and far jumps. */
453 #define RELAX_BRANCH_ENCODE(uncond, rvc, length) \
456 | ((uncond) ? 1 : 0) \
459 #define RELAX_BRANCH_P(i) (((i) & 0xf0000000) == 0xc0000000)
460 #define RELAX_BRANCH_LENGTH(i) (((i) >> 2) & 0xF)
461 #define RELAX_BRANCH_RVC(i) (((i) & 2) != 0)
462 #define RELAX_BRANCH_UNCOND(i) (((i) & 1) != 0)
464 /* Is the given value a sign-extended 32-bit value? */
465 #define IS_SEXT_32BIT_NUM(x) \
466 (((x) &~ (offsetT) 0x7fffffff) == 0 \
467 || (((x) &~ (offsetT) 0x7fffffff) == ~ (offsetT) 0x7fffffff))
469 /* Is the given value a zero-extended 32-bit value? Or a negated one? */
470 #define IS_ZEXT_32BIT_NUM(x) \
471 (((x) &~ (offsetT) 0xffffffff) == 0 \
472 || (((x) &~ (offsetT) 0xffffffff) == ~ (offsetT) 0xffffffff))
474 /* Change INSN's opcode so that the operand given by FIELD has value VALUE.
475 INSN is a riscv_cl_insn structure and VALUE is evaluated exactly once. */
476 #define INSERT_OPERAND(FIELD, INSN, VALUE) \
477 INSERT_BITS ((INSN).insn_opcode, VALUE, OP_MASK_##FIELD, OP_SH_##FIELD)
479 #define INSERT_IMM(n, s, INSN, VALUE) \
480 INSERT_BITS ((INSN).insn_opcode, VALUE, (1ULL<<n) - 1, s)
482 /* Determine if an instruction matches an opcode. */
483 #define OPCODE_MATCHES(OPCODE, OP) \
484 (((OPCODE) & MASK_##OP) == MATCH_##OP)
486 /* Create a new mapping symbol for the transition to STATE. */
489 make_mapping_symbol (enum riscv_seg_mstate state
,
492 const char *arch_str
,
493 bool odd_data_padding
)
503 if (arch_str
!= NULL
)
505 size_t size
= strlen (arch_str
) + 3; /* "$x" + '\0' */
506 buff
= xmalloc (size
);
507 snprintf (buff
, size
, "$x%s", arch_str
);
517 symbolS
*symbol
= symbol_new (name
, now_seg
, frag
, value
);
518 symbol_get_bfdsym (symbol
)->flags
|= (BSF_NO_FLAGS
| BSF_LOCAL
);
519 if (arch_str
!= NULL
)
521 /* Store current $x+arch into tc_segment_info. */
522 seg_info (now_seg
)->tc_segment_info_data
.arch_map_symbol
= symbol
;
523 xfree ((void *) buff
);
526 /* If .fill or other data filling directive generates zero sized data,
527 then mapping symbol for the following code will have the same value.
529 Please see gas/testsuite/gas/riscv/mapping.s: .text.zero.fill.first
530 and .text.zero.fill.last. */
531 symbolS
*first
= frag
->tc_frag_data
.first_map_symbol
;
532 symbolS
*last
= frag
->tc_frag_data
.last_map_symbol
;
533 symbolS
*removed
= NULL
;
538 know (S_GET_VALUE (first
) == S_GET_VALUE (symbol
)
540 /* Remove the old one. */
543 frag
->tc_frag_data
.first_map_symbol
= symbol
;
545 else if (last
!= NULL
)
547 /* The mapping symbols should be added in offset order. */
548 know (S_GET_VALUE (last
) <= S_GET_VALUE (symbol
));
549 /* Remove the old one. */
550 if (S_GET_VALUE (last
) == S_GET_VALUE (symbol
))
553 frag
->tc_frag_data
.last_map_symbol
= symbol
;
558 if (odd_data_padding
)
560 /* If the removed mapping symbol is $x+arch, then add it back to
562 const char *str
= strncmp (S_GET_NAME (removed
), "$xrv", 4) == 0
563 ? S_GET_NAME (removed
) + 2 : NULL
;
564 make_mapping_symbol (MAP_INSN
, frag
->fr_fix
+ 1, frag
, str
,
565 false/* odd_data_padding */);
567 symbol_remove (removed
, &symbol_rootP
, &symbol_lastP
);
570 /* Set the mapping state for frag_now. */
573 riscv_mapping_state (enum riscv_seg_mstate to_state
,
577 enum riscv_seg_mstate from_state
=
578 seg_info (now_seg
)->tc_segment_info_data
.map_state
;
579 bool reset_seg_arch_str
= false;
581 if (!SEG_NORMAL (now_seg
)
582 /* For now we only add the mapping symbols to text sections.
583 Therefore, the dis-assembler only show the actual contents
584 distribution for text. Other sections will be shown as
585 data without the details. */
586 || !subseg_text_p (now_seg
))
589 /* The mapping symbol should be emitted if not in the right
591 symbolS
*seg_arch_symbol
=
592 seg_info (now_seg
)->tc_segment_info_data
.arch_map_symbol
;
593 if (to_state
== MAP_INSN
&& seg_arch_symbol
== 0)
595 /* Always add $x+arch at the first instruction of section. */
596 reset_seg_arch_str
= true;
598 else if (seg_arch_symbol
!= 0
599 && to_state
== MAP_INSN
601 && strcmp (riscv_rps_as
.subset_list
->arch_str
,
602 S_GET_NAME (seg_arch_symbol
) + 2) != 0)
604 reset_seg_arch_str
= true;
606 else if (from_state
== to_state
)
609 valueT value
= (valueT
) (frag_now_fix () - max_chars
);
610 seg_info (now_seg
)->tc_segment_info_data
.map_state
= to_state
;
611 const char *arch_str
= reset_seg_arch_str
612 ? riscv_rps_as
.subset_list
->arch_str
: NULL
;
613 make_mapping_symbol (to_state
, value
, frag_now
, arch_str
,
614 false/* odd_data_padding */);
617 /* Add the odd bytes of paddings for riscv_handle_align. */
620 riscv_add_odd_padding_symbol (fragS
*frag
)
622 /* If there was already a mapping symbol, it should be
623 removed in the make_mapping_symbol.
625 Please see gas/testsuite/gas/riscv/mapping.s: .text.odd.align.*. */
626 make_mapping_symbol (MAP_DATA
, frag
->fr_fix
, frag
,
627 NULL
/* arch_str */, true/* odd_data_padding */);
630 /* Remove any excess mapping symbols generated for alignment frags in
631 SEC. We may have created a mapping symbol before a zero byte
632 alignment; remove it if there's a mapping symbol after the
636 riscv_check_mapping_symbols (bfd
*abfd ATTRIBUTE_UNUSED
,
638 void *dummy ATTRIBUTE_UNUSED
)
640 segment_info_type
*seginfo
= seg_info (sec
);
643 if (seginfo
== NULL
|| seginfo
->frchainP
== NULL
)
646 for (fragp
= seginfo
->frchainP
->frch_root
;
648 fragp
= fragp
->fr_next
)
650 symbolS
*last
= fragp
->tc_frag_data
.last_map_symbol
;
651 fragS
*next
= fragp
->fr_next
;
653 if (last
== NULL
|| next
== NULL
)
656 /* Check the last mapping symbol if it is at the boundary of
658 if (S_GET_VALUE (last
) < next
->fr_address
)
660 know (S_GET_VALUE (last
) == next
->fr_address
);
664 symbolS
*next_first
= next
->tc_frag_data
.first_map_symbol
;
665 if (next_first
!= NULL
)
667 /* The last mapping symbol overlaps with another one
668 which at the start of the next frag.
670 Please see the gas/testsuite/gas/riscv/mapping.s:
671 .text.zero.fill.align.A and .text.zero.fill.align.B. */
672 know (S_GET_VALUE (last
) == S_GET_VALUE (next_first
));
673 symbolS
*removed
= last
;
674 if (strncmp (S_GET_NAME (last
), "$xrv", 4) == 0
675 && strcmp (S_GET_NAME (next_first
), "$x") == 0)
676 removed
= next_first
;
677 symbol_remove (removed
, &symbol_rootP
, &symbol_lastP
);
681 if (next
->fr_next
== NULL
)
683 /* The last mapping symbol is at the end of the section.
685 Please see the gas/testsuite/gas/riscv/mapping.s:
686 .text.last.section. */
687 know (next
->fr_fix
== 0 && next
->fr_var
== 0);
688 symbol_remove (last
, &symbol_rootP
, &symbol_lastP
);
692 /* Since we may have empty frags without any mapping symbols,
693 keep looking until the non-empty frag. */
694 if (next
->fr_address
!= next
->fr_next
->fr_address
)
697 next
= next
->fr_next
;
699 while (next
!= NULL
);
703 /* The default target format to use. */
706 riscv_target_format (void)
708 if (target_big_endian
)
709 return xlen
== 64 ? "elf64-bigriscv" : "elf32-bigriscv";
711 return xlen
== 64 ? "elf64-littleriscv" : "elf32-littleriscv";
714 /* Return the length of instruction INSN. */
716 static inline unsigned int
717 insn_length (const struct riscv_cl_insn
*insn
)
719 return riscv_insn_length (insn
->insn_opcode
);
722 /* Initialise INSN from opcode entry MO. Leave its position unspecified. */
725 create_insn (struct riscv_cl_insn
*insn
, const struct riscv_opcode
*mo
)
728 insn
->insn_opcode
= mo
->match
;
729 insn
->insn_long_opcode
[0] = 0;
735 /* Install INSN at the location specified by its "frag" and "where" fields. */
738 install_insn (const struct riscv_cl_insn
*insn
)
740 char *f
= insn
->frag
->fr_literal
+ insn
->where
;
741 if (insn
->insn_long_opcode
[0] != 0)
742 memcpy (f
, insn
->insn_long_opcode
, insn_length (insn
));
744 number_to_chars_littleendian (f
, insn
->insn_opcode
, insn_length (insn
));
747 /* Move INSN to offset WHERE in FRAG. Adjust the fixups accordingly
748 and install the opcode in the new location. */
751 move_insn (struct riscv_cl_insn
*insn
, fragS
*frag
, long where
)
755 if (insn
->fixp
!= NULL
)
757 insn
->fixp
->fx_frag
= frag
;
758 insn
->fixp
->fx_where
= where
;
763 /* Add INSN to the end of the output. */
766 add_fixed_insn (struct riscv_cl_insn
*insn
)
768 char *f
= frag_more (insn_length (insn
));
769 move_insn (insn
, frag_now
, f
- frag_now
->fr_literal
);
773 add_relaxed_insn (struct riscv_cl_insn
*insn
, int max_chars
, int var
,
774 relax_substateT subtype
, symbolS
*symbol
, offsetT offset
)
776 frag_grow (max_chars
);
777 move_insn (insn
, frag_now
, frag_more (0) - frag_now
->fr_literal
);
778 frag_var (rs_machine_dependent
, max_chars
, var
,
779 subtype
, symbol
, offset
, NULL
);
782 /* Compute the length of a branch sequence, and adjust the stored length
783 accordingly. If FRAGP is NULL, the worst-case length is returned. */
786 relaxed_branch_length (fragS
*fragp
, asection
*sec
, int update
)
788 int jump
, rvc
, length
= 8;
793 jump
= RELAX_BRANCH_UNCOND (fragp
->fr_subtype
);
794 rvc
= RELAX_BRANCH_RVC (fragp
->fr_subtype
);
795 length
= RELAX_BRANCH_LENGTH (fragp
->fr_subtype
);
797 /* Assume jumps are in range; the linker will catch any that aren't. */
798 length
= jump
? 4 : 8;
800 if (fragp
->fr_symbol
!= NULL
801 && S_IS_DEFINED (fragp
->fr_symbol
)
802 && !S_IS_WEAK (fragp
->fr_symbol
)
803 && sec
== S_GET_SEGMENT (fragp
->fr_symbol
))
805 offsetT val
= S_GET_VALUE (fragp
->fr_symbol
) + fragp
->fr_offset
;
806 bfd_vma rvc_range
= jump
? RVC_JUMP_REACH
: RVC_BRANCH_REACH
;
807 val
-= fragp
->fr_address
+ fragp
->fr_fix
;
809 if (rvc
&& (bfd_vma
)(val
+ rvc_range
/2) < rvc_range
)
811 else if ((bfd_vma
)(val
+ RISCV_BRANCH_REACH
/2) < RISCV_BRANCH_REACH
)
813 else if (!jump
&& rvc
)
818 fragp
->fr_subtype
= RELAX_BRANCH_ENCODE (jump
, rvc
, length
);
823 /* Information about an opcode name, mnemonics and its value. */
830 /* List for all supported opcode name. */
831 static const struct opcode_name_t opcode_name_list
[] =
876 /* Hash table for lookup opcode name. */
877 static htab_t opcode_names_hash
= NULL
;
879 /* Initialization for hash table of opcode name. */
882 init_opcode_names_hash (void)
884 const struct opcode_name_t
*opcode
;
886 for (opcode
= &opcode_name_list
[0]; opcode
->name
!= NULL
; ++opcode
)
887 if (str_hash_insert (opcode_names_hash
, opcode
->name
, opcode
, 0) != NULL
)
888 as_fatal (_("internal: duplicate %s"), opcode
->name
);
891 /* Find `s` is a valid opcode name or not, return the opcode name info
894 static const struct opcode_name_t
*
895 opcode_name_lookup (char **s
)
899 struct opcode_name_t
*o
;
901 /* Find end of name. */
903 if (is_name_beginner (*e
))
905 while (is_part_of_name (*e
))
908 /* Terminate name. */
912 o
= (struct opcode_name_t
*) str_hash_find (opcode_names_hash
, *s
);
914 /* Advance to next token if one was recognized. */
924 /* All RISC-V registers belong to one of these classes. */
936 static htab_t reg_names_hash
= NULL
;
937 static htab_t csr_extra_hash
= NULL
;
939 #define ENCODE_REG_HASH(cls, n) \
940 ((void *)(uintptr_t)((n) * RCLASS_MAX + (cls) + 1))
941 #define DECODE_REG_CLASS(hash) (((uintptr_t)(hash) - 1) % RCLASS_MAX)
942 #define DECODE_REG_NUM(hash) (((uintptr_t)(hash) - 1) / RCLASS_MAX)
945 hash_reg_name (enum reg_class
class, const char *name
, unsigned n
)
947 void *hash
= ENCODE_REG_HASH (class, n
);
948 if (str_hash_insert (reg_names_hash
, name
, hash
, 0) != NULL
)
949 as_fatal (_("internal: duplicate %s"), name
);
953 hash_reg_names (enum reg_class
class, const char * const names
[], unsigned n
)
957 for (i
= 0; i
< n
; i
++)
958 hash_reg_name (class, names
[i
], i
);
961 /* Init hash table csr_extra_hash to handle CSR. */
964 riscv_init_csr_hash (const char *name
,
966 enum riscv_csr_class
class,
967 enum riscv_spec_class define_version
,
968 enum riscv_spec_class abort_version
)
970 struct riscv_csr_extra
*entry
, *pre_entry
;
971 bool need_enrty
= true;
974 entry
= (struct riscv_csr_extra
*) str_hash_find (csr_extra_hash
, name
);
975 while (need_enrty
&& entry
!= NULL
)
977 if (entry
->csr_class
== class
978 && entry
->address
== address
979 && entry
->define_version
== define_version
980 && entry
->abort_version
== abort_version
)
990 entry
= notes_alloc (sizeof (*entry
));
991 entry
->csr_class
= class;
992 entry
->address
= address
;
993 entry
->define_version
= define_version
;
994 entry
->abort_version
= abort_version
;
997 if (pre_entry
== NULL
)
998 str_hash_insert (csr_extra_hash
, name
, entry
, 0);
1000 pre_entry
->next
= entry
;
1003 /* Return the CSR address after checking the ISA dependency and
1004 the privileged spec version.
1006 There are one warning and two errors for CSR,
1008 Invalid CSR: the CSR was defined, but isn't allowed for the current ISA
1009 or the privileged spec, report warning only if -mcsr-check is set.
1010 Unknown CSR: the CSR has never been defined, report error.
1011 Improper CSR: the CSR number over the range (> 0xfff), report error. */
1014 riscv_csr_address (const char *csr_name
,
1015 struct riscv_csr_extra
*entry
)
1017 struct riscv_csr_extra
*saved_entry
= entry
;
1018 enum riscv_csr_class csr_class
= entry
->csr_class
;
1019 bool need_check_version
= false;
1020 bool is_rv32_only
= false;
1021 bool is_h_required
= false;
1022 const char* extension
= NULL
;
1026 case CSR_CLASS_I_32
:
1027 is_rv32_only
= true;
1030 need_check_version
= true;
1033 case CSR_CLASS_H_32
:
1034 is_rv32_only
= true;
1046 extension
= "zve32x";
1048 case CSR_CLASS_SMAIA_32
:
1049 is_rv32_only
= true;
1051 case CSR_CLASS_SMAIA
:
1052 extension
= "smaia";
1054 case CSR_CLASS_SMSTATEEN_32
:
1055 is_rv32_only
= true;
1057 case CSR_CLASS_SMSTATEEN
:
1058 extension
= "smstateen";
1060 case CSR_CLASS_SSAIA
:
1061 case CSR_CLASS_SSAIA_AND_H
:
1062 case CSR_CLASS_SSAIA_32
:
1063 case CSR_CLASS_SSAIA_AND_H_32
:
1064 is_rv32_only
= (csr_class
== CSR_CLASS_SSAIA_32
1065 || csr_class
== CSR_CLASS_SSAIA_AND_H_32
);
1066 is_h_required
= (csr_class
== CSR_CLASS_SSAIA_AND_H
1067 || csr_class
== CSR_CLASS_SSAIA_AND_H_32
);
1068 extension
= "ssaia";
1070 case CSR_CLASS_SSSTATEEN_AND_H_32
:
1071 is_rv32_only
= true;
1073 case CSR_CLASS_SSSTATEEN_AND_H
:
1074 is_h_required
= true;
1076 case CSR_CLASS_SSSTATEEN
:
1077 extension
= "ssstateen";
1079 case CSR_CLASS_SSCOFPMF_32
:
1080 is_rv32_only
= true;
1082 case CSR_CLASS_SSCOFPMF
:
1083 extension
= "sscofpmf";
1085 case CSR_CLASS_SSTC
:
1086 case CSR_CLASS_SSTC_AND_H
:
1087 case CSR_CLASS_SSTC_32
:
1088 case CSR_CLASS_SSTC_AND_H_32
:
1089 is_rv32_only
= (csr_class
== CSR_CLASS_SSTC_32
1090 || csr_class
== CSR_CLASS_SSTC_AND_H_32
);
1091 is_h_required
= (csr_class
== CSR_CLASS_SSTC_AND_H
1092 || csr_class
== CSR_CLASS_SSTC_AND_H_32
);
1095 case CSR_CLASS_DEBUG
:
1098 as_bad (_("internal: bad RISC-V CSR class (0x%x)"), csr_class
);
1101 if (riscv_opts
.csr_check
)
1103 if (is_rv32_only
&& xlen
!= 32)
1104 as_warn (_("invalid CSR `%s', needs rv32i extension"), csr_name
);
1105 if (is_h_required
&& !riscv_subset_supports (&riscv_rps_as
, "h"))
1106 as_warn (_("invalid CSR `%s', needs `h' extension"), csr_name
);
1108 if (extension
!= NULL
1109 && !riscv_subset_supports (&riscv_rps_as
, extension
))
1110 as_warn (_("invalid CSR `%s', needs `%s' extension"),
1111 csr_name
, extension
);
1114 while (entry
!= NULL
)
1116 if (!need_check_version
1117 || (default_priv_spec
>= entry
->define_version
1118 && default_priv_spec
< entry
->abort_version
))
1120 /* Find the CSR according to the specific version. */
1121 return entry
->address
;
1123 entry
= entry
->next
;
1126 /* Can not find the CSR address from the chosen privileged version,
1127 so use the newly defined value. */
1128 if (riscv_opts
.csr_check
)
1130 const char *priv_name
= NULL
;
1131 RISCV_GET_PRIV_SPEC_NAME (priv_name
, default_priv_spec
);
1132 if (priv_name
!= NULL
)
1133 as_warn (_("invalid CSR `%s' for the privileged spec `%s'"),
1134 csr_name
, priv_name
);
1137 return saved_entry
->address
;
1140 /* Return -1 if the CSR has never been defined. Otherwise, return
1144 reg_csr_lookup_internal (const char *s
)
1146 struct riscv_csr_extra
*r
=
1147 (struct riscv_csr_extra
*) str_hash_find (csr_extra_hash
, s
);
1152 return riscv_csr_address (s
, r
);
1156 reg_lookup_internal (const char *s
, enum reg_class
class)
1160 if (class == RCLASS_CSR
)
1161 return reg_csr_lookup_internal (s
);
1163 r
= str_hash_find (reg_names_hash
, s
);
1164 if (r
== NULL
|| DECODE_REG_CLASS (r
) != class)
1167 if (riscv_subset_supports (&riscv_rps_as
, "e")
1168 && class == RCLASS_GPR
1169 && DECODE_REG_NUM (r
) > 15)
1172 return DECODE_REG_NUM (r
);
1176 reg_lookup (char **s
, enum reg_class
class, unsigned int *regnop
)
1182 /* Find end of name. */
1184 if (is_name_beginner (*e
))
1186 while (is_part_of_name (*e
))
1189 /* Terminate name. */
1193 /* Look for the register. Advance to next token if one was recognized. */
1194 if ((reg
= reg_lookup_internal (*s
, class)) >= 0)
1204 arg_lookup (char **s
, const char *const *array
, size_t size
, unsigned *regnop
)
1206 const char *p
= strchr (*s
, ',');
1207 size_t i
, len
= p
? (size_t)(p
- *s
) : strlen (*s
);
1212 for (i
= 0; i
< size
; i
++)
1213 if (array
[i
] != NULL
&& strncmp (array
[i
], *s
, len
) == 0
1214 && array
[i
][len
] == '\0')
1225 flt_lookup (float f
, const float *array
, size_t size
, unsigned *regnop
)
1229 for (i
= 0; i
< size
; i
++)
1239 #define USE_BITS(mask,shift) (used_bits |= ((insn_t)(mask) << (shift)))
1240 #define USE_IMM(n, s) \
1241 (used_bits |= ((insn_t)((1ull<<n)-1) << (s)))
1243 /* For consistency checking, verify that all bits are specified either
1244 by the match/mask part of the instruction definition, or by the
1245 operand list. The `length` could be the actual instruction length or
1246 0 for auto-detection. */
1249 validate_riscv_insn (const struct riscv_opcode
*opc
, int length
)
1251 const char *oparg
, *opargStart
;
1252 insn_t used_bits
= opc
->mask
;
1254 insn_t required_bits
;
1257 length
= riscv_insn_length (opc
->match
);
1258 /* We don't support instructions longer than 64-bits yet. */
1261 insn_width
= 8 * length
;
1263 required_bits
= ((insn_t
)~0ULL) >> (64 - insn_width
);
1265 if ((used_bits
& opc
->match
) != (opc
->match
& required_bits
))
1267 as_bad (_("internal: bad RISC-V opcode (mask error): %s %s"),
1268 opc
->name
, opc
->args
);
1272 for (oparg
= opc
->args
; *oparg
; ++oparg
)
1280 case 'U': break; /* CRS1, constrained to equal RD. */
1281 case 'c': break; /* CRS1, constrained to equal sp. */
1282 case 'T': /* CRS2, floating point. */
1283 case 'V': USE_BITS (OP_MASK_CRS2
, OP_SH_CRS2
); break;
1284 case 'S': /* CRS1S, floating point. */
1285 case 's': USE_BITS (OP_MASK_CRS1S
, OP_SH_CRS1S
); break;
1286 case 'w': break; /* CRS1S, constrained to equal RD. */
1287 case 'D': /* CRS2S, floating point. */
1288 case 't': USE_BITS (OP_MASK_CRS2S
, OP_SH_CRS2S
); break;
1289 case 'x': break; /* CRS2S, constrained to equal RD. */
1290 case 'z': break; /* CRS2S, constrained to be x0. */
1291 case '>': /* CITYPE immediate, compressed shift. */
1292 case 'u': /* CITYPE immediate, compressed lui. */
1293 case 'v': /* CITYPE immediate, li to compressed lui. */
1294 case 'o': /* CITYPE immediate, allow zero. */
1295 case 'j': used_bits
|= ENCODE_CITYPE_IMM (-1U); break;
1296 case 'L': used_bits
|= ENCODE_CITYPE_ADDI16SP_IMM (-1U); break;
1297 case 'm': used_bits
|= ENCODE_CITYPE_LWSP_IMM (-1U); break;
1298 case 'n': used_bits
|= ENCODE_CITYPE_LDSP_IMM (-1U); break;
1299 case '6': used_bits
|= ENCODE_CSSTYPE_IMM (-1U); break;
1300 case 'M': used_bits
|= ENCODE_CSSTYPE_SWSP_IMM (-1U); break;
1301 case 'N': used_bits
|= ENCODE_CSSTYPE_SDSP_IMM (-1U); break;
1302 case '8': used_bits
|= ENCODE_CIWTYPE_IMM (-1U); break;
1303 case 'K': used_bits
|= ENCODE_CIWTYPE_ADDI4SPN_IMM (-1U); break;
1304 /* CLTYPE and CSTYPE have the same immediate encoding. */
1305 case '5': used_bits
|= ENCODE_CLTYPE_IMM (-1U); break;
1306 case 'k': used_bits
|= ENCODE_CLTYPE_LW_IMM (-1U); break;
1307 case 'l': used_bits
|= ENCODE_CLTYPE_LD_IMM (-1U); break;
1308 case 'p': used_bits
|= ENCODE_CBTYPE_IMM (-1U); break;
1309 case 'a': used_bits
|= ENCODE_CJTYPE_IMM (-1U); break;
1310 case 'F': /* Compressed funct for .insn directive. */
1313 case '6': USE_BITS (OP_MASK_CFUNCT6
, OP_SH_CFUNCT6
); break;
1314 case '4': USE_BITS (OP_MASK_CFUNCT4
, OP_SH_CFUNCT4
); break;
1315 case '3': USE_BITS (OP_MASK_CFUNCT3
, OP_SH_CFUNCT3
); break;
1316 case '2': USE_BITS (OP_MASK_CFUNCT2
, OP_SH_CFUNCT2
); break;
1318 goto unknown_validate_operand
;
1322 goto unknown_validate_operand
;
1324 break; /* end RVC */
1329 case 'f': USE_BITS (OP_MASK_VD
, OP_SH_VD
); break;
1330 case 'e': USE_BITS (OP_MASK_VWD
, OP_SH_VWD
); break;
1331 case 's': USE_BITS (OP_MASK_VS1
, OP_SH_VS1
); break;
1332 case 't': USE_BITS (OP_MASK_VS2
, OP_SH_VS2
); break;
1333 case 'u': USE_BITS (OP_MASK_VS1
, OP_SH_VS1
);
1334 USE_BITS (OP_MASK_VS2
, OP_SH_VS2
); break;
1335 case 'v': USE_BITS (OP_MASK_VD
, OP_SH_VD
);
1336 USE_BITS (OP_MASK_VS1
, OP_SH_VS1
);
1337 USE_BITS (OP_MASK_VS2
, OP_SH_VS2
); break;
1339 case 'b': used_bits
|= ENCODE_RVV_VB_IMM (-1U); break;
1340 case 'c': used_bits
|= ENCODE_RVV_VC_IMM (-1U); break;
1343 case 'k': USE_BITS (OP_MASK_VIMM
, OP_SH_VIMM
); break;
1344 case 'l': used_bits
|= ENCODE_RVV_VI_UIMM6 (-1U); break;
1345 case 'm': USE_BITS (OP_MASK_VMASK
, OP_SH_VMASK
); break;
1346 case 'M': break; /* Macro operand, must be a mask register. */
1347 case 'T': break; /* Macro operand, must be a vector register. */
1349 goto unknown_validate_operand
;
1351 break; /* end RVV */
1355 case '<': USE_BITS (OP_MASK_SHAMTW
, OP_SH_SHAMTW
); break;
1356 case '>': USE_BITS (OP_MASK_SHAMT
, OP_SH_SHAMT
); break;
1357 case 'A': break; /* Macro operand, must be symbol. */
1358 case 'B': break; /* Macro operand, must be symbol or constant. */
1359 case 'c': break; /* Macro operand, must be symbol or constant. */
1360 case 'I': break; /* Macro operand, must be constant. */
1361 case 'D': /* RD, floating point. */
1362 case 'd': USE_BITS (OP_MASK_RD
, OP_SH_RD
); break;
1363 case 'y': USE_BITS (OP_MASK_BS
, OP_SH_BS
); break;
1364 case 'Y': USE_BITS (OP_MASK_RNUM
, OP_SH_RNUM
); break;
1365 case 'Z': /* RS1, CSR number. */
1366 case 'S': /* RS1, floating point. */
1367 case 's': USE_BITS (OP_MASK_RS1
, OP_SH_RS1
); break;
1368 case 'U': /* RS1 and RS2 are the same, floating point. */
1369 USE_BITS (OP_MASK_RS1
, OP_SH_RS1
);
1371 case 'T': /* RS2, floating point. */
1372 case 't': USE_BITS (OP_MASK_RS2
, OP_SH_RS2
); break;
1373 case 'R': /* RS3, floating point. */
1374 case 'r': USE_BITS (OP_MASK_RS3
, OP_SH_RS3
); break;
1375 case 'm': USE_BITS (OP_MASK_RM
, OP_SH_RM
); break;
1376 case 'E': USE_BITS (OP_MASK_CSR
, OP_SH_CSR
); break;
1377 case 'P': USE_BITS (OP_MASK_PRED
, OP_SH_PRED
); break;
1378 case 'Q': USE_BITS (OP_MASK_SUCC
, OP_SH_SUCC
); break;
1379 case 'o': /* ITYPE immediate, load displacement. */
1380 case 'j': used_bits
|= ENCODE_ITYPE_IMM (-1U); break;
1381 case 'a': used_bits
|= ENCODE_JTYPE_IMM (-1U); break;
1382 case 'p': used_bits
|= ENCODE_BTYPE_IMM (-1U); break;
1383 case 'q': used_bits
|= ENCODE_STYPE_IMM (-1U); break;
1384 case 'u': used_bits
|= ENCODE_UTYPE_IMM (-1U); break;
1385 case 'z': break; /* Zero immediate. */
1386 case '[': break; /* Unused operand. */
1387 case ']': break; /* Unused operand. */
1388 case '0': break; /* AMO displacement, must to zero. */
1389 case '1': break; /* Relaxation operand. */
1390 case 'F': /* Funct for .insn directive. */
1393 case '7': USE_BITS (OP_MASK_FUNCT7
, OP_SH_FUNCT7
); break;
1394 case '3': USE_BITS (OP_MASK_FUNCT3
, OP_SH_FUNCT3
); break;
1395 case '2': USE_BITS (OP_MASK_FUNCT2
, OP_SH_FUNCT2
); break;
1397 goto unknown_validate_operand
;
1400 case 'O': /* Opcode for .insn directive. */
1403 case '4': USE_BITS (OP_MASK_OP
, OP_SH_OP
); break;
1404 case '2': USE_BITS (OP_MASK_OP2
, OP_SH_OP2
); break;
1406 goto unknown_validate_operand
;
1409 case 'W': /* Various operands. */
1415 case 'f': used_bits
|= ENCODE_STYPE_IMM (-1U); break;
1417 goto unknown_validate_operand
;
1423 case 'v': USE_BITS (OP_MASK_RS1
, OP_SH_RS1
); break;
1425 goto unknown_validate_operand
;
1429 goto unknown_validate_operand
;
1432 case 'X': /* Integer immediate. */
1439 case 'l': /* Literal. */
1440 oparg
+= strcspn(oparg
, ",") - 1;
1442 case 's': /* 'XsN@S' ... N-bit signed immediate at bit S. */
1444 case 'u': /* 'XuN@S' ... N-bit unsigned immediate at bit S. */
1447 n
= strtol (oparg
+ 1, (char **)&oparg
, 10);
1449 goto unknown_validate_operand
;
1450 s
= strtol (oparg
+ 1, (char **)&oparg
, 10);
1456 goto unknown_validate_operand
;
1461 unknown_validate_operand
:
1462 as_bad (_("internal: bad RISC-V opcode "
1463 "(unknown operand type `%s'): %s %s"),
1464 opargStart
, opc
->name
, opc
->args
);
1469 if (used_bits
!= required_bits
)
1471 as_bad (_("internal: bad RISC-V opcode "
1472 "(bits %#llx undefined or invalid): %s %s"),
1473 (unsigned long long)(used_bits
^ required_bits
),
1474 opc
->name
, opc
->args
);
1482 struct percent_op_match
1485 bfd_reloc_code_real_type reloc
;
1488 /* Common hash table initialization function for instruction and .insn
1492 init_opcode_hash (const struct riscv_opcode
*opcodes
,
1493 bool insn_directive_p
)
1497 htab_t hash
= str_htab_create ();
1498 while (opcodes
[i
].name
)
1500 const char *name
= opcodes
[i
].name
;
1501 if (str_hash_insert (hash
, name
, &opcodes
[i
], 0) != NULL
)
1502 as_fatal (_("internal: duplicate %s"), name
);
1506 if (opcodes
[i
].pinfo
!= INSN_MACRO
)
1508 if (insn_directive_p
)
1509 length
= ((name
[0] == 'c') ? 2 : 4);
1511 length
= 0; /* Let assembler determine the length. */
1512 if (!validate_riscv_insn (&opcodes
[i
], length
))
1513 as_fatal (_("internal: broken assembler. "
1514 "No assembly attempted"));
1517 gas_assert (!insn_directive_p
);
1520 while (opcodes
[i
].name
&& !strcmp (opcodes
[i
].name
, name
));
1526 /* This function is called once, at assembler startup time. It should set up
1527 all the tables, etc. that the MD part of the assembler will need. */
1532 unsigned long mach
= xlen
== 64 ? bfd_mach_riscv64
: bfd_mach_riscv32
;
1534 if (! bfd_set_arch_mach (stdoutput
, bfd_arch_riscv
, mach
))
1535 as_warn (_("could not set architecture and machine"));
1537 op_hash
= init_opcode_hash (riscv_opcodes
, false);
1538 insn_type_hash
= init_opcode_hash (riscv_insn_types
, true);
1540 reg_names_hash
= str_htab_create ();
1541 hash_reg_names (RCLASS_GPR
, riscv_gpr_names_numeric
, NGPR
);
1542 hash_reg_names (RCLASS_GPR
, riscv_gpr_names_abi
, NGPR
);
1543 hash_reg_names (RCLASS_FPR
, riscv_fpr_names_numeric
, NFPR
);
1544 hash_reg_names (RCLASS_FPR
, riscv_fpr_names_abi
, NFPR
);
1545 hash_reg_names (RCLASS_VECR
, riscv_vecr_names_numeric
, NVECR
);
1546 hash_reg_names (RCLASS_VECM
, riscv_vecm_names_numeric
, NVECM
);
1547 /* Add "fp" as an alias for "s0". */
1548 hash_reg_name (RCLASS_GPR
, "fp", 8);
1550 /* Create and insert CSR hash tables. */
1551 csr_extra_hash
= str_htab_create ();
1552 #define DECLARE_CSR(name, num, class, define_version, abort_version) \
1553 riscv_init_csr_hash (#name, num, class, define_version, abort_version);
1554 #define DECLARE_CSR_ALIAS(name, num, class, define_version, abort_version) \
1555 DECLARE_CSR(name, num, class, define_version, abort_version);
1556 #include "opcode/riscv-opc.h"
1559 opcode_names_hash
= str_htab_create ();
1560 init_opcode_names_hash ();
1562 /* Set the default alignment for the text section. */
1563 record_alignment (text_section
, riscv_opts
.rvc
? 1 : 2);
1567 riscv_apply_const_reloc (bfd_reloc_code_real_type reloc_type
, bfd_vma value
)
1574 case BFD_RELOC_RISCV_HI20
:
1575 return ENCODE_UTYPE_IMM (RISCV_CONST_HIGH_PART (value
));
1577 case BFD_RELOC_RISCV_LO12_S
:
1578 return ENCODE_STYPE_IMM (value
);
1580 case BFD_RELOC_RISCV_LO12_I
:
1581 return ENCODE_ITYPE_IMM (value
);
1588 /* Output an instruction. IP is the instruction information.
1589 ADDRESS_EXPR is an operand of the instruction to be used with
1593 append_insn (struct riscv_cl_insn
*ip
, expressionS
*address_expr
,
1594 bfd_reloc_code_real_type reloc_type
)
1596 dwarf2_emit_insn (0);
1598 if (reloc_type
!= BFD_RELOC_UNUSED
)
1600 reloc_howto_type
*howto
;
1602 gas_assert (address_expr
);
1603 if (reloc_type
== BFD_RELOC_12_PCREL
1604 || reloc_type
== BFD_RELOC_RISCV_JMP
)
1606 int j
= reloc_type
== BFD_RELOC_RISCV_JMP
;
1607 int best_case
= insn_length (ip
);
1608 unsigned worst_case
= relaxed_branch_length (NULL
, NULL
, 0);
1610 if (now_seg
== absolute_section
)
1612 as_bad (_("relaxable branches not supported in absolute section"));
1616 add_relaxed_insn (ip
, worst_case
, best_case
,
1617 RELAX_BRANCH_ENCODE (j
, best_case
== 2, worst_case
),
1618 address_expr
->X_add_symbol
,
1619 address_expr
->X_add_number
);
1624 howto
= bfd_reloc_type_lookup (stdoutput
, reloc_type
);
1626 as_bad (_("internal: unsupported RISC-V relocation number %d"),
1629 ip
->fixp
= fix_new_exp (ip
->frag
, ip
->where
,
1630 bfd_get_reloc_size (howto
),
1631 address_expr
, false, reloc_type
);
1633 ip
->fixp
->fx_tcbit
= riscv_opts
.relax
;
1637 add_fixed_insn (ip
);
1639 /* We need to start a new frag after any instruction that can be
1640 optimized away or compressed by the linker during relaxation, to prevent
1641 the assembler from computing static offsets across such an instruction.
1642 This is necessary to get correct EH info. */
1643 if (reloc_type
== BFD_RELOC_RISCV_HI20
1644 || reloc_type
== BFD_RELOC_RISCV_PCREL_HI20
1645 || reloc_type
== BFD_RELOC_RISCV_TPREL_HI20
1646 || reloc_type
== BFD_RELOC_RISCV_TPREL_ADD
)
1648 frag_wane (frag_now
);
1653 /* Build an instruction created by a macro expansion. This is passed
1654 a pointer to the count of instructions created so far, an expression,
1655 the name of the instruction to build, an operand format string, and
1656 corresponding arguments. */
1659 macro_build (expressionS
*ep
, const char *name
, const char *fmt
, ...)
1661 const struct riscv_opcode
*mo
;
1662 struct riscv_cl_insn insn
;
1663 bfd_reloc_code_real_type r
;
1665 const char *fmtStart
;
1667 va_start (args
, fmt
);
1669 r
= BFD_RELOC_UNUSED
;
1670 mo
= (struct riscv_opcode
*) str_hash_find (op_hash
, name
);
1673 /* Find a non-RVC variant of the instruction. append_insn will compress
1675 while (riscv_insn_length (mo
->match
) < 4)
1677 gas_assert (strcmp (name
, mo
->name
) == 0);
1679 create_insn (&insn
, mo
);
1689 INSERT_OPERAND (VD
, insn
, va_arg (args
, int));
1692 INSERT_OPERAND (VS1
, insn
, va_arg (args
, int));
1695 INSERT_OPERAND (VS2
, insn
, va_arg (args
, int));
1699 int reg
= va_arg (args
, int);
1702 INSERT_OPERAND (VMASK
, insn
, 1);
1707 INSERT_OPERAND (VMASK
, insn
, 0);
1711 goto unknown_macro_argument
;
1714 goto unknown_macro_argument
;
1719 INSERT_OPERAND (RD
, insn
, va_arg (args
, int));
1722 INSERT_OPERAND (RS1
, insn
, va_arg (args
, int));
1725 INSERT_OPERAND (RS2
, insn
, va_arg (args
, int));
1731 gas_assert (ep
!= NULL
);
1732 r
= va_arg (args
, int);
1740 unknown_macro_argument
:
1741 as_fatal (_("internal: invalid macro argument `%s'"), fmtStart
);
1746 gas_assert (r
== BFD_RELOC_UNUSED
? ep
== NULL
: ep
!= NULL
);
1748 append_insn (&insn
, ep
, r
);
1751 /* Build an instruction created by a macro expansion. Like md_assemble but
1752 accept a printf-style format string and arguments. */
1755 md_assemblef (const char *format
, ...)
1761 va_start (ap
, format
);
1763 r
= vasprintf (&buf
, format
, ap
);
1766 as_fatal (_("internal: vasprintf failed"));
1774 /* Sign-extend 32-bit mode constants that have bit 31 set and all higher bits
1778 normalize_constant_expr (expressionS
*ex
)
1782 if ((ex
->X_op
== O_constant
|| ex
->X_op
== O_symbol
)
1783 && IS_ZEXT_32BIT_NUM (ex
->X_add_number
))
1784 ex
->X_add_number
= (((ex
->X_add_number
& 0xffffffff) ^ 0x80000000)
1788 /* Fail if an expression EX is not a constant. IP is the instruction using EX.
1789 MAYBE_CSR is true if the symbol may be an unrecognized CSR name. */
1792 check_absolute_expr (struct riscv_cl_insn
*ip
, expressionS
*ex
,
1795 if (ex
->X_op
== O_big
)
1796 as_bad (_("unsupported large constant"));
1797 else if (maybe_csr
&& ex
->X_op
== O_symbol
)
1798 as_bad (_("unknown CSR `%s'"),
1799 S_GET_NAME (ex
->X_add_symbol
));
1800 else if (ex
->X_op
!= O_constant
)
1801 as_bad (_("instruction %s requires absolute expression"),
1803 normalize_constant_expr (ex
);
1807 make_internal_label (void)
1809 return (symbolS
*) local_symbol_make (FAKE_LABEL_NAME
, now_seg
, frag_now
,
1813 /* Load an entry from the GOT. */
1816 pcrel_access (int destreg
, int tempreg
, expressionS
*ep
,
1817 const char *lo_insn
, const char *lo_pattern
,
1818 bfd_reloc_code_real_type hi_reloc
,
1819 bfd_reloc_code_real_type lo_reloc
)
1822 ep2
.X_op
= O_symbol
;
1823 ep2
.X_add_symbol
= make_internal_label ();
1824 ep2
.X_add_number
= 0;
1826 macro_build (ep
, "auipc", "d,u", tempreg
, hi_reloc
);
1827 macro_build (&ep2
, lo_insn
, lo_pattern
, destreg
, tempreg
, lo_reloc
);
1831 pcrel_load (int destreg
, int tempreg
, expressionS
*ep
, const char *lo_insn
,
1832 bfd_reloc_code_real_type hi_reloc
,
1833 bfd_reloc_code_real_type lo_reloc
)
1835 pcrel_access (destreg
, tempreg
, ep
, lo_insn
, "d,s,j", hi_reloc
, lo_reloc
);
1839 pcrel_store (int srcreg
, int tempreg
, expressionS
*ep
, const char *lo_insn
,
1840 bfd_reloc_code_real_type hi_reloc
,
1841 bfd_reloc_code_real_type lo_reloc
)
1843 pcrel_access (srcreg
, tempreg
, ep
, lo_insn
, "t,s,q", hi_reloc
, lo_reloc
);
1846 /* PC-relative function call using AUIPC/JALR, relaxed to JAL. */
1849 riscv_call (int destreg
, int tempreg
, expressionS
*ep
,
1850 bfd_reloc_code_real_type reloc
)
1852 /* Ensure the jalr is emitted to the same frag as the auipc. */
1854 macro_build (ep
, "auipc", "d,u", tempreg
, reloc
);
1855 macro_build (NULL
, "jalr", "d,s", destreg
, tempreg
);
1856 /* See comment at end of append_insn. */
1857 frag_wane (frag_now
);
1861 /* Load an integer constant into a register. */
1864 load_const (int reg
, expressionS
*ep
)
1866 int shift
= RISCV_IMM_BITS
;
1867 bfd_vma upper_imm
, sign
= (bfd_vma
) 1 << (RISCV_IMM_BITS
- 1);
1868 expressionS upper
= *ep
, lower
= *ep
;
1869 lower
.X_add_number
= ((ep
->X_add_number
& (sign
+ sign
- 1)) ^ sign
) - sign
;
1870 upper
.X_add_number
-= lower
.X_add_number
;
1872 if (ep
->X_op
!= O_constant
)
1874 as_bad (_("unsupported large constant"));
1878 if (xlen
> 32 && !IS_SEXT_32BIT_NUM (ep
->X_add_number
))
1880 /* Reduce to a signed 32-bit constant using SLLI and ADDI. */
1881 while (((upper
.X_add_number
>> shift
) & 1) == 0)
1884 upper
.X_add_number
= (int64_t) upper
.X_add_number
>> shift
;
1885 load_const (reg
, &upper
);
1887 md_assemblef ("slli x%d, x%d, 0x%x", reg
, reg
, shift
);
1888 if (lower
.X_add_number
!= 0)
1889 md_assemblef ("addi x%d, x%d, %" PRId64
, reg
, reg
,
1890 (int64_t) lower
.X_add_number
);
1894 /* Simply emit LUI and/or ADDI to build a 32-bit signed constant. */
1897 if (upper
.X_add_number
!= 0)
1899 /* Discard low part and zero-extend upper immediate. */
1900 upper_imm
= ((uint32_t)upper
.X_add_number
>> shift
);
1902 md_assemblef ("lui x%d, 0x%" PRIx64
, reg
, (uint64_t) upper_imm
);
1906 if (lower
.X_add_number
!= 0 || hi_reg
== 0)
1907 md_assemblef ("%s x%d, x%d, %" PRId64
, ADD32_INSN
, reg
, hi_reg
,
1908 (int64_t) lower
.X_add_number
);
1912 /* Zero extend and sign extend byte/half-word/word. */
1915 riscv_ext (int destreg
, int srcreg
, unsigned shift
, bool sign
)
1919 md_assemblef ("slli x%d, x%d, 0x%x", destreg
, srcreg
, shift
);
1920 md_assemblef ("srai x%d, x%d, 0x%x", destreg
, destreg
, shift
);
1924 md_assemblef ("slli x%d, x%d, 0x%x", destreg
, srcreg
, shift
);
1925 md_assemblef ("srli x%d, x%d, 0x%x", destreg
, destreg
, shift
);
1929 /* Expand RISC-V Vector macros into one or more instructions. */
1932 vector_macro (struct riscv_cl_insn
*ip
)
1934 int vd
= (ip
->insn_opcode
>> OP_SH_VD
) & OP_MASK_VD
;
1935 int vs1
= (ip
->insn_opcode
>> OP_SH_VS1
) & OP_MASK_VS1
;
1936 int vs2
= (ip
->insn_opcode
>> OP_SH_VS2
) & OP_MASK_VS2
;
1937 int vm
= (ip
->insn_opcode
>> OP_SH_VMASK
) & OP_MASK_VMASK
;
1938 int vtemp
= (ip
->insn_opcode
>> OP_SH_VFUNCT6
) & OP_MASK_VFUNCT6
;
1939 int mask
= ip
->insn_mo
->mask
;
1947 macro_build (NULL
, "vmslt.vx", "Vd,Vt,sVm", vd
, vs2
, vs1
, -1);
1948 macro_build (NULL
, "vmnand.mm", "Vd,Vt,Vs", vd
, vd
, vd
);
1953 /* Masked. Have vtemp to avoid overlap constraints. */
1956 macro_build (NULL
, "vmslt.vx", "Vd,Vt,s", vtemp
, vs2
, vs1
);
1957 macro_build (NULL
, "vmandnot.mm", "Vd,Vt,Vs", vd
, vm
, vtemp
);
1961 /* Preserve the value of vd if not updating by vm. */
1962 macro_build (NULL
, "vmslt.vx", "Vd,Vt,s", vtemp
, vs2
, vs1
);
1963 macro_build (NULL
, "vmandnot.mm", "Vd,Vt,Vs", vtemp
, vm
, vtemp
);
1964 macro_build (NULL
, "vmandnot.mm", "Vd,Vt,Vs", vd
, vd
, vm
);
1965 macro_build (NULL
, "vmor.mm", "Vd,Vt,Vs", vd
, vtemp
, vd
);
1970 /* Masked. This may cause the vd overlaps vs2, when LMUL > 1. */
1971 macro_build (NULL
, "vmslt.vx", "Vd,Vt,sVm", vd
, vs2
, vs1
, vm
);
1972 macro_build (NULL
, "vmxor.mm", "Vd,Vt,Vs", vd
, vd
, vm
);
1975 as_bad (_("must provide temp if destination overlaps mask"));
1982 macro_build (NULL
, "vmsltu.vx", "Vd,Vt,sVm", vd
, vs2
, vs1
, -1);
1983 macro_build (NULL
, "vmnand.mm", "Vd,Vt,Vs", vd
, vd
, vd
);
1988 /* Masked. Have vtemp to avoid overlap constraints. */
1991 macro_build (NULL
, "vmsltu.vx", "Vd,Vt,s", vtemp
, vs2
, vs1
);
1992 macro_build (NULL
, "vmandnot.mm", "Vd,Vt,Vs", vd
, vm
, vtemp
);
1996 /* Preserve the value of vd if not updating by vm. */
1997 macro_build (NULL
, "vmsltu.vx", "Vd,Vt,s", vtemp
, vs2
, vs1
);
1998 macro_build (NULL
, "vmandnot.mm", "Vd,Vt,Vs", vtemp
, vm
, vtemp
);
1999 macro_build (NULL
, "vmandnot.mm", "Vd,Vt,Vs", vd
, vd
, vm
);
2000 macro_build (NULL
, "vmor.mm", "Vd,Vt,Vs", vd
, vtemp
, vd
);
2005 /* Masked. This may cause the vd overlaps vs2, when LMUL > 1. */
2006 macro_build (NULL
, "vmsltu.vx", "Vd,Vt,sVm", vd
, vs2
, vs1
, vm
);
2007 macro_build (NULL
, "vmxor.mm", "Vd,Vt,Vs", vd
, vd
, vm
);
2010 as_bad (_("must provide temp if destination overlaps mask"));
2018 /* Expand RISC-V assembly macros into one or more instructions. */
2021 macro (struct riscv_cl_insn
*ip
, expressionS
*imm_expr
,
2022 bfd_reloc_code_real_type
*imm_reloc
)
2024 int rd
= (ip
->insn_opcode
>> OP_SH_RD
) & OP_MASK_RD
;
2025 int rs1
= (ip
->insn_opcode
>> OP_SH_RS1
) & OP_MASK_RS1
;
2026 int rs2
= (ip
->insn_opcode
>> OP_SH_RS2
) & OP_MASK_RS2
;
2027 int mask
= ip
->insn_mo
->mask
;
2032 load_const (rd
, imm_expr
);
2038 /* Load the address of a symbol into a register. */
2039 if (!IS_SEXT_32BIT_NUM (imm_expr
->X_add_number
))
2040 as_bad (_("offset too large"));
2042 if (imm_expr
->X_op
== O_constant
)
2043 load_const (rd
, imm_expr
);
2044 /* Global PIC symbol. */
2045 else if ((riscv_opts
.pic
&& mask
== M_LA
)
2047 pcrel_load (rd
, rd
, imm_expr
, LOAD_ADDRESS_INSN
,
2048 BFD_RELOC_RISCV_GOT_HI20
, BFD_RELOC_RISCV_PCREL_LO12_I
);
2049 /* Local PIC symbol, or any non-PIC symbol. */
2051 pcrel_load (rd
, rd
, imm_expr
, "addi",
2052 BFD_RELOC_RISCV_PCREL_HI20
, BFD_RELOC_RISCV_PCREL_LO12_I
);
2056 pcrel_load (rd
, rd
, imm_expr
, "addi",
2057 BFD_RELOC_RISCV_TLS_GD_HI20
, BFD_RELOC_RISCV_PCREL_LO12_I
);
2061 pcrel_load (rd
, rd
, imm_expr
, LOAD_ADDRESS_INSN
,
2062 BFD_RELOC_RISCV_TLS_GOT_HI20
, BFD_RELOC_RISCV_PCREL_LO12_I
);
2066 pcrel_load (rd
, rd
, imm_expr
, "lb",
2067 BFD_RELOC_RISCV_PCREL_HI20
, BFD_RELOC_RISCV_PCREL_LO12_I
);
2071 pcrel_load (rd
, rd
, imm_expr
, "lbu",
2072 BFD_RELOC_RISCV_PCREL_HI20
, BFD_RELOC_RISCV_PCREL_LO12_I
);
2076 pcrel_load (rd
, rd
, imm_expr
, "lh",
2077 BFD_RELOC_RISCV_PCREL_HI20
, BFD_RELOC_RISCV_PCREL_LO12_I
);
2081 pcrel_load (rd
, rd
, imm_expr
, "lhu",
2082 BFD_RELOC_RISCV_PCREL_HI20
, BFD_RELOC_RISCV_PCREL_LO12_I
);
2086 pcrel_load (rd
, rd
, imm_expr
, "lw",
2087 BFD_RELOC_RISCV_PCREL_HI20
, BFD_RELOC_RISCV_PCREL_LO12_I
);
2091 pcrel_load (rd
, rd
, imm_expr
, "lwu",
2092 BFD_RELOC_RISCV_PCREL_HI20
, BFD_RELOC_RISCV_PCREL_LO12_I
);
2096 pcrel_load (rd
, rd
, imm_expr
, "ld",
2097 BFD_RELOC_RISCV_PCREL_HI20
, BFD_RELOC_RISCV_PCREL_LO12_I
);
2101 pcrel_load (rd
, rs1
, imm_expr
, "flw",
2102 BFD_RELOC_RISCV_PCREL_HI20
, BFD_RELOC_RISCV_PCREL_LO12_I
);
2106 pcrel_load (rd
, rs1
, imm_expr
, "fld",
2107 BFD_RELOC_RISCV_PCREL_HI20
, BFD_RELOC_RISCV_PCREL_LO12_I
);
2111 pcrel_store (rs2
, rs1
, imm_expr
, "sb",
2112 BFD_RELOC_RISCV_PCREL_HI20
, BFD_RELOC_RISCV_PCREL_LO12_S
);
2116 pcrel_store (rs2
, rs1
, imm_expr
, "sh",
2117 BFD_RELOC_RISCV_PCREL_HI20
, BFD_RELOC_RISCV_PCREL_LO12_S
);
2121 pcrel_store (rs2
, rs1
, imm_expr
, "sw",
2122 BFD_RELOC_RISCV_PCREL_HI20
, BFD_RELOC_RISCV_PCREL_LO12_S
);
2126 pcrel_store (rs2
, rs1
, imm_expr
, "sd",
2127 BFD_RELOC_RISCV_PCREL_HI20
, BFD_RELOC_RISCV_PCREL_LO12_S
);
2131 pcrel_store (rs2
, rs1
, imm_expr
, "fsw",
2132 BFD_RELOC_RISCV_PCREL_HI20
, BFD_RELOC_RISCV_PCREL_LO12_S
);
2136 pcrel_store (rs2
, rs1
, imm_expr
, "fsd",
2137 BFD_RELOC_RISCV_PCREL_HI20
, BFD_RELOC_RISCV_PCREL_LO12_S
);
2141 riscv_call (rd
, rs1
, imm_expr
, *imm_reloc
);
2145 riscv_ext (rd
, rs1
, xlen
- 16, false);
2149 riscv_ext (rd
, rs1
, xlen
- 32, false);
2153 riscv_ext (rd
, rs1
, xlen
- 8, true);
2157 riscv_ext (rd
, rs1
, xlen
- 16, true);
2166 pcrel_load (rd
, rs1
, imm_expr
, "flh",
2167 BFD_RELOC_RISCV_PCREL_HI20
, BFD_RELOC_RISCV_PCREL_LO12_I
);
2170 pcrel_store (rs2
, rs1
, imm_expr
, "fsh",
2171 BFD_RELOC_RISCV_PCREL_HI20
, BFD_RELOC_RISCV_PCREL_LO12_S
);
2175 as_bad (_("internal: macro %s not implemented"), ip
->insn_mo
->name
);
2180 static const struct percent_op_match percent_op_utype
[] =
2182 {"tprel_hi", BFD_RELOC_RISCV_TPREL_HI20
},
2183 {"pcrel_hi", BFD_RELOC_RISCV_PCREL_HI20
},
2184 {"got_pcrel_hi", BFD_RELOC_RISCV_GOT_HI20
},
2185 {"tls_ie_pcrel_hi", BFD_RELOC_RISCV_TLS_GOT_HI20
},
2186 {"tls_gd_pcrel_hi", BFD_RELOC_RISCV_TLS_GD_HI20
},
2187 {"hi", BFD_RELOC_RISCV_HI20
},
2191 static const struct percent_op_match percent_op_itype
[] =
2193 {"lo", BFD_RELOC_RISCV_LO12_I
},
2194 {"tprel_lo", BFD_RELOC_RISCV_TPREL_LO12_I
},
2195 {"pcrel_lo", BFD_RELOC_RISCV_PCREL_LO12_I
},
2199 static const struct percent_op_match percent_op_stype
[] =
2201 {"lo", BFD_RELOC_RISCV_LO12_S
},
2202 {"tprel_lo", BFD_RELOC_RISCV_TPREL_LO12_S
},
2203 {"pcrel_lo", BFD_RELOC_RISCV_PCREL_LO12_S
},
2207 static const struct percent_op_match percent_op_rtype
[] =
2209 {"tprel_add", BFD_RELOC_RISCV_TPREL_ADD
},
2213 static const struct percent_op_match percent_op_null
[] =
2218 /* Return true if *STR points to a relocation operator. When returning true,
2219 move *STR over the operator and store its relocation code in *RELOC.
2220 Leave both *STR and *RELOC alone when returning false. */
2223 parse_relocation (char **str
, bfd_reloc_code_real_type
*reloc
,
2224 const struct percent_op_match
*percent_op
)
2226 for ( ; percent_op
->str
; percent_op
++)
2227 if (strncasecmp (*str
+ 1, percent_op
->str
, strlen (percent_op
->str
)) == 0)
2229 size_t len
= 1 + strlen (percent_op
->str
);
2231 while (ISSPACE ((*str
)[len
]))
2233 if ((*str
)[len
] != '(')
2237 *reloc
= percent_op
->reloc
;
2239 /* Check whether the output BFD supports this relocation.
2240 If not, issue an error and fall back on something safe. */
2241 if (*reloc
!= BFD_RELOC_UNUSED
2242 && !bfd_reloc_type_lookup (stdoutput
, *reloc
))
2244 as_bad ("internal: relocation %s isn't supported by the "
2245 "current ABI", percent_op
->str
);
2246 *reloc
= BFD_RELOC_UNUSED
;
2254 my_getExpression (expressionS
*ep
, char *str
)
2258 save_in
= input_line_pointer
;
2259 input_line_pointer
= str
;
2261 expr_parse_end
= input_line_pointer
;
2262 input_line_pointer
= save_in
;
2265 /* Parse string STR as a 16-bit relocatable operand. Store the
2266 expression in *EP and the relocation, if any, in RELOC.
2267 Return the number of relocation operators used (0 or 1).
2269 On exit, EXPR_PARSE_END points to the first character after the
2273 my_getSmallExpression (expressionS
*ep
, bfd_reloc_code_real_type
*reloc
,
2274 char *str
, const struct percent_op_match
*percent_op
)
2277 unsigned crux_depth
, str_depth
;
2278 bool orig_probing
= probing_insn_operands
;
2281 /* Search for the start of the main expression.
2283 End the loop with CRUX pointing to the start of the main expression and
2284 with CRUX_DEPTH containing the number of open brackets at that point. */
2291 crux_depth
= str_depth
;
2293 /* Skip over whitespace and brackets, keeping count of the number
2295 while (*str
== ' ' || *str
== '\t' || *str
== '(')
2301 && parse_relocation (&str
, reloc
, percent_op
));
2305 /* expression() will choke on anything looking like an (unrecognized)
2306 relocation specifier. Don't even call it, avoiding multiple (and
2307 perhaps redundant) error messages; our caller will issue one. */
2308 ep
->X_op
= O_illegal
;
2312 /* Anything inside parentheses or subject to a relocation operator cannot
2313 be a register and hence can be treated the same as operands to
2314 directives (other than .insn). */
2315 if (str_depth
|| reloc_index
)
2316 probing_insn_operands
= false;
2318 my_getExpression (ep
, crux
);
2319 str
= expr_parse_end
;
2321 probing_insn_operands
= orig_probing
;
2323 /* Match every open bracket. */
2324 while (crux_depth
> 0 && (*str
== ')' || *str
== ' ' || *str
== '\t'))
2329 as_bad ("unclosed '('");
2331 expr_parse_end
= str
;
2336 /* Parse opcode name, could be an mnemonics or number. */
2339 my_getOpcodeExpression (expressionS
*ep
, bfd_reloc_code_real_type
*reloc
,
2342 const struct opcode_name_t
*o
= opcode_name_lookup (&str
);
2346 ep
->X_op
= O_constant
;
2347 ep
->X_add_number
= o
->val
;
2351 return my_getSmallExpression (ep
, reloc
, str
, percent_op_null
);
2354 /* Parse string STR as a vsetvli operand. Store the expression in *EP.
2355 On exit, EXPR_PARSE_END points to the first character after the
2359 my_getVsetvliExpression (expressionS
*ep
, char *str
)
2361 unsigned int vsew_value
= 0, vlmul_value
= 0;
2362 unsigned int vta_value
= 0, vma_value
= 0;
2363 bfd_boolean vsew_found
= FALSE
, vlmul_found
= FALSE
;
2364 bfd_boolean vta_found
= FALSE
, vma_found
= FALSE
;
2366 if (arg_lookup (&str
, riscv_vsew
, ARRAY_SIZE (riscv_vsew
), &vsew_value
))
2371 as_bad (_("multiple vsew constants"));
2374 if (arg_lookup (&str
, riscv_vlmul
, ARRAY_SIZE (riscv_vlmul
), &vlmul_value
))
2379 as_bad (_("multiple vlmul constants"));
2382 if (arg_lookup (&str
, riscv_vta
, ARRAY_SIZE (riscv_vta
), &vta_value
))
2387 as_bad (_("multiple vta constants"));
2390 if (arg_lookup (&str
, riscv_vma
, ARRAY_SIZE (riscv_vma
), &vma_value
))
2395 as_bad (_("multiple vma constants"));
2399 if (vsew_found
|| vlmul_found
|| vta_found
|| vma_found
)
2401 ep
->X_op
= O_constant
;
2402 ep
->X_add_number
= (vlmul_value
<< OP_SH_VLMUL
)
2403 | (vsew_value
<< OP_SH_VSEW
)
2404 | (vta_value
<< OP_SH_VTA
)
2405 | (vma_value
<< OP_SH_VMA
);
2406 expr_parse_end
= str
;
2410 my_getExpression (ep
, str
);
2411 str
= expr_parse_end
;
2415 /* Detect and handle implicitly zero load-store offsets. For example,
2416 "lw t0, (t1)" is shorthand for "lw t0, 0(t1)". Return true if such
2417 an implicit offset was detected. */
2420 riscv_handle_implicit_zero_offset (expressionS
*ep
, const char *s
)
2422 /* Check whether there is only a single bracketed expression left.
2423 If so, it must be the base register and the constant must be zero. */
2424 if (*s
== '(' && strchr (s
+ 1, '(') == 0)
2426 ep
->X_op
= O_constant
;
2427 ep
->X_add_number
= 0;
2434 /* All RISC-V CSR instructions belong to one of these classes. */
2443 /* Return which CSR instruction is checking. */
2445 static enum csr_insn_type
2446 riscv_csr_insn_type (insn_t insn
)
2448 if (((insn
^ MATCH_CSRRW
) & MASK_CSRRW
) == 0
2449 || ((insn
^ MATCH_CSRRWI
) & MASK_CSRRWI
) == 0)
2451 else if (((insn
^ MATCH_CSRRS
) & MASK_CSRRS
) == 0
2452 || ((insn
^ MATCH_CSRRSI
) & MASK_CSRRSI
) == 0)
2454 else if (((insn
^ MATCH_CSRRC
) & MASK_CSRRC
) == 0
2455 || ((insn
^ MATCH_CSRRCI
) & MASK_CSRRCI
) == 0)
2458 return INSN_NOT_CSR
;
2461 /* CSRRW and CSRRWI always write CSR. CSRRS, CSRRC, CSRRSI and CSRRCI write
2462 CSR when RS1 isn't zero. The CSR is read only if the [11:10] bits of
2463 CSR address is 0x3. */
2466 riscv_csr_read_only_check (insn_t insn
)
2468 int csr
= (insn
& (OP_MASK_CSR
<< OP_SH_CSR
)) >> OP_SH_CSR
;
2469 int rs1
= (insn
& (OP_MASK_RS1
<< OP_SH_RS1
)) >> OP_SH_RS1
;
2470 int readonly
= (((csr
& (0x3 << 10)) >> 10) == 0x3);
2471 enum csr_insn_type csr_insn
= riscv_csr_insn_type (insn
);
2474 && (((csr_insn
== INSN_CSRRS
2475 || csr_insn
== INSN_CSRRC
)
2477 || csr_insn
== INSN_CSRRW
))
2483 /* Return true if it is a privileged instruction. Otherwise, return false.
2485 uret is actually a N-ext instruction. So it is better to regard it as
2486 an user instruction rather than the priv instruction.
2488 hret is used to return from traps in H-mode. H-mode is removed since
2489 the v1.10 priv spec, but probably be added in the new hypervisor spec.
2490 Therefore, hret should be controlled by the hypervisor spec rather than
2491 priv spec in the future.
2493 dret is defined in the debug spec, so it should be checked in the future,
2497 riscv_is_priv_insn (insn_t insn
)
2499 return (((insn
^ MATCH_SRET
) & MASK_SRET
) == 0
2500 || ((insn
^ MATCH_MRET
) & MASK_MRET
) == 0
2501 || ((insn
^ MATCH_SFENCE_VMA
) & MASK_SFENCE_VMA
) == 0
2502 || ((insn
^ MATCH_WFI
) & MASK_WFI
) == 0
2503 /* The sfence.vm is dropped in the v1.10 priv specs, but we still need to
2504 check it here to keep the compatible. */
2505 || ((insn
^ MATCH_SFENCE_VM
) & MASK_SFENCE_VM
) == 0);
2508 static symbolS
*deferred_sym_rootP
;
2509 static symbolS
*deferred_sym_lastP
;
2510 /* Since symbols can't easily be freed, try to recycle ones which weren't
2512 static symbolS
*orphan_sym_rootP
;
2513 static symbolS
*orphan_sym_lastP
;
2515 /* This routine assembles an instruction into its binary format. As a
2516 side effect, it sets the global variable imm_reloc to the type of
2517 relocation to do if one of the operands is an address expression. */
2519 static struct riscv_ip_error
2520 riscv_ip (char *str
, struct riscv_cl_insn
*ip
, expressionS
*imm_expr
,
2521 bfd_reloc_code_real_type
*imm_reloc
, htab_t hash
)
2523 /* The operand string defined in the riscv_opcodes. */
2524 const char *oparg
, *opargStart
;
2525 /* The parsed operands from assembly. */
2526 char *asarg
, *asargStart
;
2528 struct riscv_opcode
*insn
;
2530 const struct percent_op_match
*p
;
2531 struct riscv_ip_error error
;
2532 error
.msg
= "unrecognized opcode";
2533 error
.statement
= str
;
2534 error
.missing_ext
= NULL
;
2535 /* Indicate we are assembling instruction with CSR. */
2536 bool insn_with_csr
= false;
2538 /* Parse the name of the instruction. Terminate the string if whitespace
2539 is found so that str_hash_find only sees the name part of the string. */
2540 for (asarg
= str
; *asarg
!= '\0'; ++asarg
)
2541 if (ISSPACE (*asarg
))
2548 insn
= (struct riscv_opcode
*) str_hash_find (hash
, str
);
2550 probing_insn_operands
= true;
2553 for ( ; insn
&& insn
->name
&& strcmp (insn
->name
, str
) == 0; insn
++)
2555 if ((insn
->xlen_requirement
!= 0) && (xlen
!= insn
->xlen_requirement
))
2558 if (!riscv_multi_subset_supports (&riscv_rps_as
, insn
->insn_class
))
2560 error
.missing_ext
= riscv_multi_subset_supports_ext (&riscv_rps_as
,
2565 /* Reset error message of the previous round. */
2566 error
.msg
= _("illegal operands");
2567 error
.missing_ext
= NULL
;
2569 /* Purge deferred symbols from the previous round, if any. */
2570 while (deferred_sym_rootP
)
2572 symbolS
*sym
= deferred_sym_rootP
;
2574 symbol_remove (sym
, &deferred_sym_rootP
, &deferred_sym_lastP
);
2575 symbol_append (sym
, orphan_sym_lastP
, &orphan_sym_rootP
,
2579 create_insn (ip
, insn
);
2581 imm_expr
->X_op
= O_absent
;
2582 *imm_reloc
= BFD_RELOC_UNUSED
;
2583 p
= percent_op_null
;
2585 for (oparg
= insn
->args
;; ++oparg
)
2588 asarg
+= strspn (asarg
, " \t");
2591 case '\0': /* End of args. */
2592 if (insn
->pinfo
!= INSN_MACRO
)
2594 if (!insn
->match_func (insn
, ip
->insn_opcode
))
2597 /* For .insn, insn->match and insn->mask are 0. */
2598 if (riscv_insn_length ((insn
->match
== 0 && insn
->mask
== 0)
2604 if (riscv_is_priv_insn (ip
->insn_opcode
))
2605 explicit_priv_attr
= true;
2607 /* Check if we write a read-only CSR by the CSR
2610 && riscv_opts
.csr_check
2611 && !riscv_csr_read_only_check (ip
->insn_opcode
))
2613 /* Restore the character in advance, since we want to
2614 report the detailed warning message here. */
2616 *(asargStart
- 1) = save_c
;
2617 as_warn (_("read-only CSR is written `%s'"), str
);
2618 insn_with_csr
= false;
2621 /* The (segmant) load and store with EEW 64 cannot be used
2622 when zve32x is enabled. */
2623 if (ip
->insn_mo
->pinfo
& INSN_V_EEW64
2624 && riscv_subset_supports (&riscv_rps_as
, "zve32x")
2625 && !riscv_subset_supports (&riscv_rps_as
, "zve64x"))
2627 error
.msg
= _("illegal opcode for zve32x");
2634 /* Successful assembly. */
2636 insn_with_csr
= false;
2638 /* Commit deferred symbols, if any. */
2639 while (deferred_sym_rootP
)
2641 symbolS
*sym
= deferred_sym_rootP
;
2643 symbol_remove (sym
, &deferred_sym_rootP
,
2644 &deferred_sym_lastP
);
2645 symbol_append (sym
, symbol_lastP
, &symbol_rootP
,
2647 symbol_table_insert (sym
);
2654 case 's': /* RS1 x8-x15. */
2655 if (!reg_lookup (&asarg
, RCLASS_GPR
, ®no
)
2656 || !(regno
>= 8 && regno
<= 15))
2658 INSERT_OPERAND (CRS1S
, *ip
, regno
% 8);
2660 case 'w': /* RS1 x8-x15, constrained to equal RD x8-x15. */
2661 if (!reg_lookup (&asarg
, RCLASS_GPR
, ®no
)
2662 || EXTRACT_OPERAND (CRS1S
, ip
->insn_opcode
) + 8 != regno
)
2665 case 't': /* RS2 x8-x15. */
2666 if (!reg_lookup (&asarg
, RCLASS_GPR
, ®no
)
2667 || !(regno
>= 8 && regno
<= 15))
2669 INSERT_OPERAND (CRS2S
, *ip
, regno
% 8);
2671 case 'x': /* RS2 x8-x15, constrained to equal RD x8-x15. */
2672 if (!reg_lookup (&asarg
, RCLASS_GPR
, ®no
)
2673 || EXTRACT_OPERAND (CRS2S
, ip
->insn_opcode
) + 8 != regno
)
2676 case 'U': /* RS1, constrained to equal RD. */
2677 if (!reg_lookup (&asarg
, RCLASS_GPR
, ®no
)
2678 || EXTRACT_OPERAND (RD
, ip
->insn_opcode
) != regno
)
2682 if (!reg_lookup (&asarg
, RCLASS_GPR
, ®no
))
2684 INSERT_OPERAND (CRS2
, *ip
, regno
);
2686 case 'c': /* RS1, constrained to equal sp. */
2687 if (!reg_lookup (&asarg
, RCLASS_GPR
, ®no
)
2691 case 'z': /* RS2, constrained to equal x0. */
2692 if (!reg_lookup (&asarg
, RCLASS_GPR
, ®no
)
2696 case '>': /* Shift amount, 0 - (XLEN-1). */
2697 if (my_getSmallExpression (imm_expr
, imm_reloc
, asarg
, p
)
2698 || imm_expr
->X_op
!= O_constant
2699 || (unsigned long) imm_expr
->X_add_number
>= xlen
)
2701 ip
->insn_opcode
|= ENCODE_CITYPE_IMM (imm_expr
->X_add_number
);
2703 asarg
= expr_parse_end
;
2704 imm_expr
->X_op
= O_absent
;
2707 if (my_getSmallExpression (imm_expr
, imm_reloc
, asarg
, p
)
2708 || imm_expr
->X_op
!= O_constant
2709 || imm_expr
->X_add_number
< 0
2710 || imm_expr
->X_add_number
>= 32
2711 || !VALID_CLTYPE_IMM ((valueT
) imm_expr
->X_add_number
))
2713 ip
->insn_opcode
|= ENCODE_CLTYPE_IMM (imm_expr
->X_add_number
);
2716 if (my_getSmallExpression (imm_expr
, imm_reloc
, asarg
, p
)
2717 || imm_expr
->X_op
!= O_constant
2718 || imm_expr
->X_add_number
< 0
2719 || imm_expr
->X_add_number
>= 64
2720 || !VALID_CSSTYPE_IMM ((valueT
) imm_expr
->X_add_number
))
2722 ip
->insn_opcode
|= ENCODE_CSSTYPE_IMM (imm_expr
->X_add_number
);
2725 if (my_getSmallExpression (imm_expr
, imm_reloc
, asarg
, p
)
2726 || imm_expr
->X_op
!= O_constant
2727 || imm_expr
->X_add_number
< 0
2728 || imm_expr
->X_add_number
>= 256
2729 || !VALID_CIWTYPE_IMM ((valueT
) imm_expr
->X_add_number
))
2731 ip
->insn_opcode
|= ENCODE_CIWTYPE_IMM (imm_expr
->X_add_number
);
2734 if (my_getSmallExpression (imm_expr
, imm_reloc
, asarg
, p
)
2735 || imm_expr
->X_op
!= O_constant
2736 || imm_expr
->X_add_number
== 0
2737 || !VALID_CITYPE_IMM ((valueT
) imm_expr
->X_add_number
))
2739 ip
->insn_opcode
|= ENCODE_CITYPE_IMM (imm_expr
->X_add_number
);
2742 if (riscv_handle_implicit_zero_offset (imm_expr
, asarg
))
2744 if (my_getSmallExpression (imm_expr
, imm_reloc
, asarg
, p
)
2745 || imm_expr
->X_op
!= O_constant
2746 || !VALID_CLTYPE_LW_IMM ((valueT
) imm_expr
->X_add_number
))
2748 ip
->insn_opcode
|= ENCODE_CLTYPE_LW_IMM (imm_expr
->X_add_number
);
2751 if (riscv_handle_implicit_zero_offset (imm_expr
, asarg
))
2753 if (my_getSmallExpression (imm_expr
, imm_reloc
, asarg
, p
)
2754 || imm_expr
->X_op
!= O_constant
2755 || !VALID_CLTYPE_LD_IMM ((valueT
) imm_expr
->X_add_number
))
2757 ip
->insn_opcode
|= ENCODE_CLTYPE_LD_IMM (imm_expr
->X_add_number
);
2760 if (riscv_handle_implicit_zero_offset (imm_expr
, asarg
))
2762 if (my_getSmallExpression (imm_expr
, imm_reloc
, asarg
, p
)
2763 || imm_expr
->X_op
!= O_constant
2764 || !VALID_CITYPE_LWSP_IMM ((valueT
) imm_expr
->X_add_number
))
2767 ENCODE_CITYPE_LWSP_IMM (imm_expr
->X_add_number
);
2770 if (riscv_handle_implicit_zero_offset (imm_expr
, asarg
))
2772 if (my_getSmallExpression (imm_expr
, imm_reloc
, asarg
, p
)
2773 || imm_expr
->X_op
!= O_constant
2774 || !VALID_CITYPE_LDSP_IMM ((valueT
) imm_expr
->X_add_number
))
2777 ENCODE_CITYPE_LDSP_IMM (imm_expr
->X_add_number
);
2780 if (my_getSmallExpression (imm_expr
, imm_reloc
, asarg
, p
)
2781 || imm_expr
->X_op
!= O_constant
2782 /* C.addiw, c.li, and c.andi allow zero immediate.
2783 C.addi allows zero immediate as hint. Otherwise this
2785 || !VALID_CITYPE_IMM ((valueT
) imm_expr
->X_add_number
))
2787 ip
->insn_opcode
|= ENCODE_CITYPE_IMM (imm_expr
->X_add_number
);
2790 if (my_getSmallExpression (imm_expr
, imm_reloc
, asarg
, p
)
2791 || imm_expr
->X_op
!= O_constant
2792 || imm_expr
->X_add_number
== 0
2793 || !VALID_CIWTYPE_ADDI4SPN_IMM ((valueT
) imm_expr
->X_add_number
))
2796 ENCODE_CIWTYPE_ADDI4SPN_IMM (imm_expr
->X_add_number
);
2799 if (my_getSmallExpression (imm_expr
, imm_reloc
, asarg
, p
)
2800 || imm_expr
->X_op
!= O_constant
2801 || !VALID_CITYPE_ADDI16SP_IMM ((valueT
) imm_expr
->X_add_number
))
2804 ENCODE_CITYPE_ADDI16SP_IMM (imm_expr
->X_add_number
);
2807 if (riscv_handle_implicit_zero_offset (imm_expr
, asarg
))
2809 if (my_getSmallExpression (imm_expr
, imm_reloc
, asarg
, p
)
2810 || imm_expr
->X_op
!= O_constant
2811 || !VALID_CSSTYPE_SWSP_IMM ((valueT
) imm_expr
->X_add_number
))
2814 ENCODE_CSSTYPE_SWSP_IMM (imm_expr
->X_add_number
);
2817 if (riscv_handle_implicit_zero_offset (imm_expr
, asarg
))
2819 if (my_getSmallExpression (imm_expr
, imm_reloc
, asarg
, p
)
2820 || imm_expr
->X_op
!= O_constant
2821 || !VALID_CSSTYPE_SDSP_IMM ((valueT
) imm_expr
->X_add_number
))
2824 ENCODE_CSSTYPE_SDSP_IMM (imm_expr
->X_add_number
);
2827 p
= percent_op_utype
;
2828 if (my_getSmallExpression (imm_expr
, imm_reloc
, asarg
, p
))
2831 if (imm_expr
->X_op
!= O_constant
2832 || imm_expr
->X_add_number
<= 0
2833 || imm_expr
->X_add_number
>= RISCV_BIGIMM_REACH
2834 || (imm_expr
->X_add_number
>= RISCV_RVC_IMM_REACH
/ 2
2835 && (imm_expr
->X_add_number
<
2836 RISCV_BIGIMM_REACH
- RISCV_RVC_IMM_REACH
/ 2)))
2838 ip
->insn_opcode
|= ENCODE_CITYPE_IMM (imm_expr
->X_add_number
);
2841 if (my_getSmallExpression (imm_expr
, imm_reloc
, asarg
, p
)
2842 || (imm_expr
->X_add_number
& (RISCV_IMM_REACH
- 1))
2843 || ((int32_t)imm_expr
->X_add_number
2844 != imm_expr
->X_add_number
))
2846 imm_expr
->X_add_number
=
2847 ((uint32_t) imm_expr
->X_add_number
) >> RISCV_IMM_BITS
;
2853 case 'S': /* Floating-point RS1 x8-x15. */
2854 if (!reg_lookup (&asarg
, RCLASS_FPR
, ®no
)
2855 || !(regno
>= 8 && regno
<= 15))
2857 INSERT_OPERAND (CRS1S
, *ip
, regno
% 8);
2859 case 'D': /* Floating-point RS2 x8-x15. */
2860 if (!reg_lookup (&asarg
, RCLASS_FPR
, ®no
)
2861 || !(regno
>= 8 && regno
<= 15))
2863 INSERT_OPERAND (CRS2S
, *ip
, regno
% 8);
2865 case 'T': /* Floating-point RS2. */
2866 if (!reg_lookup (&asarg
, RCLASS_FPR
, ®no
))
2868 INSERT_OPERAND (CRS2
, *ip
, regno
);
2874 if (my_getSmallExpression (imm_expr
, imm_reloc
, asarg
, p
)
2875 || imm_expr
->X_op
!= O_constant
2876 || imm_expr
->X_add_number
< 0
2877 || imm_expr
->X_add_number
>= 64)
2879 as_bad (_("bad value for compressed funct6 "
2880 "field, value must be 0...63"));
2883 INSERT_OPERAND (CFUNCT6
, *ip
, imm_expr
->X_add_number
);
2884 imm_expr
->X_op
= O_absent
;
2885 asarg
= expr_parse_end
;
2889 if (my_getSmallExpression (imm_expr
, imm_reloc
, asarg
, p
)
2890 || imm_expr
->X_op
!= O_constant
2891 || imm_expr
->X_add_number
< 0
2892 || imm_expr
->X_add_number
>= 16)
2894 as_bad (_("bad value for compressed funct4 "
2895 "field, value must be 0...15"));
2898 INSERT_OPERAND (CFUNCT4
, *ip
, imm_expr
->X_add_number
);
2899 imm_expr
->X_op
= O_absent
;
2900 asarg
= expr_parse_end
;
2904 if (my_getSmallExpression (imm_expr
, imm_reloc
, asarg
, p
)
2905 || imm_expr
->X_op
!= O_constant
2906 || imm_expr
->X_add_number
< 0
2907 || imm_expr
->X_add_number
>= 8)
2909 as_bad (_("bad value for compressed funct3 "
2910 "field, value must be 0...7"));
2913 INSERT_OPERAND (CFUNCT3
, *ip
, imm_expr
->X_add_number
);
2914 imm_expr
->X_op
= O_absent
;
2915 asarg
= expr_parse_end
;
2919 if (my_getSmallExpression (imm_expr
, imm_reloc
, asarg
, p
)
2920 || imm_expr
->X_op
!= O_constant
2921 || imm_expr
->X_add_number
< 0
2922 || imm_expr
->X_add_number
>= 4)
2924 as_bad (_("bad value for compressed funct2 "
2925 "field, value must be 0...3"));
2928 INSERT_OPERAND (CFUNCT2
, *ip
, imm_expr
->X_add_number
);
2929 imm_expr
->X_op
= O_absent
;
2930 asarg
= expr_parse_end
;
2934 goto unknown_riscv_ip_operand
;
2939 goto unknown_riscv_ip_operand
;
2941 break; /* end RVC */
2947 if (!reg_lookup (&asarg
, RCLASS_VECR
, ®no
))
2949 INSERT_OPERAND (VD
, *ip
, regno
);
2952 case 'e': /* AMO VD */
2953 if (reg_lookup (&asarg
, RCLASS_GPR
, ®no
) && regno
== 0)
2954 INSERT_OPERAND (VWD
, *ip
, 0);
2955 else if (reg_lookup (&asarg
, RCLASS_VECR
, ®no
))
2957 INSERT_OPERAND (VWD
, *ip
, 1);
2958 INSERT_OPERAND (VD
, *ip
, regno
);
2964 case 'f': /* AMO VS3 */
2965 if (!reg_lookup (&asarg
, RCLASS_VECR
, ®no
))
2967 if (!EXTRACT_OPERAND (VWD
, ip
->insn_opcode
))
2968 INSERT_OPERAND (VD
, *ip
, regno
);
2971 /* VS3 must match VD. */
2972 if (EXTRACT_OPERAND (VD
, ip
->insn_opcode
) != regno
)
2978 if (!reg_lookup (&asarg
, RCLASS_VECR
, ®no
))
2980 INSERT_OPERAND (VS1
, *ip
, regno
);
2984 if (!reg_lookup (&asarg
, RCLASS_VECR
, ®no
))
2986 INSERT_OPERAND (VS2
, *ip
, regno
);
2989 case 'u': /* VS1 == VS2 */
2990 if (!reg_lookup (&asarg
, RCLASS_VECR
, ®no
))
2992 INSERT_OPERAND (VS1
, *ip
, regno
);
2993 INSERT_OPERAND (VS2
, *ip
, regno
);
2996 case 'v': /* VD == VS1 == VS2 */
2997 if (!reg_lookup (&asarg
, RCLASS_VECR
, ®no
))
2999 INSERT_OPERAND (VD
, *ip
, regno
);
3000 INSERT_OPERAND (VS1
, *ip
, regno
);
3001 INSERT_OPERAND (VS2
, *ip
, regno
);
3004 /* The `V0` is carry-in register for v[m]adc and v[m]sbc,
3005 and is used to choose vs1/rs1/frs1/imm or vs2 for
3006 v[f]merge. It use the same encoding as the vector mask
3009 if (reg_lookup (&asarg
, RCLASS_VECR
, ®no
) && regno
== 0)
3013 case 'b': /* vtypei for vsetivli */
3014 my_getVsetvliExpression (imm_expr
, asarg
);
3015 check_absolute_expr (ip
, imm_expr
, FALSE
);
3016 if (!VALID_RVV_VB_IMM (imm_expr
->X_add_number
))
3017 as_bad (_("bad value for vsetivli immediate field, "
3018 "value must be 0..1023"));
3020 |= ENCODE_RVV_VB_IMM (imm_expr
->X_add_number
);
3021 imm_expr
->X_op
= O_absent
;
3022 asarg
= expr_parse_end
;
3025 case 'c': /* vtypei for vsetvli */
3026 my_getVsetvliExpression (imm_expr
, asarg
);
3027 check_absolute_expr (ip
, imm_expr
, FALSE
);
3028 if (!VALID_RVV_VC_IMM (imm_expr
->X_add_number
))
3029 as_bad (_("bad value for vsetvli immediate field, "
3030 "value must be 0..2047"));
3032 |= ENCODE_RVV_VC_IMM (imm_expr
->X_add_number
);
3033 imm_expr
->X_op
= O_absent
;
3034 asarg
= expr_parse_end
;
3037 case 'i': /* vector arith signed immediate */
3038 my_getExpression (imm_expr
, asarg
);
3039 check_absolute_expr (ip
, imm_expr
, FALSE
);
3040 if (imm_expr
->X_add_number
> 15
3041 || imm_expr
->X_add_number
< -16)
3042 as_bad (_("bad value for vector immediate field, "
3043 "value must be -16...15"));
3044 INSERT_OPERAND (VIMM
, *ip
, imm_expr
->X_add_number
);
3045 imm_expr
->X_op
= O_absent
;
3046 asarg
= expr_parse_end
;
3049 case 'j': /* vector arith unsigned immediate */
3050 my_getExpression (imm_expr
, asarg
);
3051 check_absolute_expr (ip
, imm_expr
, FALSE
);
3052 if (imm_expr
->X_add_number
< 0
3053 || imm_expr
->X_add_number
>= 32)
3054 as_bad (_("bad value for vector immediate field, "
3055 "value must be 0...31"));
3056 INSERT_OPERAND (VIMM
, *ip
, imm_expr
->X_add_number
);
3057 imm_expr
->X_op
= O_absent
;
3058 asarg
= expr_parse_end
;
3061 case 'k': /* vector arith signed immediate, minus 1 */
3062 my_getExpression (imm_expr
, asarg
);
3063 check_absolute_expr (ip
, imm_expr
, FALSE
);
3064 if (imm_expr
->X_add_number
> 16
3065 || imm_expr
->X_add_number
< -15)
3066 as_bad (_("bad value for vector immediate field, "
3067 "value must be -15...16"));
3068 INSERT_OPERAND (VIMM
, *ip
, imm_expr
->X_add_number
- 1);
3069 imm_expr
->X_op
= O_absent
;
3070 asarg
= expr_parse_end
;
3073 case 'l': /* 6-bit vector arith unsigned immediate */
3074 my_getExpression (imm_expr
, asarg
);
3075 check_absolute_expr (ip
, imm_expr
, FALSE
);
3076 if (imm_expr
->X_add_number
< 0
3077 || imm_expr
->X_add_number
>= 64)
3078 as_bad (_("bad value for vector immediate field, "
3079 "value must be 0...63"));
3080 ip
->insn_opcode
|= ENCODE_RVV_VI_UIMM6 (imm_expr
->X_add_number
);
3081 imm_expr
->X_op
= O_absent
;
3082 asarg
= expr_parse_end
;
3085 case 'm': /* optional vector mask */
3088 INSERT_OPERAND (VMASK
, *ip
, 1);
3091 else if (*asarg
== ',' && asarg
++
3092 && reg_lookup (&asarg
, RCLASS_VECM
, ®no
)
3095 INSERT_OPERAND (VMASK
, *ip
, 0);
3100 case 'M': /* required vector mask */
3101 if (reg_lookup (&asarg
, RCLASS_VECM
, ®no
) && regno
== 0)
3103 INSERT_OPERAND (VMASK
, *ip
, 0);
3108 case 'T': /* vector macro temporary register */
3109 if (!reg_lookup (&asarg
, RCLASS_VECR
, ®no
) || regno
== 0)
3111 /* Store it in the FUNCT6 field as we don't have anyplace
3112 else to store it. */
3113 INSERT_OPERAND (VFUNCT6
, *ip
, regno
);
3117 goto unknown_riscv_ip_operand
;
3119 break; /* end RVV */
3122 if (*asarg
++ == *oparg
)
3131 if (*asarg
++ == *oparg
)
3135 case '<': /* Shift amount, 0 - 31. */
3136 my_getExpression (imm_expr
, asarg
);
3137 check_absolute_expr (ip
, imm_expr
, false);
3138 if ((unsigned long) imm_expr
->X_add_number
> 31)
3139 as_bad (_("improper shift amount (%"PRIu64
")"),
3140 imm_expr
->X_add_number
);
3141 INSERT_OPERAND (SHAMTW
, *ip
, imm_expr
->X_add_number
);
3142 imm_expr
->X_op
= O_absent
;
3143 asarg
= expr_parse_end
;
3146 case '>': /* Shift amount, 0 - (XLEN-1). */
3147 my_getExpression (imm_expr
, asarg
);
3148 check_absolute_expr (ip
, imm_expr
, false);
3149 if ((unsigned long) imm_expr
->X_add_number
>= xlen
)
3150 as_bad (_("improper shift amount (%"PRIu64
")"),
3151 imm_expr
->X_add_number
);
3152 INSERT_OPERAND (SHAMT
, *ip
, imm_expr
->X_add_number
);
3153 imm_expr
->X_op
= O_absent
;
3154 asarg
= expr_parse_end
;
3157 case 'Z': /* CSRRxI immediate. */
3158 my_getExpression (imm_expr
, asarg
);
3159 check_absolute_expr (ip
, imm_expr
, false);
3160 if ((unsigned long) imm_expr
->X_add_number
> 31)
3161 as_bad (_("improper CSRxI immediate (%"PRIu64
")"),
3162 imm_expr
->X_add_number
);
3163 INSERT_OPERAND (RS1
, *ip
, imm_expr
->X_add_number
);
3164 imm_expr
->X_op
= O_absent
;
3165 asarg
= expr_parse_end
;
3168 case 'E': /* Control register. */
3169 insn_with_csr
= true;
3170 explicit_priv_attr
= true;
3171 if (reg_lookup (&asarg
, RCLASS_CSR
, ®no
))
3172 INSERT_OPERAND (CSR
, *ip
, regno
);
3175 my_getExpression (imm_expr
, asarg
);
3176 check_absolute_expr (ip
, imm_expr
, true);
3177 if ((unsigned long) imm_expr
->X_add_number
> 0xfff)
3178 as_bad (_("improper CSR address (%"PRIu64
")"),
3179 imm_expr
->X_add_number
);
3180 INSERT_OPERAND (CSR
, *ip
, imm_expr
->X_add_number
);
3181 imm_expr
->X_op
= O_absent
;
3182 asarg
= expr_parse_end
;
3186 case 'm': /* Rounding mode. */
3187 if (arg_lookup (&asarg
, riscv_rm
,
3188 ARRAY_SIZE (riscv_rm
), ®no
))
3190 INSERT_OPERAND (RM
, *ip
, regno
);
3196 case 'Q': /* Fence predecessor/successor. */
3197 if (arg_lookup (&asarg
, riscv_pred_succ
,
3198 ARRAY_SIZE (riscv_pred_succ
), ®no
))
3201 INSERT_OPERAND (PRED
, *ip
, regno
);
3203 INSERT_OPERAND (SUCC
, *ip
, regno
);
3208 case 'd': /* Destination register. */
3209 case 's': /* Source register. */
3210 case 't': /* Target register. */
3212 if (reg_lookup (&asarg
, RCLASS_GPR
, ®no
))
3218 /* Now that we have assembled one operand, we use the args
3219 string to figure out where it goes in the instruction. */
3223 INSERT_OPERAND (RS1
, *ip
, regno
);
3226 INSERT_OPERAND (RD
, *ip
, regno
);
3229 INSERT_OPERAND (RS2
, *ip
, regno
);
3232 INSERT_OPERAND (RS3
, *ip
, regno
);
3239 case 'D': /* Floating point RD. */
3240 case 'S': /* Floating point RS1. */
3241 case 'T': /* Floating point RS2. */
3242 case 'U': /* Floating point RS1 and RS2. */
3243 case 'R': /* Floating point RS3. */
3244 if (reg_lookup (&asarg
,
3245 (riscv_subset_supports (&riscv_rps_as
, "zfinx")
3246 ? RCLASS_GPR
: RCLASS_FPR
), ®no
))
3254 INSERT_OPERAND (RD
, *ip
, regno
);
3257 INSERT_OPERAND (RS1
, *ip
, regno
);
3260 INSERT_OPERAND (RS1
, *ip
, regno
);
3263 INSERT_OPERAND (RS2
, *ip
, regno
);
3266 INSERT_OPERAND (RS3
, *ip
, regno
);
3274 my_getExpression (imm_expr
, asarg
);
3275 if (imm_expr
->X_op
!= O_big
3276 && imm_expr
->X_op
!= O_constant
)
3278 normalize_constant_expr (imm_expr
);
3279 asarg
= expr_parse_end
;
3283 my_getExpression (imm_expr
, asarg
);
3284 normalize_constant_expr (imm_expr
);
3285 /* The 'A' format specifier must be a symbol. */
3286 if (imm_expr
->X_op
!= O_symbol
)
3288 *imm_reloc
= BFD_RELOC_32
;
3289 asarg
= expr_parse_end
;
3293 my_getExpression (imm_expr
, asarg
);
3294 normalize_constant_expr (imm_expr
);
3295 /* The 'B' format specifier must be a symbol or a constant. */
3296 if (imm_expr
->X_op
!= O_symbol
&& imm_expr
->X_op
!= O_constant
)
3298 if (imm_expr
->X_op
== O_symbol
)
3299 *imm_reloc
= BFD_RELOC_32
;
3300 asarg
= expr_parse_end
;
3303 case 'j': /* Sign-extended immediate. */
3304 p
= percent_op_itype
;
3305 *imm_reloc
= BFD_RELOC_RISCV_LO12_I
;
3307 case 'q': /* Store displacement. */
3308 p
= percent_op_stype
;
3309 *imm_reloc
= BFD_RELOC_RISCV_LO12_S
;
3311 case 'o': /* Load displacement. */
3312 p
= percent_op_itype
;
3313 *imm_reloc
= BFD_RELOC_RISCV_LO12_I
;
3316 /* This is used for TLS, where the fourth operand is
3317 %tprel_add, to get a relocation applied to an add
3318 instruction, for relaxation to use. */
3319 p
= percent_op_rtype
;
3321 case '0': /* AMO displacement, which must be zero. */
3323 if (riscv_handle_implicit_zero_offset (imm_expr
, asarg
))
3326 /* If this value won't fit into a 16 bit offset, then go
3327 find a macro that will generate the 32 bit offset
3329 if (!my_getSmallExpression (imm_expr
, imm_reloc
, asarg
, p
))
3331 normalize_constant_expr (imm_expr
);
3332 if (imm_expr
->X_op
!= O_constant
3333 || (*oparg
== '0' && imm_expr
->X_add_number
!= 0)
3335 || imm_expr
->X_add_number
>= (signed)RISCV_IMM_REACH
/2
3336 || imm_expr
->X_add_number
< -(signed)RISCV_IMM_REACH
/2)
3339 asarg
= expr_parse_end
;
3342 case 'p': /* PC-relative offset. */
3344 *imm_reloc
= BFD_RELOC_12_PCREL
;
3345 my_getExpression (imm_expr
, asarg
);
3346 asarg
= expr_parse_end
;
3349 case 'u': /* Upper 20 bits. */
3350 p
= percent_op_utype
;
3351 if (!my_getSmallExpression (imm_expr
, imm_reloc
, asarg
, p
))
3353 if (imm_expr
->X_op
!= O_constant
)
3356 if (imm_expr
->X_add_number
< 0
3357 || imm_expr
->X_add_number
>= (signed)RISCV_BIGIMM_REACH
)
3358 as_bad (_("lui expression not in range 0..1048575"));
3360 *imm_reloc
= BFD_RELOC_RISCV_HI20
;
3361 imm_expr
->X_add_number
<<= RISCV_IMM_BITS
;
3363 asarg
= expr_parse_end
;
3366 case 'a': /* 20-bit PC-relative offset. */
3368 my_getExpression (imm_expr
, asarg
);
3369 asarg
= expr_parse_end
;
3370 *imm_reloc
= BFD_RELOC_RISCV_JMP
;
3374 my_getExpression (imm_expr
, asarg
);
3375 asarg
= expr_parse_end
;
3376 if (strcmp (asarg
, "@plt") == 0)
3378 *imm_reloc
= BFD_RELOC_RISCV_CALL_PLT
;
3385 if (my_getOpcodeExpression (imm_expr
, imm_reloc
, asarg
)
3386 || imm_expr
->X_op
!= O_constant
3387 || imm_expr
->X_add_number
< 0
3388 || imm_expr
->X_add_number
>= 128
3389 || (imm_expr
->X_add_number
& 0x3) != 3)
3391 as_bad (_("bad value for opcode field, "
3392 "value must be 0...127 and "
3393 "lower 2 bits must be 0x3"));
3396 INSERT_OPERAND (OP
, *ip
, imm_expr
->X_add_number
);
3397 imm_expr
->X_op
= O_absent
;
3398 asarg
= expr_parse_end
;
3402 if (my_getOpcodeExpression (imm_expr
, imm_reloc
, asarg
)
3403 || imm_expr
->X_op
!= O_constant
3404 || imm_expr
->X_add_number
< 0
3405 || imm_expr
->X_add_number
>= 3)
3407 as_bad (_("bad value for opcode field, "
3408 "value must be 0...2"));
3411 INSERT_OPERAND (OP2
, *ip
, imm_expr
->X_add_number
);
3412 imm_expr
->X_op
= O_absent
;
3413 asarg
= expr_parse_end
;
3417 goto unknown_riscv_ip_operand
;
3425 if (my_getSmallExpression (imm_expr
, imm_reloc
, asarg
, p
)
3426 || imm_expr
->X_op
!= O_constant
3427 || imm_expr
->X_add_number
< 0
3428 || imm_expr
->X_add_number
>= 128)
3430 as_bad (_("bad value for funct7 field, "
3431 "value must be 0...127"));
3434 INSERT_OPERAND (FUNCT7
, *ip
, imm_expr
->X_add_number
);
3435 imm_expr
->X_op
= O_absent
;
3436 asarg
= expr_parse_end
;
3440 if (my_getSmallExpression (imm_expr
, imm_reloc
, asarg
, p
)
3441 || imm_expr
->X_op
!= O_constant
3442 || imm_expr
->X_add_number
< 0
3443 || imm_expr
->X_add_number
>= 8)
3445 as_bad (_("bad value for funct3 field, "
3446 "value must be 0...7"));
3449 INSERT_OPERAND (FUNCT3
, *ip
, imm_expr
->X_add_number
);
3450 imm_expr
->X_op
= O_absent
;
3451 asarg
= expr_parse_end
;
3455 if (my_getSmallExpression (imm_expr
, imm_reloc
, asarg
, p
)
3456 || imm_expr
->X_op
!= O_constant
3457 || imm_expr
->X_add_number
< 0
3458 || imm_expr
->X_add_number
>= 4)
3460 as_bad (_("bad value for funct2 field, "
3461 "value must be 0...3"));
3464 INSERT_OPERAND (FUNCT2
, *ip
, imm_expr
->X_add_number
);
3465 imm_expr
->X_op
= O_absent
;
3466 asarg
= expr_parse_end
;
3470 goto unknown_riscv_ip_operand
;
3474 case 'y': /* bs immediate */
3475 my_getExpression (imm_expr
, asarg
);
3476 check_absolute_expr (ip
, imm_expr
, FALSE
);
3477 if ((unsigned long)imm_expr
->X_add_number
> 3)
3478 as_bad(_("Improper bs immediate (%lu)"),
3479 (unsigned long)imm_expr
->X_add_number
);
3480 INSERT_OPERAND(BS
, *ip
, imm_expr
->X_add_number
);
3481 imm_expr
->X_op
= O_absent
;
3482 asarg
= expr_parse_end
;
3485 case 'Y': /* rnum immediate */
3486 my_getExpression (imm_expr
, asarg
);
3487 check_absolute_expr (ip
, imm_expr
, FALSE
);
3488 if ((unsigned long)imm_expr
->X_add_number
> 10)
3489 as_bad(_("Improper rnum immediate (%lu)"),
3490 (unsigned long)imm_expr
->X_add_number
);
3491 INSERT_OPERAND(RNUM
, *ip
, imm_expr
->X_add_number
);
3492 imm_expr
->X_op
= O_absent
;
3493 asarg
= expr_parse_end
;
3497 if (my_getSmallExpression (imm_expr
, imm_reloc
, asarg
, p
)
3498 || imm_expr
->X_op
!= O_constant
3499 || imm_expr
->X_add_number
!= 0)
3501 asarg
= expr_parse_end
;
3502 imm_expr
->X_op
= O_absent
;
3505 case 'W': /* Various operands. */
3512 /* Prefetch offset for 'Zicbop' extension.
3513 pseudo S-type but lower 5-bits zero. */
3514 if (riscv_handle_implicit_zero_offset (imm_expr
, asarg
))
3516 my_getExpression (imm_expr
, asarg
);
3517 check_absolute_expr (ip
, imm_expr
, false);
3518 if (((unsigned) (imm_expr
->X_add_number
) & 0x1fU
)
3519 || imm_expr
->X_add_number
>= RISCV_IMM_REACH
/ 2
3520 || imm_expr
->X_add_number
< -RISCV_IMM_REACH
/ 2)
3521 as_bad (_ ("improper prefetch offset (%ld)"),
3522 (long) imm_expr
->X_add_number
);
3523 ip
->insn_opcode
|= ENCODE_STYPE_IMM (
3524 (unsigned) (imm_expr
->X_add_number
) & ~0x1fU
);
3525 imm_expr
->X_op
= O_absent
;
3526 asarg
= expr_parse_end
;
3529 goto unknown_riscv_ip_operand
;
3536 /* FLI.[HSDQ] value field for 'Zfa' extension. */
3537 if (!arg_lookup (&asarg
, riscv_fli_symval
,
3538 ARRAY_SIZE (riscv_fli_symval
), ®no
))
3540 /* 0.0 is not a valid entry in riscv_fli_numval. */
3542 float f
= strtof (asarg
, &asarg
);
3543 if (errno
!= 0 || f
== 0.0
3544 || !flt_lookup (f
, riscv_fli_numval
,
3545 ARRAY_SIZE(riscv_fli_numval
),
3548 as_bad (_("bad fli constant operand, "
3549 "supported constants must be in "
3550 "decimal or hexadecimal floating-point "
3555 INSERT_OPERAND (RS1
, *ip
, regno
);
3558 goto unknown_riscv_ip_operand
;
3562 goto unknown_riscv_ip_operand
;
3566 case 'X': /* Integer immediate. */
3574 case 'l': /* Literal. */
3575 n
= strcspn (++oparg
, ",");
3576 if (strncmp (oparg
, asarg
, n
))
3577 as_bad (_("unexpected literal (%s)"), asarg
);
3581 case 's': /* 'XsN@S' ... N-bit signed immediate at bit S. */
3584 case 'u': /* 'XuN@S' ... N-bit unsigned immediate at bit S. */
3588 n
= strtol (oparg
+ 1, (char **)&oparg
, 10);
3590 goto unknown_riscv_ip_operand
;
3591 s
= strtol (oparg
+ 1, (char **)&oparg
, 10);
3594 my_getExpression (imm_expr
, asarg
);
3595 check_absolute_expr (ip
, imm_expr
, false);
3598 if (!VALIDATE_U_IMM (imm_expr
->X_add_number
, n
))
3599 as_bad (_("improper immediate value (%"PRIu64
")"),
3600 imm_expr
->X_add_number
);
3604 if (!VALIDATE_S_IMM (imm_expr
->X_add_number
, n
))
3605 as_bad (_("improper immediate value (%"PRIi64
")"),
3606 imm_expr
->X_add_number
);
3608 INSERT_IMM (n
, s
, *ip
, imm_expr
->X_add_number
);
3609 imm_expr
->X_op
= O_absent
;
3610 asarg
= expr_parse_end
;
3613 goto unknown_riscv_ip_operand
;
3619 unknown_riscv_ip_operand
:
3620 as_fatal (_("internal: unknown argument type `%s'"),
3626 insn_with_csr
= false;
3630 /* Restore the character we might have clobbered above. */
3632 *(asargStart
- 1) = save_c
;
3634 probing_insn_operands
= false;
3639 /* Similar to riscv_ip, but assembles an instruction according to the
3640 hardcode values of .insn directive. */
3643 riscv_ip_hardcode (char *str
,
3644 struct riscv_cl_insn
*ip
,
3645 expressionS
*imm_expr
,
3648 struct riscv_opcode
*insn
;
3649 insn_t values
[2] = {0, 0};
3650 unsigned int num
= 0;
3652 input_line_pointer
= str
;
3655 expression (imm_expr
);
3656 switch (imm_expr
->X_op
)
3659 values
[num
++] = (insn_t
) imm_expr
->X_add_number
;
3662 /* Extract lower 32-bits of a big number.
3663 Assume that generic_bignum_to_int32 work on such number. */
3664 values
[num
++] = (insn_t
) generic_bignum_to_int32 ();
3667 /* The first value isn't constant, so it should be
3668 .insn <type> <operands>. We have been parsed it
3672 return _("values must be constant");
3675 while (*input_line_pointer
++ == ',' && num
< 2 && imm_expr
->X_op
!= O_big
);
3677 input_line_pointer
--;
3678 if (*input_line_pointer
!= '\0')
3679 return _("unrecognized values");
3681 insn
= XNEW (struct riscv_opcode
);
3682 insn
->match
= values
[num
- 1];
3683 create_insn (ip
, insn
);
3684 unsigned int bytes
= riscv_insn_length (insn
->match
);
3686 if (num
== 2 && values
[0] != bytes
)
3687 return _("value conflicts with instruction length");
3689 if (imm_expr
->X_op
== O_big
)
3691 unsigned int llen
= 0;
3692 for (LITTLENUM_TYPE lval
= generic_bignum
[imm_expr
->X_add_number
- 1];
3694 lval
>>= BITS_PER_CHAR
;
3695 unsigned int repr_bytes
3696 = (imm_expr
->X_add_number
- 1) * CHARS_PER_LITTLENUM
+ llen
;
3697 if (bytes
< repr_bytes
)
3698 return _("value conflicts with instruction length");
3699 for (num
= 0; num
< imm_expr
->X_add_number
- 1; ++num
)
3700 number_to_chars_littleendian (
3701 ip
->insn_long_opcode
+ num
* CHARS_PER_LITTLENUM
,
3702 generic_bignum
[num
],
3703 CHARS_PER_LITTLENUM
);
3705 number_to_chars_littleendian (
3706 ip
->insn_long_opcode
+ num
* CHARS_PER_LITTLENUM
,
3707 generic_bignum
[num
],
3709 memset(ip
->insn_long_opcode
+ repr_bytes
, 0, bytes
- repr_bytes
);
3713 if (bytes
< sizeof(values
[0]) && values
[num
- 1] >> (8 * bytes
) != 0)
3714 return _("value conflicts with instruction length");
3720 md_assemble (char *str
)
3722 struct riscv_cl_insn insn
;
3723 expressionS imm_expr
;
3724 bfd_reloc_code_real_type imm_reloc
= BFD_RELOC_UNUSED
;
3726 /* The architecture and privileged elf attributes should be set
3727 before assembling. */
3728 if (!start_assemble
)
3730 start_assemble
= true;
3732 riscv_set_abi_by_arch ();
3733 if (!riscv_set_default_priv_spec (NULL
))
3737 riscv_mapping_state (MAP_INSN
, 0, false/* fr_align_code */);
3739 const struct riscv_ip_error error
= riscv_ip (str
, &insn
, &imm_expr
,
3740 &imm_reloc
, op_hash
);
3744 if (error
.missing_ext
)
3745 as_bad ("%s `%s', extension `%s' required", error
.msg
,
3746 error
.statement
, error
.missing_ext
);
3748 as_bad ("%s `%s'", error
.msg
, error
.statement
);
3752 if (insn
.insn_mo
->pinfo
== INSN_MACRO
)
3753 macro (&insn
, &imm_expr
, &imm_reloc
);
3755 append_insn (&insn
, &imm_expr
, imm_reloc
);
3759 md_atof (int type
, char *litP
, int *sizeP
)
3761 return ieee_md_atof (type
, litP
, sizeP
, target_big_endian
);
3765 md_number_to_chars (char *buf
, valueT val
, int n
)
3767 if (target_big_endian
)
3768 number_to_chars_bigendian (buf
, val
, n
);
3770 number_to_chars_littleendian (buf
, val
, n
);
3773 const char *md_shortopts
= "O::g::G:";
3777 OPTION_MARCH
= OPTION_MD_BASE
,
3784 OPTION_NO_ARCH_ATTR
,
3786 OPTION_NO_CSR_CHECK
,
3790 OPTION_LITTLE_ENDIAN
,
3794 struct option md_longopts
[] =
3796 {"march", required_argument
, NULL
, OPTION_MARCH
},
3797 {"fPIC", no_argument
, NULL
, OPTION_PIC
},
3798 {"fpic", no_argument
, NULL
, OPTION_PIC
},
3799 {"fno-pic", no_argument
, NULL
, OPTION_NO_PIC
},
3800 {"mabi", required_argument
, NULL
, OPTION_MABI
},
3801 {"mrelax", no_argument
, NULL
, OPTION_RELAX
},
3802 {"mno-relax", no_argument
, NULL
, OPTION_NO_RELAX
},
3803 {"march-attr", no_argument
, NULL
, OPTION_ARCH_ATTR
},
3804 {"mno-arch-attr", no_argument
, NULL
, OPTION_NO_ARCH_ATTR
},
3805 {"mcsr-check", no_argument
, NULL
, OPTION_CSR_CHECK
},
3806 {"mno-csr-check", no_argument
, NULL
, OPTION_NO_CSR_CHECK
},
3807 {"misa-spec", required_argument
, NULL
, OPTION_MISA_SPEC
},
3808 {"mpriv-spec", required_argument
, NULL
, OPTION_MPRIV_SPEC
},
3809 {"mbig-endian", no_argument
, NULL
, OPTION_BIG_ENDIAN
},
3810 {"mlittle-endian", no_argument
, NULL
, OPTION_LITTLE_ENDIAN
},
3812 {NULL
, no_argument
, NULL
, 0}
3814 size_t md_longopts_size
= sizeof (md_longopts
);
3817 md_parse_option (int c
, const char *arg
)
3822 default_arch_with_ext
= arg
;
3826 riscv_opts
.pic
= false;
3830 riscv_opts
.pic
= true;
3834 if (strcmp (arg
, "ilp32") == 0)
3835 riscv_set_abi (32, FLOAT_ABI_SOFT
, false);
3836 else if (strcmp (arg
, "ilp32e") == 0)
3837 riscv_set_abi (32, FLOAT_ABI_SOFT
, true);
3838 else if (strcmp (arg
, "ilp32f") == 0)
3839 riscv_set_abi (32, FLOAT_ABI_SINGLE
, false);
3840 else if (strcmp (arg
, "ilp32d") == 0)
3841 riscv_set_abi (32, FLOAT_ABI_DOUBLE
, false);
3842 else if (strcmp (arg
, "ilp32q") == 0)
3843 riscv_set_abi (32, FLOAT_ABI_QUAD
, false);
3844 else if (strcmp (arg
, "lp64") == 0)
3845 riscv_set_abi (64, FLOAT_ABI_SOFT
, false);
3846 else if (strcmp (arg
, "lp64f") == 0)
3847 riscv_set_abi (64, FLOAT_ABI_SINGLE
, false);
3848 else if (strcmp (arg
, "lp64d") == 0)
3849 riscv_set_abi (64, FLOAT_ABI_DOUBLE
, false);
3850 else if (strcmp (arg
, "lp64q") == 0)
3851 riscv_set_abi (64, FLOAT_ABI_QUAD
, false);
3854 explicit_mabi
= true;
3858 riscv_opts
.relax
= true;
3861 case OPTION_NO_RELAX
:
3862 riscv_opts
.relax
= false;
3865 case OPTION_ARCH_ATTR
:
3866 riscv_opts
.arch_attr
= true;
3869 case OPTION_NO_ARCH_ATTR
:
3870 riscv_opts
.arch_attr
= false;
3873 case OPTION_CSR_CHECK
:
3874 riscv_opts
.csr_check
= true;
3877 case OPTION_NO_CSR_CHECK
:
3878 riscv_opts
.csr_check
= false;
3881 case OPTION_MISA_SPEC
:
3882 return riscv_set_default_isa_spec (arg
);
3884 case OPTION_MPRIV_SPEC
:
3885 return riscv_set_default_priv_spec (arg
);
3887 case OPTION_BIG_ENDIAN
:
3888 target_big_endian
= 1;
3891 case OPTION_LITTLE_ENDIAN
:
3892 target_big_endian
= 0;
3903 riscv_after_parse_args (void)
3905 /* The --with-arch is optional for now, so we still need to set the xlen
3906 according to the default_arch, which is set by the --target. */
3909 if (strcmp (default_arch
, "riscv32") == 0)
3911 else if (strcmp (default_arch
, "riscv64") == 0)
3914 as_bad ("unknown default architecture `%s'", default_arch
);
3917 /* Set default specs. */
3918 if (default_isa_spec
== ISA_SPEC_CLASS_NONE
)
3919 riscv_set_default_isa_spec (DEFAULT_RISCV_ISA_SPEC
);
3920 if (default_priv_spec
== PRIV_SPEC_CLASS_NONE
)
3921 riscv_set_default_priv_spec (DEFAULT_RISCV_PRIV_SPEC
);
3923 riscv_set_arch (default_arch_with_ext
);
3925 /* If the CIE to be produced has not been overridden on the command line,
3926 then produce version 3 by default. This allows us to use the full
3927 range of registers in a .cfi_return_column directive. */
3928 if (flag_dwarf_cie_version
== -1)
3929 flag_dwarf_cie_version
= 3;
3932 bool riscv_parse_name (const char *name
, struct expressionS
*ep
,
3933 enum expr_mode mode
)
3938 if (!probing_insn_operands
)
3941 gas_assert (mode
== expr_normal
);
3943 regno
= reg_lookup_internal (name
, RCLASS_GPR
);
3944 if (regno
== (unsigned int)-1)
3947 if (symbol_find (name
) != NULL
)
3950 /* Create a symbol without adding it to the symbol table yet.
3951 Insertion will happen only once we commit to using the insn
3952 we're probing operands for. */
3953 for (sym
= deferred_sym_rootP
; sym
; sym
= symbol_next (sym
))
3954 if (strcmp (name
, S_GET_NAME (sym
)) == 0)
3958 for (sym
= orphan_sym_rootP
; sym
; sym
= symbol_next (sym
))
3959 if (strcmp (name
, S_GET_NAME (sym
)) == 0)
3961 symbol_remove (sym
, &orphan_sym_rootP
, &orphan_sym_lastP
);
3965 sym
= symbol_create (name
, undefined_section
,
3966 &zero_address_frag
, 0);
3968 symbol_append (sym
, deferred_sym_lastP
, &deferred_sym_rootP
,
3969 &deferred_sym_lastP
);
3972 ep
->X_op
= O_symbol
;
3973 ep
->X_add_symbol
= sym
;
3974 ep
->X_add_number
= 0;
3980 md_pcrel_from (fixS
*fixP
)
3982 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
3985 /* Apply a fixup to the object file. */
3988 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
3990 unsigned int subtype
;
3991 bfd_byte
*buf
= (bfd_byte
*) (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
);
3992 bool relaxable
= false;
3996 /* Remember value for tc_gen_reloc. */
3997 fixP
->fx_addnumber
= *valP
;
3999 switch (fixP
->fx_r_type
)
4001 case BFD_RELOC_RISCV_HI20
:
4002 case BFD_RELOC_RISCV_LO12_I
:
4003 case BFD_RELOC_RISCV_LO12_S
:
4004 bfd_putl32 (riscv_apply_const_reloc (fixP
->fx_r_type
, *valP
)
4005 | bfd_getl32 (buf
), buf
);
4006 if (fixP
->fx_addsy
== NULL
)
4007 fixP
->fx_done
= true;
4011 case BFD_RELOC_RISCV_GOT_HI20
:
4012 case BFD_RELOC_RISCV_ADD8
:
4013 case BFD_RELOC_RISCV_ADD16
:
4014 case BFD_RELOC_RISCV_ADD32
:
4015 case BFD_RELOC_RISCV_ADD64
:
4016 case BFD_RELOC_RISCV_SUB6
:
4017 case BFD_RELOC_RISCV_SUB8
:
4018 case BFD_RELOC_RISCV_SUB16
:
4019 case BFD_RELOC_RISCV_SUB32
:
4020 case BFD_RELOC_RISCV_SUB64
:
4021 case BFD_RELOC_RISCV_RELAX
:
4022 /* cvt_frag_to_fill () has called output_leb128 (). */
4023 case BFD_RELOC_RISCV_SET_ULEB128
:
4024 case BFD_RELOC_RISCV_SUB_ULEB128
:
4027 case BFD_RELOC_RISCV_TPREL_HI20
:
4028 case BFD_RELOC_RISCV_TPREL_LO12_I
:
4029 case BFD_RELOC_RISCV_TPREL_LO12_S
:
4030 case BFD_RELOC_RISCV_TPREL_ADD
:
4034 case BFD_RELOC_RISCV_TLS_GOT_HI20
:
4035 case BFD_RELOC_RISCV_TLS_GD_HI20
:
4036 case BFD_RELOC_RISCV_TLS_DTPREL32
:
4037 case BFD_RELOC_RISCV_TLS_DTPREL64
:
4038 if (fixP
->fx_addsy
!= NULL
)
4039 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
4041 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4042 _("TLS relocation against a constant"));
4046 /* Use pc-relative relocation for FDE initial location.
4047 The symbol address in .eh_frame may be adjusted in
4048 _bfd_elf_discard_section_eh_frame, and the content of
4049 .eh_frame will be adjusted in _bfd_elf_write_section_eh_frame.
4050 Therefore, we cannot insert a relocation whose addend symbol is
4051 in .eh_frame. Othrewise, the value may be adjusted twice. */
4052 if (fixP
->fx_addsy
&& fixP
->fx_subsy
4053 && (sub_segment
= S_GET_SEGMENT (fixP
->fx_subsy
))
4054 && strcmp (sub_segment
->name
, ".eh_frame") == 0
4055 && S_GET_VALUE (fixP
->fx_subsy
)
4056 == fixP
->fx_frag
->fr_address
+ fixP
->fx_where
)
4058 fixP
->fx_r_type
= BFD_RELOC_RISCV_32_PCREL
;
4059 fixP
->fx_subsy
= NULL
;
4066 case BFD_RELOC_RISCV_CFA
:
4067 if (fixP
->fx_addsy
&& fixP
->fx_subsy
)
4069 fixP
->fx_next
= xmemdup (fixP
, sizeof (*fixP
), sizeof (*fixP
));
4070 fixP
->fx_next
->fx_addsy
= fixP
->fx_subsy
;
4071 fixP
->fx_next
->fx_subsy
= NULL
;
4072 fixP
->fx_next
->fx_offset
= 0;
4073 fixP
->fx_subsy
= NULL
;
4075 switch (fixP
->fx_r_type
)
4078 fixP
->fx_r_type
= BFD_RELOC_RISCV_ADD64
;
4079 fixP
->fx_next
->fx_r_type
= BFD_RELOC_RISCV_SUB64
;
4083 fixP
->fx_r_type
= BFD_RELOC_RISCV_ADD32
;
4084 fixP
->fx_next
->fx_r_type
= BFD_RELOC_RISCV_SUB32
;
4088 fixP
->fx_r_type
= BFD_RELOC_RISCV_ADD16
;
4089 fixP
->fx_next
->fx_r_type
= BFD_RELOC_RISCV_SUB16
;
4093 fixP
->fx_r_type
= BFD_RELOC_RISCV_ADD8
;
4094 fixP
->fx_next
->fx_r_type
= BFD_RELOC_RISCV_SUB8
;
4097 case BFD_RELOC_RISCV_CFA
:
4098 /* Load the byte to get the subtype. */
4099 subtype
= bfd_get_8 (NULL
, &((fragS
*) (fixP
->fx_frag
->fr_opcode
))->fr_literal
[fixP
->fx_where
]);
4100 loc
= fixP
->fx_frag
->fr_fix
- (subtype
& 7);
4103 case DW_CFA_advance_loc1
:
4104 fixP
->fx_where
= loc
+ 1;
4105 fixP
->fx_next
->fx_where
= loc
+ 1;
4106 fixP
->fx_r_type
= BFD_RELOC_RISCV_SET8
;
4107 fixP
->fx_next
->fx_r_type
= BFD_RELOC_RISCV_SUB8
;
4110 case DW_CFA_advance_loc2
:
4112 fixP
->fx_next
->fx_size
= 2;
4113 fixP
->fx_where
= loc
+ 1;
4114 fixP
->fx_next
->fx_where
= loc
+ 1;
4115 fixP
->fx_r_type
= BFD_RELOC_RISCV_SET16
;
4116 fixP
->fx_next
->fx_r_type
= BFD_RELOC_RISCV_SUB16
;
4119 case DW_CFA_advance_loc4
:
4121 fixP
->fx_next
->fx_size
= 4;
4122 fixP
->fx_where
= loc
;
4123 fixP
->fx_next
->fx_where
= loc
;
4124 fixP
->fx_r_type
= BFD_RELOC_RISCV_SET32
;
4125 fixP
->fx_next
->fx_r_type
= BFD_RELOC_RISCV_SUB32
;
4129 if (subtype
< 0x80 && (subtype
& 0x40))
4131 /* DW_CFA_advance_loc */
4132 fixP
->fx_frag
= (fragS
*) fixP
->fx_frag
->fr_opcode
;
4133 fixP
->fx_next
->fx_frag
= fixP
->fx_frag
;
4134 fixP
->fx_r_type
= BFD_RELOC_RISCV_SET6
;
4135 fixP
->fx_next
->fx_r_type
= BFD_RELOC_RISCV_SUB6
;
4138 as_fatal (_("internal: bad CFA value #%d"), subtype
);
4144 /* This case is unreachable. */
4151 /* If we are deleting this reloc entry, we must fill in the
4152 value now. This can happen if we have a .word which is not
4153 resolved when it appears but is later defined. */
4154 if (fixP
->fx_addsy
== NULL
)
4156 gas_assert (fixP
->fx_size
<= sizeof (valueT
));
4157 md_number_to_chars ((char *) buf
, *valP
, fixP
->fx_size
);
4162 case BFD_RELOC_RISCV_JMP
:
4165 /* Fill in a tentative value to improve objdump readability. */
4166 bfd_vma target
= S_GET_VALUE (fixP
->fx_addsy
) + *valP
;
4167 bfd_vma delta
= target
- md_pcrel_from (fixP
);
4168 bfd_putl32 (bfd_getl32 (buf
) | ENCODE_JTYPE_IMM (delta
), buf
);
4172 case BFD_RELOC_12_PCREL
:
4175 /* Fill in a tentative value to improve objdump readability. */
4176 bfd_vma target
= S_GET_VALUE (fixP
->fx_addsy
) + *valP
;
4177 bfd_vma delta
= target
- md_pcrel_from (fixP
);
4178 bfd_putl32 (bfd_getl32 (buf
) | ENCODE_BTYPE_IMM (delta
), buf
);
4182 case BFD_RELOC_RISCV_RVC_BRANCH
:
4185 /* Fill in a tentative value to improve objdump readability. */
4186 bfd_vma target
= S_GET_VALUE (fixP
->fx_addsy
) + *valP
;
4187 bfd_vma delta
= target
- md_pcrel_from (fixP
);
4188 bfd_putl16 (bfd_getl16 (buf
) | ENCODE_CBTYPE_IMM (delta
), buf
);
4192 case BFD_RELOC_RISCV_RVC_JUMP
:
4195 /* Fill in a tentative value to improve objdump readability. */
4196 bfd_vma target
= S_GET_VALUE (fixP
->fx_addsy
) + *valP
;
4197 bfd_vma delta
= target
- md_pcrel_from (fixP
);
4198 bfd_putl16 (bfd_getl16 (buf
) | ENCODE_CJTYPE_IMM (delta
), buf
);
4202 case BFD_RELOC_RISCV_CALL
:
4203 case BFD_RELOC_RISCV_CALL_PLT
:
4207 case BFD_RELOC_RISCV_PCREL_HI20
:
4208 case BFD_RELOC_RISCV_PCREL_LO12_S
:
4209 case BFD_RELOC_RISCV_PCREL_LO12_I
:
4210 relaxable
= riscv_opts
.relax
;
4213 case BFD_RELOC_RISCV_ALIGN
:
4217 /* We ignore generic BFD relocations we don't know about. */
4218 if (bfd_reloc_type_lookup (stdoutput
, fixP
->fx_r_type
) != NULL
)
4219 as_fatal (_("internal: bad relocation #%d"), fixP
->fx_r_type
);
4222 if (fixP
->fx_subsy
!= NULL
)
4223 as_bad_subtract (fixP
);
4225 /* Add an R_RISCV_RELAX reloc if the reloc is relaxable. */
4226 if (relaxable
&& fixP
->fx_tcbit
&& fixP
->fx_addsy
!= NULL
)
4228 fixP
->fx_next
= xmemdup (fixP
, sizeof (*fixP
), sizeof (*fixP
));
4229 fixP
->fx_next
->fx_addsy
= fixP
->fx_next
->fx_subsy
= NULL
;
4230 fixP
->fx_next
->fx_r_type
= BFD_RELOC_RISCV_RELAX
;
4231 fixP
->fx_next
->fx_size
= 0;
4235 /* Because the value of .cfi_remember_state may changed after relaxation,
4236 we insert a fix to relocate it again in link-time. */
4239 riscv_pre_output_hook (void)
4241 const frchainS
*frch
;
4244 /* Save the current segment info. */
4246 subsegT subseg
= now_subseg
;
4248 for (s
= stdoutput
->sections
; s
; s
= s
->next
)
4249 for (frch
= seg_info (s
)->frchainP
; frch
; frch
= frch
->frch_next
)
4253 for (frag
= frch
->frch_root
; frag
; frag
= frag
->fr_next
)
4255 if (frag
->fr_type
== rs_cfa
)
4258 expressionS
*symval
;
4260 symval
= symbol_get_value_expression (frag
->fr_symbol
);
4261 exp
.X_op
= O_subtract
;
4262 exp
.X_add_symbol
= symval
->X_add_symbol
;
4263 exp
.X_add_number
= 0;
4264 exp
.X_op_symbol
= symval
->X_op_symbol
;
4266 /* We must set the segment before creating a frag after all
4267 frag chains have been chained together. */
4268 subseg_set (s
, frch
->frch_subseg
);
4270 fix_new_exp (frag
, (int) frag
->fr_offset
, 1, &exp
, 0,
4271 BFD_RELOC_RISCV_CFA
);
4276 /* Restore the original segment info. */
4277 subseg_set (seg
, subseg
);
4280 /* Handle the .option pseudo-op. */
4283 s_riscv_option (int x ATTRIBUTE_UNUSED
)
4285 char *name
= input_line_pointer
, ch
;
4287 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
4288 ++input_line_pointer
;
4289 ch
= *input_line_pointer
;
4290 *input_line_pointer
= '\0';
4292 if (strcmp (name
, "rvc") == 0)
4294 riscv_update_subset (&riscv_rps_as
, "+c");
4295 riscv_reset_subsets_list_arch_str ();
4296 riscv_set_rvc (true);
4298 else if (strcmp (name
, "norvc") == 0)
4300 riscv_update_subset (&riscv_rps_as
, "-c");
4301 riscv_reset_subsets_list_arch_str ();
4302 riscv_set_rvc (false);
4304 else if (strcmp (name
, "pic") == 0)
4305 riscv_opts
.pic
= true;
4306 else if (strcmp (name
, "nopic") == 0)
4307 riscv_opts
.pic
= false;
4308 else if (strcmp (name
, "relax") == 0)
4309 riscv_opts
.relax
= true;
4310 else if (strcmp (name
, "norelax") == 0)
4311 riscv_opts
.relax
= false;
4312 else if (strcmp (name
, "csr-check") == 0)
4313 riscv_opts
.csr_check
= true;
4314 else if (strcmp (name
, "no-csr-check") == 0)
4315 riscv_opts
.csr_check
= false;
4316 else if (strncmp (name
, "arch,", 5) == 0)
4319 if (ISSPACE (*name
) && *name
!= '\0')
4321 riscv_update_subset (&riscv_rps_as
, name
);
4322 riscv_reset_subsets_list_arch_str ();
4324 riscv_set_rvc (false);
4325 if (riscv_subset_supports (&riscv_rps_as
, "c"))
4326 riscv_set_rvc (true);
4328 if (riscv_subset_supports (&riscv_rps_as
, "ztso"))
4331 else if (strcmp (name
, "push") == 0)
4333 struct riscv_option_stack
*s
;
4335 s
= XNEW (struct riscv_option_stack
);
4336 s
->next
= riscv_opts_stack
;
4337 s
->options
= riscv_opts
;
4338 s
->subset_list
= riscv_rps_as
.subset_list
;
4339 riscv_opts_stack
= s
;
4340 riscv_rps_as
.subset_list
= riscv_copy_subset_list (s
->subset_list
);
4342 else if (strcmp (name
, "pop") == 0)
4344 struct riscv_option_stack
*s
;
4346 s
= riscv_opts_stack
;
4348 as_bad (_(".option pop with no .option push"));
4351 riscv_subset_list_t
*release_subsets
= riscv_rps_as
.subset_list
;
4352 riscv_opts_stack
= s
->next
;
4353 riscv_opts
= s
->options
;
4354 riscv_rps_as
.subset_list
= s
->subset_list
;
4355 riscv_release_subset_list (release_subsets
);
4361 as_warn (_("unrecognized .option directive: %s"), name
);
4363 *input_line_pointer
= ch
;
4364 demand_empty_rest_of_line ();
4367 /* Handle the .dtprelword and .dtpreldword pseudo-ops. They generate
4368 a 32-bit or 64-bit DTP-relative relocation (BYTES says which) for
4369 use in DWARF debug information. */
4372 s_dtprel (int bytes
)
4379 if (ex
.X_op
!= O_symbol
)
4381 as_bad (_("unsupported use of %s"), (bytes
== 8
4384 ignore_rest_of_line ();
4387 p
= frag_more (bytes
);
4388 md_number_to_chars (p
, 0, bytes
);
4389 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, bytes
, &ex
, false,
4391 ? BFD_RELOC_RISCV_TLS_DTPREL64
4392 : BFD_RELOC_RISCV_TLS_DTPREL32
));
4394 demand_empty_rest_of_line ();
4397 /* Handle the .bss pseudo-op. */
4400 s_bss (int ignore ATTRIBUTE_UNUSED
)
4402 subseg_set (bss_section
, 0);
4403 demand_empty_rest_of_line ();
4407 riscv_make_nops (char *buf
, bfd_vma bytes
)
4411 /* RISC-V instructions cannot begin or end on odd addresses, so this case
4412 means we are not within a valid instruction sequence. It is thus safe
4413 to use a zero byte, even though that is not a valid instruction. */
4417 /* Use at most one 2-byte NOP. */
4418 if ((bytes
- i
) % 4 == 2)
4420 number_to_chars_littleendian (buf
+ i
, RVC_NOP
, 2);
4424 /* Fill the remainder with 4-byte NOPs. */
4425 for ( ; i
< bytes
; i
+= 4)
4426 number_to_chars_littleendian (buf
+ i
, RISCV_NOP
, 4);
4429 /* Called from md_do_align. Used to create an alignment frag in a
4430 code section by emitting a worst-case NOP sequence that the linker
4431 will later relax to the correct number of NOPs. We can't compute
4432 the correct alignment now because of other linker relaxations. */
4435 riscv_frag_align_code (int n
)
4437 bfd_vma bytes
= (bfd_vma
) 1 << n
;
4438 bfd_vma insn_alignment
= riscv_opts
.rvc
? 2 : 4;
4439 bfd_vma worst_case_bytes
= bytes
- insn_alignment
;
4443 /* If we are moving to a smaller alignment than the instruction size, then no
4444 alignment is required. */
4445 if (bytes
<= insn_alignment
)
4448 /* When not relaxing, riscv_handle_align handles code alignment. */
4449 if (!riscv_opts
.relax
)
4452 /* Maybe we should use frag_var to create a new rs_align_code fragment,
4453 rather than just use frag_more to handle an alignment here? So that we
4454 don't need to call riscv_mapping_state again later, and then only need
4455 to check frag->fr_type to see if it is frag_align_code. */
4456 nops
= frag_more (worst_case_bytes
);
4458 ex
.X_op
= O_constant
;
4459 ex
.X_add_number
= worst_case_bytes
;
4461 riscv_make_nops (nops
, worst_case_bytes
);
4463 fix_new_exp (frag_now
, nops
- frag_now
->fr_literal
, 0,
4464 &ex
, false, BFD_RELOC_RISCV_ALIGN
);
4466 riscv_mapping_state (MAP_INSN
, worst_case_bytes
, true/* fr_align_code */);
4468 /* We need to start a new frag after the alignment which may be removed by
4469 the linker, to prevent the assembler from computing static offsets.
4470 This is necessary to get correct EH info. */
4471 frag_wane (frag_now
);
4477 /* Implement HANDLE_ALIGN. */
4480 riscv_handle_align (fragS
*fragP
)
4482 switch (fragP
->fr_type
)
4485 /* When relaxing, riscv_frag_align_code handles code alignment. */
4486 if (!riscv_opts
.relax
)
4488 bfd_signed_vma bytes
= (fragP
->fr_next
->fr_address
4489 - fragP
->fr_address
- fragP
->fr_fix
);
4490 /* We have 4 byte uncompressed nops. */
4491 bfd_signed_vma size
= 4;
4492 bfd_signed_vma excess
= bytes
% size
;
4493 bfd_boolean odd_padding
= (excess
% 2 == 1);
4494 char *p
= fragP
->fr_literal
+ fragP
->fr_fix
;
4499 /* Insert zeros or compressed nops to get 4 byte alignment. */
4503 riscv_add_odd_padding_symbol (fragP
);
4504 riscv_make_nops (p
, excess
);
4505 fragP
->fr_fix
+= excess
;
4509 /* The frag will be changed to `rs_fill` later. The function
4510 `write_contents` will try to fill the remaining spaces
4511 according to the patterns we give. In this case, we give
4512 a 4 byte uncompressed nop as the pattern, and set the size
4513 of the pattern into `fr_var`. The nop will be output to the
4514 file `fr_offset` times. However, `fr_offset` could be zero
4515 if we don't need to pad the boundary finally. */
4516 riscv_make_nops (p
, size
);
4517 fragP
->fr_var
= size
;
4526 /* This usually called from frag_var. */
4529 riscv_init_frag (fragS
* fragP
, int max_chars
)
4531 /* Do not add mapping symbol to debug sections. */
4532 if (bfd_section_flags (now_seg
) & SEC_DEBUGGING
)
4535 switch (fragP
->fr_type
)
4540 riscv_mapping_state (MAP_DATA
, max_chars
, false/* fr_align_code */);
4543 riscv_mapping_state (MAP_INSN
, max_chars
, true/* fr_align_code */);
4551 md_estimate_size_before_relax (fragS
*fragp
, asection
*segtype
)
4553 return (fragp
->fr_var
= relaxed_branch_length (fragp
, segtype
, false));
4556 /* Translate internal representation of relocation info to BFD target
4560 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
, fixS
*fixp
)
4562 arelent
*reloc
= (arelent
*) xmalloc (sizeof (arelent
));
4564 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
4565 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
4566 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4567 reloc
->addend
= fixp
->fx_addnumber
;
4569 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
4570 if (reloc
->howto
== NULL
)
4572 if ((fixp
->fx_r_type
== BFD_RELOC_16
|| fixp
->fx_r_type
== BFD_RELOC_8
)
4573 && fixp
->fx_addsy
!= NULL
&& fixp
->fx_subsy
!= NULL
)
4575 /* We don't have R_RISCV_8/16, but for this special case,
4576 we can use R_RISCV_ADD8/16 with R_RISCV_SUB8/16. */
4580 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4581 _("cannot represent %s relocation in object file"),
4582 bfd_get_reloc_code_name (fixp
->fx_r_type
));
4590 riscv_relax_frag (asection
*sec
, fragS
*fragp
, long stretch ATTRIBUTE_UNUSED
)
4592 if (RELAX_BRANCH_P (fragp
->fr_subtype
))
4594 offsetT old_var
= fragp
->fr_var
;
4595 fragp
->fr_var
= relaxed_branch_length (fragp
, sec
, true);
4596 return fragp
->fr_var
- old_var
;
4602 /* Expand far branches to multi-instruction sequences. */
4605 md_convert_frag_branch (fragS
*fragp
)
4613 buf
= (bfd_byte
*)fragp
->fr_literal
+ fragp
->fr_fix
;
4615 exp
.X_op
= O_symbol
;
4616 exp
.X_add_symbol
= fragp
->fr_symbol
;
4617 exp
.X_add_number
= fragp
->fr_offset
;
4619 gas_assert (fragp
->fr_var
== RELAX_BRANCH_LENGTH (fragp
->fr_subtype
));
4621 if (RELAX_BRANCH_RVC (fragp
->fr_subtype
))
4623 switch (RELAX_BRANCH_LENGTH (fragp
->fr_subtype
))
4627 /* Expand the RVC branch into a RISC-V one. */
4628 insn
= bfd_getl16 (buf
);
4629 rs1
= 8 + ((insn
>> OP_SH_CRS1S
) & OP_MASK_CRS1S
);
4630 if ((insn
& MASK_C_J
) == MATCH_C_J
)
4632 else if ((insn
& MASK_C_JAL
) == MATCH_C_JAL
)
4633 insn
= MATCH_JAL
| (X_RA
<< OP_SH_RD
);
4634 else if ((insn
& MASK_C_BEQZ
) == MATCH_C_BEQZ
)
4635 insn
= MATCH_BEQ
| (rs1
<< OP_SH_RS1
);
4636 else if ((insn
& MASK_C_BNEZ
) == MATCH_C_BNEZ
)
4637 insn
= MATCH_BNE
| (rs1
<< OP_SH_RS1
);
4640 bfd_putl32 (insn
, buf
);
4644 /* Invert the branch condition. Branch over the jump. */
4645 insn
= bfd_getl16 (buf
);
4646 insn
^= MATCH_C_BEQZ
^ MATCH_C_BNEZ
;
4647 insn
|= ENCODE_CBTYPE_IMM (6);
4648 bfd_putl16 (insn
, buf
);
4653 /* Just keep the RVC branch. */
4654 reloc
= RELAX_BRANCH_UNCOND (fragp
->fr_subtype
)
4655 ? BFD_RELOC_RISCV_RVC_JUMP
: BFD_RELOC_RISCV_RVC_BRANCH
;
4656 fixp
= fix_new_exp (fragp
, buf
- (bfd_byte
*)fragp
->fr_literal
,
4657 2, &exp
, false, reloc
);
4666 switch (RELAX_BRANCH_LENGTH (fragp
->fr_subtype
))
4669 gas_assert (!RELAX_BRANCH_UNCOND (fragp
->fr_subtype
));
4671 /* Invert the branch condition. Branch over the jump. */
4672 insn
= bfd_getl32 (buf
);
4673 insn
^= MATCH_BEQ
^ MATCH_BNE
;
4674 insn
|= ENCODE_BTYPE_IMM (8);
4675 bfd_putl32 (insn
, buf
);
4679 /* Jump to the target. */
4680 fixp
= fix_new_exp (fragp
, buf
- (bfd_byte
*)fragp
->fr_literal
,
4681 4, &exp
, false, BFD_RELOC_RISCV_JMP
);
4682 bfd_putl32 (MATCH_JAL
, buf
);
4687 reloc
= RELAX_BRANCH_UNCOND (fragp
->fr_subtype
)
4688 ? BFD_RELOC_RISCV_JMP
: BFD_RELOC_12_PCREL
;
4689 fixp
= fix_new_exp (fragp
, buf
- (bfd_byte
*)fragp
->fr_literal
,
4690 4, &exp
, false, reloc
);
4699 fixp
->fx_file
= fragp
->fr_file
;
4700 fixp
->fx_line
= fragp
->fr_line
;
4702 gas_assert (buf
== (bfd_byte
*)fragp
->fr_literal
4703 + fragp
->fr_fix
+ fragp
->fr_var
);
4705 fragp
->fr_fix
+= fragp
->fr_var
;
4708 /* Relax a machine dependent frag. This returns the amount by which
4709 the current size of the frag should change. */
4712 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
, segT asec ATTRIBUTE_UNUSED
,
4715 gas_assert (RELAX_BRANCH_P (fragp
->fr_subtype
));
4716 md_convert_frag_branch (fragp
);
4720 md_show_usage (FILE *stream
)
4722 fprintf (stream
, _("\
4724 -fpic or -fPIC generate position-independent code\n\
4725 -fno-pic don't generate position-independent code (default)\n\
4726 -march=ISA set the RISC-V architecture\n\
4727 -misa-spec=ISAspec set the RISC-V ISA spec (2.2, 20190608, 20191213)\n\
4728 -mpriv-spec=PRIVspec set the RISC-V privilege spec (1.9.1, 1.10, 1.11, 1.12)\n\
4729 -mabi=ABI set the RISC-V ABI\n\
4730 -mrelax enable relax (default)\n\
4731 -mno-relax disable relax\n\
4732 -march-attr generate RISC-V arch attribute\n\
4733 -mno-arch-attr don't generate RISC-V arch attribute\n\
4734 -mcsr-check enable the csr ISA and privilege spec version checks\n\
4735 -mno-csr-check disable the csr ISA and privilege spec version checks (default)\n\
4736 -mbig-endian assemble for big-endian\n\
4737 -mlittle-endian assemble for little-endian\n\
4741 /* Standard calling conventions leave the CFA at SP on entry. */
4744 riscv_cfi_frame_initial_instructions (void)
4746 cfi_add_CFA_def_cfa_register (X_SP
);
4750 tc_riscv_regname_to_dw2regnum (char *regname
)
4754 if ((reg
= reg_lookup_internal (regname
, RCLASS_GPR
)) >= 0)
4757 if ((reg
= reg_lookup_internal (regname
, RCLASS_FPR
)) >= 0)
4760 if ((reg
= reg_lookup_internal (regname
, RCLASS_VECR
)) >= 0)
4763 /* CSRs are numbered 4096 -> 8191. */
4764 if ((reg
= reg_lookup_internal (regname
, RCLASS_CSR
)) >= 0)
4767 as_bad (_("unknown register `%s'"), regname
);
4772 riscv_elf_final_processing (void)
4774 riscv_set_abi_by_arch ();
4775 riscv_release_subset_list (riscv_rps_as
.subset_list
);
4776 elf_elfheader (stdoutput
)->e_flags
|= elf_flags
;
4779 /* Parse the .sleb128 and .uleb128 pseudos. Only allow constant expressions,
4780 since these directives break relaxation when used with symbol deltas. */
4783 s_riscv_leb128 (int sign
)
4786 char *save_in
= input_line_pointer
;
4789 if (sign
&& exp
.X_op
!= O_constant
)
4790 as_bad (_("non-constant .sleb128 is not supported"));
4791 else if (!sign
&& exp
.X_op
!= O_constant
&& exp
.X_op
!= O_subtract
)
4792 as_bad (_(".uleb128 only supports constant or subtract expressions"));
4794 demand_empty_rest_of_line ();
4796 input_line_pointer
= save_in
;
4797 return s_leb128 (sign
);
4800 /* Parse the .insn directive. There are three formats,
4801 Format 1: .insn <type> <operand1>, <operand2>, ...
4802 Format 2: .insn <length>, <value>
4803 Format 3: .insn <value>. */
4806 s_riscv_insn (int x ATTRIBUTE_UNUSED
)
4808 char *str
= input_line_pointer
;
4809 struct riscv_cl_insn insn
;
4810 expressionS imm_expr
;
4811 bfd_reloc_code_real_type imm_reloc
= BFD_RELOC_UNUSED
;
4814 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
4815 ++input_line_pointer
;
4817 save_c
= *input_line_pointer
;
4818 *input_line_pointer
= '\0';
4820 riscv_mapping_state (MAP_INSN
, 0, false/* fr_align_code */);
4822 struct riscv_ip_error error
= riscv_ip (str
, &insn
, &imm_expr
,
4823 &imm_reloc
, insn_type_hash
);
4826 char *save_in
= input_line_pointer
;
4827 error
.msg
= riscv_ip_hardcode (str
, &insn
, &imm_expr
, error
.msg
);
4828 input_line_pointer
= save_in
;
4833 if (error
.missing_ext
)
4834 as_bad ("%s `%s', extension `%s' required", error
.msg
, error
.statement
,
4837 as_bad ("%s `%s'", error
.msg
, error
.statement
);
4841 gas_assert (insn
.insn_mo
->pinfo
!= INSN_MACRO
);
4842 append_insn (&insn
, &imm_expr
, imm_reloc
);
4845 *input_line_pointer
= save_c
;
4846 demand_empty_rest_of_line ();
4849 /* Update architecture and privileged elf attributes. If we don't set
4850 them, then try to output the default ones. */
4853 riscv_write_out_attrs (void)
4855 const char *arch_str
, *priv_str
, *p
;
4856 /* versions[0]: major version.
4857 versions[1]: minor version.
4858 versions[2]: revision version. */
4859 unsigned versions
[3] = {0}, number
= 0;
4862 /* Re-write architecture elf attribute. */
4863 arch_str
= riscv_rps_as
.subset_list
->arch_str
;
4864 bfd_elf_add_proc_attr_string (stdoutput
, Tag_RISCV_arch
, arch_str
);
4866 /* For the file without any instruction, we don't set the default_priv_spec
4867 according to the privileged elf attributes since the md_assemble isn't
4870 && !riscv_set_default_priv_spec (NULL
))
4873 /* If we already have set privileged elf attributes, then no need to do
4874 anything. Otherwise, don't generate or update them when no CSR and
4875 privileged instructions are used. */
4876 if (!explicit_priv_attr
)
4879 RISCV_GET_PRIV_SPEC_NAME (priv_str
, default_priv_spec
);
4881 for (i
= 0; *p
; ++p
)
4883 if (*p
== '.' && i
< 3)
4885 versions
[i
++] = number
;
4888 else if (ISDIGIT (*p
))
4889 number
= (number
* 10) + (*p
- '0');
4892 as_bad (_("internal: bad RISC-V privileged spec (%s)"), priv_str
);
4896 versions
[i
] = number
;
4898 /* Re-write privileged elf attributes. */
4899 bfd_elf_add_proc_attr_int (stdoutput
, Tag_RISCV_priv_spec
, versions
[0]);
4900 bfd_elf_add_proc_attr_int (stdoutput
, Tag_RISCV_priv_spec_minor
, versions
[1]);
4901 bfd_elf_add_proc_attr_int (stdoutput
, Tag_RISCV_priv_spec_revision
, versions
[2]);
4904 /* Add the default contents for the .riscv.attributes section. */
4907 riscv_set_public_attributes (void)
4909 if (riscv_opts
.arch_attr
|| explicit_attr
)
4910 riscv_write_out_attrs ();
4913 /* Scan uleb128 subtraction expressions and insert fixups for them.
4914 e.g., .uleb128 .L1 - .L0
4915 Because relaxation may change the value of the subtraction, we
4916 must resolve them at link-time. */
4919 riscv_insert_uleb128_fixes (bfd
*abfd ATTRIBUTE_UNUSED
,
4920 asection
*sec
, void *xxx ATTRIBUTE_UNUSED
)
4922 segment_info_type
*seginfo
= seg_info (sec
);
4925 subseg_set (sec
, 0);
4927 for (fragP
= seginfo
->frchainP
->frch_root
;
4928 fragP
; fragP
= fragP
->fr_next
)
4930 expressionS
*exp
, *exp_dup
;
4932 if (fragP
->fr_type
!= rs_leb128
|| fragP
->fr_symbol
== NULL
)
4935 exp
= symbol_get_value_expression (fragP
->fr_symbol
);
4937 if (exp
->X_op
!= O_subtract
)
4940 /* Only unsigned leb128 can be handled. */
4941 gas_assert (fragP
->fr_subtype
== 0);
4942 exp_dup
= xmemdup (exp
, sizeof (*exp
), sizeof (*exp
));
4943 exp_dup
->X_op
= O_symbol
;
4944 exp_dup
->X_op_symbol
= NULL
;
4946 /* Insert relocations to resolve the subtraction at link-time.
4947 Emit the SET relocation first in riscv. */
4948 exp_dup
->X_add_symbol
= exp
->X_add_symbol
;
4949 fix_new_exp (fragP
, fragP
->fr_fix
, 0,
4950 exp_dup
, 0, BFD_RELOC_RISCV_SET_ULEB128
);
4951 exp_dup
->X_add_symbol
= exp
->X_op_symbol
;
4952 fix_new_exp (fragP
, fragP
->fr_fix
, 0,
4953 exp_dup
, 0, BFD_RELOC_RISCV_SUB_ULEB128
);
4957 /* Called after all assembly has been done. */
4960 riscv_md_finish (void)
4962 riscv_set_public_attributes ();
4963 if (riscv_opts
.relax
)
4964 bfd_map_over_sections (stdoutput
, riscv_insert_uleb128_fixes
, NULL
);
4967 /* Adjust the symbol table. */
4970 riscv_adjust_symtab (void)
4972 bfd_map_over_sections (stdoutput
, riscv_check_mapping_symbols
, (char *) 0);
4973 elf_adjust_symtab ();
4976 /* Given a symbolic attribute NAME, return the proper integer value.
4977 Returns -1 if the attribute is not known. */
4980 riscv_convert_symbolic_attribute (const char *name
)
4989 /* When you modify this table you should
4990 also modify the list in doc/c-riscv.texi. */
4991 #define T(tag) {#tag, Tag_RISCV_##tag}, {"Tag_RISCV_" #tag, Tag_RISCV_##tag}
4995 T(priv_spec_revision
),
4996 T(unaligned_access
),
5005 for (i
= 0; i
< ARRAY_SIZE (attribute_table
); i
++)
5006 if (strcmp (name
, attribute_table
[i
].name
) == 0)
5007 return attribute_table
[i
].tag
;
5012 /* Parse a .attribute directive. */
5015 s_riscv_attribute (int ignored ATTRIBUTE_UNUSED
)
5017 int tag
= obj_elf_vendor_attribute (OBJ_ATTR_PROC
);
5019 obj_attribute
*attr
;
5021 explicit_attr
= true;
5024 case Tag_RISCV_arch
:
5026 attr
= elf_known_obj_attributes_proc (stdoutput
);
5027 if (!start_assemble
)
5028 riscv_set_arch (attr
[Tag_RISCV_arch
].s
);
5030 as_fatal (_("architecture elf attributes must set before "
5031 "any instructions"));
5033 if (old_xlen
!= xlen
)
5035 /* We must re-init bfd again if xlen is changed. */
5036 unsigned long mach
= xlen
== 64 ? bfd_mach_riscv64
: bfd_mach_riscv32
;
5037 bfd_find_target (riscv_target_format (), stdoutput
);
5039 if (! bfd_set_arch_mach (stdoutput
, bfd_arch_riscv
, mach
))
5040 as_warn (_("could not set architecture and machine"));
5044 case Tag_RISCV_priv_spec
:
5045 case Tag_RISCV_priv_spec_minor
:
5046 case Tag_RISCV_priv_spec_revision
:
5048 as_fatal (_("privileged elf attributes must set before "
5049 "any instructions"));
5057 /* Mark symbol that it follows a variant CC convention. */
5060 s_variant_cc (int ignored ATTRIBUTE_UNUSED
)
5066 elf_symbol_type
*elfsym
;
5068 c
= get_symbol_name (&name
);
5070 as_bad (_("missing symbol name for .variant_cc directive"));
5071 sym
= symbol_find_or_make (name
);
5072 restore_line_pointer (c
);
5073 demand_empty_rest_of_line ();
5075 bfdsym
= symbol_get_bfdsym (sym
);
5076 elfsym
= elf_symbol_from (bfdsym
);
5077 gas_assert (elfsym
);
5078 elfsym
->internal_elf_sym
.st_other
|= STO_RISCV_VARIANT_CC
;
5081 /* Same as elf_copy_symbol_attributes, but without copying st_other.
5082 This is needed so RISC-V specific st_other values can be independently
5083 specified for an IFUNC resolver (that is called by the dynamic linker)
5084 and the symbol it resolves (aliased to the resolver). In particular,
5085 if a function symbol has special st_other value set via directives,
5086 then attaching an IFUNC resolver to that symbol should not override
5087 the st_other setting. Requiring the directive on the IFUNC resolver
5088 symbol would be unexpected and problematic in C code, where the two
5089 symbols appear as two independent function declarations. */
5092 riscv_elf_copy_symbol_attributes (symbolS
*dest
, symbolS
*src
)
5094 struct elf_obj_sy
*srcelf
= symbol_get_obj (src
);
5095 struct elf_obj_sy
*destelf
= symbol_get_obj (dest
);
5096 /* If size is unset, copy size from src. Because we don't track whether
5097 .size has been used, we can't differentiate .size dest, 0 from the case
5098 where dest's size is unset. */
5099 if (!destelf
->size
&& S_GET_SIZE (dest
) == 0)
5103 destelf
->size
= XNEW (expressionS
);
5104 *destelf
->size
= *srcelf
->size
;
5106 S_SET_SIZE (dest
, S_GET_SIZE (src
));
5110 /* RISC-V pseudo-ops table. */
5111 static const pseudo_typeS riscv_pseudo_table
[] =
5113 {"option", s_riscv_option
, 0},
5117 {"dtprelword", s_dtprel
, 4},
5118 {"dtpreldword", s_dtprel
, 8},
5120 {"uleb128", s_riscv_leb128
, 0},
5121 {"sleb128", s_riscv_leb128
, 1},
5122 {"insn", s_riscv_insn
, 0},
5123 {"attribute", s_riscv_attribute
, 0},
5124 {"variant_cc", s_variant_cc
, 0},
5125 {"float16", float_cons
, 'h'},
5131 riscv_pop_insert (void)
5133 extern void pop_insert (const pseudo_typeS
*);
5135 pop_insert (riscv_pseudo_table
);