1 /* GNU/Linux/CRIS specific low level interface, for the remote server for GDB.
2 Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2007 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
21 #include "linux-low.h"
22 #include <sys/ptrace.h>
25 #define cris_num_regs 49
27 /* Note: Ignoring USP (having the stack pointer in two locations causes trouble
28 without any significant gain). */
30 /* Locations need to match <include/asm/arch/ptrace.h>. */
31 static int cris_regmap
[] = {
34 9*4, 10*4, 11*4, 12*4,
35 13*4, 14*4, 24*4, 15*4,
45 30*4, 31*4, 32*4, 33*4,
46 34*4, 35*4, 36*4, 37*4,
51 extern int debug_threads
;
57 collect_register_by_name ("pc", &pc
);
59 fprintf (stderr
, "stop pc is %08lx\n", pc
);
64 cris_set_pc (CORE_ADDR pc
)
66 unsigned long newpc
= pc
;
67 supply_register_by_name ("pc", &newpc
);
70 static const unsigned short cris_breakpoint
= 0xe938;
71 #define cris_breakpoint_len 2
74 cris_breakpoint_at (CORE_ADDR where
)
78 (*the_target
->read_memory
) (where
, (unsigned char *) &insn
,
80 if (insn
== cris_breakpoint
)
83 /* If necessary, recognize more trap instructions here. GDB only uses the
88 /* We only place breakpoints in empty marker functions, and thread locking
89 is outside of the function. So rather than importing software single-step,
90 we can just run until exit. */
92 /* FIXME: This function should not be needed, since we have PTRACE_SINGLESTEP
93 for CRISv32. Without it, td_ta_event_getmsg in thread_db_create_event
94 will fail when debugging multi-threaded applications. */
97 cris_reinsert_addr (void)
100 collect_register_by_name ("srp", &pc
);
105 cris_write_data_breakpoint (int bp
, unsigned long start
, unsigned long end
)
110 supply_register_by_name ("s3", &start
);
111 supply_register_by_name ("s4", &end
);
114 supply_register_by_name ("s5", &start
);
115 supply_register_by_name ("s6", &end
);
118 supply_register_by_name ("s7", &start
);
119 supply_register_by_name ("s8", &end
);
122 supply_register_by_name ("s9", &start
);
123 supply_register_by_name ("s10", &end
);
126 supply_register_by_name ("s11", &start
);
127 supply_register_by_name ("s12", &end
);
130 supply_register_by_name ("s13", &start
);
131 supply_register_by_name ("s14", &end
);
137 cris_insert_watchpoint (char type
, CORE_ADDR addr
, int len
)
140 unsigned long bp_ctrl
;
141 unsigned long start
, end
;
144 /* Breakpoint/watchpoint types (GDB terminology):
145 0 = memory breakpoint for instructions
146 (not supported; done via memory write instead)
147 1 = hardware breakpoint for instructions (not supported)
148 2 = write watchpoint (supported)
149 3 = read watchpoint (supported)
150 4 = access watchpoint (supported). */
152 if (type
< '2' || type
> '4')
158 /* Read watchpoints are set as access watchpoints, because of GDB's
159 inability to deal with pure read watchpoints. */
163 /* Get the configuration register. */
164 collect_register_by_name ("s0", &bp_ctrl
);
166 /* The watchpoint allocation scheme is the simplest possible.
167 For example, if a region is watched for read and
168 a write watch is requested, a new watchpoint will
169 be used. Also, if a watch for a region that is already
170 covered by one or more existing watchpoints, a new
171 watchpoint will be used. */
173 /* First, find a free data watchpoint. */
174 for (bp
= 0; bp
< 6; bp
++)
176 /* Each data watchpoint's control registers occupy 2 bits
177 (hence the 3), starting at bit 2 for D0 (hence the 2)
178 with 4 bits between for each watchpoint (yes, the 4). */
179 if (!(bp_ctrl
& (0x3 << (2 + (bp
* 4)))))
185 /* We're out of watchpoints. */
189 /* Configure the control register first. */
190 if (type
== '3' || type
== '4')
192 /* Trigger on read. */
193 bp_ctrl
|= (1 << (2 + bp
* 4));
195 if (type
== '2' || type
== '4')
197 /* Trigger on write. */
198 bp_ctrl
|= (2 << (2 + bp
* 4));
201 /* Setup the configuration register. */
202 supply_register_by_name ("s0", &bp_ctrl
);
204 /* Setup the range. */
206 end
= addr
+ len
- 1;
208 /* Configure the watchpoint register. */
209 cris_write_data_breakpoint (bp
, start
, end
);
211 collect_register_by_name ("ccs", &ccs
);
212 /* Set the S1 flag to enable watchpoints. */
214 supply_register_by_name ("ccs", &ccs
);
220 cris_remove_watchpoint (char type
, CORE_ADDR addr
, int len
)
223 unsigned long bp_ctrl
;
224 unsigned long start
, end
;
226 /* Breakpoint/watchpoint types:
227 0 = memory breakpoint for instructions
228 (not supported; done via memory write instead)
229 1 = hardware breakpoint for instructions (not supported)
230 2 = write watchpoint (supported)
231 3 = read watchpoint (supported)
232 4 = access watchpoint (supported). */
233 if (type
< '2' || type
> '4')
236 /* Read watchpoints are set as access watchpoints, because of GDB's
237 inability to deal with pure read watchpoints. */
241 /* Get the configuration register. */
242 collect_register_by_name ("s0", &bp_ctrl
);
244 /* Try to find a watchpoint that is configured for the
245 specified range, then check that read/write also matches. */
247 /* Ugly pointer arithmetic, since I cannot rely on a
248 single switch (addr) as there may be several watchpoints with
249 the same start address for example. */
251 unsigned long bp_d_regs
[12];
253 /* Get all range registers to simplify search. */
254 collect_register_by_name ("s3", &bp_d_regs
[0]);
255 collect_register_by_name ("s4", &bp_d_regs
[1]);
256 collect_register_by_name ("s5", &bp_d_regs
[2]);
257 collect_register_by_name ("s6", &bp_d_regs
[3]);
258 collect_register_by_name ("s7", &bp_d_regs
[4]);
259 collect_register_by_name ("s8", &bp_d_regs
[5]);
260 collect_register_by_name ("s9", &bp_d_regs
[6]);
261 collect_register_by_name ("s10", &bp_d_regs
[7]);
262 collect_register_by_name ("s11", &bp_d_regs
[8]);
263 collect_register_by_name ("s12", &bp_d_regs
[9]);
264 collect_register_by_name ("s13", &bp_d_regs
[10]);
265 collect_register_by_name ("s14", &bp_d_regs
[11]);
267 for (bp
= 0; bp
< 6; bp
++)
269 if (bp_d_regs
[bp
* 2] == addr
270 && bp_d_regs
[bp
* 2 + 1] == (addr
+ len
- 1)) {
271 /* Matching range. */
272 int bitpos
= 2 + bp
* 4;
275 /* Read/write bits for this BP. */
276 rw_bits
= (bp_ctrl
& (0x3 << bitpos
)) >> bitpos
;
278 if ((type
== '3' && rw_bits
== 0x1)
279 || (type
== '2' && rw_bits
== 0x2)
280 || (type
== '4' && rw_bits
== 0x3))
282 /* Read/write matched. */
290 /* No watchpoint matched. */
294 /* Found a matching watchpoint. Now, deconfigure it by
295 both disabling read/write in bp_ctrl and zeroing its
296 start/end addresses. */
297 bp_ctrl
&= ~(3 << (2 + (bp
* 4)));
298 /* Setup the configuration register. */
299 supply_register_by_name ("s0", &bp_ctrl
);
302 /* Configure the watchpoint register. */
303 cris_write_data_breakpoint (bp
, start
, end
);
305 /* Note that we don't clear the S1 flag here. It's done when continuing. */
310 cris_stopped_by_watchpoint (void)
314 collect_register_by_name ("exs", &exs
);
316 return (((exs
& 0xff00) >> 8) == 0xc);
320 cris_stopped_data_address (void)
324 collect_register_by_name ("eda", &eda
);
326 /* FIXME: Possibly adjust to match watched range. */
331 cris_fill_gregset (void *buf
)
335 for (i
= 0; i
< cris_num_regs
; i
++)
337 if (cris_regmap
[i
] != -1)
338 collect_register (i
, ((char *) buf
) + cris_regmap
[i
]);
343 cris_store_gregset (const void *buf
)
347 for (i
= 0; i
< cris_num_regs
; i
++)
349 if (cris_regmap
[i
] != -1)
350 supply_register (i
, ((char *) buf
) + cris_regmap
[i
]);
354 typedef unsigned long elf_gregset_t
[cris_num_regs
];
356 struct regset_info target_regsets
[] = {
357 { PTRACE_GETREGS
, PTRACE_SETREGS
, sizeof (elf_gregset_t
),
358 GENERAL_REGS
, cris_fill_gregset
, cris_store_gregset
},
359 { 0, 0, -1, -1, NULL
, NULL
}
362 struct linux_target_ops the_low_target
= {
369 (const unsigned char *) &cris_breakpoint
,
374 cris_insert_watchpoint
,
375 cris_remove_watchpoint
,
376 cris_stopped_by_watchpoint
,
377 cris_stopped_data_address
,