1 /* RISC-V spec version controlling support.
2    Copyright (C) 2019-2024 Free Software Foundation, Inc.
3 
4    This file is part of BFD, the Binary File Descriptor library.
5 
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10 
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15 
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19    MA 02110-1301, USA.  */
20 
21 enum riscv_spec_class
22 {
23   /* ISA spec.  */
24   ISA_SPEC_CLASS_NONE = 0,
25   ISA_SPEC_CLASS_2P2,
26   ISA_SPEC_CLASS_20190608,
27   ISA_SPEC_CLASS_20191213,
28   ISA_SPEC_CLASS_DRAFT,
29 
30   /* Privileged spec.  */
31   PRIV_SPEC_CLASS_NONE,
32   PRIV_SPEC_CLASS_1P9P1,
33   PRIV_SPEC_CLASS_1P10,
34   PRIV_SPEC_CLASS_1P11,
35   PRIV_SPEC_CLASS_1P12,
36   PRIV_SPEC_CLASS_DRAFT,
37 };
38 
39 struct riscv_spec
40 {
41   const char *name;
42   enum riscv_spec_class spec_class;
43 };
44 
45 extern const struct riscv_spec riscv_isa_specs[];
46 extern const struct riscv_spec riscv_priv_specs[];
47 
48 #define RISCV_GET_SPEC_CLASS(UTYPE, LTYPE, NAME, CLASS)                         \
49   do                                                                                      \
50     {                                                                                     \
51       if (NAME == NULL)                                                                   \
52           break;                                                                          \
53                                                                                           \
54       int i_spec = UTYPE##_SPEC_CLASS_NONE + 1;                                 \
55       for (; i_spec < UTYPE##_SPEC_CLASS_DRAFT; i_spec++)             \
56           {                                                                               \
57             int j_spec = i_spec - UTYPE##_SPEC_CLASS_NONE -1;                   \
58             if (riscv_##LTYPE##_specs[j_spec].name                              \
59                 && strcmp (riscv_##LTYPE##_specs[j_spec].name, NAME) == 0)\
60             {                                                                             \
61               CLASS = riscv_##LTYPE##_specs[j_spec].spec_class;                 \
62               break;                                                                      \
63             }                                                                             \
64           }                                                                               \
65     }                                                                                     \
66   while (0)
67 
68 #define RISCV_GET_SPEC_NAME(UTYPE, LTYPE, NAME, CLASS)                          \
69   (NAME) = riscv_##LTYPE##_specs[(CLASS) - UTYPE##_SPEC_CLASS_NONE - 1].name
70 
71 #define RISCV_GET_ISA_SPEC_CLASS(NAME, CLASS)     \
72   RISCV_GET_SPEC_CLASS(ISA, isa, NAME, CLASS)
73 #define RISCV_GET_PRIV_SPEC_CLASS(NAME, CLASS)    \
74   RISCV_GET_SPEC_CLASS(PRIV, priv, NAME, CLASS)
75 #define RISCV_GET_PRIV_SPEC_NAME(NAME, CLASS)     \
76   RISCV_GET_SPEC_NAME(PRIV, priv, NAME, CLASS)
77 
78 extern void
79 riscv_get_priv_spec_class_from_numbers (unsigned int,
80                                                   unsigned int,
81                                                   unsigned int,
82                                                   enum riscv_spec_class *);
83 
84 extern bool
85 riscv_elf_is_mapping_symbols (const char *);
86