]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdbserver/linux-csky-low.cc
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdbserver / linux-csky-low.cc
CommitLineData
02cd1b4e 1/* GNU/Linux/MIPS specific low level interface, for the remote server for GDB.
1d506c26 2 Copyright (C) 2022-2024 Free Software Foundation, Inc.
02cd1b4e
JL
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19#include "server.h"
20#include "tdesc.h"
21#include "linux-low.h"
22#include <sys/ptrace.h>
23#include "gdb_proc_service.h"
24#include <asm/ptrace.h>
25#include <elf.h>
26#include "arch/csky.h"
27
28/* Linux target op definitions for the CSKY architecture. */
29
30class csky_target : public linux_process_target
31{
32public:
33
34 const regs_info *get_regs_info () override;
35
36 const gdb_byte *sw_breakpoint_from_kind (int kind, int *size) override;
37
38 bool supports_z_point_type (char z_type) override;
39
40 bool supports_hardware_single_step () override;
41
42protected:
43
44 void low_arch_setup () override;
45
46 bool low_cannot_fetch_register (int regno) override;
47
48 bool low_cannot_store_register (int regno) 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
59static csky_target the_csky_target;
60
61/* Return the ptrace "address" of register REGNO. */
62static int csky_regmap[] = {
63 0*4, 1*4, 2*4, 3*4, 4*4, 5*4, 6*4, 7*4,
64 8*4, 9*4, 10*4, 11*4, 12*4, 13*4, 14*4, 15*4,
65 16*4, 17*4, 18*4, 19*4, 20*4, 21*4, 22*4, 23*4,
66 24*4, 25*4, 26*4, 27*4, 28*4, 29*4, 30*4, 31*4,
67 -1, -1, -1, -1, 34*4, 35*4, -1, -1,
68 40*4, 42*4, 44*4, 46*4, 48*4, 50*4, 52*4, 54*4, /* fr0 ~ fr15, 64bit */
69 56*4, 58*4, 60*4, 62*4, 64*4, 66*4, 68*4, 70*4,
70 72*4, 76*4, 80*4, 84*4, 88*4, 92*4, 96*4,100*4, /* vr0 ~ vr15, 128bit */
71 104*4,108*4,112*4,116*4,120*4,124*4,128*4,132*4,
72 33*4, /* pc */
73 -1, -1, -1, -1, -1, -1, -1, -1,
74 -1, -1, -1, -1, -1, -1, -1, -1,
75 32*4, -1, -1, -1, -1, -1, -1, -1, /* psr */
76 -1, -1, -1, -1, -1, -1, -1, -1,
77 -1, -1, -1, -1, -1, -1, -1, -1,
78 -1, -1, -1, -1, -1, -1, -1, -1,
79 73*4, 72*4, 74*4, -1, -1, -1, 14*4, /* fcr, fid, fesr, usp */
80};
81
82/* CSKY software breakpoint instruction code. */
83
84/* When the kernel code version is behind v4.x,
85 illegal insn 0x1464 will be a software bkpt trigger.
86 When an illegal insn exception happens, the case
87 that insn at EPC is 0x1464 will be recognized as SIGTRAP. */
88static unsigned short csky_breakpoint_illegal_2_v2 = 0x1464;
89static unsigned int csky_breakpoint_illegal_4_v2 = 0x14641464;
90
91bool
92csky_target::low_cannot_fetch_register (int regno)
93{
94 if (csky_regmap[regno] == -1)
95 return true;
96
97 return false;
98}
99
100bool
101csky_target::low_cannot_store_register (int regno)
102{
103 if (csky_regmap[regno] == -1)
104 return true;
105
106 return false;
107}
108
109/* Get the value of pc register. */
110
111CORE_ADDR
112csky_target::low_get_pc (struct regcache *regcache)
113{
114 unsigned long pc;
115 collect_register_by_name (regcache, "pc", &pc);
116 return pc;
117}
118
119/* Set pc register. */
120
121void
122csky_target::low_set_pc (struct regcache *regcache, CORE_ADDR pc)
123{
124 unsigned long new_pc = pc;
125 supply_register_by_name (regcache, "pc", &new_pc);
126}
127
128
129void
130csky_target::low_arch_setup ()
131{
132 static const char *expedite_regs[] = { "r14", "pc", NULL };
133 target_desc_up tdesc = csky_create_target_description ();
134
dd6a9ec1
AB
135 if (tdesc->expedite_regs.empty ())
136 {
137 init_target_desc (tdesc.get (), expedite_regs);
138 gdb_assert (!tdesc->expedite_regs.empty ());
139 }
02cd1b4e
JL
140
141 current_process ()->tdesc = tdesc.release ();
142
143 return;
144}
145
146/* Fetch the thread-local storage pointer for libthread_db. */
147
148ps_err_e
149ps_get_thread_area (struct ps_prochandle *ph,
150 lwpid_t lwpid, int idx, void **base)
151{
152 struct pt_regs regset;
153 if (ptrace (PTRACE_GETREGSET, lwpid,
154 (PTRACE_TYPE_ARG3) (long) NT_PRSTATUS, &regset) != 0)
155 return PS_ERR;
156
157 *base = (void *) regset.tls;
158
159 /* IDX is the bias from the thread pointer to the beginning of the
160 thread descriptor. It has to be subtracted due to implementation
161 quirks in libthread_db. */
162 *base = (void *) ((char *)*base - idx);
163
164 return PS_OK;
165}
166
167/* Gdbserver uses PTRACE_GET/SET_RGESET. */
168
169static void
170csky_fill_pt_gregset (struct regcache *regcache, void *buf)
171{
172 int i, base;
173 struct pt_regs *regset = (struct pt_regs *)buf;
174
175 collect_register_by_name (regcache, "r15", &regset->lr);
176 collect_register_by_name (regcache, "pc", &regset->pc);
177 collect_register_by_name (regcache, "psr", &regset->sr);
178 collect_register_by_name (regcache, "r14", &regset->usp);
179
180 collect_register_by_name (regcache, "r0", &regset->a0);
181 collect_register_by_name (regcache, "r1", &regset->a1);
182 collect_register_by_name (regcache, "r2", &regset->a2);
183 collect_register_by_name (regcache, "r3", &regset->a3);
184
185 base = find_regno (regcache->tdesc, "r4");
186
187 for (i = 0; i < 10; i++)
188 collect_register (regcache, base + i, &regset->regs[i]);
189
190 base = find_regno (regcache->tdesc, "r16");
191 for (i = 0; i < 16; i++)
192 collect_register (regcache, base + i, &regset->exregs[i]);
193
194 collect_register_by_name (regcache, "hi", &regset->rhi);
195 collect_register_by_name (regcache, "lo", &regset->rlo);
196}
197
198static void
199csky_store_pt_gregset (struct regcache *regcache, const void *buf)
200{
201 int i, base;
202 const struct pt_regs *regset = (const struct pt_regs *) buf;
203
204 supply_register_by_name (regcache, "r15", &regset->lr);
205 supply_register_by_name (regcache, "pc", &regset->pc);
206 supply_register_by_name (regcache, "psr", &regset->sr);
207 supply_register_by_name (regcache, "r14", &regset->usp);
208
209 supply_register_by_name (regcache, "r0", &regset->a0);
210 supply_register_by_name (regcache, "r1", &regset->a1);
211 supply_register_by_name (regcache, "r2", &regset->a2);
212 supply_register_by_name (regcache, "r3", &regset->a3);
213
214 base = find_regno (regcache->tdesc, "r4");
215
216 for (i = 0; i < 10; i++)
217 supply_register (regcache, base + i, &regset->regs[i]);
218
219 base = find_regno (regcache->tdesc, "r16");
220 for (i = 0; i < 16; i++)
221 supply_register (regcache, base + i, &regset->exregs[i]);
222
223 supply_register_by_name (regcache, "hi", &regset->rhi);
224 supply_register_by_name (regcache, "lo", &regset->rlo);
225}
226
227static void
228csky_fill_pt_vrregset (struct regcache *regcache, void *buf)
229{
230 int i, base;
231 struct user_fp *regset = (struct user_fp *)buf;
232
233 base = find_regno (regcache->tdesc, "vr0");
234
235 for (i = 0; i < 16; i++)
236 collect_register (regcache, base + i, &regset->vr[i * 4]);
237 collect_register_by_name (regcache, "fcr", &regset->fcr);
238 collect_register_by_name (regcache, "fesr", &regset->fesr);
239 collect_register_by_name (regcache, "fid", &regset->fid);
240}
241
242
243static void
244csky_store_pt_vrregset (struct regcache *regcache, const void *buf)
245{
246 int i, base;
247 const struct user_fp *regset = (const struct user_fp *)buf;
248
249 base = find_regno (regcache->tdesc, "vr0");
250
251 for (i = 0; i < 16; i++)
252 supply_register (regcache, base + i, &regset->vr[i * 4]);
253
254 base = find_regno (regcache->tdesc, "fr0");
255
256 for (i = 0; i < 16; i++)
257 supply_register (regcache, base + i, &regset->vr[i * 4]);
258 supply_register_by_name (regcache, "fcr", &regset->fcr);
259 supply_register_by_name (regcache, "fesr", &regset->fesr);
260 supply_register_by_name (regcache, "fid", &regset->fid);
261}
262
263struct regset_info csky_regsets[] = {
264 { PTRACE_GETREGSET, PTRACE_SETREGSET, NT_PRSTATUS, sizeof(struct pt_regs),
265 GENERAL_REGS, csky_fill_pt_gregset, csky_store_pt_gregset},
266
267 { PTRACE_GETREGSET, PTRACE_SETREGSET, NT_FPREGSET, sizeof(struct user_fp),
268 FP_REGS, csky_fill_pt_vrregset, csky_store_pt_vrregset},
269 NULL_REGSET
270};
271
272
273static struct regsets_info csky_regsets_info =
274{
275 csky_regsets, /* Regsets */
276 0, /* Num_regsets */
277 NULL, /* Disabled_regsets */
278};
279
280
281static struct regs_info csky_regs_info =
282{
283 NULL, /* FIXME: what's this */
33b5899f 284 NULL, /* PEEKUSER/POKEUSR isn't supported by kernel > 4.x */
02cd1b4e
JL
285 &csky_regsets_info
286};
287
288
289const regs_info *
290csky_target::get_regs_info ()
291{
292 return &csky_regs_info;
293}
294
295/* Implementation of linux_target_ops method "sw_breakpoint_from_kind". */
296
297const gdb_byte *
298csky_target::sw_breakpoint_from_kind (int kind, int *size)
299{
300 if (kind == 4)
301 {
302 *size = 4;
303 return (const gdb_byte *) &csky_breakpoint_illegal_4_v2;
304 }
305 else
306 {
307 *size = 2;
308 return (const gdb_byte *) &csky_breakpoint_illegal_2_v2;
309 }
310}
311
312bool
313csky_target::supports_z_point_type (char z_type)
314{
315 /* FIXME: hardware breakpoint support ?? */
316 if (z_type == Z_PACKET_SW_BP)
317 return true;
318
319 return false;
320}
321
322bool
323csky_target::low_breakpoint_at (CORE_ADDR where)
324{
325 unsigned int insn;
326
327 /* Here just read 2 bytes, as csky_breakpoint_illegal_4_v2
328 is double of csky_breakpoint_illegal_2_v2, csky_breakpoint_bkpt_4
329 is double of csky_breakpoint_bkpt_2. Others are 2 bytes bkpt. */
330 read_memory (where, (unsigned char *) &insn, 2);
331
332 if (insn == csky_breakpoint_illegal_2_v2)
333 return true;
334
335 return false;
336}
337
338/* Support for hardware single step. */
339
340bool
341csky_target::supports_hardware_single_step ()
342{
343 return true;
344}
345
346/* The linux target ops object. */
347
348linux_process_target *the_linux_target = &the_csky_target;
349
350void
351initialize_low_arch (void)
352{
353 initialize_regsets_info (&csky_regsets_info);
354}