gdb/
[deliverable/binutils-gdb.git] / gdb / remote-m32r-sdi.c
1 /* Remote debugging interface for M32R/SDI.
2
3 Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
4
5 Contributed by Renesas Technology Co.
6 Written by Kei Sakamoto <sakamoto.kei@renesas.com>.
7
8 This file is part of GDB.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 Boston, MA 02110-1301, USA. */
24
25 #include "defs.h"
26 #include "gdbcmd.h"
27 #include "gdbcore.h"
28 #include "inferior.h"
29 #include "target.h"
30 #include "regcache.h"
31 #include "gdb_string.h"
32 #include <ctype.h>
33 #include <signal.h>
34 #include <netinet/in.h>
35 #include <sys/types.h>
36 #include <sys/time.h>
37 #include <signal.h>
38 #include <time.h>
39
40
41 #include "serial.h"
42
43 /* Descriptor for I/O to remote machine. */
44
45 static struct serial *sdi_desc = NULL;
46
47 #define SDI_TIMEOUT 30
48
49
50 #define SDIPORT 3232
51
52 static char chip_name[64];
53
54 static int step_mode;
55 static unsigned long last_pc_addr = 0xffffffff;
56 static unsigned char last_pc_addr_data[2];
57
58 static int mmu_on = 0;
59
60 static int use_ib_breakpoints = 1;
61
62 #define MAX_BREAKPOINTS 1024
63 static int max_ib_breakpoints;
64 static unsigned long bp_address[MAX_BREAKPOINTS];
65 static unsigned char bp_data[MAX_BREAKPOINTS][4];
66
67 /* dbt -> nop */
68 static const unsigned char dbt_bp_entry[] = {
69 0x10, 0xe0, 0x70, 0x00
70 };
71
72 #define MAX_ACCESS_BREAKS 4
73 static int max_access_breaks;
74 static unsigned long ab_address[MAX_ACCESS_BREAKS];
75 static unsigned int ab_type[MAX_ACCESS_BREAKS];
76 static unsigned int ab_size[MAX_ACCESS_BREAKS];
77 static CORE_ADDR hit_watchpoint_addr = 0;
78
79 static int interrupted = 0;
80
81 /* Forward data declarations */
82 extern struct target_ops m32r_ops;
83
84
85 /* Commands */
86 #define SDI_OPEN 1
87 #define SDI_CLOSE 2
88 #define SDI_RELEASE 3
89 #define SDI_READ_CPU_REG 4
90 #define SDI_WRITE_CPU_REG 5
91 #define SDI_READ_MEMORY 6
92 #define SDI_WRITE_MEMORY 7
93 #define SDI_EXEC_CPU 8
94 #define SDI_STOP_CPU 9
95 #define SDI_WAIT_FOR_READY 10
96 #define SDI_GET_ATTR 11
97 #define SDI_SET_ATTR 12
98 #define SDI_STATUS 13
99
100 /* Attributes */
101 #define SDI_ATTR_NAME 1
102 #define SDI_ATTR_BRK 2
103 #define SDI_ATTR_ABRK 3
104 #define SDI_ATTR_CACHE 4
105 #define SDI_CACHE_TYPE_M32102 0
106 #define SDI_CACHE_TYPE_CHAOS 1
107 #define SDI_ATTR_MEM_ACCESS 5
108 #define SDI_MEM_ACCESS_DEBUG_DMA 0
109 #define SDI_MEM_ACCESS_MON_CODE 1
110
111 /* Registers */
112 #define SDI_REG_R0 0
113 #define SDI_REG_R1 1
114 #define SDI_REG_R2 2
115 #define SDI_REG_R3 3
116 #define SDI_REG_R4 4
117 #define SDI_REG_R5 5
118 #define SDI_REG_R6 6
119 #define SDI_REG_R7 7
120 #define SDI_REG_R8 8
121 #define SDI_REG_R9 9
122 #define SDI_REG_R10 10
123 #define SDI_REG_R11 11
124 #define SDI_REG_R12 12
125 #define SDI_REG_FP 13
126 #define SDI_REG_LR 14
127 #define SDI_REG_SP 15
128 #define SDI_REG_PSW 16
129 #define SDI_REG_CBR 17
130 #define SDI_REG_SPI 18
131 #define SDI_REG_SPU 19
132 #define SDI_REG_CR4 20
133 #define SDI_REG_EVB 21
134 #define SDI_REG_BPC 22
135 #define SDI_REG_CR7 23
136 #define SDI_REG_BBPSW 24
137 #define SDI_REG_CR9 25
138 #define SDI_REG_CR10 26
139 #define SDI_REG_CR11 27
140 #define SDI_REG_CR12 28
141 #define SDI_REG_WR 29
142 #define SDI_REG_BBPC 30
143 #define SDI_REG_PBP 31
144 #define SDI_REG_ACCH 32
145 #define SDI_REG_ACCL 33
146 #define SDI_REG_ACC1H 34
147 #define SDI_REG_ACC1L 35
148
149
150 /* Low level communication functions */
151
152 /* Check an ack packet from the target */
153 static int
154 get_ack (void)
155 {
156 int c;
157
158 if (!sdi_desc)
159 return -1;
160
161 c = serial_readchar (sdi_desc, SDI_TIMEOUT);
162
163 if (c < 0)
164 return -1;
165
166 if (c != '+') /* error */
167 return -1;
168
169 return 0;
170 }
171
172 /* Send data to the target and check an ack packet */
173 static int
174 send_data (void *buf, int len)
175 {
176 int ret;
177
178 if (!sdi_desc)
179 return -1;
180
181 if (serial_write (sdi_desc, buf, len) != 0)
182 return -1;
183
184 if (get_ack () == -1)
185 return -1;
186
187 return len;
188 }
189
190 /* Receive data from the target */
191 static int
192 recv_data (void *buf, int len)
193 {
194 int total = 0;
195 int c;
196
197 if (!sdi_desc)
198 return -1;
199
200 while (total < len)
201 {
202 c = serial_readchar (sdi_desc, SDI_TIMEOUT);
203
204 if (c < 0)
205 return -1;
206
207 ((unsigned char *) buf)[total++] = c;
208 }
209
210 return len;
211 }
212
213 /* Store unsigned long parameter on packet */
214 static void
215 store_long_parameter (void *buf, long val)
216 {
217 val = htonl (val);
218 memcpy (buf, &val, 4);
219 }
220
221 static int
222 send_cmd (unsigned char cmd)
223 {
224 unsigned char buf[1];
225 buf[0] = cmd;
226 return send_data (buf, 1);
227 }
228
229 static int
230 send_one_arg_cmd (unsigned char cmd, unsigned char arg1)
231 {
232 unsigned char buf[2];
233 buf[0] = cmd;
234 buf[1] = arg1;
235 return send_data (buf, 2);
236 }
237
238 static int
239 send_two_arg_cmd (unsigned char cmd, unsigned char arg1, unsigned long arg2)
240 {
241 unsigned char buf[6];
242 buf[0] = cmd;
243 buf[1] = arg1;
244 store_long_parameter (buf + 2, arg2);
245 return send_data (buf, 6);
246 }
247
248 static int
249 send_three_arg_cmd (unsigned char cmd, unsigned long arg1, unsigned long arg2,
250 unsigned long arg3)
251 {
252 unsigned char buf[13];
253 buf[0] = cmd;
254 store_long_parameter (buf + 1, arg1);
255 store_long_parameter (buf + 5, arg2);
256 store_long_parameter (buf + 9, arg3);
257 return send_data (buf, 13);
258 }
259
260 static unsigned char
261 recv_char_data (void)
262 {
263 unsigned char val;
264 recv_data (&val, 1);
265 return val;
266 }
267
268 static unsigned long
269 recv_long_data (void)
270 {
271 unsigned long val;
272 recv_data (&val, 4);
273 return ntohl (val);
274 }
275
276
277 /* Check if MMU is on */
278 static void
279 check_mmu_status (void)
280 {
281 unsigned long val;
282
283 /* Read PC address */
284 if (send_one_arg_cmd (SDI_READ_CPU_REG, SDI_REG_BPC) == -1)
285 return;
286 val = recv_long_data ();
287 if ((val & 0xc0000000) == 0x80000000)
288 {
289 mmu_on = 1;
290 return;
291 }
292
293 /* Read EVB address */
294 if (send_one_arg_cmd (SDI_READ_CPU_REG, SDI_REG_EVB) == -1)
295 return;
296 val = recv_long_data ();
297 if ((val & 0xc0000000) == 0x80000000)
298 {
299 mmu_on = 1;
300 return;
301 }
302
303 mmu_on = 0;
304 }
305
306
307 /* This is called not only when we first attach, but also when the
308 user types "run" after having attached. */
309 static void
310 m32r_create_inferior (char *execfile, char *args, char **env, int from_tty)
311 {
312 CORE_ADDR entry_pt;
313
314 if (args && *args)
315 error (_("Cannot pass arguments to remote STDEBUG process"));
316
317 if (execfile == 0 || exec_bfd == 0)
318 error (_("No executable file specified"));
319
320 if (remote_debug)
321 fprintf_unfiltered (gdb_stdlog, "m32r_create_inferior(%s,%s)\n", execfile,
322 args);
323
324 entry_pt = bfd_get_start_address (exec_bfd);
325
326 /* The "process" (board) is already stopped awaiting our commands, and
327 the program is already downloaded. We just set its PC and go. */
328
329 clear_proceed_status ();
330
331 /* Tell wait_for_inferior that we've started a new process. */
332 init_wait_for_inferior ();
333
334 /* Set up the "saved terminal modes" of the inferior
335 based on what modes we are starting it with. */
336 target_terminal_init ();
337
338 /* Install inferior's terminal modes. */
339 target_terminal_inferior ();
340
341 write_pc (entry_pt);
342 }
343
344 /* Open a connection to a remote debugger.
345 NAME is the filename used for communication. */
346
347 static void
348 m32r_open (char *args, int from_tty)
349 {
350 struct hostent *host_ent;
351 struct sockaddr_in server_addr;
352 char *port_str, hostname[256];
353 int port;
354 int i, n;
355 int yes = 1;
356
357 if (remote_debug)
358 fprintf_unfiltered (gdb_stdlog, "m32r_open(%d)\n", from_tty);
359
360 target_preopen (from_tty);
361
362 push_target (&m32r_ops);
363
364 if (args == NULL)
365 sprintf (hostname, "localhost:%d", SDIPORT);
366 else
367 {
368 port_str = strchr (args, ':');
369 if (port_str == NULL)
370 sprintf (hostname, "%s:%d", args, SDIPORT);
371 else
372 strcpy (hostname, args);
373 }
374
375 sdi_desc = serial_open (hostname);
376 if (!sdi_desc)
377 error (_("Connection refused."));
378
379 if (get_ack () == -1)
380 error (_("Cannot connect to SDI target."));
381
382 if (send_cmd (SDI_OPEN) == -1)
383 error (_("Cannot connect to SDI target."));
384
385 /* Get maximum number of ib breakpoints */
386 send_one_arg_cmd (SDI_GET_ATTR, SDI_ATTR_BRK);
387 max_ib_breakpoints = recv_char_data ();
388 if (remote_debug)
389 printf_filtered ("Max IB Breakpoints = %d\n", max_ib_breakpoints);
390
391 /* Initialize breakpoints. */
392 for (i = 0; i < MAX_BREAKPOINTS; i++)
393 bp_address[i] = 0xffffffff;
394
395 /* Get maximum number of access breaks. */
396 send_one_arg_cmd (SDI_GET_ATTR, SDI_ATTR_ABRK);
397 max_access_breaks = recv_char_data ();
398 if (remote_debug)
399 printf_filtered ("Max Access Breaks = %d\n", max_access_breaks);
400
401 /* Initialize access breask. */
402 for (i = 0; i < MAX_ACCESS_BREAKS; i++)
403 ab_address[i] = 0x00000000;
404
405 check_mmu_status ();
406
407 /* Get the name of chip on target board. */
408 send_one_arg_cmd (SDI_GET_ATTR, SDI_ATTR_NAME);
409 recv_data (chip_name, 64);
410
411 if (from_tty)
412 printf_filtered ("Remote %s connected to %s\n", target_shortname,
413 chip_name);
414 }
415
416 /* Close out all files and local state before this target loses control. */
417
418 static void
419 m32r_close (int quitting)
420 {
421 if (remote_debug)
422 fprintf_unfiltered (gdb_stdlog, "m32r_close(%d)\n", quitting);
423
424 if (sdi_desc)
425 {
426 send_cmd (SDI_CLOSE);
427 serial_close (sdi_desc);
428 sdi_desc = NULL;
429 }
430
431 inferior_ptid = null_ptid;
432 return;
433 }
434
435 /* Tell the remote machine to resume. */
436
437 static void
438 m32r_resume (ptid_t ptid, int step, enum target_signal sig)
439 {
440 unsigned long pc_addr, bp_addr, ab_addr;
441 int ib_breakpoints;
442 unsigned char buf[13];
443 int i;
444
445 if (remote_debug)
446 {
447 if (step)
448 fprintf_unfiltered (gdb_stdlog, "\nm32r_resume(step)\n");
449 else
450 fprintf_unfiltered (gdb_stdlog, "\nm32r_resume(cont)\n");
451 }
452
453 check_mmu_status ();
454
455 pc_addr = read_pc ();
456 if (remote_debug)
457 fprintf_unfiltered (gdb_stdlog, "pc <= 0x%lx\n", pc_addr);
458
459 /* At pc address there is a parallel instruction with +2 offset,
460 so we have to make it a serial instruction or avoid it. */
461 if (pc_addr == last_pc_addr)
462 {
463 /* Avoid a parallel nop. */
464 if (last_pc_addr_data[0] == 0xf0 && last_pc_addr_data[1] == 0x00)
465 {
466 pc_addr += 2;
467 /* Now we can forget this instruction. */
468 last_pc_addr = 0xffffffff;
469 }
470 /* Clear a parallel bit. */
471 else
472 {
473 buf[0] = SDI_WRITE_MEMORY;
474 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
475 store_long_parameter (buf + 1, pc_addr);
476 else
477 store_long_parameter (buf + 1, pc_addr - 1);
478 store_long_parameter (buf + 5, 1);
479 buf[9] = last_pc_addr_data[0] & 0x7f;
480 send_data (buf, 10);
481 }
482 }
483
484 /* Set PC. */
485 send_two_arg_cmd (SDI_WRITE_CPU_REG, SDI_REG_BPC, pc_addr);
486
487 /* step mode. */
488 step_mode = step;
489 if (step)
490 {
491 /* Set PBP. */
492 send_two_arg_cmd (SDI_WRITE_CPU_REG, SDI_REG_PBP, pc_addr | 1);
493 }
494 else
495 {
496 /* Unset PBP. */
497 send_two_arg_cmd (SDI_WRITE_CPU_REG, SDI_REG_PBP, 0x00000000);
498 }
499
500 if (use_ib_breakpoints)
501 ib_breakpoints = max_ib_breakpoints;
502 else
503 ib_breakpoints = 0;
504
505 /* Set ib breakpoints. */
506 for (i = 0; i < ib_breakpoints; i++)
507 {
508 bp_addr = bp_address[i];
509
510 if (bp_addr == 0xffffffff)
511 continue;
512
513 /* Set PBP. */
514 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
515 send_three_arg_cmd (SDI_WRITE_MEMORY, 0xffff8000 + 4 * i, 4,
516 0x00000006);
517 else
518 send_three_arg_cmd (SDI_WRITE_MEMORY, 0xffff8000 + 4 * i, 4,
519 0x06000000);
520
521 send_three_arg_cmd (SDI_WRITE_MEMORY, 0xffff8080 + 4 * i, 4, bp_addr);
522 }
523
524 /* Set dbt breakpoints. */
525 for (i = ib_breakpoints; i < MAX_BREAKPOINTS; i++)
526 {
527 bp_addr = bp_address[i];
528
529 if (bp_addr == 0xffffffff)
530 continue;
531
532 if (!mmu_on)
533 bp_addr &= 0x7fffffff;
534
535 /* Write DBT instruction. */
536 buf[0] = SDI_WRITE_MEMORY;
537 store_long_parameter (buf + 1, (bp_addr & 0xfffffffc));
538 store_long_parameter (buf + 5, 4);
539 if ((bp_addr & 2) == 0 && bp_addr != (pc_addr & 0xfffffffc))
540 {
541 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
542 {
543 buf[9] = dbt_bp_entry[0];
544 buf[10] = dbt_bp_entry[1];
545 buf[11] = dbt_bp_entry[2];
546 buf[12] = dbt_bp_entry[3];
547 }
548 else
549 {
550 buf[9] = dbt_bp_entry[3];
551 buf[10] = dbt_bp_entry[2];
552 buf[11] = dbt_bp_entry[1];
553 buf[12] = dbt_bp_entry[0];
554 }
555 }
556 else
557 {
558 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
559 {
560 if ((bp_addr & 2) == 0)
561 {
562 buf[9] = dbt_bp_entry[0];
563 buf[10] = dbt_bp_entry[1];
564 buf[11] = bp_data[i][2] & 0x7f;
565 buf[12] = bp_data[i][3];
566 }
567 else
568 {
569 buf[9] = bp_data[i][0];
570 buf[10] = bp_data[i][1];
571 buf[11] = dbt_bp_entry[0];
572 buf[12] = dbt_bp_entry[1];
573 }
574 }
575 else
576 {
577 if ((bp_addr & 2) == 0)
578 {
579 buf[9] = bp_data[i][0];
580 buf[10] = bp_data[i][1] & 0x7f;
581 buf[11] = dbt_bp_entry[1];
582 buf[12] = dbt_bp_entry[0];
583 }
584 else
585 {
586 buf[9] = dbt_bp_entry[1];
587 buf[10] = dbt_bp_entry[0];
588 buf[11] = bp_data[i][2];
589 buf[12] = bp_data[i][3];
590 }
591 }
592 }
593 send_data (buf, 13);
594 }
595
596 /* Set access breaks. */
597 for (i = 0; i < max_access_breaks; i++)
598 {
599 ab_addr = ab_address[i];
600
601 if (ab_addr == 0x00000000)
602 continue;
603
604 /* DBC register */
605 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
606 {
607 switch (ab_type[i])
608 {
609 case 0: /* write watch */
610 send_three_arg_cmd (SDI_WRITE_MEMORY, 0xffff8100 + 4 * i, 4,
611 0x00000086);
612 break;
613 case 1: /* read watch */
614 send_three_arg_cmd (SDI_WRITE_MEMORY, 0xffff8100 + 4 * i, 4,
615 0x00000046);
616 break;
617 case 2: /* access watch */
618 send_three_arg_cmd (SDI_WRITE_MEMORY, 0xffff8100 + 4 * i, 4,
619 0x00000006);
620 break;
621 }
622 }
623 else
624 {
625 switch (ab_type[i])
626 {
627 case 0: /* write watch */
628 send_three_arg_cmd (SDI_WRITE_MEMORY, 0xffff8100 + 4 * i, 4,
629 0x86000000);
630 break;
631 case 1: /* read watch */
632 send_three_arg_cmd (SDI_WRITE_MEMORY, 0xffff8100 + 4 * i, 4,
633 0x46000000);
634 break;
635 case 2: /* access watch */
636 send_three_arg_cmd (SDI_WRITE_MEMORY, 0xffff8100 + 4 * i, 4,
637 0x06000000);
638 break;
639 }
640 }
641
642 /* DBAH register */
643 send_three_arg_cmd (SDI_WRITE_MEMORY, 0xffff8180 + 4 * i, 4, ab_addr);
644
645 /* DBAL register */
646 send_three_arg_cmd (SDI_WRITE_MEMORY, 0xffff8200 + 4 * i, 4,
647 0xffffffff);
648
649 /* DBD register */
650 send_three_arg_cmd (SDI_WRITE_MEMORY, 0xffff8280 + 4 * i, 4,
651 0x00000000);
652
653 /* DBDM register */
654 send_three_arg_cmd (SDI_WRITE_MEMORY, 0xffff8300 + 4 * i, 4,
655 0x00000000);
656 }
657
658 /* Resume program. */
659 send_cmd (SDI_EXEC_CPU);
660
661 /* Without this, some commands which require an active target (such as kill)
662 won't work. This variable serves (at least) double duty as both the pid
663 of the target process (if it has such), and as a flag indicating that a
664 target is active. These functions should be split out into seperate
665 variables, especially since GDB will someday have a notion of debugging
666 several processes. */
667 inferior_ptid = pid_to_ptid (32);
668
669 return;
670 }
671
672 /* Wait until the remote machine stops, then return,
673 storing status in STATUS just as `wait' would. */
674
675 static void
676 gdb_cntrl_c (int signo)
677 {
678 if (remote_debug)
679 fprintf_unfiltered (gdb_stdlog, "interrupt\n");
680 interrupted = 1;
681 }
682
683 static ptid_t
684 m32r_wait (ptid_t ptid, struct target_waitstatus *status)
685 {
686 static RETSIGTYPE (*prev_sigint) ();
687 unsigned long bp_addr, pc_addr;
688 int ib_breakpoints;
689 long i;
690 unsigned char buf[13];
691 unsigned long val;
692 int ret, c;
693
694 if (remote_debug)
695 fprintf_unfiltered (gdb_stdlog, "m32r_wait()\n");
696
697 status->kind = TARGET_WAITKIND_EXITED;
698 status->value.sig = 0;
699
700 interrupted = 0;
701 prev_sigint = signal (SIGINT, gdb_cntrl_c);
702
703 /* Wait for ready */
704 buf[0] = SDI_WAIT_FOR_READY;
705 if (serial_write (sdi_desc, buf, 1) != 0)
706 error (_("Remote connection closed"));
707
708 while (1)
709 {
710 c = serial_readchar (sdi_desc, SDI_TIMEOUT);
711 if (c < 0)
712 error (_("Remote connection closed"));
713
714 if (c == '-') /* error */
715 {
716 status->kind = TARGET_WAITKIND_STOPPED;
717 status->value.sig = TARGET_SIGNAL_HUP;
718 return inferior_ptid;
719 }
720 else if (c == '+') /* stopped */
721 break;
722
723 if (interrupted)
724 ret = serial_write (sdi_desc, "!", 1); /* packet to interrupt */
725 else
726 ret = serial_write (sdi_desc, ".", 1); /* packet to wait */
727 if (ret != 0)
728 error (_("Remote connection closed"));
729 }
730
731 status->kind = TARGET_WAITKIND_STOPPED;
732 if (interrupted)
733 status->value.sig = TARGET_SIGNAL_INT;
734 else
735 status->value.sig = TARGET_SIGNAL_TRAP;
736
737 interrupted = 0;
738 signal (SIGINT, prev_sigint);
739
740 check_mmu_status ();
741
742 /* Recover parallel bit. */
743 if (last_pc_addr != 0xffffffff)
744 {
745 buf[0] = SDI_WRITE_MEMORY;
746 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
747 store_long_parameter (buf + 1, last_pc_addr);
748 else
749 store_long_parameter (buf + 1, last_pc_addr - 1);
750 store_long_parameter (buf + 5, 1);
751 buf[9] = last_pc_addr_data[0];
752 send_data (buf, 10);
753 last_pc_addr = 0xffffffff;
754 }
755
756 if (use_ib_breakpoints)
757 ib_breakpoints = max_ib_breakpoints;
758 else
759 ib_breakpoints = 0;
760
761 /* Set back pc by 2 if m32r is stopped with dbt. */
762 last_pc_addr = 0xffffffff;
763 send_one_arg_cmd (SDI_READ_CPU_REG, SDI_REG_BPC);
764 pc_addr = recv_long_data () - 2;
765 for (i = ib_breakpoints; i < MAX_BREAKPOINTS; i++)
766 {
767 if (pc_addr == bp_address[i])
768 {
769 send_two_arg_cmd (SDI_WRITE_CPU_REG, SDI_REG_BPC, pc_addr);
770
771 /* If there is a parallel instruction with +2 offset at pc
772 address, we have to take care of it later. */
773 if ((pc_addr & 0x2) != 0)
774 {
775 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
776 {
777 if ((bp_data[i][2] & 0x80) != 0)
778 {
779 last_pc_addr = pc_addr;
780 last_pc_addr_data[0] = bp_data[i][2];
781 last_pc_addr_data[1] = bp_data[i][3];
782 }
783 }
784 else
785 {
786 if ((bp_data[i][1] & 0x80) != 0)
787 {
788 last_pc_addr = pc_addr;
789 last_pc_addr_data[0] = bp_data[i][1];
790 last_pc_addr_data[1] = bp_data[i][0];
791 }
792 }
793 }
794 break;
795 }
796 }
797
798 /* Remove ib breakpoints. */
799 for (i = 0; i < ib_breakpoints; i++)
800 {
801 if (bp_address[i] != 0xffffffff)
802 send_three_arg_cmd (SDI_WRITE_MEMORY, 0xffff8000 + 4 * i, 4,
803 0x00000000);
804 }
805 /* Remove dbt breakpoints. */
806 for (i = ib_breakpoints; i < MAX_BREAKPOINTS; i++)
807 {
808 bp_addr = bp_address[i];
809 if (bp_addr != 0xffffffff)
810 {
811 if (!mmu_on)
812 bp_addr &= 0x7fffffff;
813 buf[0] = SDI_WRITE_MEMORY;
814 store_long_parameter (buf + 1, bp_addr & 0xfffffffc);
815 store_long_parameter (buf + 5, 4);
816 buf[9] = bp_data[i][0];
817 buf[10] = bp_data[i][1];
818 buf[11] = bp_data[i][2];
819 buf[12] = bp_data[i][3];
820 send_data (buf, 13);
821 }
822 }
823
824 /* Remove access breaks. */
825 hit_watchpoint_addr = 0;
826 for (i = 0; i < max_access_breaks; i++)
827 {
828 if (ab_address[i] != 0x00000000)
829 {
830 buf[0] = SDI_READ_MEMORY;
831 store_long_parameter (buf + 1, 0xffff8100 + 4 * i);
832 store_long_parameter (buf + 5, 4);
833 serial_write (sdi_desc, buf, 9);
834 c = serial_readchar (sdi_desc, SDI_TIMEOUT);
835 if (c != '-' && recv_data (buf, 4) != -1)
836 {
837 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
838 {
839 if ((buf[3] & 0x1) == 0x1)
840 hit_watchpoint_addr = ab_address[i];
841 }
842 else
843 {
844 if ((buf[0] & 0x1) == 0x1)
845 hit_watchpoint_addr = ab_address[i];
846 }
847 }
848
849 send_three_arg_cmd (SDI_WRITE_MEMORY, 0xffff8100 + 4 * i, 4,
850 0x00000000);
851 }
852 }
853
854 if (remote_debug)
855 fprintf_unfiltered (gdb_stdlog, "pc => 0x%lx\n", pc_addr);
856
857 return inferior_ptid;
858 }
859
860 /* Terminate the open connection to the remote debugger.
861 Use this when you want to detach and do something else
862 with your gdb. */
863 static void
864 m32r_detach (char *args, int from_tty)
865 {
866 if (remote_debug)
867 fprintf_unfiltered (gdb_stdlog, "m32r_detach(%d)\n", from_tty);
868
869 m32r_resume (inferior_ptid, 0, 0);
870
871 /* calls m32r_close to do the real work */
872 pop_target ();
873 if (from_tty)
874 fprintf_unfiltered (gdb_stdlog, "Ending remote %s debugging\n",
875 target_shortname);
876 }
877
878 /* Return the id of register number REGNO. */
879
880 static int
881 get_reg_id (int regno)
882 {
883 switch (regno)
884 {
885 case 20:
886 return SDI_REG_BBPC;
887 case 21:
888 return SDI_REG_BPC;
889 case 22:
890 return SDI_REG_ACCL;
891 case 23:
892 return SDI_REG_ACCH;
893 case 24:
894 return SDI_REG_EVB;
895 }
896
897 return regno;
898 }
899
900 /* Read the remote registers into the block REGS. */
901
902 static void m32r_fetch_register (int);
903
904 static void
905 m32r_fetch_registers (void)
906 {
907 int regno;
908
909 for (regno = 0; regno < NUM_REGS; regno++)
910 m32r_fetch_register (regno);
911 }
912
913 /* Fetch register REGNO, or all registers if REGNO is -1.
914 Returns errno value. */
915 static void
916 m32r_fetch_register (int regno)
917 {
918 unsigned long val, val2, regid;
919
920 if (regno == -1)
921 m32r_fetch_registers ();
922 else
923 {
924 char buffer[MAX_REGISTER_SIZE];
925
926 regid = get_reg_id (regno);
927 send_one_arg_cmd (SDI_READ_CPU_REG, regid);
928 val = recv_long_data ();
929
930 if (regid == SDI_REG_PSW)
931 {
932 send_one_arg_cmd (SDI_READ_CPU_REG, SDI_REG_BBPSW);
933 val2 = recv_long_data ();
934 val = ((0x00c1 & val2) << 8) | ((0xc100 & val) >> 8);
935 }
936
937 if (remote_debug)
938 fprintf_unfiltered (gdb_stdlog, "m32r_fetch_register(%d,0x%08lx)\n",
939 regno, val);
940
941 /* We got the number the register holds, but gdb expects to see a
942 value in the target byte ordering. */
943 store_unsigned_integer (buffer, 4, val);
944 regcache_raw_supply (current_regcache, regno, buffer);
945 }
946 return;
947 }
948
949 /* Store the remote registers from the contents of the block REGS. */
950
951 static void m32r_store_register (int);
952
953 static void
954 m32r_store_registers (void)
955 {
956 int regno;
957
958 for (regno = 0; regno < NUM_REGS; regno++)
959 m32r_store_register (regno);
960
961 registers_changed ();
962 }
963
964 /* Store register REGNO, or all if REGNO == 0.
965 Return errno value. */
966 static void
967 m32r_store_register (int regno)
968 {
969 int regid;
970 ULONGEST regval, tmp;
971
972 if (regno == -1)
973 m32r_store_registers ();
974 else
975 {
976 regcache_cooked_read_unsigned (current_regcache, regno, &regval);
977 regid = get_reg_id (regno);
978
979 if (regid == SDI_REG_PSW)
980 {
981 unsigned long psw, bbpsw;
982
983 send_one_arg_cmd (SDI_READ_CPU_REG, SDI_REG_PSW);
984 psw = recv_long_data ();
985
986 send_one_arg_cmd (SDI_READ_CPU_REG, SDI_REG_BBPSW);
987 bbpsw = recv_long_data ();
988
989 tmp = (0x00c1 & psw) | ((0x00c1 & regval) << 8);
990 send_two_arg_cmd (SDI_WRITE_CPU_REG, SDI_REG_PSW, tmp);
991
992 tmp = (0x0030 & bbpsw) | ((0xc100 & regval) >> 8);
993 send_two_arg_cmd (SDI_WRITE_CPU_REG, SDI_REG_BBPSW, tmp);
994 }
995 else
996 {
997 send_two_arg_cmd (SDI_WRITE_CPU_REG, regid, regval);
998 }
999
1000 if (remote_debug)
1001 fprintf_unfiltered (gdb_stdlog, "m32r_store_register(%d,0x%08lu)\n",
1002 regno, (unsigned long) regval);
1003 }
1004 }
1005
1006 /* Get ready to modify the registers array. On machines which store
1007 individual registers, this doesn't need to do anything. On machines
1008 which store all the registers in one fell swoop, this makes sure
1009 that registers contains all the registers from the program being
1010 debugged. */
1011
1012 static void
1013 m32r_prepare_to_store (void)
1014 {
1015 /* Do nothing, since we can store individual regs */
1016 if (remote_debug)
1017 fprintf_unfiltered (gdb_stdlog, "m32r_prepare_to_store()\n");
1018 }
1019
1020 static void
1021 m32r_files_info (struct target_ops *target)
1022 {
1023 char *file = "nothing";
1024
1025 if (exec_bfd)
1026 {
1027 file = bfd_get_filename (exec_bfd);
1028 printf_filtered ("\tAttached to %s running program %s\n",
1029 chip_name, file);
1030 }
1031 }
1032
1033 /* Read/Write memory. */
1034 static int
1035 m32r_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len,
1036 int write,
1037 struct mem_attrib *attrib, struct target_ops *target)
1038 {
1039 unsigned long taddr;
1040 unsigned char buf[0x2000];
1041 int ret, c;
1042
1043 taddr = memaddr;
1044
1045 if (!mmu_on)
1046 {
1047 if ((taddr & 0xa0000000) == 0x80000000)
1048 taddr &= 0x7fffffff;
1049 }
1050
1051 if (remote_debug)
1052 {
1053 if (write)
1054 fprintf_unfiltered (gdb_stdlog, "m32r_xfer_memory(%08lx,%d,write)\n",
1055 memaddr, len);
1056 else
1057 fprintf_unfiltered (gdb_stdlog, "m32r_xfer_memory(%08lx,%d,read)\n",
1058 memaddr, len);
1059 }
1060
1061 if (write)
1062 {
1063 buf[0] = SDI_WRITE_MEMORY;
1064 store_long_parameter (buf + 1, taddr);
1065 store_long_parameter (buf + 5, len);
1066 if (len < 0x1000)
1067 {
1068 memcpy (buf + 9, myaddr, len);
1069 ret = send_data (buf, len + 9) - 9;
1070 }
1071 else
1072 {
1073 if (serial_write (sdi_desc, buf, 9) != 0)
1074 {
1075 if (remote_debug)
1076 fprintf_unfiltered (gdb_stdlog,
1077 "m32r_xfer_memory() failed\n");
1078 return 0;
1079 }
1080 ret = send_data (myaddr, len);
1081 }
1082 }
1083 else
1084 {
1085 buf[0] = SDI_READ_MEMORY;
1086 store_long_parameter (buf + 1, taddr);
1087 store_long_parameter (buf + 5, len);
1088 if (serial_write (sdi_desc, buf, 9) != 0)
1089 {
1090 if (remote_debug)
1091 fprintf_unfiltered (gdb_stdlog, "m32r_xfer_memory() failed\n");
1092 return 0;
1093 }
1094
1095 c = serial_readchar (sdi_desc, SDI_TIMEOUT);
1096 if (c < 0 || c == '-')
1097 {
1098 if (remote_debug)
1099 fprintf_unfiltered (gdb_stdlog, "m32r_xfer_memory() failed\n");
1100 return 0;
1101 }
1102
1103 ret = recv_data (myaddr, len);
1104 }
1105
1106 if (ret <= 0)
1107 {
1108 if (remote_debug)
1109 fprintf_unfiltered (gdb_stdlog, "m32r_xfer_memory() fails\n");
1110 return 0;
1111 }
1112
1113 return ret;
1114 }
1115
1116 static void
1117 m32r_kill (void)
1118 {
1119 if (remote_debug)
1120 fprintf_unfiltered (gdb_stdlog, "m32r_kill()\n");
1121
1122 inferior_ptid = null_ptid;
1123
1124 return;
1125 }
1126
1127 /* Clean up when a program exits.
1128
1129 The program actually lives on in the remote processor's RAM, and may be
1130 run again without a download. Don't leave it full of breakpoint
1131 instructions. */
1132
1133 static void
1134 m32r_mourn_inferior (void)
1135 {
1136 if (remote_debug)
1137 fprintf_unfiltered (gdb_stdlog, "m32r_mourn_inferior()\n");
1138
1139 remove_breakpoints ();
1140 generic_mourn_inferior ();
1141 }
1142
1143 static int
1144 m32r_insert_breakpoint (struct bp_target_info *bp_tgt)
1145 {
1146 CORE_ADDR addr = bp_tgt->placed_address;
1147 int ib_breakpoints;
1148 unsigned char buf[13];
1149 int i, c;
1150
1151 if (remote_debug)
1152 fprintf_unfiltered (gdb_stdlog, "m32r_insert_breakpoint(%08lx,...)\n",
1153 addr);
1154
1155 if (use_ib_breakpoints)
1156 ib_breakpoints = max_ib_breakpoints;
1157 else
1158 ib_breakpoints = 0;
1159
1160 for (i = 0; i < MAX_BREAKPOINTS; i++)
1161 {
1162 if (bp_address[i] == 0xffffffff)
1163 {
1164 bp_address[i] = addr;
1165 if (i >= ib_breakpoints)
1166 {
1167 buf[0] = SDI_READ_MEMORY;
1168 if (mmu_on)
1169 store_long_parameter (buf + 1, addr & 0xfffffffc);
1170 else
1171 store_long_parameter (buf + 1, addr & 0x7ffffffc);
1172 store_long_parameter (buf + 5, 4);
1173 serial_write (sdi_desc, buf, 9);
1174 c = serial_readchar (sdi_desc, SDI_TIMEOUT);
1175 if (c != '-')
1176 recv_data (bp_data[i], 4);
1177 }
1178 return 0;
1179 }
1180 }
1181
1182 error (_("Too many breakpoints"));
1183 return 1;
1184 }
1185
1186 static int
1187 m32r_remove_breakpoint (struct bp_target_info *bp_tgt)
1188 {
1189 CORE_ADDR addr = bp_tgt->placed_address;
1190 int i;
1191
1192 if (remote_debug)
1193 fprintf_unfiltered (gdb_stdlog, "m32r_remove_breakpoint(%08lx)\n",
1194 addr);
1195
1196 for (i = 0; i < MAX_BREAKPOINTS; i++)
1197 {
1198 if (bp_address[i] == addr)
1199 {
1200 bp_address[i] = 0xffffffff;
1201 break;
1202 }
1203 }
1204
1205 return 0;
1206 }
1207
1208 static void
1209 m32r_load (char *args, int from_tty)
1210 {
1211 struct cleanup *old_chain;
1212 asection *section;
1213 bfd *pbfd;
1214 bfd_vma entry;
1215 char *filename;
1216 int quiet;
1217 int nostart;
1218 struct timeval start_time, end_time;
1219 unsigned long data_count; /* Number of bytes transferred to memory */
1220 int ret;
1221 static RETSIGTYPE (*prev_sigint) ();
1222
1223 /* for direct tcp connections, we can do a fast binary download */
1224 quiet = 0;
1225 nostart = 0;
1226 filename = NULL;
1227
1228 while (*args != '\000')
1229 {
1230 char *arg;
1231
1232 while (isspace (*args))
1233 args++;
1234
1235 arg = args;
1236
1237 while ((*args != '\000') && !isspace (*args))
1238 args++;
1239
1240 if (*args != '\000')
1241 *args++ = '\000';
1242
1243 if (*arg != '-')
1244 filename = arg;
1245 else if (strncmp (arg, "-quiet", strlen (arg)) == 0)
1246 quiet = 1;
1247 else if (strncmp (arg, "-nostart", strlen (arg)) == 0)
1248 nostart = 1;
1249 else
1250 error (_("Unknown option `%s'"), arg);
1251 }
1252
1253 if (!filename)
1254 filename = get_exec_file (1);
1255
1256 pbfd = bfd_openr (filename, gnutarget);
1257 if (pbfd == NULL)
1258 {
1259 perror_with_name (filename);
1260 return;
1261 }
1262 old_chain = make_cleanup_bfd_close (pbfd);
1263
1264 if (!bfd_check_format (pbfd, bfd_object))
1265 error (_("\"%s\" is not an object file: %s"), filename,
1266 bfd_errmsg (bfd_get_error ()));
1267
1268 gettimeofday (&start_time, NULL);
1269 data_count = 0;
1270
1271 interrupted = 0;
1272 prev_sigint = signal (SIGINT, gdb_cntrl_c);
1273
1274 for (section = pbfd->sections; section; section = section->next)
1275 {
1276 if (bfd_get_section_flags (pbfd, section) & SEC_LOAD)
1277 {
1278 bfd_vma section_address;
1279 bfd_size_type section_size;
1280 file_ptr fptr;
1281 int n;
1282
1283 section_address = bfd_section_lma (pbfd, section);
1284 section_size = bfd_get_section_size (section);
1285
1286 if (!mmu_on)
1287 {
1288 if ((section_address & 0xa0000000) == 0x80000000)
1289 section_address &= 0x7fffffff;
1290 }
1291
1292 if (!quiet)
1293 printf_filtered ("[Loading section %s at 0x%lx (%d bytes)]\n",
1294 bfd_get_section_name (pbfd, section),
1295 section_address, (int) section_size);
1296
1297 fptr = 0;
1298
1299 data_count += section_size;
1300
1301 n = 0;
1302 while (section_size > 0)
1303 {
1304 char unsigned buf[0x1000 + 9];
1305 int count;
1306
1307 count = min (section_size, 0x1000);
1308
1309 buf[0] = SDI_WRITE_MEMORY;
1310 store_long_parameter (buf + 1, section_address);
1311 store_long_parameter (buf + 5, count);
1312
1313 bfd_get_section_contents (pbfd, section, buf + 9, fptr, count);
1314 if (send_data (buf, count + 9) <= 0)
1315 error (_("Error while downloading %s section."),
1316 bfd_get_section_name (pbfd, section));
1317
1318 if (!quiet)
1319 {
1320 printf_unfiltered (".");
1321 if (n++ > 60)
1322 {
1323 printf_unfiltered ("\n");
1324 n = 0;
1325 }
1326 gdb_flush (gdb_stdout);
1327 }
1328
1329 section_address += count;
1330 fptr += count;
1331 section_size -= count;
1332
1333 if (interrupted)
1334 break;
1335 }
1336
1337 if (!quiet && !interrupted)
1338 {
1339 printf_unfiltered ("done.\n");
1340 gdb_flush (gdb_stdout);
1341 }
1342 }
1343
1344 if (interrupted)
1345 {
1346 printf_unfiltered ("Interrupted.\n");
1347 break;
1348 }
1349 }
1350
1351 interrupted = 0;
1352 signal (SIGINT, prev_sigint);
1353
1354 gettimeofday (&end_time, NULL);
1355
1356 /* Make the PC point at the start address */
1357 if (exec_bfd)
1358 write_pc (bfd_get_start_address (exec_bfd));
1359
1360 inferior_ptid = null_ptid; /* No process now */
1361
1362 /* This is necessary because many things were based on the PC at the time
1363 that we attached to the monitor, which is no longer valid now that we
1364 have loaded new code (and just changed the PC). Another way to do this
1365 might be to call normal_stop, except that the stack may not be valid,
1366 and things would get horribly confused... */
1367
1368 clear_symtab_users ();
1369
1370 if (!nostart)
1371 {
1372 entry = bfd_get_start_address (pbfd);
1373
1374 if (!quiet)
1375 printf_unfiltered ("[Starting %s at 0x%lx]\n", filename, entry);
1376 }
1377
1378 print_transfer_performance (gdb_stdout, data_count, 0, &start_time,
1379 &end_time);
1380
1381 do_cleanups (old_chain);
1382 }
1383
1384 static void
1385 m32r_stop (void)
1386 {
1387 if (remote_debug)
1388 fprintf_unfiltered (gdb_stdlog, "m32r_stop()\n");
1389
1390 send_cmd (SDI_STOP_CPU);
1391
1392 return;
1393 }
1394
1395
1396 /* Tell whether this target can support a hardware breakpoint. CNT
1397 is the number of hardware breakpoints already installed. This
1398 implements the TARGET_CAN_USE_HARDWARE_WATCHPOINT macro. */
1399
1400 int
1401 m32r_can_use_hw_watchpoint (int type, int cnt, int othertype)
1402 {
1403 return sdi_desc != NULL && cnt < max_access_breaks;
1404 }
1405
1406 /* Set a data watchpoint. ADDR and LEN should be obvious. TYPE is 0
1407 for a write watchpoint, 1 for a read watchpoint, or 2 for a read/write
1408 watchpoint. */
1409
1410 int
1411 m32r_insert_watchpoint (CORE_ADDR addr, int len, int type)
1412 {
1413 int i;
1414
1415 if (remote_debug)
1416 fprintf_unfiltered (gdb_stdlog, "m32r_insert_watchpoint(%08lx,%d,%d)\n",
1417 addr, len, type);
1418
1419 for (i = 0; i < MAX_ACCESS_BREAKS; i++)
1420 {
1421 if (ab_address[i] == 0x00000000)
1422 {
1423 ab_address[i] = addr;
1424 ab_size[i] = len;
1425 ab_type[i] = type;
1426 return 0;
1427 }
1428 }
1429
1430 error (_("Too many watchpoints"));
1431 return 1;
1432 }
1433
1434 int
1435 m32r_remove_watchpoint (CORE_ADDR addr, int len, int type)
1436 {
1437 int i;
1438
1439 if (remote_debug)
1440 fprintf_unfiltered (gdb_stdlog, "m32r_remove_watchpoint(%08lx,%d,%d)\n",
1441 addr, len, type);
1442
1443 for (i = 0; i < MAX_ACCESS_BREAKS; i++)
1444 {
1445 if (ab_address[i] == addr)
1446 {
1447 ab_address[i] = 0x00000000;
1448 break;
1449 }
1450 }
1451
1452 return 0;
1453 }
1454
1455 int
1456 m32r_stopped_data_address (struct target_ops *target, CORE_ADDR *addr_p)
1457 {
1458 int rc = 0;
1459 if (hit_watchpoint_addr != 0x00000000)
1460 {
1461 *addr_p = hit_watchpoint_addr;
1462 rc = 1;
1463 }
1464 return rc;
1465 }
1466
1467 int
1468 m32r_stopped_by_watchpoint (void)
1469 {
1470 CORE_ADDR addr;
1471 return m32r_stopped_data_address (&current_target, &addr);
1472 }
1473
1474
1475 static void
1476 sdireset_command (char *args, int from_tty)
1477 {
1478 if (remote_debug)
1479 fprintf_unfiltered (gdb_stdlog, "m32r_sdireset()\n");
1480
1481 send_cmd (SDI_OPEN);
1482
1483 inferior_ptid = null_ptid;
1484 }
1485
1486
1487 static void
1488 sdistatus_command (char *args, int from_tty)
1489 {
1490 unsigned char buf[4096];
1491 int i, c;
1492
1493 if (remote_debug)
1494 fprintf_unfiltered (gdb_stdlog, "m32r_sdireset()\n");
1495
1496 if (!sdi_desc)
1497 return;
1498
1499 send_cmd (SDI_STATUS);
1500 for (i = 0; i < 4096; i++)
1501 {
1502 c = serial_readchar (sdi_desc, SDI_TIMEOUT);
1503 if (c < 0)
1504 return;
1505 buf[i] = c;
1506 if (c == 0)
1507 break;
1508 }
1509
1510 printf_filtered ("%s", buf);
1511 }
1512
1513
1514 static void
1515 debug_chaos_command (char *args, int from_tty)
1516 {
1517 unsigned char buf[3];
1518
1519 buf[0] = SDI_SET_ATTR;
1520 buf[1] = SDI_ATTR_CACHE;
1521 buf[2] = SDI_CACHE_TYPE_CHAOS;
1522 send_data (buf, 3);
1523 }
1524
1525
1526 static void
1527 use_debug_dma_command (char *args, int from_tty)
1528 {
1529 unsigned char buf[3];
1530
1531 buf[0] = SDI_SET_ATTR;
1532 buf[1] = SDI_ATTR_MEM_ACCESS;
1533 buf[2] = SDI_MEM_ACCESS_DEBUG_DMA;
1534 send_data (buf, 3);
1535 }
1536
1537 static void
1538 use_mon_code_command (char *args, int from_tty)
1539 {
1540 unsigned char buf[3];
1541
1542 buf[0] = SDI_SET_ATTR;
1543 buf[1] = SDI_ATTR_MEM_ACCESS;
1544 buf[2] = SDI_MEM_ACCESS_MON_CODE;
1545 send_data (buf, 3);
1546 }
1547
1548
1549 static void
1550 use_ib_breakpoints_command (char *args, int from_tty)
1551 {
1552 use_ib_breakpoints = 1;
1553 }
1554
1555 static void
1556 use_dbt_breakpoints_command (char *args, int from_tty)
1557 {
1558 use_ib_breakpoints = 0;
1559 }
1560
1561
1562 /* Define the target subroutine names */
1563
1564 struct target_ops m32r_ops;
1565
1566 static void
1567 init_m32r_ops (void)
1568 {
1569 m32r_ops.to_shortname = "m32rsdi";
1570 m32r_ops.to_longname = "Remote M32R debugging over SDI interface";
1571 m32r_ops.to_doc = "Use an M32R board using SDI debugging protocol.";
1572 m32r_ops.to_open = m32r_open;
1573 m32r_ops.to_close = m32r_close;
1574 m32r_ops.to_detach = m32r_detach;
1575 m32r_ops.to_resume = m32r_resume;
1576 m32r_ops.to_wait = m32r_wait;
1577 m32r_ops.to_fetch_registers = m32r_fetch_register;
1578 m32r_ops.to_store_registers = m32r_store_register;
1579 m32r_ops.to_prepare_to_store = m32r_prepare_to_store;
1580 m32r_ops.deprecated_xfer_memory = m32r_xfer_memory;
1581 m32r_ops.to_files_info = m32r_files_info;
1582 m32r_ops.to_insert_breakpoint = m32r_insert_breakpoint;
1583 m32r_ops.to_remove_breakpoint = m32r_remove_breakpoint;
1584 m32r_ops.to_can_use_hw_breakpoint = m32r_can_use_hw_watchpoint;
1585 m32r_ops.to_insert_watchpoint = m32r_insert_watchpoint;
1586 m32r_ops.to_remove_watchpoint = m32r_remove_watchpoint;
1587 m32r_ops.to_stopped_by_watchpoint = m32r_stopped_by_watchpoint;
1588 m32r_ops.to_stopped_data_address = m32r_stopped_data_address;
1589 m32r_ops.to_kill = m32r_kill;
1590 m32r_ops.to_load = m32r_load;
1591 m32r_ops.to_create_inferior = m32r_create_inferior;
1592 m32r_ops.to_mourn_inferior = m32r_mourn_inferior;
1593 m32r_ops.to_stop = m32r_stop;
1594 m32r_ops.to_stratum = process_stratum;
1595 m32r_ops.to_has_all_memory = 1;
1596 m32r_ops.to_has_memory = 1;
1597 m32r_ops.to_has_stack = 1;
1598 m32r_ops.to_has_registers = 1;
1599 m32r_ops.to_has_execution = 1;
1600 m32r_ops.to_magic = OPS_MAGIC;
1601 };
1602
1603
1604 extern initialize_file_ftype _initialize_remote_m32r;
1605
1606 void
1607 _initialize_remote_m32r (void)
1608 {
1609 int i;
1610
1611 init_m32r_ops ();
1612
1613 /* Initialize breakpoints. */
1614 for (i = 0; i < MAX_BREAKPOINTS; i++)
1615 bp_address[i] = 0xffffffff;
1616
1617 /* Initialize access breaks. */
1618 for (i = 0; i < MAX_ACCESS_BREAKS; i++)
1619 ab_address[i] = 0x00000000;
1620
1621 add_target (&m32r_ops);
1622
1623 add_com ("sdireset", class_obscure, sdireset_command,
1624 _("Reset SDI connection."));
1625
1626 add_com ("sdistatus", class_obscure, sdistatus_command,
1627 _("Show status of SDI connection."));
1628
1629 add_com ("debug_chaos", class_obscure, debug_chaos_command,
1630 _("Debug M32R/Chaos."));
1631
1632 add_com ("use_debug_dma", class_obscure, use_debug_dma_command,
1633 _("Use debug DMA mem access."));
1634 add_com ("use_mon_code", class_obscure, use_mon_code_command,
1635 _("Use mon code mem access."));
1636
1637 add_com ("use_ib_break", class_obscure, use_ib_breakpoints_command,
1638 _("Set breakpoints by IB break."));
1639 add_com ("use_dbt_break", class_obscure, use_dbt_breakpoints_command,
1640 _("Set breakpoints by dbt."));
1641 }
This page took 0.067019 seconds and 4 git commands to generate.