]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/arch/riscv.h
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / arch / riscv.h
1 /* Common target-dependent functionality for RISC-V
2
3 Copyright (C) 2018-2024 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #ifndef ARCH_RISCV_H
21 #define ARCH_RISCV_H
22
23 #include "gdbsupport/tdesc.h"
24
25 /* The set of RISC-V architectural features that we track that impact how
26 we configure the actual gdbarch instance. We hold one of these in the
27 gdbarch_tdep structure, and use it to distinguish between different
28 RISC-V gdbarch instances.
29
30 The information in here ideally comes from the target description,
31 however, if the target doesn't provide a target description then we will
32 create a default target description by first populating one of these
33 based on what we know about the binary being executed, and using that to
34 drive default target description creation. */
35
36 struct riscv_gdbarch_features
37 {
38 /* The size of the x-registers in bytes. This is either 4 (RV32), 8
39 (RV64), or 16 (RV128). No other value is valid. Initialise to the
40 invalid 0 value so we can spot if one of these is used
41 uninitialised. */
42 int xlen = 0;
43
44 /* The size of the f-registers in bytes. This is either 4 (RV32), 8
45 (RV64), or 16 (RV128). This can also hold the value 0 to indicate
46 that there are no f-registers. No other value is valid. */
47 int flen = 0;
48
49 /* The size of the v-registers in bytes. The value 0 indicates a target
50 with no vector registers. The minimum value for a 'V'-extension compliant
51 target should be 16 and 4 for an embedded subset compliant target (with
52 'Zve32*' extension), but GDB doesn't currently mind, and will accept any
53 vector size. */
54 int vlen = 0;
55
56 /* When true this target is RV32E. */
57 bool embedded = false;
58
59 /* Track if the target description has an fcsr, fflags, and frm
60 registers. Some targets provide all these in their target
61 descriptions, while some only offer fcsr, while others don't even
62 offer that register. If a target provides fcsr but not fflags and/or
63 frm, then we can emulate these registers as pseudo registers. */
64 bool has_fcsr_reg = false;
65 bool has_fflags_reg = false;
66 bool has_frm_reg = false;
67
68 /* Equality operator. */
69 bool operator== (const struct riscv_gdbarch_features &rhs) const
70 {
71 return (xlen == rhs.xlen && flen == rhs.flen
72 && embedded == rhs.embedded && vlen == rhs.vlen
73 && has_fflags_reg == rhs.has_fflags_reg
74 && has_frm_reg == rhs.has_frm_reg
75 && has_fcsr_reg == rhs.has_fcsr_reg);
76 }
77
78 /* Inequality operator. */
79 bool operator!= (const struct riscv_gdbarch_features &rhs) const
80 {
81 return !((*this) == rhs);
82 }
83
84 /* Used by std::unordered_map to hash feature sets. */
85 std::size_t hash () const noexcept
86 {
87 std::size_t val = ((embedded ? 1 : 0) << 10
88 | (has_fflags_reg ? 1 : 0) << 11
89 | (has_frm_reg ? 1 : 0) << 12
90 | (has_fcsr_reg ? 1 : 0) << 13
91 | (xlen & 0x1f) << 5
92 | (flen & 0x1f) << 0
93 | (vlen & 0x3fff) << 14);
94 return val;
95 }
96 };
97
98 #ifdef GDBSERVER
99
100 /* Create and return a target description that is compatible with FEATURES.
101 This is only used directly from the gdbserver where the created target
102 description is modified after it is return. */
103
104 target_desc_up riscv_create_target_description
105 (const struct riscv_gdbarch_features features);
106
107 #else
108
109 /* Lookup an already existing target description matching FEATURES, or
110 create a new target description if this is the first time we have seen
111 FEATURES. For the same FEATURES the same target_desc is always
112 returned. This is important when trying to lookup gdbarch objects as
113 GDBARCH_LIST_LOOKUP_BY_INFO performs a pointer comparison on target
114 descriptions to find candidate gdbarch objects. */
115
116 const target_desc *riscv_lookup_target_description
117 (const struct riscv_gdbarch_features features);
118
119 #endif /* GDBSERVER */
120
121
122 #endif /* ARCH_RISCV_H */