Change how complex types are printed in C
[deliverable/binutils-gdb.git] / gdb / arch / riscv.c
CommitLineData
b811d2c2 1/* Copyright (C) 2018-2020 Free Software Foundation, Inc.
b5ffee31
AB
2
3 This file is part of GDB.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
268a13a5 18#include "gdbsupport/common-defs.h"
b5ffee31
AB
19#include "riscv.h"
20#include <stdlib.h>
63449436 21#include <unordered_map>
b5ffee31
AB
22
23#include "../features/riscv/32bit-cpu.c"
24#include "../features/riscv/64bit-cpu.c"
25#include "../features/riscv/32bit-fpu.c"
26#include "../features/riscv/64bit-fpu.c"
27
d1c9b20f
AB
28#ifndef GDBSERVER
29#define STATIC_IN_GDB static
30#else
31#define STATIC_IN_GDB
32#endif
63449436 33
b5ffee31
AB
34/* See arch/riscv.h. */
35
d1c9b20f
AB
36STATIC_IN_GDB target_desc *
37riscv_create_target_description (const struct riscv_gdbarch_features features)
b5ffee31 38{
63449436 39 /* Now we should create a new target description. */
b5ffee31
AB
40 target_desc *tdesc = allocate_target_description ();
41
42#ifndef IN_PROCESS_AGENT
43 std::string arch_name = "riscv";
44
45 if (features.xlen == 4)
46 arch_name.append (":rv32i");
47 else if (features.xlen == 8)
48 arch_name.append (":rv64i");
49 else if (features.xlen == 16)
50 arch_name.append (":rv128i");
51
52 if (features.flen == 4)
53 arch_name.append ("f");
54 else if (features.flen == 8)
55 arch_name.append ("d");
56 else if (features.flen == 16)
57 arch_name.append ("q");
58
59 set_tdesc_architecture (tdesc, arch_name.c_str ());
60#endif
61
62 long regnum = 0;
63
64 /* For now we only support creating 32-bit or 64-bit x-registers. */
65 if (features.xlen == 4)
66 regnum = create_feature_riscv_32bit_cpu (tdesc, regnum);
67 else if (features.xlen == 8)
68 regnum = create_feature_riscv_64bit_cpu (tdesc, regnum);
69
70 /* For now we only support creating 32-bit or 64-bit f-registers. */
71 if (features.flen == 4)
72 regnum = create_feature_riscv_32bit_fpu (tdesc, regnum);
73 else if (features.flen == 8)
74 regnum = create_feature_riscv_64bit_fpu (tdesc, regnum);
75
d1c9b20f
AB
76 return tdesc;
77}
78
79#ifndef GDBSERVER
80
81/* Wrapper used by std::unordered_map to generate hash for feature set. */
82struct riscv_gdbarch_features_hasher
83{
84 std::size_t
85 operator() (const riscv_gdbarch_features &features) const noexcept
86 {
87 return features.hash ();
88 }
89};
90
91/* Cache of previously seen target descriptions, indexed by the feature set
92 that created them. */
93static std::unordered_map<riscv_gdbarch_features,
94 const target_desc *,
95 riscv_gdbarch_features_hasher> riscv_tdesc_cache;
96
97/* See arch/riscv.h. */
98
99const target_desc *
100riscv_lookup_target_description (const struct riscv_gdbarch_features features)
101{
102 /* Lookup in the cache. */
103 const auto it = riscv_tdesc_cache.find (features);
104 if (it != riscv_tdesc_cache.end ())
105 return it->second;
106
107 target_desc *tdesc = riscv_create_target_description (features);
108
63449436
AB
109 /* Add to the cache. */
110 riscv_tdesc_cache.emplace (features, tdesc);
111
b5ffee31
AB
112 return tdesc;
113}
d1c9b20f
AB
114
115#endif /* !GDBSERVER */
This page took 0.121301 seconds and 4 git commands to generate.