]>
Commit | Line | Data |
---|---|---|
e5ab6af5 YT |
1 | /* GNU/Linux/LoongArch specific low level interface, for the remote server |
2 | for GDB. | |
3 | Copyright (C) 2022 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 | #include "server.h" | |
21 | #include "linux-low.h" | |
22 | #include "tdesc.h" | |
23 | #include "elf/common.h" | |
24 | #include "arch/loongarch.h" | |
25 | ||
26 | /* Linux target ops definitions for the LoongArch architecture. */ | |
27 | ||
28 | class loongarch_target : public linux_process_target | |
29 | { | |
30 | public: | |
31 | ||
32 | const regs_info *get_regs_info () override; | |
33 | ||
34 | int breakpoint_kind_from_pc (CORE_ADDR *pcptr) override; | |
35 | ||
36 | const gdb_byte *sw_breakpoint_from_kind (int kind, int *size) override; | |
37 | ||
38 | protected: | |
39 | ||
40 | void low_arch_setup () override; | |
41 | ||
42 | bool low_cannot_fetch_register (int regno) override; | |
43 | ||
44 | bool low_cannot_store_register (int regno) override; | |
45 | ||
46 | bool low_fetch_register (regcache *regcache, int regno) override; | |
47 | ||
48 | bool low_supports_breakpoints () override; | |
49 | ||
50 | CORE_ADDR low_get_pc (regcache *regcache) override; | |
51 | ||
52 | void low_set_pc (regcache *regcache, CORE_ADDR newpc) override; | |
53 | ||
54 | bool low_breakpoint_at (CORE_ADDR pc) override; | |
55 | }; | |
56 | ||
57 | /* The singleton target ops object. */ | |
58 | ||
59 | static loongarch_target the_loongarch_target; | |
60 | ||
61 | bool | |
62 | loongarch_target::low_cannot_fetch_register (int regno) | |
63 | { | |
64 | gdb_assert_not_reached ("linux target op low_cannot_fetch_register " | |
65 | "is not implemented by the target"); | |
66 | } | |
67 | ||
68 | bool | |
69 | loongarch_target::low_cannot_store_register (int regno) | |
70 | { | |
71 | gdb_assert_not_reached ("linux target op low_cannot_store_register " | |
72 | "is not implemented by the target"); | |
73 | } | |
74 | ||
75 | /* Implementation of linux target ops method "low_arch_setup". */ | |
76 | ||
77 | void | |
78 | loongarch_target::low_arch_setup () | |
79 | { | |
80 | static const char *expedite_regs[] = { "r3", "pc", NULL }; | |
81 | loongarch_gdbarch_features features; | |
82 | target_desc_up tdesc; | |
83 | ||
84 | features.xlen = sizeof (elf_greg_t); | |
85 | tdesc = loongarch_create_target_description (features); | |
86 | ||
87 | if (!tdesc->expedite_regs) | |
88 | init_target_desc (tdesc.get (), expedite_regs); | |
89 | current_process ()->tdesc = tdesc.release (); | |
90 | } | |
91 | ||
92 | /* Collect GPRs from REGCACHE into BUF. */ | |
93 | ||
94 | static void | |
95 | loongarch_fill_gregset (struct regcache *regcache, void *buf) | |
96 | { | |
e5ab6af5 | 97 | elf_gregset_t *regset = (elf_gregset_t *) buf; |
e5ab6af5 YT |
98 | int i; |
99 | ||
100 | for (i = 1; i < 32; i++) | |
3eba4833 | 101 | collect_register (regcache, i, *regset + i); |
74baa6cd | 102 | collect_register (regcache, LOONGARCH_ORIG_A0_REGNUM, *regset + LOONGARCH_ORIG_A0_REGNUM); |
3eba4833 YT |
103 | collect_register (regcache, LOONGARCH_PC_REGNUM, *regset + LOONGARCH_PC_REGNUM); |
104 | collect_register (regcache, LOONGARCH_BADV_REGNUM, *regset + LOONGARCH_BADV_REGNUM); | |
e5ab6af5 YT |
105 | } |
106 | ||
107 | /* Supply GPRs from BUF into REGCACHE. */ | |
108 | ||
109 | static void | |
110 | loongarch_store_gregset (struct regcache *regcache, const void *buf) | |
111 | { | |
e5ab6af5 | 112 | const elf_gregset_t *regset = (const elf_gregset_t *) buf; |
e5ab6af5 YT |
113 | int i; |
114 | ||
3eba4833 | 115 | supply_register_zeroed (regcache, 0); |
e5ab6af5 | 116 | for (i = 1; i < 32; i++) |
3eba4833 | 117 | supply_register (regcache, i, *regset + i); |
74baa6cd | 118 | supply_register (regcache, LOONGARCH_ORIG_A0_REGNUM, *regset + LOONGARCH_ORIG_A0_REGNUM); |
3eba4833 YT |
119 | supply_register (regcache, LOONGARCH_PC_REGNUM, *regset + LOONGARCH_PC_REGNUM); |
120 | supply_register (regcache, LOONGARCH_BADV_REGNUM, *regset + LOONGARCH_BADV_REGNUM); | |
e5ab6af5 YT |
121 | } |
122 | ||
123 | /* LoongArch/Linux regsets. */ | |
124 | static struct regset_info loongarch_regsets[] = { | |
125 | { PTRACE_GETREGSET, PTRACE_SETREGSET, NT_PRSTATUS, sizeof (elf_gregset_t), | |
126 | GENERAL_REGS, loongarch_fill_gregset, loongarch_store_gregset }, | |
127 | NULL_REGSET | |
128 | }; | |
129 | ||
130 | /* LoongArch/Linux regset information. */ | |
131 | static struct regsets_info loongarch_regsets_info = | |
132 | { | |
133 | loongarch_regsets, /* regsets */ | |
134 | 0, /* num_regsets */ | |
135 | NULL, /* disabled_regsets */ | |
136 | }; | |
137 | ||
138 | /* Definition of linux_target_ops data member "regs_info". */ | |
139 | static struct regs_info loongarch_regs = | |
140 | { | |
141 | NULL, /* regset_bitmap */ | |
142 | NULL, /* usrregs */ | |
143 | &loongarch_regsets_info, | |
144 | }; | |
145 | ||
146 | /* Implementation of linux target ops method "get_regs_info". */ | |
147 | ||
148 | const regs_info * | |
149 | loongarch_target::get_regs_info () | |
150 | { | |
151 | return &loongarch_regs; | |
152 | } | |
153 | ||
154 | /* Implementation of linux target ops method "low_fetch_register". */ | |
155 | ||
156 | bool | |
157 | loongarch_target::low_fetch_register (regcache *regcache, int regno) | |
158 | { | |
3eba4833 | 159 | if (regno != 0) |
e5ab6af5 | 160 | return false; |
3eba4833 | 161 | supply_register_zeroed (regcache, 0); |
e5ab6af5 YT |
162 | return true; |
163 | } | |
164 | ||
165 | bool | |
166 | loongarch_target::low_supports_breakpoints () | |
167 | { | |
168 | return true; | |
169 | } | |
170 | ||
171 | /* Implementation of linux target ops method "low_get_pc". */ | |
172 | ||
173 | CORE_ADDR | |
174 | loongarch_target::low_get_pc (regcache *regcache) | |
175 | { | |
176 | if (register_size (regcache->tdesc, 0) == 8) | |
177 | return linux_get_pc_64bit (regcache); | |
178 | else | |
179 | return linux_get_pc_32bit (regcache); | |
180 | } | |
181 | ||
182 | /* Implementation of linux target ops method "low_set_pc". */ | |
183 | ||
184 | void | |
185 | loongarch_target::low_set_pc (regcache *regcache, CORE_ADDR newpc) | |
186 | { | |
187 | if (register_size (regcache->tdesc, 0) == 8) | |
188 | linux_set_pc_64bit (regcache, newpc); | |
189 | else | |
190 | linux_set_pc_32bit (regcache, newpc); | |
191 | } | |
192 | ||
193 | #define loongarch_breakpoint_len 4 | |
194 | ||
195 | /* LoongArch BRK software debug mode instruction. | |
196 | This instruction needs to match gdb/loongarch-tdep.c | |
197 | (loongarch_default_breakpoint). */ | |
198 | static const gdb_byte loongarch_breakpoint[] = {0x05, 0x00, 0x2a, 0x00}; | |
199 | ||
200 | /* Implementation of target ops method "breakpoint_kind_from_pc". */ | |
201 | ||
202 | int | |
203 | loongarch_target::breakpoint_kind_from_pc (CORE_ADDR *pcptr) | |
204 | { | |
205 | return loongarch_breakpoint_len; | |
206 | } | |
207 | ||
208 | /* Implementation of target ops method "sw_breakpoint_from_kind". */ | |
209 | ||
210 | const gdb_byte * | |
211 | loongarch_target::sw_breakpoint_from_kind (int kind, int *size) | |
212 | { | |
213 | *size = loongarch_breakpoint_len; | |
214 | return (const gdb_byte *) &loongarch_breakpoint; | |
215 | } | |
216 | ||
217 | /* Implementation of linux target ops method "low_breakpoint_at". */ | |
218 | ||
219 | bool | |
220 | loongarch_target::low_breakpoint_at (CORE_ADDR pc) | |
221 | { | |
222 | gdb_byte insn[loongarch_breakpoint_len]; | |
223 | ||
224 | read_memory (pc, (unsigned char *) &insn, loongarch_breakpoint_len); | |
225 | if (memcmp (insn, loongarch_breakpoint, loongarch_breakpoint_len) == 0) | |
226 | return true; | |
227 | ||
228 | return false; | |
229 | } | |
230 | ||
231 | /* The linux target ops object. */ | |
232 | ||
233 | linux_process_target *the_linux_target = &the_loongarch_target; | |
234 | ||
235 | /* Initialize the LoongArch/Linux target. */ | |
236 | ||
237 | void | |
238 | initialize_low_arch () | |
239 | { | |
240 | initialize_regsets_info (&loongarch_regsets_info); | |
241 | } |