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 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 2 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, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
23 #include "linux-low.h"
24 #include <sys/ptrace.h>
27 #define cris_num_regs 49
29 /* Note: Ignoring USP (having the stack pointer in two locations causes trouble
30 without any significant gain). */
32 /* Locations need to match <include/asm/arch/ptrace.h>. */
33 static int cris_regmap
[] = {
36 9*4, 10*4, 11*4, 12*4,
37 13*4, 14*4, 24*4, 15*4,
47 30*4, 31*4, 32*4, 33*4,
48 34*4, 35*4, 36*4, 37*4,
53 extern int debug_threads
;
59 collect_register_by_name ("pc", &pc
);
61 fprintf (stderr
, "stop pc is %08lx\n", pc
);
66 cris_set_pc (CORE_ADDR pc
)
68 unsigned long newpc
= pc
;
69 supply_register_by_name ("pc", &newpc
);
72 static const unsigned short cris_breakpoint
= 0xe938;
73 #define cris_breakpoint_len 2
76 cris_breakpoint_at (CORE_ADDR where
)
80 (*the_target
->read_memory
) (where
, (unsigned char *) &insn
,
82 if (insn
== cris_breakpoint
)
85 /* If necessary, recognize more trap instructions here. GDB only uses the
90 /* We only place breakpoints in empty marker functions, and thread locking
91 is outside of the function. So rather than importing software single-step,
92 we can just run until exit. */
94 /* FIXME: This function should not be needed, since we have PTRACE_SINGLESTEP
95 for CRISv32. Without it, td_ta_event_getmsg in thread_db_create_event
96 will fail when debugging multi-threaded applications. */
99 cris_reinsert_addr (void)
102 collect_register_by_name ("srp", &pc
);
107 cris_write_data_breakpoint (int bp
, unsigned long start
, unsigned long end
)
112 supply_register_by_name ("s3", &start
);
113 supply_register_by_name ("s4", &end
);
116 supply_register_by_name ("s5", &start
);
117 supply_register_by_name ("s6", &end
);
120 supply_register_by_name ("s7", &start
);
121 supply_register_by_name ("s8", &end
);
124 supply_register_by_name ("s9", &start
);
125 supply_register_by_name ("s10", &end
);
128 supply_register_by_name ("s11", &start
);
129 supply_register_by_name ("s12", &end
);
132 supply_register_by_name ("s13", &start
);
133 supply_register_by_name ("s14", &end
);
139 cris_insert_watchpoint (char type
, CORE_ADDR addr
, int len
)
142 unsigned long bp_ctrl
;
143 unsigned long start
, end
;
146 /* Breakpoint/watchpoint types (GDB terminology):
147 0 = memory breakpoint for instructions
148 (not supported; done via memory write instead)
149 1 = hardware breakpoint for instructions (not supported)
150 2 = write watchpoint (supported)
151 3 = read watchpoint (supported)
152 4 = access watchpoint (supported). */
154 if (type
< '2' || type
> '4')
160 /* Read watchpoints are set as access watchpoints, because of GDB's
161 inability to deal with pure read watchpoints. */
165 /* Get the configuration register. */
166 collect_register_by_name ("s0", &bp_ctrl
);
168 /* The watchpoint allocation scheme is the simplest possible.
169 For example, if a region is watched for read and
170 a write watch is requested, a new watchpoint will
171 be used. Also, if a watch for a region that is already
172 covered by one or more existing watchpoints, a new
173 watchpoint will be used. */
175 /* First, find a free data watchpoint. */
176 for (bp
= 0; bp
< 6; bp
++)
178 /* Each data watchpoint's control registers occupy 2 bits
179 (hence the 3), starting at bit 2 for D0 (hence the 2)
180 with 4 bits between for each watchpoint (yes, the 4). */
181 if (!(bp_ctrl
& (0x3 << (2 + (bp
* 4)))))
187 /* We're out of watchpoints. */
191 /* Configure the control register first. */
192 if (type
== '3' || type
== '4')
194 /* Trigger on read. */
195 bp_ctrl
|= (1 << (2 + bp
* 4));
197 if (type
== '2' || type
== '4')
199 /* Trigger on write. */
200 bp_ctrl
|= (2 << (2 + bp
* 4));
203 /* Setup the configuration register. */
204 supply_register_by_name ("s0", &bp_ctrl
);
206 /* Setup the range. */
208 end
= addr
+ len
- 1;
210 /* Configure the watchpoint register. */
211 cris_write_data_breakpoint (bp
, start
, end
);
213 collect_register_by_name ("ccs", &ccs
);
214 /* Set the S1 flag to enable watchpoints. */
216 supply_register_by_name ("ccs", &ccs
);
222 cris_remove_watchpoint (char type
, CORE_ADDR addr
, int len
)
225 unsigned long bp_ctrl
;
226 unsigned long start
, end
;
228 /* Breakpoint/watchpoint types:
229 0 = memory breakpoint for instructions
230 (not supported; done via memory write instead)
231 1 = hardware breakpoint for instructions (not supported)
232 2 = write watchpoint (supported)
233 3 = read watchpoint (supported)
234 4 = access watchpoint (supported). */
235 if (type
< '2' || type
> '4')
238 /* Read watchpoints are set as access watchpoints, because of GDB's
239 inability to deal with pure read watchpoints. */
243 /* Get the configuration register. */
244 collect_register_by_name ("s0", &bp_ctrl
);
246 /* Try to find a watchpoint that is configured for the
247 specified range, then check that read/write also matches. */
249 /* Ugly pointer arithmetic, since I cannot rely on a
250 single switch (addr) as there may be several watchpoints with
251 the same start address for example. */
253 unsigned long bp_d_regs
[12];
255 /* Get all range registers to simplify search. */
256 collect_register_by_name ("s3", &bp_d_regs
[0]);
257 collect_register_by_name ("s4", &bp_d_regs
[1]);
258 collect_register_by_name ("s5", &bp_d_regs
[2]);
259 collect_register_by_name ("s6", &bp_d_regs
[3]);
260 collect_register_by_name ("s7", &bp_d_regs
[4]);
261 collect_register_by_name ("s8", &bp_d_regs
[5]);
262 collect_register_by_name ("s9", &bp_d_regs
[6]);
263 collect_register_by_name ("s10", &bp_d_regs
[7]);
264 collect_register_by_name ("s11", &bp_d_regs
[8]);
265 collect_register_by_name ("s12", &bp_d_regs
[9]);
266 collect_register_by_name ("s13", &bp_d_regs
[10]);
267 collect_register_by_name ("s14", &bp_d_regs
[11]);
269 for (bp
= 0; bp
< 6; bp
++)
271 if (bp_d_regs
[bp
* 2] == addr
272 && bp_d_regs
[bp
* 2 + 1] == (addr
+ len
- 1)) {
273 /* Matching range. */
274 int bitpos
= 2 + bp
* 4;
277 /* Read/write bits for this BP. */
278 rw_bits
= (bp_ctrl
& (0x3 << bitpos
)) >> bitpos
;
280 if ((type
== '3' && rw_bits
== 0x1)
281 || (type
== '2' && rw_bits
== 0x2)
282 || (type
== '4' && rw_bits
== 0x3))
284 /* Read/write matched. */
292 /* No watchpoint matched. */
296 /* Found a matching watchpoint. Now, deconfigure it by
297 both disabling read/write in bp_ctrl and zeroing its
298 start/end addresses. */
299 bp_ctrl
&= ~(3 << (2 + (bp
* 4)));
300 /* Setup the configuration register. */
301 supply_register_by_name ("s0", &bp_ctrl
);
304 /* Configure the watchpoint register. */
305 cris_write_data_breakpoint (bp
, start
, end
);
307 /* Note that we don't clear the S1 flag here. It's done when continuing. */
312 cris_stopped_by_watchpoint (void)
316 collect_register_by_name ("exs", &exs
);
318 return (((exs
& 0xff00) >> 8) == 0xc);
322 cris_stopped_data_address (void)
326 collect_register_by_name ("eda", &eda
);
328 /* FIXME: Possibly adjust to match watched range. */
333 cris_fill_gregset (void *buf
)
337 for (i
= 0; i
< cris_num_regs
; i
++)
339 if (cris_regmap
[i
] != -1)
340 collect_register (i
, ((char *) buf
) + cris_regmap
[i
]);
345 cris_store_gregset (const void *buf
)
349 for (i
= 0; i
< cris_num_regs
; i
++)
351 if (cris_regmap
[i
] != -1)
352 supply_register (i
, ((char *) buf
) + cris_regmap
[i
]);
356 typedef unsigned long elf_gregset_t
[cris_num_regs
];
358 struct regset_info target_regsets
[] = {
359 { PTRACE_GETREGS
, PTRACE_SETREGS
, sizeof (elf_gregset_t
),
360 GENERAL_REGS
, cris_fill_gregset
, cris_store_gregset
},
361 { 0, 0, -1, -1, NULL
, NULL
}
364 struct linux_target_ops the_low_target
= {
371 (const unsigned char *) &cris_breakpoint
,
376 cris_insert_watchpoint
,
377 cris_remove_watchpoint
,
378 cris_stopped_by_watchpoint
,
379 cris_stopped_data_address
,