]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/arch/loongarch.h
d0a63dc2ac5abc33cb87e5f28b28769e451df9db
[thirdparty/binutils-gdb.git] / gdb / arch / loongarch.h
1 /* Common target-dependent functionality for LoongArch
2
3 Copyright (C) 2022-2023 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_LOONGARCH_H
21 #define ARCH_LOONGARCH_H
22
23 #include "gdbsupport/tdesc.h"
24
25 /* Register numbers of various important registers. */
26 enum loongarch_regnum
27 {
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,
44 };
45
46 enum loongarch_fputype
47 {
48 SINGLE_FLOAT = 1,
49 DOUBLE_FLOAT = 2,
50 };
51
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.
56
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. */
62
63 struct loongarch_gdbarch_features
64 {
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. */
68 int xlen = 0;
69
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. */
73 int fputype = 0;
74
75 /* Equality operator. */
76 bool operator== (const struct loongarch_gdbarch_features &rhs) const
77 {
78 return (xlen == rhs.xlen);
79 }
80
81 /* Inequality operator. */
82 bool operator!= (const struct loongarch_gdbarch_features &rhs) const
83 {
84 return !((*this) == rhs);
85 }
86
87 /* Used by std::unordered_map to hash feature sets. */
88 std::size_t hash () const noexcept
89 {
90 std::size_t val = (xlen & 0x1f) << 5;
91 return val;
92 }
93 };
94
95 #ifdef GDBSERVER
96
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. */
100
101 target_desc_up loongarch_create_target_description
102 (const struct loongarch_gdbarch_features features);
103
104 #else
105
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. */
112
113 const target_desc *loongarch_lookup_target_description
114 (const struct loongarch_gdbarch_features features);
115
116 #endif /* GDBSERVER */
117
118 #endif /* ARCH_LOONGARCH_H */