gdbserver/linux-low: turn 'regs_info' into a method
[deliverable/binutils-gdb.git] / gdbserver / linux-tic6x-low.cc
CommitLineData
58dbd541
YQ
1/* Target dependent code for GDB on TI C6x systems.
2
b811d2c2 3 Copyright (C) 2010-2020 Free Software Foundation, Inc.
58dbd541
YQ
4 Contributed by Andrew Jenner <andrew@codesourcery.com>
5 Contributed by Yao Qi <yao@codesourcery.com>
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21
22#include "server.h"
23#include "linux-low.h"
506fe5f4
YQ
24#include "arch/tic6x.h"
25#include "tdesc.h"
58dbd541 26
5826e159 27#include "nat/gdb_ptrace.h"
58dbd541
YQ
28#include <endian.h>
29
30#include "gdb_proc_service.h"
31
32#ifndef PTRACE_GET_THREAD_AREA
33#define PTRACE_GET_THREAD_AREA 25
34#endif
35
36/* There are at most 69 registers accessible in ptrace. */
37#define TIC6X_NUM_REGS 69
38
39#include <asm/ptrace.h>
40
ef0478f6
TBA
41/* Linux target op definitions for the TI C6x architecture. */
42
43class tic6x_target : public linux_process_target
44{
45public:
46
aa8d21c9
TBA
47 const regs_info *get_regs_info () override;
48
797bcff5
TBA
49protected:
50
51 void low_arch_setup () override;
ef0478f6
TBA
52};
53
54/* The singleton target ops object. */
55
56static tic6x_target the_tic6x_target;
57
58dbd541
YQ
58/* Defined in auto-generated file tic6x-c64xp-linux.c. */
59void init_registers_tic6x_c64xp_linux (void);
3aee8918
PA
60extern const struct target_desc *tdesc_tic6x_c64xp_linux;
61
58dbd541
YQ
62/* Defined in auto-generated file tic6x-c64x-linux.c. */
63void init_registers_tic6x_c64x_linux (void);
3aee8918
PA
64extern const struct target_desc *tdesc_tic6x_c64x_linux;
65
58dbd541
YQ
66/* Defined in auto-generated file tic62x-c6xp-linux.c. */
67void init_registers_tic6x_c62x_linux (void);
3aee8918 68extern const struct target_desc *tdesc_tic6x_c62x_linux;
58dbd541
YQ
69
70union tic6x_register
71{
72 unsigned char buf[4];
73
74 int reg32;
75};
76
77/* Return the ptrace ``address'' of register REGNO. */
78
79#if __BYTE_ORDER == __BIG_ENDIAN
80static int tic6x_regmap_c64xp[] = {
81 /* A0 - A15 */
82 53, 52, 55, 54, 57, 56, 59, 58,
83 61, 60, 63, 62, 65, 64, 67, 66,
84 /* B0 - B15 */
85 23, 22, 25, 24, 27, 26, 29, 28,
86 31, 30, 33, 32, 35, 34, 69, 68,
87 /* CSR PC */
88 5, 4,
89 /* A16 - A31 */
90 37, 36, 39, 38, 41, 40, 43, 42,
91 45, 44, 47, 46, 49, 48, 51, 50,
92 /* B16 - B31 */
93 7, 6, 9, 8, 11, 10, 13, 12,
94 15, 14, 17, 16, 19, 18, 21, 20,
95 /* TSR, ILC, RILC */
96 1, 2, 3
97};
98
99static int tic6x_regmap_c64x[] = {
100 /* A0 - A15 */
101 51, 50, 53, 52, 55, 54, 57, 56,
102 59, 58, 61, 60, 63, 62, 65, 64,
103 /* B0 - B15 */
104 21, 20, 23, 22, 25, 24, 27, 26,
105 29, 28, 31, 30, 33, 32, 67, 66,
106 /* CSR PC */
107 3, 2,
108 /* A16 - A31 */
109 35, 34, 37, 36, 39, 38, 41, 40,
110 43, 42, 45, 44, 47, 46, 49, 48,
111 /* B16 - B31 */
112 5, 4, 7, 6, 9, 8, 11, 10,
113 13, 12, 15, 14, 17, 16, 19, 18,
114 -1, -1, -1
115};
116
117static int tic6x_regmap_c62x[] = {
118 /* A0 - A15 */
119 19, 18, 21, 20, 23, 22, 25, 24,
120 27, 26, 29, 28, 31, 30, 33, 32,
121 /* B0 - B15 */
122 5, 4, 7, 6, 9, 8, 11, 10,
123 13, 12, 15, 14, 17, 16, 35, 34,
124 /* CSR, PC */
125 3, 2,
126 -1, -1, -1, -1, -1, -1, -1, -1,
127 -1, -1, -1, -1, -1, -1, -1, -1,
128 -1, -1, -1, -1, -1, -1, -1, -1,
129 -1, -1, -1, -1, -1, -1, -1, -1,
130 -1, -1, -1
131};
132
133#else
134static int tic6x_regmap_c64xp[] = {
135 /* A0 - A15 */
136 52, 53, 54, 55, 56, 57, 58, 59,
137 60, 61, 62, 63, 64, 65, 66, 67,
138 /* B0 - B15 */
139 22, 23, 24, 25, 26, 27, 28, 29,
140 30, 31, 32, 33, 34, 35, 68, 69,
141 /* CSR PC */
142 4, 5,
143 /* A16 - A31 */
144 36, 37, 38, 39, 40, 41, 42, 43,
145 44, 45, 46, 47, 48, 49, 50, 51,
146 /* B16 -B31 */
147 6, 7, 8, 9, 10, 11, 12, 13,
148 14, 15, 16, 17, 18, 19, 20, 31,
149 /* TSR, ILC, RILC */
150 0, 3, 2
151};
152
153static int tic6x_regmap_c64x[] = {
154 /* A0 - A15 */
155 50, 51, 52, 53, 54, 55, 56, 57,
156 58, 59, 60, 61, 62, 63, 64, 65,
157 /* B0 - B15 */
158 20, 21, 22, 23, 24, 25, 26, 27,
159 28, 29, 30, 31, 32, 33, 66, 67,
160 /* CSR PC */
161 2, 3,
162 /* A16 - A31 */
163 34, 35, 36, 37, 38, 39, 40, 41,
164 42, 43, 44, 45, 46, 47, 48, 49,
165 /* B16 - B31 */
166 4, 5, 6, 7, 8, 9, 10, 11,
167 12, 13, 14, 15, 16, 17, 18, 19,
168 -1, -1, -1
169};
170
171static int tic6x_regmap_c62x[] = {
172 /* A0 - A15 */
173 18, 19, 20, 21, 22, 23, 24, 25,
174 26, 27, 28, 29, 30, 31, 32, 33,
175 /* B0 - B15 */
176 4, 5, 6, 7, 8, 9, 10, 11,
177 12, 13, 14, 15, 16, 17, 34, 35,
178 /* CSR PC */
179 2, 3,
180 -1, -1, -1, -1, -1, -1, -1, -1,
181 -1, -1, -1, -1, -1, -1, -1, -1,
182 -1, -1, -1, -1, -1, -1, -1, -1,
183 -1, -1, -1, -1, -1, -1, -1, -1,
184 -1, -1, -1
185};
186
187#endif
188
189extern struct linux_target_ops the_low_target;
190
191static int *tic6x_regmap;
192static unsigned int tic6x_breakpoint;
dd373349
AT
193#define tic6x_breakpoint_len 4
194
195/* Implementation of linux_target_ops method "sw_breakpoint_from_kind". */
196
197static const gdb_byte *
198tic6x_sw_breakpoint_from_kind (int kind, int *size)
199{
200 *size = tic6x_breakpoint_len;
201 return (const gdb_byte *) &tic6x_breakpoint;
202}
58dbd541 203
3491a34c
YQ
204static struct usrregs_info tic6x_usrregs_info =
205 {
206 TIC6X_NUM_REGS,
207 NULL, /* Set in tic6x_read_description. */
208 };
3aee8918
PA
209
210static const struct target_desc *
506fe5f4 211tic6x_read_description (enum c6x_feature feature)
58dbd541 212{
506fe5f4
YQ
213 static target_desc *tdescs[C6X_LAST] = { };
214 struct target_desc **tdesc = &tdescs[feature];
58dbd541 215
506fe5f4 216 if (*tdesc == NULL)
58dbd541 217 {
506fe5f4 218 *tdesc = tic6x_create_target_description (feature);
506fe5f4 219 static const char *expedite_regs[] = { "A15", "PC", NULL };
190852c8 220 init_target_desc (*tdesc, expedite_regs);
58dbd541 221 }
506fe5f4
YQ
222
223 return *tdesc;
58dbd541
YQ
224}
225
226static int
227tic6x_cannot_fetch_register (int regno)
228{
229 return (tic6x_regmap[regno] == -1);
230}
231
232static int
233tic6x_cannot_store_register (int regno)
234{
235 return (tic6x_regmap[regno] == -1);
236}
237
238static CORE_ADDR
239tic6x_get_pc (struct regcache *regcache)
240{
241 union tic6x_register pc;
242
243 collect_register_by_name (regcache, "PC", pc.buf);
244 return pc.reg32;
245}
246
247static void
248tic6x_set_pc (struct regcache *regcache, CORE_ADDR pc)
249{
250 union tic6x_register newpc;
251
252 newpc.reg32 = pc;
253 supply_register_by_name (regcache, "PC", newpc.buf);
254}
255
58dbd541
YQ
256static int
257tic6x_breakpoint_at (CORE_ADDR where)
258{
259 unsigned int insn;
260
52405d85 261 the_target->read_memory (where, (unsigned char *) &insn, 4);
58dbd541
YQ
262 if (insn == tic6x_breakpoint)
263 return 1;
264
265 /* If necessary, recognize more trap instructions here. GDB only uses the
266 one. */
267 return 0;
268}
269
270/* Fetch the thread-local storage pointer for libthread_db. */
271
272ps_err_e
754653a7 273ps_get_thread_area (struct ps_prochandle *ph,
58dbd541
YQ
274 lwpid_t lwpid, int idx, void **base)
275{
276 if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
277 return PS_ERR;
278
279 /* IDX is the bias from the thread pointer to the beginning of the
280 thread descriptor. It has to be subtracted due to implementation
281 quirks in libthread_db. */
282 *base = (void *) ((char *) *base - idx);
283
284 return PS_OK;
285}
286
287static void
288tic6x_collect_register (struct regcache *regcache, int regno,
289 union tic6x_register *reg)
290{
291 union tic6x_register tmp_reg;
292
293 collect_register (regcache, regno, &tmp_reg.reg32);
294 reg->reg32 = tmp_reg.reg32;
295}
296
297static void
298tic6x_supply_register (struct regcache *regcache, int regno,
299 const union tic6x_register *reg)
300{
301 int offset = 0;
302
303 supply_register (regcache, regno, reg->buf + offset);
304}
305
306static void
307tic6x_fill_gregset (struct regcache *regcache, void *buf)
308{
3491a34c 309 auto regset = static_cast<union tic6x_register *> (buf);
58dbd541
YQ
310 int i;
311
312 for (i = 0; i < TIC6X_NUM_REGS; i++)
313 if (tic6x_regmap[i] != -1)
314 tic6x_collect_register (regcache, i, regset + tic6x_regmap[i]);
315}
316
317static void
318tic6x_store_gregset (struct regcache *regcache, const void *buf)
319{
3491a34c 320 const auto regset = static_cast<const union tic6x_register *> (buf);
58dbd541
YQ
321 int i;
322
323 for (i = 0; i < TIC6X_NUM_REGS; i++)
324 if (tic6x_regmap[i] != -1)
325 tic6x_supply_register (regcache, i, regset + tic6x_regmap[i]);
326}
327
3aee8918 328static struct regset_info tic6x_regsets[] = {
58dbd541
YQ
329 { PTRACE_GETREGS, PTRACE_SETREGS, 0, TIC6X_NUM_REGS * 4, GENERAL_REGS,
330 tic6x_fill_gregset, tic6x_store_gregset },
50bc912a 331 NULL_REGSET
58dbd541
YQ
332};
333
797bcff5
TBA
334void
335tic6x_target::low_arch_setup ()
3aee8918 336{
506fe5f4
YQ
337 register unsigned int csr asm ("B2");
338 unsigned int cpuid;
339 enum c6x_feature feature = C6X_CORE;
340
341 /* Determine the CPU we're running on to find the register order. */
342 __asm__ ("MVC .S2 CSR,%0" : "=r" (csr) :);
343 cpuid = csr >> 24;
344 switch (cpuid)
345 {
346 case 0x00: /* C62x */
347 case 0x02: /* C67x */
348 tic6x_regmap = tic6x_regmap_c62x;
349 tic6x_breakpoint = 0x0000a122; /* BNOP .S2 0,5 */
350 feature = C6X_CORE;
351 break;
352 case 0x03: /* C67x+ */
353 tic6x_regmap = tic6x_regmap_c64x;
354 tic6x_breakpoint = 0x0000a122; /* BNOP .S2 0,5 */
355 feature = C6X_GP;
356 break;
357 case 0x0c: /* C64x */
358 tic6x_regmap = tic6x_regmap_c64x;
359 tic6x_breakpoint = 0x0000a122; /* BNOP .S2 0,5 */
360 feature = C6X_GP;
361 break;
362 case 0x10: /* C64x+ */
363 case 0x14: /* C674x */
364 case 0x15: /* C66x */
365 tic6x_regmap = tic6x_regmap_c64xp;
366 tic6x_breakpoint = 0x56454314; /* illegal opcode */
367 feature = C6X_C6XP;
368 break;
369 default:
370 error ("Unknown CPU ID 0x%02x", cpuid);
371 }
372 tic6x_usrregs_info.regmap = tic6x_regmap;
373
374 current_process ()->tdesc = tic6x_read_description (feature);
3aee8918
PA
375}
376
7d00775e
AT
377/* Support for hardware single step. */
378
379static int
380tic6x_supports_hardware_single_step (void)
381{
382 return 1;
383}
384
3aee8918
PA
385static struct regsets_info tic6x_regsets_info =
386 {
387 tic6x_regsets, /* regsets */
388 0, /* num_regsets */
389 NULL, /* disabled_regsets */
390 };
391
aa8d21c9 392static struct regs_info myregs_info =
3aee8918
PA
393 {
394 NULL, /* regset_bitmap */
395 &tic6x_usrregs_info,
396 &tic6x_regsets_info
397 };
398
aa8d21c9
TBA
399const regs_info *
400tic6x_target::get_regs_info ()
3aee8918 401{
aa8d21c9 402 return &myregs_info;
3aee8918
PA
403}
404
58dbd541 405struct linux_target_ops the_low_target = {
58dbd541
YQ
406 tic6x_cannot_fetch_register,
407 tic6x_cannot_store_register,
c14dfd32 408 NULL, /* fetch_register */
58dbd541
YQ
409 tic6x_get_pc,
410 tic6x_set_pc,
dd373349
AT
411 NULL, /* breakpoint_kind_from_pc */
412 tic6x_sw_breakpoint_from_kind,
58dbd541
YQ
413 NULL,
414 0,
415 tic6x_breakpoint_at,
7d00775e
AT
416 NULL, /* supports_z_point_type */
417 NULL, /* insert_point */
418 NULL, /* remove_point */
419 NULL, /* stopped_by_watchpoint */
420 NULL, /* stopped_data_address */
421 NULL, /* collect_ptrace_register */
422 NULL, /* supply_ptrace_register */
423 NULL, /* siginfo_fixup */
424 NULL, /* new_process */
04ec7890 425 NULL, /* delete_process */
7d00775e 426 NULL, /* new_thread */
466eecee 427 NULL, /* delete_thread */
7d00775e
AT
428 NULL, /* new_fork */
429 NULL, /* prepare_to_resume */
430 NULL, /* process_qsupported */
431 NULL, /* supports_tracepoints */
432 NULL, /* get_thread_area */
433 NULL, /* install_fast_tracepoint_jump_pad */
434 NULL, /* emit_ops */
435 NULL, /* get_min_fast_tracepoint_insn_len */
436 NULL, /* supports_range_stepping */
437 NULL, /* breakpoint_kind_from_current_state */
438 tic6x_supports_hardware_single_step,
58dbd541 439};
3aee8918 440
506fe5f4 441#if GDB_SELF_TEST
268a13a5 442#include "gdbsupport/selftest.h"
506fe5f4
YQ
443
444namespace selftests {
445namespace tdesc {
446static void
447tic6x_tdesc_test ()
448{
449 SELF_CHECK (*tdesc_tic6x_c62x_linux == *tic6x_read_description (C6X_CORE));
450 SELF_CHECK (*tdesc_tic6x_c64x_linux == *tic6x_read_description (C6X_GP));
451 SELF_CHECK (*tdesc_tic6x_c64xp_linux == *tic6x_read_description (C6X_C6XP));
452}
453}
454}
455#endif
456
ef0478f6
TBA
457/* The linux target ops object. */
458
459linux_process_target *the_linux_target = &the_tic6x_target;
460
3aee8918
PA
461void
462initialize_low_arch (void)
463{
506fe5f4 464#if GDB_SELF_TEST
3aee8918
PA
465 /* Initialize the Linux target descriptions. */
466 init_registers_tic6x_c64xp_linux ();
467 init_registers_tic6x_c64x_linux ();
468 init_registers_tic6x_c62x_linux ();
469
506fe5f4
YQ
470 selftests::register_test ("tic6x-tdesc", selftests::tdesc::tic6x_tdesc_test);
471#endif
472
3aee8918
PA
473 initialize_regsets_info (&tic6x_regsets_info);
474}
This page took 0.833021 seconds and 4 git commands to generate.