1 /* Target dependent code for GDB on TI C6x systems.
3 Copyright (C) 2010-2015 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"
25 #include "nat/gdb_ptrace.h"
28 #include "gdb_proc_service.h"
30 #ifndef PTRACE_GET_THREAD_AREA
31 #define PTRACE_GET_THREAD_AREA 25
34 /* There are at most 69 registers accessible in ptrace. */
35 #define TIC6X_NUM_REGS 69
37 #include <asm/ptrace.h>
39 /* Defined in auto-generated file tic6x-c64xp-linux.c. */
40 void init_registers_tic6x_c64xp_linux (void);
41 extern const struct target_desc
*tdesc_tic6x_c64xp_linux
;
43 /* Defined in auto-generated file tic6x-c64x-linux.c. */
44 void init_registers_tic6x_c64x_linux (void);
45 extern const struct target_desc
*tdesc_tic6x_c64x_linux
;
47 /* Defined in auto-generated file tic62x-c6xp-linux.c. */
48 void init_registers_tic6x_c62x_linux (void);
49 extern const struct target_desc
*tdesc_tic6x_c62x_linux
;
58 /* Return the ptrace ``address'' of register REGNO. */
60 #if __BYTE_ORDER == __BIG_ENDIAN
61 static int tic6x_regmap_c64xp
[] = {
63 53, 52, 55, 54, 57, 56, 59, 58,
64 61, 60, 63, 62, 65, 64, 67, 66,
66 23, 22, 25, 24, 27, 26, 29, 28,
67 31, 30, 33, 32, 35, 34, 69, 68,
71 37, 36, 39, 38, 41, 40, 43, 42,
72 45, 44, 47, 46, 49, 48, 51, 50,
74 7, 6, 9, 8, 11, 10, 13, 12,
75 15, 14, 17, 16, 19, 18, 21, 20,
80 static int tic6x_regmap_c64x
[] = {
82 51, 50, 53, 52, 55, 54, 57, 56,
83 59, 58, 61, 60, 63, 62, 65, 64,
85 21, 20, 23, 22, 25, 24, 27, 26,
86 29, 28, 31, 30, 33, 32, 67, 66,
90 35, 34, 37, 36, 39, 38, 41, 40,
91 43, 42, 45, 44, 47, 46, 49, 48,
93 5, 4, 7, 6, 9, 8, 11, 10,
94 13, 12, 15, 14, 17, 16, 19, 18,
98 static int tic6x_regmap_c62x
[] = {
100 19, 18, 21, 20, 23, 22, 25, 24,
101 27, 26, 29, 28, 31, 30, 33, 32,
103 5, 4, 7, 6, 9, 8, 11, 10,
104 13, 12, 15, 14, 17, 16, 35, 34,
107 -1, -1, -1, -1, -1, -1, -1, -1,
108 -1, -1, -1, -1, -1, -1, -1, -1,
109 -1, -1, -1, -1, -1, -1, -1, -1,
110 -1, -1, -1, -1, -1, -1, -1, -1,
115 static int tic6x_regmap_c64xp
[] = {
117 52, 53, 54, 55, 56, 57, 58, 59,
118 60, 61, 62, 63, 64, 65, 66, 67,
120 22, 23, 24, 25, 26, 27, 28, 29,
121 30, 31, 32, 33, 34, 35, 68, 69,
125 36, 37, 38, 39, 40, 41, 42, 43,
126 44, 45, 46, 47, 48, 49, 50, 51,
128 6, 7, 8, 9, 10, 11, 12, 13,
129 14, 15, 16, 17, 18, 19, 20, 31,
134 static int tic6x_regmap_c64x
[] = {
136 50, 51, 52, 53, 54, 55, 56, 57,
137 58, 59, 60, 61, 62, 63, 64, 65,
139 20, 21, 22, 23, 24, 25, 26, 27,
140 28, 29, 30, 31, 32, 33, 66, 67,
144 34, 35, 36, 37, 38, 39, 40, 41,
145 42, 43, 44, 45, 46, 47, 48, 49,
147 4, 5, 6, 7, 8, 9, 10, 11,
148 12, 13, 14, 15, 16, 17, 18, 19,
152 static int tic6x_regmap_c62x
[] = {
154 18, 19, 20, 21, 22, 23, 24, 25,
155 26, 27, 28, 29, 30, 31, 32, 33,
157 4, 5, 6, 7, 8, 9, 10, 11,
158 12, 13, 14, 15, 16, 17, 34, 35,
161 -1, -1, -1, -1, -1, -1, -1, -1,
162 -1, -1, -1, -1, -1, -1, -1, -1,
163 -1, -1, -1, -1, -1, -1, -1, -1,
164 -1, -1, -1, -1, -1, -1, -1, -1,
170 extern struct linux_target_ops the_low_target
;
172 static int *tic6x_regmap
;
173 static unsigned int tic6x_breakpoint
;
174 #define tic6x_breakpoint_len 4
176 /* Implementation of linux_target_ops method "sw_breakpoint_from_kind". */
178 static const gdb_byte
*
179 tic6x_sw_breakpoint_from_kind (int kind
, int *size
)
181 *size
= tic6x_breakpoint_len
;
182 return (const gdb_byte
*) &tic6x_breakpoint
;
185 /* Forward definition. */
186 static struct usrregs_info tic6x_usrregs_info
;
188 static const struct target_desc
*
189 tic6x_read_description (void)
191 register unsigned int csr
asm ("B2");
193 const struct target_desc
*tdesc
;
195 /* Determine the CPU we're running on to find the register order. */
196 __asm__ ("MVC .S2 CSR,%0" : "=r" (csr
) :);
200 case 0x00: /* C62x */
201 case 0x02: /* C67x */
202 tic6x_regmap
= tic6x_regmap_c62x
;
203 tic6x_breakpoint
= 0x0000a122; /* BNOP .S2 0,5 */
204 tdesc
= tdesc_tic6x_c62x_linux
;
206 case 0x03: /* C67x+ */
207 tic6x_regmap
= tic6x_regmap_c64x
;
208 tic6x_breakpoint
= 0x0000a122; /* BNOP .S2 0,5 */
209 tdesc
= tdesc_tic6x_c64x_linux
;
211 case 0x0c: /* C64x */
212 tic6x_regmap
= tic6x_regmap_c64x
;
213 tic6x_breakpoint
= 0x0000a122; /* BNOP .S2 0,5 */
214 tdesc
= tdesc_tic6x_c64x_linux
;
216 case 0x10: /* C64x+ */
217 case 0x14: /* C674x */
218 case 0x15: /* C66x */
219 tic6x_regmap
= tic6x_regmap_c64xp
;
220 tic6x_breakpoint
= 0x56454314; /* illegal opcode */
221 tdesc
= tdesc_tic6x_c64xp_linux
;
224 error ("Unknown CPU ID 0x%02x", cpuid
);
226 tic6x_usrregs_info
.regmap
= tic6x_regmap
;
231 tic6x_cannot_fetch_register (int regno
)
233 return (tic6x_regmap
[regno
] == -1);
237 tic6x_cannot_store_register (int regno
)
239 return (tic6x_regmap
[regno
] == -1);
243 tic6x_get_pc (struct regcache
*regcache
)
245 union tic6x_register pc
;
247 collect_register_by_name (regcache
, "PC", pc
.buf
);
252 tic6x_set_pc (struct regcache
*regcache
, CORE_ADDR pc
)
254 union tic6x_register newpc
;
257 supply_register_by_name (regcache
, "PC", newpc
.buf
);
261 tic6x_breakpoint_at (CORE_ADDR where
)
265 (*the_target
->read_memory
) (where
, (unsigned char *) &insn
, 4);
266 if (insn
== tic6x_breakpoint
)
269 /* If necessary, recognize more trap instructions here. GDB only uses the
274 /* Fetch the thread-local storage pointer for libthread_db. */
277 ps_get_thread_area (const struct ps_prochandle
*ph
,
278 lwpid_t lwpid
, int idx
, void **base
)
280 if (ptrace (PTRACE_GET_THREAD_AREA
, lwpid
, NULL
, base
) != 0)
283 /* IDX is the bias from the thread pointer to the beginning of the
284 thread descriptor. It has to be subtracted due to implementation
285 quirks in libthread_db. */
286 *base
= (void *) ((char *) *base
- idx
);
292 tic6x_collect_register (struct regcache
*regcache
, int regno
,
293 union tic6x_register
*reg
)
295 union tic6x_register tmp_reg
;
297 collect_register (regcache
, regno
, &tmp_reg
.reg32
);
298 reg
->reg32
= tmp_reg
.reg32
;
302 tic6x_supply_register (struct regcache
*regcache
, int regno
,
303 const union tic6x_register
*reg
)
307 supply_register (regcache
, regno
, reg
->buf
+ offset
);
311 tic6x_fill_gregset (struct regcache
*regcache
, void *buf
)
313 union tic6x_register
*regset
= buf
;
316 for (i
= 0; i
< TIC6X_NUM_REGS
; i
++)
317 if (tic6x_regmap
[i
] != -1)
318 tic6x_collect_register (regcache
, i
, regset
+ tic6x_regmap
[i
]);
322 tic6x_store_gregset (struct regcache
*regcache
, const void *buf
)
324 const union tic6x_register
*regset
= buf
;
327 for (i
= 0; i
< TIC6X_NUM_REGS
; i
++)
328 if (tic6x_regmap
[i
] != -1)
329 tic6x_supply_register (regcache
, i
, regset
+ tic6x_regmap
[i
]);
332 static struct regset_info tic6x_regsets
[] = {
333 { PTRACE_GETREGS
, PTRACE_SETREGS
, 0, TIC6X_NUM_REGS
* 4, GENERAL_REGS
,
334 tic6x_fill_gregset
, tic6x_store_gregset
},
339 tic6x_arch_setup (void)
341 current_process ()->tdesc
= tic6x_read_description ();
344 static struct regsets_info tic6x_regsets_info
=
346 tic6x_regsets
, /* regsets */
348 NULL
, /* disabled_regsets */
351 static struct usrregs_info tic6x_usrregs_info
=
354 NULL
, /* Set in tic6x_read_description. */
357 static struct regs_info regs_info
=
359 NULL
, /* regset_bitmap */
364 static const struct regs_info
*
365 tic6x_regs_info (void)
370 struct linux_target_ops the_low_target
= {
373 tic6x_cannot_fetch_register
,
374 tic6x_cannot_store_register
,
375 NULL
, /* fetch_register */
378 NULL
, /* breakpoint_kind_from_pc */
379 tic6x_sw_breakpoint_from_kind
,
386 initialize_low_arch (void)
388 /* Initialize the Linux target descriptions. */
389 init_registers_tic6x_c64xp_linux ();
390 init_registers_tic6x_c64x_linux ();
391 init_registers_tic6x_c62x_linux ();
393 initialize_regsets_info (&tic6x_regsets_info
);