Checks
Commit Message
Use --march=help to print all supported extensions and versions.
Signed-off-by: Hau Hsu <hau.hsu@sifive.com>
---
bfd/ChangeLog | 9 ++++++
bfd/elfxx-riscv.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 81 insertions(+)
@@ -1,3 +1,12 @@
+2024-01-17 Hau Hsu <hau.hsu@sifive.com>
+
+ * elfxx-riscv.c (riscv_parse_subset): Parse 'help' keyword to print
+ available extension and versions.
+ (riscv_print_extensions): New function.
+ (riscv_same_extension_version): New function.
+ (riscv_same_extension_diff_version): New function.
+ (riscv_valid_ext): New function.
+
2024-01-15 Nick Clifton <nickc@redhat.com>
* 2.42 branch point.
@@ -2051,6 +2051,71 @@ riscv_set_default_arch (riscv_parse_subset_t *rps)
}
}
+static
+bool riscv_same_extension_version(
+ const struct riscv_supported_ext* ext1,
+ const struct riscv_supported_ext* ext2)
+{
+ return (strcmp(ext1->name, ext2->name) == 0
+ && ext1->major_version == ext2->major_version
+ && ext1->minor_version == ext2->minor_version);
+}
+
+static
+bool riscv_same_extension_diff_version(
+ const struct riscv_supported_ext* ext1,
+ const struct riscv_supported_ext* ext2)
+{
+ return (strcmp(ext1->name, ext2->name) == 0
+ && !(ext1->major_version == ext2->major_version
+ && ext1->minor_version == ext2->minor_version));
+}
+
+static
+bool riscv_valid_ext(const struct riscv_supported_ext *ext)
+{
+ return (ext->isa_spec_class != ISA_SPEC_CLASS_NONE
+ && ext->major_version != RISCV_UNKNOWN_VERSION
+ && ext->minor_version != RISCV_UNKNOWN_VERSION);
+}
+
+static
+void riscv_print_extensions()
+{
+ /* Record the previous pritned extension.
+ Print the current one if they are not the same. */
+ const struct riscv_supported_ext *cur = NULL, *prev = NULL;
+
+ int i, j;
+ printf ("All available -march extensions for RISC-V:");
+ for (i = 0; riscv_all_supported_ext[i] != NULL; i++)
+ {
+ const struct riscv_supported_ext *exts = riscv_all_supported_ext[i];
+ prev = NULL;
+ for (j = 0; exts[j].name != NULL; j++)
+ {
+ cur = &exts[j];
+ if (!riscv_valid_ext (cur))
+ continue;
+
+ if (prev && riscv_same_extension_version (prev, cur))
+ continue;
+
+ if (!prev || !riscv_same_extension_diff_version (prev, cur))
+ {
+ printf("\n\t%-40s%d.%d", cur->name, cur->major_version, cur->minor_version);
+ prev = &exts[j];
+ }
+ else
+ {
+ printf(", %d.%d", cur->major_version, cur->minor_version);
+ prev = &exts[j];
+ }
+ }
+ }
+ printf ("\n");
+}
+
/* Function for parsing ISA string.
Return Value:
@@ -2089,6 +2154,13 @@ riscv_parse_subset (riscv_parse_subset_t *rps,
}
p = arch;
+ /* List all avaiable archs. */
+ if (strcmp (p, "help") == 0)
+ {
+ riscv_print_extensions();
+ exit (EXIT_SUCCESS);
+ }
+
if (startswith (p, "rv32"))
{
*rps->xlen = 32;