[PATCH v2 6/9] RISC-V: Support configure option to choose the privilege spec version.

Nelson Chu
2020-05-06T02:55:59Z

Support new configure option --with-priv-spec to choose the privilege spec
version if we don't set the --mpriv-spec option.

* --with-priv-spec = [1.9|1.9.1|1.10|1.11]
The syntax is same as -mpriv-spec option. Assembler will check this setting
if -mpriv-spec option isn’t set.

gas/
* 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.
---
gas/config.in | 3 +++
gas/config/tc-riscv.c | 36 ++++++++++++++++++++++++--------
gas/configure | 13 ++++++++++++
gas/configure.ac | 8 +++++++
gas/testsuite/gas/riscv/csr-dw-regnums.d | 2 +-
gas/testsuite/gas/riscv/priv-reg.d | 2 +-
6 files changed, 53 insertions(+), 11 deletions(-)

diff --git a/gas/config.in b/gas/config.in
index e20d3c3..bd12504 100644
--- a/gas/config.in
+++ b/gas/config.in
@@ -62,6 +62,9 @@
/* Define default value for RISC-V -misa-spec. */
#undef DEFAULT_RISCV_ISA_SPEC

+/* Define default value for RISC-V -mpriv-spec */
+#undef DEFAULT_RISCV_PRIV_SPEC
+
/* Define to 1 if you want to generate GNU x86 used ISA and feature properties
by default. */
#undef DEFAULT_X86_USED_NOTE
diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
index 743e4bb..6fd1dcf 100644
--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -79,6 +79,10 @@ struct riscv_cl_insn
#define DEFAULT_RISCV_ISA_SPEC "2.2"
#endif

+#ifndef DEFAULT_RISCV_PRIV_SPEC
+#define DEFAULT_RISCV_PRIV_SPEC "1.11"
+#endif
+
static const char default_arch[] = DEFAULT_ARCH;
static const char *default_arch_with_ext = DEFAULT_RISCV_ARCH_WITH_EXT;
static enum riscv_isa_spec_class default_isa_spec = ISA_SPEC_CLASS_NONE;
@@ -111,6 +115,25 @@ riscv_set_default_isa_spec (const char *s)
return 1;
}

+/* Set the default_priv_spec, assembler will find the suitable CSR address
+ according to default_priv_spec. Return 0 if the input priv name isn't
+ supported. Otherwise, return 1. */
+
+static int
+riscv_set_default_priv_spec (const char *s)
+{
+ enum riscv_priv_spec_class class;
+ if (!riscv_get_priv_spec_class (s, &class))
+ {
+ as_bad (_("Unknown default privilege spec `%s' set by "
+ "-mpriv-spec or --with-priv-spec"), s);
+ return 0;
+ }
+ else
+ default_priv_spec = class;
+ return 1;
+}
+
/* This is the set of options which the .option pseudo-op may modify. */

struct riscv_set_options
@@ -2626,13 +2649,7 @@ md_parse_option (int c, const char *arg)
return riscv_set_default_isa_spec (arg);

case OPTION_MPRIV_SPEC:
- if (!riscv_get_priv_spec_class (arg, &default_priv_spec))
- {
- as_bad ("Unknown default privilege spec `%s' set by "
- "-mpriv-spec", arg);
- return 0;
- }
- break;
+ return riscv_set_default_priv_spec (arg);

default:
return 0;
@@ -2681,9 +2698,10 @@ riscv_after_parse_args (void)
if (riscv_subset_supports ("e"))
riscv_set_rve (TRUE);

- /* Set the default privilege spec to the newest one. */
+ /* If the -mpriv-spec isn't set, then we set the default privilege spec
+ according to DEFAULT_PRIV_SPEC. */
if (default_priv_spec == PRIV_SPEC_CLASS_NONE)
- default_priv_spec = PRIV_SPEC_CLASS_1P11;
+ riscv_set_default_priv_spec (DEFAULT_RISCV_PRIV_SPEC);

/* Infer ABI from ISA if not specified on command line. */
if (abi_xlen == 0)
diff --git a/gas/configure b/gas/configure
index cc21e0a..72e33d9 100755
--- a/gas/configure
+++ b/gas/configure
@@ -13054,6 +13054,19 @@ _ACEOF
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_isa_spec" >&5
$as_echo "$with_isa_spec" >&6; }
+
+ # --with-priv-spec=[1.9|1.9.1|1.10|1.11].
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for default configuration of --with-priv-spec" >&5
+$as_echo_n "checking for default configuration of --with-priv-spec... " >&6; }
+ if test "x${with_priv_spec}" != x; then
+
+cat >>confdefs.h <<_ACEOF
+#define DEFAULT_RISCV_PRIV_SPEC "$with_priv_spec"
+_ACEOF
+
+ fi
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_priv_spec" >&5
+$as_echo "$with_priv_spec" >&6; }
;;

rl78)
diff --git a/gas/configure.ac b/gas/configure.ac
index 8a5f5c5..82122e8 100644
--- a/gas/configure.ac
+++ b/gas/configure.ac
@@ -596,6 +596,14 @@ changequote([,])dnl
[Define default value for RISC-V -misa-spec.])
fi
AC_MSG_RESULT($with_isa_spec)
+
+ # --with-priv-spec=[1.9|1.9.1|1.10|1.11].
+ AC_MSG_CHECKING(for default configuration of --with-priv-spec)
+ if test "x${with_priv_spec}" != x; then
+ AC_DEFINE_UNQUOTED(DEFAULT_RISCV_PRIV_SPEC, "$with_priv_spec",
+ [Define default value for RISC-V -mpriv-spec])
+ fi
+ AC_MSG_RESULT($with_priv_spec)
;;

rl78)
diff --git a/gas/testsuite/gas/riscv/csr-dw-regnums.d b/gas/testsuite/gas/riscv/csr-dw-regnums.d
index df9642f..c03d459 100644
--- a/gas/testsuite/gas/riscv/csr-dw-regnums.d
+++ b/gas/testsuite/gas/riscv/csr-dw-regnums.d
@@ -1,4 +1,4 @@
-#as: -march=rv32if
+#as: -march=rv32if -mpriv-spec=1.11
#objdump: --dwarf=frames

diff --git a/gas/testsuite/gas/riscv/priv-reg.d b/gas/testsuite/gas/riscv/priv-reg.d
index 8fc41d2..a0c3cd7 100644
--- a/gas/testsuite/gas/riscv/priv-reg.d
+++ b/gas/testsuite/gas/riscv/priv-reg.d
@@ -1,4 +1,4 @@
-#as: -march=rv32if
+#as: -march=rv32if -mpriv-spec=1.11
#objdump: -dr

.*:[ ]+file format .*
--
2.7.4