]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/arch/loongarch.h
gdb: LoongArch: Change LOONGARCH_FIRST_FP_REGNUM to 35
[thirdparty/binutils-gdb.git] / gdb / arch / loongarch.h
1 /* Common target-dependent functionality for LoongArch
2
3 Copyright (C) 2022-2024 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_USED_NUM_GREGSET = 35, /* 32 GPR, ORIG_A0, PC, BADV. */
37 LOONGARCH_LINUX_NUM_GREGSET = 45, /* 32 GPR, ORIG_A0, PC, BADV, RESERVED 10. */
38 LOONGARCH_ARG_REGNUM = 8, /* r4-r11: general-purpose argument registers.
39 f0-f7: floating-point argument registers. */
40 LOONGARCH_FIRST_FP_REGNUM = LOONGARCH_USED_NUM_GREGSET,
41 LOONGARCH_LINUX_NUM_FPREGSET = 32,
42 LOONGARCH_FIRST_FCC_REGNUM = LOONGARCH_FIRST_FP_REGNUM + LOONGARCH_LINUX_NUM_FPREGSET,
43 LOONGARCH_LINUX_NUM_FCC = 8,
44 LOONGARCH_FCSR_REGNUM = LOONGARCH_FIRST_FCC_REGNUM + LOONGARCH_LINUX_NUM_FCC,
45 LOONGARCH_FIRST_LSX_REGNUM = LOONGARCH_FCSR_REGNUM + 1,
46 LOONGARCH_LINUX_NUM_LSXREGSET = 32,
47 LOONGARCH_FIRST_LASX_REGNUM = LOONGARCH_FIRST_LSX_REGNUM + LOONGARCH_LINUX_NUM_LSXREGSET,
48 LOONGARCH_LINUX_NUM_LASXREGSET = 32,
49
50 LOONGARCH_FIRST_SCR_REGNUM = LOONGARCH_FIRST_LASX_REGNUM + LOONGARCH_LINUX_NUM_LASXREGSET,
51 LOONGARCH_LINUX_NUM_SCR = 4,
52 LOONGARCH_LAST_SCR_REGNUM = LOONGARCH_FIRST_SCR_REGNUM + LOONGARCH_LINUX_NUM_SCR - 1,
53 LOONGARCH_EFLAGS_REGNUM = LOONGARCH_LAST_SCR_REGNUM + 1,
54 LOONGARCH_FTOP_REGNUM = LOONGARCH_EFLAGS_REGNUM + 1,
55 };
56
57 enum loongarch_fputype
58 {
59 SINGLE_FLOAT = 1,
60 DOUBLE_FLOAT = 2,
61 };
62
63 #define LOONGARCH_LBT_REGS_SIZE (8 * LOONGARCH_LINUX_NUM_SCR + 4 + 4)
64
65 /* The set of LoongArch architectural features that we track that impact how
66 we configure the actual gdbarch instance. We hold one of these in the
67 gdbarch_tdep structure, and use it to distinguish between different
68 LoongArch gdbarch instances.
69
70 The information in here ideally comes from the target description,
71 however, if the target doesn't provide a target description then we will
72 create a default target description by first populating one of these
73 based on what we know about the binary being executed, and using that to
74 drive default target description creation. */
75
76 struct loongarch_gdbarch_features
77 {
78 /* The size of the x-registers in bytes. This is either 4 (loongarch32)
79 or 8 (loongarch64). No other value is valid. Initialise to the invalid
80 0 value so we can spot if one of these is used uninitialised. */
81 int xlen = 0;
82
83 /* The type of floating-point. This is either 1 (single float) or 2
84 (double float). No other value is valid. Initialise to the invalid
85 0 value so we can spot if one of these is used uninitialised. */
86 int fputype = 0;
87
88 /* Equality operator. */
89 bool operator== (const struct loongarch_gdbarch_features &rhs) const
90 {
91 return (xlen == rhs.xlen);
92 }
93
94 /* Inequality operator. */
95 bool operator!= (const struct loongarch_gdbarch_features &rhs) const
96 {
97 return !((*this) == rhs);
98 }
99
100 /* Used by std::unordered_map to hash feature sets. */
101 std::size_t hash () const noexcept
102 {
103 std::size_t val = (xlen & 0x1f) << 5;
104 return val;
105 }
106 };
107
108 #ifdef GDBSERVER
109
110 /* Create and return a target description that is compatible with FEATURES.
111 This is only used directly from the gdbserver where the created target
112 description is modified after it is return. */
113
114 target_desc_up loongarch_create_target_description
115 (const struct loongarch_gdbarch_features features);
116
117 #else
118
119 /* Lookup an already existing target description matching FEATURES, or
120 create a new target description if this is the first time we have seen
121 FEATURES. For the same FEATURES the same target_desc is always
122 returned. This is important when trying to lookup gdbarch objects as
123 GDBARCH_LIST_LOOKUP_BY_INFO performs a pointer comparison on target
124 descriptions to find candidate gdbarch objects. */
125
126 const target_desc *loongarch_lookup_target_description
127 (const struct loongarch_gdbarch_features features);
128
129 #endif /* GDBSERVER */
130
131 #endif /* ARCH_LOONGARCH_H */