diff options
author | Nelson Chu <nelson.chu@sifive.com> | 2020-05-20 17:22:48 +0100 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2020-05-20 17:22:48 +0100 |
commit | 8f595e9b4fd0a3a74d53ddffd69f2825627ae5c6 (patch) | |
tree | 3668cb480143c82412d9050ad70d4a0e2786a7e7 /bfd/elfxx-riscv.c | |
parent | 41977d16e4ee5b9ad01abf2cfce6edbfb6d79541 (diff) | |
download | gdb-8f595e9b4fd0a3a74d53ddffd69f2825627ae5c6.zip gdb-8f595e9b4fd0a3a74d53ddffd69f2825627ae5c6.tar.gz gdb-8f595e9b4fd0a3a74d53ddffd69f2825627ae5c6.tar.bz2 |
[PATCH v2 0/9] RISC-V: Support version controling for ISA standard extensions and CSR
1. Remove the -mriscv-isa-version and --with-riscv-isa-version options.
We can still use -march to choose the version for each extensions, so there is
no need to add these.
2. Change the arguments of options from [1p9|1p9p1|...] to [1.9|1.9.1|...].
Unlike the architecture string has specified by spec, ther is no need to do
the same thing for options.
3. Spilt the patches to reduce the burdens of review.
[PATCH 3/7] RISC-V: Support new GAS options and configure options to set ISA versions
to
[PATCH v2 3/9] RISC-V: Support GAS option -misa-spec to set ISA versions
[PATCH v2 4/9] RISC-V: Support configure options to set ISA versions by default.
[PATCH 4/7] RISC-V: Support version checking for CSR according to privilege version.
to
[PATCH v2 5/9] RISC-V: Support version checking for CSR according to privilege spec version.
[PATCH v2 6/9] RISC-V: Support configure option to choose the privilege spec version.
4. Use enum class rather than string to compare the choosen ISA spec in opcodes/riscv-opc.c.
The behavior is same as comparing the choosen privilege spec.
include * opcode/riscv.h: Include "bfd.h" to support bfd_boolean.
(enum riscv_isa_spec_class): New enum class. All supported ISA spec
belong to one of the class
(struct riscv_ext_version): New structure holds version information
for the specific ISA.
* opcode/riscv-opc.h (DECLARE_CSR): There are two version information,
define_version and abort_version. The define_version means which
privilege spec is started to define the CSR, and the abort_version
means which privilege spec is started to abort the CSR. If the CSR is
valid for the newest spec, then the abort_version should be
PRIV_SPEC_CLASS_DRAFT.
(DECLARE_CSR_ALIAS): Same as DECLARE_CSR, but only for the obselete CSR.
* opcode/riscv.h (enum riscv_priv_spec_class): New enum class. Define
the current supported privilege spec versions.
(struct riscv_csr_extra): Add new fields to store more information
about the CSR. We use these information to find the suitable CSR
address when user choosing a specific privilege spec.
binutils * dwarf.c: Updated since DECLARE_CSR is changed.
opcodes * riscv-opc.c (riscv_ext_version_table): The table used to store
all information about the supported spec and the corresponding ISA
versions. Currently, only Zicsr is supported to verify the
correctness of Z sub extension settings. Others will be supported
in the future patches.
(struct isa_spec_t, isa_specs): List for all supported ISA spec
classes and the corresponding strings.
(riscv_get_isa_spec_class): New function. Get the corresponding ISA
spec class by giving a ISA spec string.
* riscv-opc.c (struct priv_spec_t): New structure.
(struct priv_spec_t priv_specs): List for all supported privilege spec
classes and the corresponding strings.
(riscv_get_priv_spec_class): New function. Get the corresponding
privilege spec class by giving a spec string.
(riscv_get_priv_spec_name): New function. Get the corresponding
privilege spec string by giving a CSR version class.
* riscv-dis.c: Updated since DECLARE_CSR is changed.
* riscv-dis.c: Add new disassembler option -Mpriv-spec to dump the CSR
according to the chosen version. Build a hash table riscv_csr_hash to
store the valid CSR for the chosen pirv verison. Dump the direct
CSR address rather than it's name if it is invalid.
(parse_riscv_dis_option_without_args): New function. Parse the options
without arguments.
(parse_riscv_dis_option): Call parse_riscv_dis_option_without_args to
parse the options without arguments first, and then handle the options
with arguments. Add the new option -Mpriv-spec, which has argument.
* riscv-dis.c (print_riscv_disassembler_options): Add description
about the new OBJDUMP option.
ld * testsuite/ld-riscv-elf/attr-merge-arch-01.d: Updated
priv attributes according to the -mpriv-spec option.
* testsuite/ld-riscv-elf/attr-merge-arch-02.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-arch-03.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-a.s: Likewise.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-b.s: Likewise.
* testsuite/ld-riscv-elf/attr-merge-priv-spec.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-stack-align.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-strict-align-01.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-strict-align-02.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-strict-align-03.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-strict-align-04.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-strict-align-05.d: Likewise.
bfd * elfxx-riscv.h (riscv_parse_subset_t): Add new callback function
get_default_version. It is used to find the default version for
the specific extension.
* elfxx-riscv.c (riscv_parsing_subset_version): Remove the parameters
default_major_version and default_minor_version. Add new bfd_boolean
parameter *use_default_version. Set it to TRUE if we need to call
the callback rps->get_default_version to find the default version.
(riscv_parse_std_ext): Call rps->get_default_version if we fail to find
the default version in riscv_parsing_subset_version, and then call
riscv_add_subset to add the subset into subset list.
(riscv_parse_prefixed_ext): Likewise.
(riscv_std_z_ext_strtab): Support Zicsr extensions.
* elfnn-riscv.c (riscv_merge_std_ext): Use strcasecmp to compare the
strings rather than characters.
riscv_merge_arch_attr_info): The callback function get_default_version
is only needed for assembler, so set it to NULL int the linker.
* elfxx-riscv.c (riscv_estimate_digit): Remove the static.
* elfxx-riscv.h: Updated.
gas * testsuite/gas/riscv/priv-reg-fail-read-only-01.s: Updated.
* config/tc-riscv.c (default_arch_with_ext, default_isa_spec):
Static variables which are used to set the ISA extensions. You can
use -march (or ELF build attributes) and -misa-spec to set them,
respectively.
(ext_version_hash): The hash table used to handle the extensions
with versions.
(init_ext_version_hash): Initialize the ext_version_hash according
to riscv_ext_version_table.
(riscv_get_default_ext_version): The callback function of
riscv_parse_subset_t. According to the choosed ISA spec,
get the default version for the specific extension.
(riscv_set_arch): Set the callback function.
(enum options, struct option md_longopts): Add new option -misa-spec.
(md_parse_option): Do not call riscv_set_arch for -march. We will
call it later in riscv_after_parse_args. Call riscv_get_isa_spec_class
to set default_isa_spec class.
(riscv_after_parse_args): Call init_ext_version_hash to initialize the
ext_version_hash, and then call riscv_set_arch to set the architecture
with versions according to default_arch_with_ext.
* testsuite/gas/riscv/attribute-02.d: Set 0p0 as default version for
x extensions.
* testsuite/gas/riscv/attribute-03.d: Likewise.
* testsuite/gas/riscv/attribute-09.d: New testcase. For i-ext, we
already set it's version to 2p1 by march, so no need to use the default
2p2 version. For m-ext, we do not set the version by -march and ELF arch
attribute, so set the default 2p0 to it. For zicsr, it is not defined in
ISA spec 2p2, so set 0p0 to it.
* testsuite/gas/riscv/attribute-10.d: New testcase. The version of
zicsr is 2p0 according to ISA spec 20191213.
* config/tc-riscv.c (DEFAULT_RISCV_ARCH_WITH_EXT)
(DEFAULT_RISCV_ISA_SPEC): Default configure option settings.
You can set them by configure options --with-arch and
--with-isa-spec, respectively.
(riscv_set_default_isa_spec): New function used to set the
default ISA spec.
(md_parse_option): Call riscv_set_default_isa_spec rather than
call riscv_get_isa_spec_class directly.
(riscv_after_parse_args): If the -isa-spec is not set, then we
set the default ISA spec according to DEFAULT_RISCV_ISA_SPEC by
calling riscv_set_default_isa_spec.
* testsuite/gas/riscv/attribute-01.d: Add -misa-spec=2.2, since
the --with-isa-spec may be set to different ISA spec.
* testsuite/gas/riscv/attribute-02.d: Likewise.
* testsuite/gas/riscv/attribute-03.d: Likewise.
* testsuite/gas/riscv/attribute-04.d: Likewise.
* testsuite/gas/riscv/attribute-05.d: Likewise.
* testsuite/gas/riscv/attribute-06.d: Likewise.
* testsuite/gas/riscv/attribute-07.d: Likewise.
* configure.ac: Add configure options, --with-arch and
--with-isa-spec.
* configure: Regenerated.
* config.in: Regenerated.
* config/tc-riscv.c (default_priv_spec): Static variable which is
used to check if the CSR is valid for the chosen privilege spec. You
can use -mpriv-spec to set it.
(enum reg_class): We now get the CSR address from csr_extra_hash rather
than reg_names_hash. Therefore, move RCLASS_CSR behind RCLASS_MAX.
(riscv_init_csr_hashes): Only need to initialize one hash table
csr_extra_hash.
(riscv_csr_class_check): Change the return type to void. Don't check
the ISA dependency if -mcsr-check isn't set.
(riscv_csr_version_check): New function. Check and find the CSR address
from csr_extra_hash, according to default_priv_spec. Report warning
for the invalid CSR if -mcsr-check is set.
(reg_csr_lookup_internal): Updated.
(reg_lookup_internal): Likewise.
(md_begin): Updated since DECLARE_CSR and DECLARE_CSR_ALIAS are changed.
(enum options, struct option md_longopts): Add new GAS option -mpriv-spec.
(md_parse_option): Call riscv_set_default_priv_version to set
default_priv_spec.
(riscv_after_parse_args): If -mpriv-spec isn't set, then set the default
privilege spec to the newest one.
(enum riscv_csr_class, struct riscv_csr_extra): Move them to
include/opcode/riscv.h.
* testsuite/gas/riscv/priv-reg-fail-fext.d: This test case just want
to check the ISA dependency for CSR, so fix the spec version by adding
-mpriv-spec=1.11.
* testsuite/gas/riscv/priv-reg-fail-fext.l: Likewise. There are some
version warnings for the test case.
* gas/testsuite/gas/riscv/priv-reg-fail-read-only-01.d: Likewise.
* gas/testsuite/gas/riscv/priv-reg-fail-read-only-01.l: Likewise.
* gas/testsuite/gas/riscv/priv-reg-fail-read-only-02.d: Likewise.
* gas/testsuite/gas/riscv/priv-reg-fail-rv32-only.d: Likewise.
* gas/testsuite/gas/riscv/priv-reg-fail-rv32-only.l: Likewise.
* gas/testsuite/gas/riscv/priv-reg-fail-version-1p9.d: New test case.
Check whether the CSR is valid when privilege version 1.9 is choosed.
* gas/testsuite/gas/riscv/priv-reg-fail-version-1p9.l: Likewise.
* gas/testsuite/gas/riscv/priv-reg-fail-version-1p9p1.d: New test case.
Check whether the CSR is valid when privilege version 1.9.1 is choosed.
* gas/testsuite/gas/riscv/priv-reg-fail-version-1p9p1.l: Likewise.
* gas/testsuite/gas/riscv/priv-reg-fail-version-1p10.d: New test case.
Check whether the CSR is valid when privilege version 1.10 is choosed.
* gas/testsuite/gas/riscv/priv-reg-fail-version-1p10.l: Likewise.
* gas/testsuite/gas/riscv/priv-reg-fail-version-1p11.d: New test case.
Check whether the CSR is valid when privilege version 1.11 is choosed.
* gas/testsuite/gas/riscv/priv-reg-fail-version-1p11.l: Likewise.
* config/tc-riscv.c (DEFAULT_RISCV_ISA_SPEC): Default configure option
setting. You can set it by configure option --with-priv-spec.
(riscv_set_default_priv_spec): New function used to set the default
privilege spec.
(md_parse_option): Call riscv_set_default_priv_spec rather than
call riscv_get_priv_spec_class directly.
(riscv_after_parse_args): If -mpriv-spec isn't set, then we set the
default privilege spec according to DEFAULT_RISCV_PRIV_SPEC by
calling riscv_set_default_priv_spec.
* testsuite/gas/riscv/csr-dw-regnums.d: Add -mpriv-spec=1.11, since
the --with-priv-spec may be set to different privilege spec.
* testsuite/gas/riscv/priv-reg.d: Likewise.
* configure.ac: Add configure option --with-priv-spec.
* configure: Regenerated.
* config.in: Regenerated.
* config/tc-riscv.c (explicit_attr): Rename explicit_arch_attr to
explicit_attr. Set it to TRUE if any ELF attribute is found.
(riscv_set_default_priv_spec): Try to set the default_priv_spec if
the priv attributes are set.
(md_assemble): Set the default_priv_spec according to the priv
attributes when we start to assemble instruction.
(riscv_write_out_attrs): Rename riscv_write_out_arch_attr to
riscv_write_out_attrs. Update the arch and priv attributes. If we
don't set the corresponding ELF attributes, then try to output the
default ones.
(riscv_set_public_attributes): If any ELF attribute or -march-attr
options is set (explicit_attr is TRUE), then call riscv_write_out_attrs
to update the arch and priv attributes.
(s_riscv_attribute): Make sure all arch and priv attributes are set
before any instruction.
* testsuite/gas/riscv/attribute-01.d: Update the priv attributes if any
ELF attribute or -march-attr is set. If the priv attributes are not
set, then try to update them by the default setting (-mpriv-spec or
--with-priv-spec).
* testsuite/gas/riscv/attribute-02.d: Likewise.
* testsuite/gas/riscv/attribute-03.d: Likewise.
* testsuite/gas/riscv/attribute-04.d: Likewise.
* testsuite/gas/riscv/attribute-06.d: Likewise.
* testsuite/gas/riscv/attribute-07.d: Likewise.
* testsuite/gas/riscv/attribute-08.d: Likewise.
* testsuite/gas/riscv/attribute-09.d: Likewise.
* testsuite/gas/riscv/attribute-10.d: Likewise.
* testsuite/gas/riscv/attribute-unknown.d: Likewise.
* testsuite/gas/riscv/attribute-05.d: Likewise. Also, the priv spec
set by priv attributes must be supported.
* testsuite/gas/riscv/attribute-05.s: Likewise.
* testsuite/gas/riscv/priv-reg-fail-version-1p9.d: Likewise. Updated
priv attributes according to the -mpriv-spec option.
* testsuite/gas/riscv/priv-reg-fail-version-1p9p1.d: Likewise.
* testsuite/gas/riscv/priv-reg-fail-version-1p10.d: Likewise.
* testsuite/gas/riscv/priv-reg-fail-version-1p11.d: Likewise.
* testsuite/gas/riscv/priv-reg.d: Removed.
* testsuite/gas/riscv/priv-reg-version-1p9.d: New test case. Dump the
CSR according to the priv spec 1.9.
* testsuite/gas/riscv/priv-reg-version-1p9p1.d: New test case. Dump the
CSR according to the priv spec 1.9.1.
* testsuite/gas/riscv/priv-reg-version-1p10.d: New test case. Dump the
CSR according to the priv spec 1.10.
* testsuite/gas/riscv/priv-reg-version-1p11.d: New test case. Dump the
CSR according to the priv spec 1.11.
* config/tc-riscv.c (md_show_usage): Add descriptions about
the new GAS options.
* doc/c-riscv.texi: Likewise.
Diffstat (limited to 'bfd/elfxx-riscv.c')
-rw-r--r-- | bfd/elfxx-riscv.c | 285 |
1 files changed, 166 insertions, 119 deletions
diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c index b15fdee..5dd36ab 100644 --- a/bfd/elfxx-riscv.c +++ b/bfd/elfxx-riscv.c @@ -1025,9 +1025,8 @@ riscv_elf_add_sub_reloc (bfd *abfd, `minor_version`: Parsing result of minor version, set to 0 if version is not present in arch string, but set to `default_minor_version` if `major_version` using default_major_version. - `default_major_version`: Default major version. - `default_minor_version`: Default minor version. - `std_ext_p`: True if parsing std extension. */ + `std_ext_p`: True if parsing std extension. + `use_default_version`: Set it to True if we need the default version. */ static const char * riscv_parsing_subset_version (riscv_parse_subset_t *rps, @@ -1035,17 +1034,16 @@ riscv_parsing_subset_version (riscv_parse_subset_t *rps, const char *p, unsigned *major_version, unsigned *minor_version, - unsigned default_major_version, - unsigned default_minor_version, - bfd_boolean std_ext_p) + bfd_boolean std_ext_p, + bfd_boolean *use_default_version) { bfd_boolean major_p = TRUE; unsigned version = 0; - unsigned major = 0; - unsigned minor = 0; char np; - for (;*p; ++p) + *major_version = 0; + *minor_version = 0; + for (; *p; ++p) { if (*p == 'p') { @@ -1062,13 +1060,14 @@ riscv_parsing_subset_version (riscv_parse_subset_t *rps, } else { - rps->error_handler ("-march=%s: Expect number after `%dp'.", - march, version); + rps->error_handler + (_("-march=%s: Expect number after `%dp'."), + march, version); return NULL; } } - major = version; + *major_version = version; major_p = FALSE; version = 0; } @@ -1079,21 +1078,15 @@ riscv_parsing_subset_version (riscv_parse_subset_t *rps, } if (major_p) - major = version; + *major_version = version; else - minor = version; + *minor_version = version; - if (major == 0 && minor == 0) - { - /* We don't found any version string, use default version. */ - *major_version = default_major_version; - *minor_version = default_minor_version; - } - else - { - *major_version = major; - *minor_version = minor; - } + /* We can not find any version in string, need to parse default version. */ + if (use_default_version != NULL + && *major_version == 0 + && *minor_version == 0) + *use_default_version = TRUE; return p; } @@ -1118,78 +1111,114 @@ riscv_supported_std_ext (void) static const char * riscv_parse_std_ext (riscv_parse_subset_t *rps, - const char *march, const char *p) + const char *march, + const char *p) { const char *all_std_exts = riscv_supported_std_ext (); const char *std_exts = all_std_exts; - unsigned major_version = 0; unsigned minor_version = 0; char std_ext = '\0'; + bfd_boolean use_default_version = FALSE; /* First letter must start with i, e or g. */ switch (*p) { case 'i': - p++; - p = riscv_parsing_subset_version ( - rps, - march, - p, &major_version, &minor_version, - /* default_major_version= */ 2, - /* default_minor_version= */ 0, - /* std_ext_p= */TRUE); - riscv_add_subset (rps->subset_list, "i", major_version, minor_version); + p = riscv_parsing_subset_version (rps, + march, + ++p, + &major_version, + &minor_version, + /* std_ext_p= */TRUE, + &use_default_version); + + /* Find the default version if needed. */ + if (use_default_version + && rps->get_default_version != NULL) + rps->get_default_version ("i", + &major_version, + &minor_version); + riscv_add_subset (rps->subset_list, "i", + major_version, minor_version); break; case 'e': - p++; - p = riscv_parsing_subset_version ( - rps, - march, - p, &major_version, &minor_version, - /* default_major_version= */ 1, - /* default_minor_version= */ 9, - /* std_ext_p= */TRUE); - - riscv_add_subset (rps->subset_list, "e", major_version, minor_version); - riscv_add_subset (rps->subset_list, "i", 2, 0); + p = riscv_parsing_subset_version (rps, + march, + ++p, + &major_version, + &minor_version, + /* std_ext_p= */TRUE, + &use_default_version); + + /* Find the default version if needed. */ + if (use_default_version + && rps->get_default_version != NULL) + rps->get_default_version ("e", + &major_version, + &minor_version); + riscv_add_subset (rps->subset_list, "e", + major_version, minor_version); + + /* i-ext must be enabled. */ + if (rps->get_default_version != NULL) + rps->get_default_version ("i", + &major_version, + &minor_version); + riscv_add_subset (rps->subset_list, "i", + major_version, minor_version); if (*rps->xlen > 32) { - rps->error_handler ("-march=%s: rv%de is not a valid base ISA", - march, *rps->xlen); + rps->error_handler + (_("-march=%s: rv%de is not a valid base ISA"), + march, *rps->xlen); return NULL; } - break; case 'g': - p++; - p = riscv_parsing_subset_version ( - rps, - march, - p, &major_version, &minor_version, - /* default_major_version= */ 2, - /* default_minor_version= */ 0, - /* std_ext_p= */TRUE); - riscv_add_subset (rps->subset_list, "i", major_version, minor_version); + /* The g-ext shouldn't has the version, so we just + skip the setting if user set a version to it. */ + p = riscv_parsing_subset_version (rps, + march, + ++p, + &major_version, + &minor_version, + TRUE, + &use_default_version); + + /* i-ext must be enabled. */ + if (rps->get_default_version != NULL) + rps->get_default_version ("i", + &major_version, + &minor_version); + riscv_add_subset (rps->subset_list, "i", + major_version, minor_version); for ( ; *std_exts != 'q'; std_exts++) { const char subset[] = {*std_exts, '\0'}; - riscv_add_subset ( - rps->subset_list, subset, major_version, minor_version); + + if (rps->get_default_version != NULL) + rps->get_default_version (subset, + &major_version, + &minor_version); + riscv_add_subset (rps->subset_list, subset, + major_version, minor_version); } break; default: - rps->error_handler ( - "-march=%s: first ISA subset must be `e', `i' or `g'", march); + rps->error_handler + (_("-march=%s: first ISA subset must be `e', `i' or `g'"), march); return NULL; } - while (*p) + /* The riscv_parsing_subset_version may set `p` to NULL, so I think we should + skip parsing the string if `p` is NULL or value of `p` is `\0`. */ + while (p != NULL && *p != '\0') { char subset[2] = {0, 0}; @@ -1210,29 +1239,35 @@ riscv_parse_std_ext (riscv_parse_subset_t *rps, if (std_ext != *std_exts) { if (strchr (all_std_exts, std_ext) == NULL) - rps->error_handler ( - "-march=%s: unsupported ISA subset `%c'", march, *p); + rps->error_handler + (_("-march=%s: unsupported ISA subset `%c'"), march, *p); else - rps->error_handler ( - "-march=%s: ISA string is not in canonical order. `%c'", - march, *p); + rps->error_handler + (_("-march=%s: ISA string is not in canonical order. `%c'"), + march, *p); return NULL; } std_exts++; - p++; - p = riscv_parsing_subset_version ( - rps, - march, - p, &major_version, &minor_version, - /* default_major_version= */ 2, - /* default_minor_version= */ 0, - /* std_ext_p= */TRUE); - + use_default_version = FALSE; subset[0] = std_ext; - - riscv_add_subset (rps->subset_list, subset, major_version, minor_version); + p = riscv_parsing_subset_version (rps, + march, + ++p, + &major_version, + &minor_version, + TRUE, + &use_default_version); + + /* Find the default version if needed. */ + if (use_default_version + && rps->get_default_version != NULL) + rps->get_default_version (subset, + &major_version, + &minor_version); + riscv_add_subset (rps->subset_list, subset, + major_version, minor_version); } return p; } @@ -1272,9 +1307,10 @@ typedef struct riscv_parse_config } riscv_parse_config_t; /* Parse a generic prefixed extension. - march: The full architecture string as passed in by "-march=...". - p: Point from which to start parsing the -march string. - config: What class of extensions to parse, predicate funcs, + `rps`: Hooks and status for parsing subset. + `march`: The full architecture string as passed in by "-march=...". + `p`: Point from which to start parsing the -march string. + `config`: What class of extensions to parse, predicate funcs, and strings to use in error reporting. */ static const char * @@ -1287,6 +1323,7 @@ riscv_parse_prefixed_ext (riscv_parse_subset_t *rps, unsigned minor_version = 0; const char *last_name; riscv_isa_ext_class_t class; + bfd_boolean use_default_version; while (*p) { @@ -1309,15 +1346,11 @@ riscv_parse_prefixed_ext (riscv_parse_subset_t *rps, while (*++q != '\0' && *q != '_' && !ISDIGIT (*q)) ; + use_default_version = FALSE; end_of_version = - riscv_parsing_subset_version ( - rps, - march, - q, &major_version, &minor_version, - /* default_major_version= */ 2, - /* default_minor_version= */ 0, - /* std_ext_p= */FALSE); - + riscv_parsing_subset_version (rps, march, q, &major_version, + &minor_version, FALSE, + &use_default_version); *q = '\0'; /* Check that the name is valid. @@ -1329,7 +1362,7 @@ riscv_parse_prefixed_ext (riscv_parse_subset_t *rps, if (!config->ext_valid_p (subset)) { rps->error_handler - ("-march=%s: Invalid or unknown %s ISA extension: '%s'", + (_("-march=%s: Invalid or unknown %s ISA extension: '%s'"), march, config->prefix, subset); free (subset); return NULL; @@ -1337,11 +1370,11 @@ riscv_parse_prefixed_ext (riscv_parse_subset_t *rps, /* Check that the last item is not the same as this. */ last_name = rps->subset_list->tail->name; - if (!strcasecmp (last_name, subset)) { - rps->error_handler ("-march=%s: Duplicate %s ISA extension: \'%s\'", - march, config->prefix, subset); + rps->error_handler + (_("-march=%s: Duplicate %s ISA extension: \'%s\'"), + march, config->prefix, subset); free (subset); return NULL; } @@ -1350,20 +1383,29 @@ riscv_parse_prefixed_ext (riscv_parse_subset_t *rps, if (!strncasecmp (last_name, config->prefix, 1) && strcasecmp (last_name, subset) > 0) { - rps->error_handler ("-march=%s: %s ISA extension not in alphabetical " - "order: \'%s\' must come before \'%s\'.", - march, config->prefix, subset, last_name); + rps->error_handler + (_("\ +-march=%s: %s ISA extension not in alphabetical order: \'%s\' must come before \'%s\'."), + march, config->prefix, subset, last_name); free (subset); return NULL; } - riscv_add_subset (rps->subset_list, subset, major_version, minor_version); + /* Find the default version if needed. */ + if (use_default_version + && rps->get_default_version != NULL) + rps->get_default_version (subset, + &major_version, + &minor_version); + riscv_add_subset (rps->subset_list, subset, + major_version, minor_version); + free (subset); p += end_of_version - subset; if (*p != '\0' && *p != '_') { - rps->error_handler ("-march=%s: %s must separate with _", + rps->error_handler (_("-march=%s: %s must separate with _"), march, config->prefix); return NULL; } @@ -1384,7 +1426,7 @@ riscv_parse_prefixed_ext (riscv_parse_subset_t *rps, static const char * const riscv_std_z_ext_strtab[] = { - NULL + "zicsr", NULL }; /* Same as `riscv_std_z_ext_strtab', but for S-class extensions. */ @@ -1478,8 +1520,9 @@ riscv_parse_subset (riscv_parse_subset_t *rps, } else { - rps->error_handler ("-march=%s: ISA string must begin with rv32 or rv64", - arch); + rps->error_handler + (_("-march=%s: ISA string must begin with rv32 or rv64"), + arch); return FALSE; } @@ -1490,7 +1533,6 @@ riscv_parse_subset (riscv_parse_subset_t *rps, return FALSE; /* Parse the different classes of extensions in the specified order. */ - for (i = 0; i < ARRAY_SIZE (parse_config); ++i) { p = riscv_parse_prefixed_ext (rps, arch, p, &parse_config[i]); @@ -1500,7 +1542,7 @@ riscv_parse_subset (riscv_parse_subset_t *rps, if (*p != '\0') { - rps->error_handler ("-march=%s: unexpected ISA string at end: %s", + rps->error_handler (_("-march=%s: unexpected ISA string at end: %s"), arch, p); return FALSE; } @@ -1508,31 +1550,35 @@ riscv_parse_subset (riscv_parse_subset_t *rps, if (riscv_lookup_subset (rps->subset_list, "e") && riscv_lookup_subset (rps->subset_list, "f")) { - rps->error_handler ("-march=%s: rv32e does not support the `f' extension", - arch); + rps->error_handler + (_("-march=%s: rv32e does not support the `f' extension"), + arch); return FALSE; } if (riscv_lookup_subset (rps->subset_list, "d") && !riscv_lookup_subset (rps->subset_list, "f")) { - rps->error_handler ("-march=%s: `d' extension requires `f' extension", - arch); + rps->error_handler + (_("-march=%s: `d' extension requires `f' extension"), + arch); return FALSE; } if (riscv_lookup_subset (rps->subset_list, "q") && !riscv_lookup_subset (rps->subset_list, "d")) { - rps->error_handler ("-march=%s: `q' extension requires `d' extension", - arch); + rps->error_handler + (_("-march=%s: `q' extension requires `d' extension"), + arch); return FALSE; } if (riscv_lookup_subset (rps->subset_list, "q") && *rps->xlen < 64) { - rps->error_handler ("-march=%s: rv32 does not support the `q' extension", - arch); + rps->error_handler + (_("-march=%s: rv32 does not support the `q' extension"), + arch); return FALSE; } return TRUE; @@ -1543,7 +1589,8 @@ riscv_parse_subset (riscv_parse_subset_t *rps, void riscv_add_subset (riscv_subset_list_t *subset_list, const char *subset, - int major, int minor) + int major, + int minor) { riscv_subset_t *s = xmalloc (sizeof *s); @@ -1567,10 +1614,10 @@ riscv_subset_t * riscv_lookup_subset (const riscv_subset_list_t *subset_list, const char *subset) { - return riscv_lookup_subset_version ( - subset_list, subset, - RISCV_DONT_CARE_VERSION, - RISCV_DONT_CARE_VERSION); + return riscv_lookup_subset_version + (subset_list, subset, + RISCV_DONT_CARE_VERSION, + RISCV_DONT_CARE_VERSION); } /* Find subset in list with version checking, return NULL if not found. */ @@ -1617,7 +1664,7 @@ riscv_release_subset_list (riscv_subset_list_t *subset_list) /* Return the number of digits for the input. */ -static size_t +size_t riscv_estimate_digit (unsigned num) { size_t digit = 0; |