1 /* Common target-dependent functionality for LoongArch
3 Copyright (C) 2022 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
20 #ifndef ARCH_LOONGARCH_H
21 #define ARCH_LOONGARCH_H
23 #include "gdbsupport/tdesc.h"
25 /* The set of LoongArch 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 LoongArch gdbarch instances.
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. */
36 struct loongarch_gdbarch_features
38 /* The size of the x-registers in bytes. This is either 4 (loongarch32)
39 or 8 (loongarch64). No other value is valid. Initialise to the invalid
40 0 value so we can spot if one of these is used uninitialised. */
43 /* Equality operator. */
44 bool operator== (const struct loongarch_gdbarch_features
&rhs
) const
46 return (xlen
== rhs
.xlen
);
49 /* Inequality operator. */
50 bool operator!= (const struct loongarch_gdbarch_features
&rhs
) const
52 return !((*this) == rhs
);
55 /* Used by std::unordered_map to hash feature sets. */
56 std::size_t hash () const noexcept
58 std::size_t val
= (xlen
& 0x1f) << 5;
63 /* Lookup an already existing target description matching FEATURES, or
64 create a new target description if this is the first time we have seen
65 FEATURES. For the same FEATURES the same target_desc is always
66 returned. This is important when trying to lookup gdbarch objects as
67 GDBARCH_LIST_LOOKUP_BY_INFO performs a pointer comparison on target
68 descriptions to find candidate gdbarch objects. */
70 const target_desc
*loongarch_lookup_target_description
71 (const struct loongarch_gdbarch_features features
);
73 #endif /* ARCH_LOONGARCH_H */