]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/arch/arc.c
bfd/aarch64-linux: Support reading and writing the GCS core file note
[thirdparty/binutils-gdb.git] / gdb / arch / arc.c
CommitLineData
d01e8234 1/* Copyright (C) 2017-2025 Free Software Foundation, Inc.
817a7585
AK
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
18
817a7585 19#include "arc.h"
995d3a19
SV
20#include <stdlib.h>
21#include <unordered_map>
22#include <string>
817a7585
AK
23
24/* Target description features. */
995d3a19
SV
25#include "features/arc/v1-core.c"
26#include "features/arc/v1-aux.c"
27#include "features/arc/v2-core.c"
28#include "features/arc/v2-aux.c"
817a7585 29
995d3a19
SV
30#ifndef GDBSERVER
31#define STATIC_IN_GDB static
32#else
33#define STATIC_IN_GDB
34#endif
817a7585 35
bbb826f5 36STATIC_IN_GDB target_desc_up
e4bd363f 37arc_create_target_description (const struct arc_arch_features &features)
817a7585 38{
995d3a19 39 /* Create a new target description. */
bbb826f5 40 target_desc_up tdesc = allocate_target_description ();
817a7585 41
817a7585 42#ifndef IN_PROCESS_AGENT
995d3a19 43 std::string arch_name;
817a7585 44
995d3a19
SV
45 /* Architecture names here must match the ones in
46 ARCH_INFO_STRUCT in bfd/cpu-arc.c. */
47 if (features.isa == ARC_ISA_ARCV1 && features.reg_size == 4)
48 arch_name = "arc:ARC700";
49 else if (features.isa == ARC_ISA_ARCV2 && features.reg_size == 4)
50 arch_name = "arc:ARCv2";
51 else
817a7585 52 {
995d3a19
SV
53 std::string msg = string_printf
54 ("Cannot determine architecture: ISA=%d; bitness=%d",
55 features.isa, 8 * features.reg_size);
557b4d76 56 gdb_assert_not_reached ("%s", msg.c_str ());
817a7585 57 }
995d3a19 58
bbb826f5 59 set_tdesc_architecture (tdesc.get (), arch_name.c_str ());
995d3a19
SV
60#endif
61
62 long regnum = 0;
63
64 switch (features.isa)
817a7585 65 {
995d3a19 66 case ARC_ISA_ARCV1:
bbb826f5
AB
67 regnum = create_feature_arc_v1_core (tdesc.get (), regnum);
68 regnum = create_feature_arc_v1_aux (tdesc.get (), regnum);
995d3a19
SV
69 break;
70 case ARC_ISA_ARCV2:
bbb826f5
AB
71 regnum = create_feature_arc_v2_core (tdesc.get (), regnum);
72 regnum = create_feature_arc_v2_aux (tdesc.get (), regnum);
995d3a19
SV
73 break;
74 default:
75 std::string msg = string_printf
76 ("Cannot choose target description XML: %d", features.isa);
557b4d76 77 gdb_assert_not_reached ("%s", msg.c_str ());
817a7585
AK
78 }
79
80 return tdesc;
81}
995d3a19
SV
82
83#ifndef GDBSERVER
84
85/* Wrapper used by std::unordered_map to generate hash for features set. */
e4bd363f 86struct arc_arch_features_hasher
995d3a19
SV
87{
88 std::size_t
e4bd363f 89 operator() (const arc_arch_features &features) const noexcept
995d3a19
SV
90 {
91 return features.hash ();
92 }
93};
94
95/* Cache of previously created target descriptions, indexed by the hash
96 of the features set used to create them. */
e4bd363f 97static std::unordered_map<arc_arch_features,
995d3a19 98 const target_desc_up,
e4bd363f 99 arc_arch_features_hasher> arc_tdesc_cache;
995d3a19
SV
100
101/* See arch/arc.h. */
102
103const target_desc *
e4bd363f 104arc_lookup_target_description (const struct arc_arch_features &features)
995d3a19
SV
105{
106 /* Lookup in the cache first. If found, return the pointer from the
107 "target_desc_up" type which is a "unique_ptr". This should be fine
108 as the "arc_tdesc_cache" will persist until GDB terminates. */
109 const auto it = arc_tdesc_cache.find (features);
110 if (it != arc_tdesc_cache.end ())
111 return it->second.get ();
112
bbb826f5 113 target_desc_up tdesc = arc_create_target_description (features);
995d3a19 114
995d3a19 115
bbb826f5
AB
116 /* Add to the cache, and return a pointer borrowed from the
117 target_desc_up. This is safe as the cache (and the pointers
118 contained within it) are not deleted until GDB exits. */
119 target_desc *ptr = tdesc.get ();
120 arc_tdesc_cache.emplace (features, std::move (tdesc));
121 return ptr;
995d3a19
SV
122}
123
124#endif /* !GDBSERVER */