1 /* Target dependent code for GDB on TI C6x systems.
3 Copyright (C) 2010-2018 Free Software Foundation, Inc.
4 Contributed by Andrew Jenner <andrew@codesourcery.com>
5 Contributed by Yao Qi <yao@codesourcery.com>
7 This file is part of GDB.
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.
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.
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/>. */
23 #include "linux-low.h"
24 #include "arch/tic6x.h"
27 #include "nat/gdb_ptrace.h"
30 #include "gdb_proc_service.h"
32 #ifndef PTRACE_GET_THREAD_AREA
33 #define PTRACE_GET_THREAD_AREA 25
36 /* There are at most 69 registers accessible in ptrace. */
37 #define TIC6X_NUM_REGS 69
39 #include <asm/ptrace.h>
41 /* Defined in auto-generated file tic6x-c64xp-linux.c. */
42 void init_registers_tic6x_c64xp_linux (void);
43 extern const struct target_desc
*tdesc_tic6x_c64xp_linux
;
45 /* Defined in auto-generated file tic6x-c64x-linux.c. */
46 void init_registers_tic6x_c64x_linux (void);
47 extern const struct target_desc
*tdesc_tic6x_c64x_linux
;
49 /* Defined in auto-generated file tic62x-c6xp-linux.c. */
50 void init_registers_tic6x_c62x_linux (void);
51 extern const struct target_desc
*tdesc_tic6x_c62x_linux
;
60 /* Return the ptrace ``address'' of register REGNO. */
62 #if __BYTE_ORDER == __BIG_ENDIAN
63 static int tic6x_regmap_c64xp
[] = {
65 53, 52, 55, 54, 57, 56, 59, 58,
66 61, 60, 63, 62, 65, 64, 67, 66,
68 23, 22, 25, 24, 27, 26, 29, 28,
69 31, 30, 33, 32, 35, 34, 69, 68,
73 37, 36, 39, 38, 41, 40, 43, 42,
74 45, 44, 47, 46, 49, 48, 51, 50,
76 7, 6, 9, 8, 11, 10, 13, 12,
77 15, 14, 17, 16, 19, 18, 21, 20,
82 static int tic6x_regmap_c64x
[] = {
84 51, 50, 53, 52, 55, 54, 57, 56,
85 59, 58, 61, 60, 63, 62, 65, 64,
87 21, 20, 23, 22, 25, 24, 27, 26,
88 29, 28, 31, 30, 33, 32, 67, 66,
92 35, 34, 37, 36, 39, 38, 41, 40,
93 43, 42, 45, 44, 47, 46, 49, 48,
95 5, 4, 7, 6, 9, 8, 11, 10,
96 13, 12, 15, 14, 17, 16, 19, 18,
100 static int tic6x_regmap_c62x
[] = {
102 19, 18, 21, 20, 23, 22, 25, 24,
103 27, 26, 29, 28, 31, 30, 33, 32,
105 5, 4, 7, 6, 9, 8, 11, 10,
106 13, 12, 15, 14, 17, 16, 35, 34,
109 -1, -1, -1, -1, -1, -1, -1, -1,
110 -1, -1, -1, -1, -1, -1, -1, -1,
111 -1, -1, -1, -1, -1, -1, -1, -1,
112 -1, -1, -1, -1, -1, -1, -1, -1,
117 static int tic6x_regmap_c64xp
[] = {
119 52, 53, 54, 55, 56, 57, 58, 59,
120 60, 61, 62, 63, 64, 65, 66, 67,
122 22, 23, 24, 25, 26, 27, 28, 29,
123 30, 31, 32, 33, 34, 35, 68, 69,
127 36, 37, 38, 39, 40, 41, 42, 43,
128 44, 45, 46, 47, 48, 49, 50, 51,
130 6, 7, 8, 9, 10, 11, 12, 13,
131 14, 15, 16, 17, 18, 19, 20, 31,
136 static int tic6x_regmap_c64x
[] = {
138 50, 51, 52, 53, 54, 55, 56, 57,
139 58, 59, 60, 61, 62, 63, 64, 65,
141 20, 21, 22, 23, 24, 25, 26, 27,
142 28, 29, 30, 31, 32, 33, 66, 67,
146 34, 35, 36, 37, 38, 39, 40, 41,
147 42, 43, 44, 45, 46, 47, 48, 49,
149 4, 5, 6, 7, 8, 9, 10, 11,
150 12, 13, 14, 15, 16, 17, 18, 19,
154 static int tic6x_regmap_c62x
[] = {
156 18, 19, 20, 21, 22, 23, 24, 25,
157 26, 27, 28, 29, 30, 31, 32, 33,
159 4, 5, 6, 7, 8, 9, 10, 11,
160 12, 13, 14, 15, 16, 17, 34, 35,
163 -1, -1, -1, -1, -1, -1, -1, -1,
164 -1, -1, -1, -1, -1, -1, -1, -1,
165 -1, -1, -1, -1, -1, -1, -1, -1,
166 -1, -1, -1, -1, -1, -1, -1, -1,
172 extern struct linux_target_ops the_low_target
;
174 static int *tic6x_regmap
;
175 static unsigned int tic6x_breakpoint
;
176 #define tic6x_breakpoint_len 4
178 /* Implementation of linux_target_ops method "sw_breakpoint_from_kind". */
180 static const gdb_byte
*
181 tic6x_sw_breakpoint_from_kind (int kind
, int *size
)
183 *size
= tic6x_breakpoint_len
;
184 return (const gdb_byte
*) &tic6x_breakpoint
;
187 static struct usrregs_info tic6x_usrregs_info
=
190 NULL
, /* Set in tic6x_read_description. */
193 static const struct target_desc
*
194 tic6x_read_description (enum c6x_feature feature
)
196 static target_desc
*tdescs
[C6X_LAST
] = { };
197 struct target_desc
**tdesc
= &tdescs
[feature
];
201 *tdesc
= tic6x_create_target_description (feature
);
202 init_target_desc (*tdesc
);
204 static const char *expedite_regs
[] = { "A15", "PC", NULL
};
205 (*tdesc
)->expedite_regs
= expedite_regs
;
212 tic6x_cannot_fetch_register (int regno
)
214 return (tic6x_regmap
[regno
] == -1);
218 tic6x_cannot_store_register (int regno
)
220 return (tic6x_regmap
[regno
] == -1);
224 tic6x_get_pc (struct regcache
*regcache
)
226 union tic6x_register pc
;
228 collect_register_by_name (regcache
, "PC", pc
.buf
);
233 tic6x_set_pc (struct regcache
*regcache
, CORE_ADDR pc
)
235 union tic6x_register newpc
;
238 supply_register_by_name (regcache
, "PC", newpc
.buf
);
242 tic6x_breakpoint_at (CORE_ADDR where
)
246 (*the_target
->read_memory
) (where
, (unsigned char *) &insn
, 4);
247 if (insn
== tic6x_breakpoint
)
250 /* If necessary, recognize more trap instructions here. GDB only uses the
255 /* Fetch the thread-local storage pointer for libthread_db. */
258 ps_get_thread_area (struct ps_prochandle
*ph
,
259 lwpid_t lwpid
, int idx
, void **base
)
261 if (ptrace (PTRACE_GET_THREAD_AREA
, lwpid
, NULL
, base
) != 0)
264 /* IDX is the bias from the thread pointer to the beginning of the
265 thread descriptor. It has to be subtracted due to implementation
266 quirks in libthread_db. */
267 *base
= (void *) ((char *) *base
- idx
);
273 tic6x_collect_register (struct regcache
*regcache
, int regno
,
274 union tic6x_register
*reg
)
276 union tic6x_register tmp_reg
;
278 collect_register (regcache
, regno
, &tmp_reg
.reg32
);
279 reg
->reg32
= tmp_reg
.reg32
;
283 tic6x_supply_register (struct regcache
*regcache
, int regno
,
284 const union tic6x_register
*reg
)
288 supply_register (regcache
, regno
, reg
->buf
+ offset
);
292 tic6x_fill_gregset (struct regcache
*regcache
, void *buf
)
294 auto regset
= static_cast<union tic6x_register
*> (buf
);
297 for (i
= 0; i
< TIC6X_NUM_REGS
; i
++)
298 if (tic6x_regmap
[i
] != -1)
299 tic6x_collect_register (regcache
, i
, regset
+ tic6x_regmap
[i
]);
303 tic6x_store_gregset (struct regcache
*regcache
, const void *buf
)
305 const auto regset
= static_cast<const union tic6x_register
*> (buf
);
308 for (i
= 0; i
< TIC6X_NUM_REGS
; i
++)
309 if (tic6x_regmap
[i
] != -1)
310 tic6x_supply_register (regcache
, i
, regset
+ tic6x_regmap
[i
]);
313 static struct regset_info tic6x_regsets
[] = {
314 { PTRACE_GETREGS
, PTRACE_SETREGS
, 0, TIC6X_NUM_REGS
* 4, GENERAL_REGS
,
315 tic6x_fill_gregset
, tic6x_store_gregset
},
320 tic6x_arch_setup (void)
322 register unsigned int csr
asm ("B2");
324 enum c6x_feature feature
= C6X_CORE
;
326 /* Determine the CPU we're running on to find the register order. */
327 __asm__ ("MVC .S2 CSR,%0" : "=r" (csr
) :);
331 case 0x00: /* C62x */
332 case 0x02: /* C67x */
333 tic6x_regmap
= tic6x_regmap_c62x
;
334 tic6x_breakpoint
= 0x0000a122; /* BNOP .S2 0,5 */
337 case 0x03: /* C67x+ */
338 tic6x_regmap
= tic6x_regmap_c64x
;
339 tic6x_breakpoint
= 0x0000a122; /* BNOP .S2 0,5 */
342 case 0x0c: /* C64x */
343 tic6x_regmap
= tic6x_regmap_c64x
;
344 tic6x_breakpoint
= 0x0000a122; /* BNOP .S2 0,5 */
347 case 0x10: /* C64x+ */
348 case 0x14: /* C674x */
349 case 0x15: /* C66x */
350 tic6x_regmap
= tic6x_regmap_c64xp
;
351 tic6x_breakpoint
= 0x56454314; /* illegal opcode */
355 error ("Unknown CPU ID 0x%02x", cpuid
);
357 tic6x_usrregs_info
.regmap
= tic6x_regmap
;
359 current_process ()->tdesc
= tic6x_read_description (feature
);
362 /* Support for hardware single step. */
365 tic6x_supports_hardware_single_step (void)
370 static struct regsets_info tic6x_regsets_info
=
372 tic6x_regsets
, /* regsets */
374 NULL
, /* disabled_regsets */
377 static struct regs_info regs_info
=
379 NULL
, /* regset_bitmap */
384 static const struct regs_info
*
385 tic6x_regs_info (void)
390 struct linux_target_ops the_low_target
= {
393 tic6x_cannot_fetch_register
,
394 tic6x_cannot_store_register
,
395 NULL
, /* fetch_register */
398 NULL
, /* breakpoint_kind_from_pc */
399 tic6x_sw_breakpoint_from_kind
,
403 NULL
, /* supports_z_point_type */
404 NULL
, /* insert_point */
405 NULL
, /* remove_point */
406 NULL
, /* stopped_by_watchpoint */
407 NULL
, /* stopped_data_address */
408 NULL
, /* collect_ptrace_register */
409 NULL
, /* supply_ptrace_register */
410 NULL
, /* siginfo_fixup */
411 NULL
, /* new_process */
412 NULL
, /* delete_process */
413 NULL
, /* new_thread */
414 NULL
, /* delete_thread */
416 NULL
, /* prepare_to_resume */
417 NULL
, /* process_qsupported */
418 NULL
, /* supports_tracepoints */
419 NULL
, /* get_thread_area */
420 NULL
, /* install_fast_tracepoint_jump_pad */
422 NULL
, /* get_min_fast_tracepoint_insn_len */
423 NULL
, /* supports_range_stepping */
424 NULL
, /* breakpoint_kind_from_current_state */
425 tic6x_supports_hardware_single_step
,
429 #include "common/selftest.h"
431 namespace selftests
{
436 SELF_CHECK (*tdesc_tic6x_c62x_linux
== *tic6x_read_description (C6X_CORE
));
437 SELF_CHECK (*tdesc_tic6x_c64x_linux
== *tic6x_read_description (C6X_GP
));
438 SELF_CHECK (*tdesc_tic6x_c64xp_linux
== *tic6x_read_description (C6X_C6XP
));
445 initialize_low_arch (void)
448 /* Initialize the Linux target descriptions. */
449 init_registers_tic6x_c64xp_linux ();
450 init_registers_tic6x_c64x_linux ();
451 init_registers_tic6x_c62x_linux ();
453 selftests::register_test ("tic6x-tdesc", selftests::tdesc::tic6x_tdesc_test
);
456 initialize_regsets_info (&tic6x_regsets_info
);