1 /* Common target-dependent functionality for LoongArch
3 Copyright (C) 2022-2023 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 /* Register numbers of various important registers. */
28 LOONGARCH_RA_REGNUM
= 1, /* Return Address. */
29 LOONGARCH_SP_REGNUM
= 3, /* Stack Pointer. */
30 LOONGARCH_A0_REGNUM
= 4, /* First Argument/Return Value. */
31 LOONGARCH_A7_REGNUM
= 11, /* Seventh Argument/Syscall Number. */
32 LOONGARCH_FP_REGNUM
= 22, /* Frame Pointer. */
33 LOONGARCH_ORIG_A0_REGNUM
= 32, /* Syscall's original arg0. */
34 LOONGARCH_PC_REGNUM
= 33, /* Program Counter. */
35 LOONGARCH_BADV_REGNUM
= 34, /* Bad Vaddr for Addressing Exception. */
36 LOONGARCH_LINUX_NUM_GREGSET
= 45, /* 32 GPR, ORIG_A0, PC, BADV, RESERVED 10. */
37 LOONGARCH_ARG_REGNUM
= 8, /* r4-r11: general-purpose argument registers.
38 f0-f7: floating-point argument registers. */
39 LOONGARCH_FIRST_FP_REGNUM
= LOONGARCH_LINUX_NUM_GREGSET
,
40 LOONGARCH_LINUX_NUM_FPREGSET
= 32,
41 LOONGARCH_FIRST_FCC_REGNUM
= LOONGARCH_FIRST_FP_REGNUM
+ LOONGARCH_LINUX_NUM_FPREGSET
,
42 LOONGARCH_LINUX_NUM_FCC
= 8,
43 LOONGARCH_FCSR_REGNUM
= LOONGARCH_FIRST_FCC_REGNUM
+ LOONGARCH_LINUX_NUM_FCC
,
46 enum loongarch_fputype
52 /* The set of LoongArch architectural features that we track that impact how
53 we configure the actual gdbarch instance. We hold one of these in the
54 gdbarch_tdep structure, and use it to distinguish between different
55 LoongArch gdbarch instances.
57 The information in here ideally comes from the target description,
58 however, if the target doesn't provide a target description then we will
59 create a default target description by first populating one of these
60 based on what we know about the binary being executed, and using that to
61 drive default target description creation. */
63 struct loongarch_gdbarch_features
65 /* The size of the x-registers in bytes. This is either 4 (loongarch32)
66 or 8 (loongarch64). No other value is valid. Initialise to the invalid
67 0 value so we can spot if one of these is used uninitialised. */
70 /* The type of floating-point. This is either 1 (single float) or 2
71 (double float). No other value is valid. Initialise to the invalid
72 0 value so we can spot if one of these is used uninitialised. */
75 /* Equality operator. */
76 bool operator== (const struct loongarch_gdbarch_features
&rhs
) const
78 return (xlen
== rhs
.xlen
);
81 /* Inequality operator. */
82 bool operator!= (const struct loongarch_gdbarch_features
&rhs
) const
84 return !((*this) == rhs
);
87 /* Used by std::unordered_map to hash feature sets. */
88 std::size_t hash () const noexcept
90 std::size_t val
= (xlen
& 0x1f) << 5;
97 /* Create and return a target description that is compatible with FEATURES.
98 This is only used directly from the gdbserver where the created target
99 description is modified after it is return. */
101 target_desc_up loongarch_create_target_description
102 (const struct loongarch_gdbarch_features features
);
106 /* Lookup an already existing target description matching FEATURES, or
107 create a new target description if this is the first time we have seen
108 FEATURES. For the same FEATURES the same target_desc is always
109 returned. This is important when trying to lookup gdbarch objects as
110 GDBARCH_LIST_LOOKUP_BY_INFO performs a pointer comparison on target
111 descriptions to find candidate gdbarch objects. */
113 const target_desc
*loongarch_lookup_target_description
114 (const struct loongarch_gdbarch_features features
);
116 #endif /* GDBSERVER */
118 #endif /* ARCH_LOONGARCH_H */