summaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorNelson Chu <nelson.chu@sifive.com>2021-01-28 10:45:56 +0800
committerNelson Chu <nelson.chu@sifive.com>2021-02-18 15:09:16 +0800
commit3d73d29e4eff8701ae6251347d03dd6057911178 (patch)
treece9f9774e088fdf2760261983841664b13dc1e4a /bfd
parent6a780b6766378e3dc9610cba7e12d7eaba196f52 (diff)
RISC-V: Add bfd/cpu-riscv.h to support all spec versions controlling.
Make the opcode/riscv-opc.c and include/opcode/riscv.h tidy, move the spec versions stuff to bfd/cpu-riscv.h. Also move the csr stuff and ext_version_table to gas/config/tc-riscv.c for internal use. To avoid too many repeated code, define general RISCV_GET_SPEC_NAME/SPEC_CLASS macros. Therefore, assembler/dis-assembler/linker/gdb can get all spec versions related stuff from cpu-riscv.h and cpu-riscv.c, since the stuff are defined there uniformly. bfd/ * Makefile.am: Added cpu-riscv.h. * Makefile.in: Regenerated. * po/SRC-POTFILES.in: Regenerated. * cpu-riscv.h: Added to support spec versions controlling. Also added extern arrays and functions for cpu-riscv.c. (enum riscv_spec_class): Define all spec classes here uniformly. (struct riscv_spec): Added for all specs. (RISCV_GET_SPEC_CLASS): Added to reduce repeated code. (RISCV_GET_SPEC_NAME): Likewise. (RISCV_GET_ISA_SPEC_CLASS): Added to get ISA spec class. (RISCV_GET_PRIV_SPEC_CLASS): Added to get privileged spec class. (RISCV_GET_PRIV_SPEC_NAME): Added to get privileged spec name. * cpu-riscv.c (struct priv_spec_t): Replaced with struct riscv_spec. (riscv_get_priv_spec_class): Replaced with RISCV_GET_PRIV_SPEC_CLASS. (riscv_get_priv_spec_name): Replaced with RISCV_GET_PRIV_SPEC_NAME. (riscv_priv_specs): Moved below. (riscv_get_priv_spec_class_from_numbers): Likewise, updated. (riscv_isa_specs): Moved from include/opcode/riscv.h. * elfnn-riscv.c: Included cpu-riscv.h. (riscv_merge_attributes): Initialize in_priv_spec and out_priv_spec. * elfxx-riscv.c: Included cpu-riscv.h and opcode/riscv.h. (RISCV_UNKNOWN_VERSION): Moved from include/opcode/riscv.h. * elfxx-riscv.h: Removed extern functions to cpu-riscv.h. gas/ * config/tc-riscv.c: Included cpu-riscv.h. (enum riscv_csr_clas): Moved from include/opcode/riscv.h. (struct riscv_csr_extra): Likewise. (struct riscv_ext_version): Likewise. (ext_version_table): Moved from opcodes/riscv-opc.c. (default_isa_spec): Updated type to riscv_spec_class. (default_priv_spec): Likewise. (riscv_set_default_isa_spec): Updated. (init_ext_version_hash): Likewise. (riscv_init_csr_hash): Likewise, also fixed indent. include/ * opcode/riscv.h: Moved stuff and make the file tidy. opcodes/ * riscv-dis.c: Included cpu-riscv.h, and removed elfxx-riscv.h. (default_priv_spec): Updated type to riscv_spec_class. (parse_riscv_dis_option): Updated. * riscv-opc.c: Moved stuff and make the file tidy.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog26
-rw-r--r--bfd/Makefile.am2
-rw-r--r--bfd/Makefile.in2
-rw-r--r--bfd/cpu-riscv.c123
-rw-r--r--bfd/cpu-riscv.h81
-rw-r--r--bfd/elfnn-riscv.c5
-rw-r--r--bfd/elfxx-riscv.c5
-rw-r--r--bfd/elfxx-riscv.h12
-rw-r--r--bfd/po/SRC-POTFILES.in1
9 files changed, 156 insertions, 101 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 7feb6087ce..0197e7b0f0 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,29 @@
+2021-02-18 Nelson Chu <nelson.chu@sifive.com>
+
+ * Makefile.am: Added cpu-riscv.h.
+ * Makefile.in: Regenerated.
+ * po/SRC-POTFILES.in: Regenerated.
+ * cpu-riscv.h: Added to support spec versions controlling.
+ Also added extern arrays and functions for cpu-riscv.c.
+ (enum riscv_spec_class): Define all spec classes here uniformly.
+ (struct riscv_spec): Added for all specs.
+ (RISCV_GET_SPEC_CLASS): Added to reduce repeated code.
+ (RISCV_GET_SPEC_NAME): Likewise.
+ (RISCV_GET_ISA_SPEC_CLASS): Added to get ISA spec class.
+ (RISCV_GET_PRIV_SPEC_CLASS): Added to get privileged spec class.
+ (RISCV_GET_PRIV_SPEC_NAME): Added to get privileged spec name.
+ * cpu-riscv.c (struct priv_spec_t): Replaced with struct riscv_spec.
+ (riscv_get_priv_spec_class): Replaced with RISCV_GET_PRIV_SPEC_CLASS.
+ (riscv_get_priv_spec_name): Replaced with RISCV_GET_PRIV_SPEC_NAME.
+ (riscv_priv_specs): Moved below.
+ (riscv_get_priv_spec_class_from_numbers): Likewise, updated.
+ (riscv_isa_specs): Moved from include/opcode/riscv.h.
+ * elfnn-riscv.c: Included cpu-riscv.h.
+ (riscv_merge_attributes): Initialize in_priv_spec and out_priv_spec.
+ * elfxx-riscv.c: Included cpu-riscv.h and opcode/riscv.h.
+ (RISCV_UNKNOWN_VERSION): Moved from include/opcode/riscv.h.
+ * elfxx-riscv.h: Removed extern functions to cpu-riscv.h.
+
2021-02-17 Alan Modra <amodra@gmail.com>
* wasm-module.c: Guard include of limits.h.
diff --git a/bfd/Makefile.am b/bfd/Makefile.am
index 9908249fdd..3f143dc227 100644
--- a/bfd/Makefile.am
+++ b/bfd/Makefile.am
@@ -675,7 +675,7 @@ CFILES = $(SOURCE_CFILES) $(BUILD_CFILES)
SOURCE_HFILES = \
aout-target.h aoutx.h arc-got.h arc-plt.h \
coff-arm.h coff-bfd.h coffcode.h coffswap.h \
- cpu-aarch64.h cpu-arm.h cpu-h8300.h cpu-m68k.h \
+ cpu-aarch64.h cpu-arm.h cpu-h8300.h cpu-m68k.h cpu-riscv.h \
ecoff-bfd.h ecoffswap.h \
elf32-arm.h elf32-avr.h elf32-bfin.h elf32-cr16.h elf32-csky.h \
elf32-dlx.h elf32-hppa.h elf32-m68hc1x.h elf32-m68k.h \
diff --git a/bfd/Makefile.in b/bfd/Makefile.in
index a5d1f8e882..bd64658335 100644
--- a/bfd/Makefile.in
+++ b/bfd/Makefile.in
@@ -1099,7 +1099,7 @@ CFILES = $(SOURCE_CFILES) $(BUILD_CFILES)
SOURCE_HFILES = \
aout-target.h aoutx.h arc-got.h arc-plt.h \
coff-arm.h coff-bfd.h coffcode.h coffswap.h \
- cpu-aarch64.h cpu-arm.h cpu-h8300.h cpu-m68k.h \
+ cpu-aarch64.h cpu-arm.h cpu-h8300.h cpu-m68k.h cpu-riscv.h \
ecoff-bfd.h ecoffswap.h \
elf32-arm.h elf32-avr.h elf32-bfin.h elf32-cr16.h elf32-csky.h \
elf32-dlx.h elf32-hppa.h elf32-m68hc1x.h elf32-m68k.h \
diff --git a/bfd/cpu-riscv.c b/bfd/cpu-riscv.c
index eec61b401c..ce87ccf238 100644
--- a/bfd/cpu-riscv.c
+++ b/bfd/cpu-riscv.c
@@ -23,89 +23,7 @@
#include "sysdep.h"
#include "bfd.h"
#include "libbfd.h"
-#include "elfxx-riscv.h"
-
-/* Record the priv spec version string and the corresponding class. */
-
-struct priv_spec_t
-{
- const char *name;
- enum riscv_priv_spec_class class;
-};
-
-/* List for all supported privilege versions. */
-
-static const struct priv_spec_t priv_specs[] =
-{
- {"1.9.1", PRIV_SPEC_CLASS_1P9P1},
- {"1.10", PRIV_SPEC_CLASS_1P10},
- {"1.11", PRIV_SPEC_CLASS_1P11},
-
-/* Terminate the list. */
- {NULL, 0}
-};
-
-/* Get the corresponding CSR version class by giving a privilege
- version string. */
-
-int
-riscv_get_priv_spec_class (const char *s,
- enum riscv_priv_spec_class *class)
-{
- const struct priv_spec_t *version;
-
- if (s == NULL)
- return 0;
-
- for (version = &priv_specs[0]; version->name != NULL; ++version)
- if (strcmp (version->name, s) == 0)
- {
- *class = version->class;
- return 1;
- }
-
- /* Can not find the supported privilege version. */
- return 0;
-}
-
-/* Get the corresponding CSR version class by giving privilege
- version numbers. It is usually used to convert the priv
- attribute numbers into the corresponding class. */
-
-int
-riscv_get_priv_spec_class_from_numbers (unsigned int major,
- unsigned int minor,
- unsigned int revision,
- enum riscv_priv_spec_class *class)
-{
- char buf[36];
-
- if (major == 0 && minor == 0 && revision == 0)
- {
- *class = PRIV_SPEC_CLASS_NONE;
- return 1;
- }
-
- if (revision != 0)
- snprintf (buf, sizeof (buf), "%u.%u.%u", major, minor, revision);
- else
- snprintf (buf, sizeof (buf), "%u.%u", major, minor);
-
- return riscv_get_priv_spec_class (buf, class);
-}
-
-/* Get the corresponding privilege version string by giving a CSR
- version class. */
-
-const char *
-riscv_get_priv_spec_name (enum riscv_priv_spec_class class)
-{
- /* The first enum is PRIV_SPEC_CLASS_NONE. */
- return priv_specs[class - 1].name;
-}
-
-/* This routine is provided two arch_infos and returns an arch_info
- that is compatible with both, or NULL if none exists. */
+#include "cpu-riscv.h"
static const bfd_arch_info_type *
riscv_compatible (const bfd_arch_info_type *a, const bfd_arch_info_type *b)
@@ -182,6 +100,43 @@ static const bfd_arch_info_type arch_info_struct[] =
};
/* The default architecture is riscv:rv64. */
-
const bfd_arch_info_type bfd_riscv_arch =
N (64, 0, "riscv", TRUE, &arch_info_struct[0]);
+
+/* List for all supported ISA spec versions. */
+const struct riscv_spec riscv_isa_specs[] =
+{
+ {"2.2", ISA_SPEC_CLASS_2P2},
+ {"20190608", ISA_SPEC_CLASS_20190608},
+ {"20191213", ISA_SPEC_CLASS_20191213},
+};
+
+/* List for all supported privileged spec versions. */
+const struct riscv_spec riscv_priv_specs[] =
+{
+ {"1.9.1", PRIV_SPEC_CLASS_1P9P1},
+ {"1.10", PRIV_SPEC_CLASS_1P10},
+ {"1.11", PRIV_SPEC_CLASS_1P11},
+};
+
+/* Get the corresponding CSR version class by giving privilege
+ version numbers. It is usually used to convert the priv
+ attribute numbers into the corresponding class. */
+
+void
+riscv_get_priv_spec_class_from_numbers (unsigned int major,
+ unsigned int minor,
+ unsigned int revision,
+ enum riscv_spec_class *class)
+{
+ enum riscv_spec_class class_t = *class;
+ char buf[36];
+
+ if (revision != 0)
+ snprintf (buf, sizeof (buf), "%u.%u.%u", major, minor, revision);
+ else
+ snprintf (buf, sizeof (buf), "%u.%u", major, minor);
+
+ RISCV_GET_PRIV_SPEC_CLASS (buf, class_t);
+ *class = class_t;
+}
diff --git a/bfd/cpu-riscv.h b/bfd/cpu-riscv.h
new file mode 100644
index 0000000000..cafaca23be
--- /dev/null
+++ b/bfd/cpu-riscv.h
@@ -0,0 +1,81 @@
+/* RISC-V spec version controlling support.
+ Copyright (C) 2019-2020 Free Software Foundation, Inc.
+
+ This file is part of BFD, the Binary File Descriptor library.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+ MA 02110-1301, USA. */
+
+enum riscv_spec_class
+{
+ /* ISA spec. */
+ ISA_SPEC_CLASS_NONE = 0,
+ ISA_SPEC_CLASS_2P2,
+ ISA_SPEC_CLASS_20190608,
+ ISA_SPEC_CLASS_20191213,
+ ISA_SPEC_CLASS_DRAFT,
+
+ /* Privileged spec. */
+ PRIV_SPEC_CLASS_NONE,
+ PRIV_SPEC_CLASS_1P9P1,
+ PRIV_SPEC_CLASS_1P10,
+ PRIV_SPEC_CLASS_1P11,
+ PRIV_SPEC_CLASS_DRAFT,
+};
+
+struct riscv_spec
+{
+ const char *name;
+ enum riscv_spec_class spec_class;
+};
+
+extern const struct riscv_spec riscv_isa_specs[];
+extern const struct riscv_spec riscv_priv_specs[];
+
+#define RISCV_GET_SPEC_CLASS(UTYPE, LTYPE, NAME, CLASS) \
+ do \
+ { \
+ if (NAME == NULL) \
+ break; \
+ \
+ int i_spec = UTYPE##_SPEC_CLASS_NONE + 1; \
+ for (; i_spec < UTYPE##_SPEC_CLASS_DRAFT; i_spec++) \
+ { \
+ int j_spec = i_spec - UTYPE##_SPEC_CLASS_NONE -1; \
+ if (riscv_##LTYPE##_specs[j_spec].name \
+ && strcmp (riscv_##LTYPE##_specs[j_spec].name, NAME) == 0)\
+ { \
+ CLASS = riscv_##LTYPE##_specs[j_spec].spec_class; \
+ break; \
+ } \
+ } \
+ } \
+ while (0)
+
+#define RISCV_GET_SPEC_NAME(UTYPE, LTYPE, NAME, CLASS) \
+ (NAME) = riscv_##LTYPE##_specs[(CLASS) - UTYPE##_SPEC_CLASS_NONE - 1].name
+
+#define RISCV_GET_ISA_SPEC_CLASS(NAME, CLASS) \
+ RISCV_GET_SPEC_CLASS(ISA, isa, NAME, CLASS)
+#define RISCV_GET_PRIV_SPEC_CLASS(NAME, CLASS) \
+ RISCV_GET_SPEC_CLASS(PRIV, priv, NAME, CLASS)
+#define RISCV_GET_PRIV_SPEC_NAME(NAME, CLASS) \
+ RISCV_GET_SPEC_NAME(PRIV, priv, NAME, CLASS)
+
+extern void
+riscv_get_priv_spec_class_from_numbers (unsigned int,
+ unsigned int,
+ unsigned int,
+ enum riscv_spec_class *);
diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index 66272f5c66..8739673079 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -32,6 +32,7 @@
#include "elf/riscv.h"
#include "opcode/riscv.h"
#include "objalloc.h"
+#include "cpu-riscv.h"
#ifdef HAVE_LIMITS_H
#include <limits.h>
@@ -3679,8 +3680,8 @@ riscv_merge_attributes (bfd *ibfd, struct bfd_link_info *info)
unsigned int Tag_a = Tag_RISCV_priv_spec;
unsigned int Tag_b = Tag_RISCV_priv_spec_minor;
unsigned int Tag_c = Tag_RISCV_priv_spec_revision;
- enum riscv_priv_spec_class in_priv_spec;
- enum riscv_priv_spec_class out_priv_spec;
+ enum riscv_spec_class in_priv_spec = PRIV_SPEC_CLASS_NONE;
+ enum riscv_spec_class out_priv_spec = PRIV_SPEC_CLASS_NONE;
/* Get the privileged spec class from elf attributes. */
riscv_get_priv_spec_class_from_numbers (in_attr[Tag_a].i,
diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c
index fa7bce92ce..d3b882b1e8 100644
--- a/bfd/elfxx-riscv.c
+++ b/bfd/elfxx-riscv.c
@@ -25,9 +25,11 @@
#include "libbfd.h"
#include "elf-bfd.h"
#include "elf/riscv.h"
+#include "opcode/riscv.h"
#include "libiberty.h"
#include "elfxx-riscv.h"
#include "safe-ctype.h"
+#include "cpu-riscv.h"
#define MINUS_ONE ((bfd_vma)0 - 1)
@@ -1024,12 +1026,13 @@ riscv_elf_add_sub_reloc (bfd *abfd,
return bfd_reloc_ok;
}
+#define RISCV_UNKNOWN_VERSION -1
+
/* Array is used to compare the orders of all extensions quickly.
Zero value: Preserved keyword.
Negative value: Prefixed keyword (s, h, x, z).
Positive value: Standard extension. */
-
static int riscv_ext_order[26] = {0};
/* Similar to the strcmp. It returns an integer less than, equal to,
diff --git a/bfd/elfxx-riscv.h b/bfd/elfxx-riscv.h
index 87ebaf4930..a7d348ca02 100644
--- a/bfd/elfxx-riscv.h
+++ b/bfd/elfxx-riscv.h
@@ -104,16 +104,4 @@ riscv_isa_ext_class_t
riscv_get_prefix_class (const char *);
extern int
-riscv_get_priv_spec_class (const char *, enum riscv_priv_spec_class *);
-
-extern int
-riscv_get_priv_spec_class_from_numbers (unsigned int,
- unsigned int,
- unsigned int,
- enum riscv_priv_spec_class *);
-
-extern const char *
-riscv_get_priv_spec_name (enum riscv_priv_spec_class);
-
-extern int
riscv_compare_subsets (const char *, const char *);
diff --git a/bfd/po/SRC-POTFILES.in b/bfd/po/SRC-POTFILES.in
index 83530b27f2..c83b86cd66 100644
--- a/bfd/po/SRC-POTFILES.in
+++ b/bfd/po/SRC-POTFILES.in
@@ -101,6 +101,7 @@ cpu-pj.c
cpu-powerpc.c
cpu-pru.c
cpu-riscv.c
+cpu-riscv.h
cpu-rl78.c
cpu-rs6000.c
cpu-rx.c