1 /* Remote debugging interface for M32R/SDI.
3 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
4 Free Software Foundation, Inc.
6 Contributed by Renesas Technology Co.
7 Written by Kei Sakamoto <sakamoto.kei@renesas.com>.
9 This file is part of GDB.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>. */
30 #include "gdb_string.h"
36 #include <netinet/in.h>
38 #include <sys/types.h>
46 /* Descriptor for I/O to remote machine. */
48 static struct serial
*sdi_desc
= NULL
;
50 #define SDI_TIMEOUT 30
55 static char chip_name
[64];
58 static unsigned long last_pc_addr
= 0xffffffff;
59 static unsigned char last_pc_addr_data
[2];
61 static int mmu_on
= 0;
63 static int use_ib_breakpoints
= 1;
65 #define MAX_BREAKPOINTS 1024
66 static int max_ib_breakpoints
;
67 static unsigned long bp_address
[MAX_BREAKPOINTS
];
68 static unsigned char bp_data
[MAX_BREAKPOINTS
][4];
71 static const unsigned char dbt_bp_entry
[] = {
72 0x10, 0xe0, 0x70, 0x00
75 #define MAX_ACCESS_BREAKS 4
76 static int max_access_breaks
;
77 static unsigned long ab_address
[MAX_ACCESS_BREAKS
];
78 static unsigned int ab_type
[MAX_ACCESS_BREAKS
];
79 static unsigned int ab_size
[MAX_ACCESS_BREAKS
];
80 static CORE_ADDR hit_watchpoint_addr
= 0;
82 static int interrupted
= 0;
84 /* Forward data declarations */
85 extern struct target_ops m32r_ops
;
92 #define SDI_READ_CPU_REG 4
93 #define SDI_WRITE_CPU_REG 5
94 #define SDI_READ_MEMORY 6
95 #define SDI_WRITE_MEMORY 7
96 #define SDI_EXEC_CPU 8
97 #define SDI_STOP_CPU 9
98 #define SDI_WAIT_FOR_READY 10
99 #define SDI_GET_ATTR 11
100 #define SDI_SET_ATTR 12
101 #define SDI_STATUS 13
104 #define SDI_ATTR_NAME 1
105 #define SDI_ATTR_BRK 2
106 #define SDI_ATTR_ABRK 3
107 #define SDI_ATTR_CACHE 4
108 #define SDI_CACHE_TYPE_M32102 0
109 #define SDI_CACHE_TYPE_CHAOS 1
110 #define SDI_ATTR_MEM_ACCESS 5
111 #define SDI_MEM_ACCESS_DEBUG_DMA 0
112 #define SDI_MEM_ACCESS_MON_CODE 1
125 #define SDI_REG_R10 10
126 #define SDI_REG_R11 11
127 #define SDI_REG_R12 12
128 #define SDI_REG_FP 13
129 #define SDI_REG_LR 14
130 #define SDI_REG_SP 15
131 #define SDI_REG_PSW 16
132 #define SDI_REG_CBR 17
133 #define SDI_REG_SPI 18
134 #define SDI_REG_SPU 19
135 #define SDI_REG_CR4 20
136 #define SDI_REG_EVB 21
137 #define SDI_REG_BPC 22
138 #define SDI_REG_CR7 23
139 #define SDI_REG_BBPSW 24
140 #define SDI_REG_CR9 25
141 #define SDI_REG_CR10 26
142 #define SDI_REG_CR11 27
143 #define SDI_REG_CR12 28
144 #define SDI_REG_WR 29
145 #define SDI_REG_BBPC 30
146 #define SDI_REG_PBP 31
147 #define SDI_REG_ACCH 32
148 #define SDI_REG_ACCL 33
149 #define SDI_REG_ACC1H 34
150 #define SDI_REG_ACC1L 35
153 /* Low level communication functions */
155 /* Check an ack packet from the target */
164 c
= serial_readchar (sdi_desc
, SDI_TIMEOUT
);
169 if (c
!= '+') /* error */
175 /* Send data to the target and check an ack packet */
177 send_data (void *buf
, int len
)
184 if (serial_write (sdi_desc
, buf
, len
) != 0)
187 if (get_ack () == -1)
193 /* Receive data from the target */
195 recv_data (void *buf
, int len
)
205 c
= serial_readchar (sdi_desc
, SDI_TIMEOUT
);
210 ((unsigned char *) buf
)[total
++] = c
;
216 /* Store unsigned long parameter on packet */
218 store_long_parameter (void *buf
, long val
)
221 memcpy (buf
, &val
, 4);
225 send_cmd (unsigned char cmd
)
227 unsigned char buf
[1];
229 return send_data (buf
, 1);
233 send_one_arg_cmd (unsigned char cmd
, unsigned char arg1
)
235 unsigned char buf
[2];
238 return send_data (buf
, 2);
242 send_two_arg_cmd (unsigned char cmd
, unsigned char arg1
, unsigned long arg2
)
244 unsigned char buf
[6];
247 store_long_parameter (buf
+ 2, arg2
);
248 return send_data (buf
, 6);
252 send_three_arg_cmd (unsigned char cmd
, unsigned long arg1
, unsigned long arg2
,
255 unsigned char buf
[13];
257 store_long_parameter (buf
+ 1, arg1
);
258 store_long_parameter (buf
+ 5, arg2
);
259 store_long_parameter (buf
+ 9, arg3
);
260 return send_data (buf
, 13);
264 recv_char_data (void)
272 recv_long_data (void)
280 /* Check if MMU is on */
282 check_mmu_status (void)
286 /* Read PC address */
287 if (send_one_arg_cmd (SDI_READ_CPU_REG
, SDI_REG_BPC
) == -1)
289 val
= recv_long_data ();
290 if ((val
& 0xc0000000) == 0x80000000)
296 /* Read EVB address */
297 if (send_one_arg_cmd (SDI_READ_CPU_REG
, SDI_REG_EVB
) == -1)
299 val
= recv_long_data ();
300 if ((val
& 0xc0000000) == 0x80000000)
310 /* This is called not only when we first attach, but also when the
311 user types "run" after having attached. */
313 m32r_create_inferior (char *execfile
, char *args
, char **env
, int from_tty
)
318 error (_("Cannot pass arguments to remote STDEBUG process"));
320 if (execfile
== 0 || exec_bfd
== 0)
321 error (_("No executable file specified"));
324 fprintf_unfiltered (gdb_stdlog
, "m32r_create_inferior(%s,%s)\n", execfile
,
327 entry_pt
= bfd_get_start_address (exec_bfd
);
329 /* The "process" (board) is already stopped awaiting our commands, and
330 the program is already downloaded. We just set its PC and go. */
332 clear_proceed_status ();
334 /* Tell wait_for_inferior that we've started a new process. */
335 init_wait_for_inferior ();
337 /* Set up the "saved terminal modes" of the inferior
338 based on what modes we are starting it with. */
339 target_terminal_init ();
341 /* Install inferior's terminal modes. */
342 target_terminal_inferior ();
347 /* Open a connection to a remote debugger.
348 NAME is the filename used for communication. */
351 m32r_open (char *args
, int from_tty
)
353 struct hostent
*host_ent
;
354 struct sockaddr_in server_addr
;
355 char *port_str
, hostname
[256];
361 fprintf_unfiltered (gdb_stdlog
, "m32r_open(%d)\n", from_tty
);
363 target_preopen (from_tty
);
365 push_target (&m32r_ops
);
368 sprintf (hostname
, "localhost:%d", SDIPORT
);
371 port_str
= strchr (args
, ':');
372 if (port_str
== NULL
)
373 sprintf (hostname
, "%s:%d", args
, SDIPORT
);
375 strcpy (hostname
, args
);
378 sdi_desc
= serial_open (hostname
);
380 error (_("Connection refused."));
382 if (get_ack () == -1)
383 error (_("Cannot connect to SDI target."));
385 if (send_cmd (SDI_OPEN
) == -1)
386 error (_("Cannot connect to SDI target."));
388 /* Get maximum number of ib breakpoints */
389 send_one_arg_cmd (SDI_GET_ATTR
, SDI_ATTR_BRK
);
390 max_ib_breakpoints
= recv_char_data ();
392 printf_filtered ("Max IB Breakpoints = %d\n", max_ib_breakpoints
);
394 /* Initialize breakpoints. */
395 for (i
= 0; i
< MAX_BREAKPOINTS
; i
++)
396 bp_address
[i
] = 0xffffffff;
398 /* Get maximum number of access breaks. */
399 send_one_arg_cmd (SDI_GET_ATTR
, SDI_ATTR_ABRK
);
400 max_access_breaks
= recv_char_data ();
402 printf_filtered ("Max Access Breaks = %d\n", max_access_breaks
);
404 /* Initialize access breask. */
405 for (i
= 0; i
< MAX_ACCESS_BREAKS
; i
++)
406 ab_address
[i
] = 0x00000000;
410 /* Get the name of chip on target board. */
411 send_one_arg_cmd (SDI_GET_ATTR
, SDI_ATTR_NAME
);
412 recv_data (chip_name
, 64);
415 printf_filtered ("Remote %s connected to %s\n", target_shortname
,
419 /* Close out all files and local state before this target loses control. */
422 m32r_close (int quitting
)
425 fprintf_unfiltered (gdb_stdlog
, "m32r_close(%d)\n", quitting
);
429 send_cmd (SDI_CLOSE
);
430 serial_close (sdi_desc
);
434 inferior_ptid
= null_ptid
;
438 /* Tell the remote machine to resume. */
441 m32r_resume (ptid_t ptid
, int step
, enum target_signal sig
)
443 unsigned long pc_addr
, bp_addr
, ab_addr
;
445 unsigned char buf
[13];
451 fprintf_unfiltered (gdb_stdlog
, "\nm32r_resume(step)\n");
453 fprintf_unfiltered (gdb_stdlog
, "\nm32r_resume(cont)\n");
458 pc_addr
= read_pc ();
460 fprintf_unfiltered (gdb_stdlog
, "pc <= 0x%lx\n", pc_addr
);
462 /* At pc address there is a parallel instruction with +2 offset,
463 so we have to make it a serial instruction or avoid it. */
464 if (pc_addr
== last_pc_addr
)
466 /* Avoid a parallel nop. */
467 if (last_pc_addr_data
[0] == 0xf0 && last_pc_addr_data
[1] == 0x00)
470 /* Now we can forget this instruction. */
471 last_pc_addr
= 0xffffffff;
473 /* Clear a parallel bit. */
476 buf
[0] = SDI_WRITE_MEMORY
;
477 if (gdbarch_byte_order (current_gdbarch
) == BFD_ENDIAN_BIG
)
478 store_long_parameter (buf
+ 1, pc_addr
);
480 store_long_parameter (buf
+ 1, pc_addr
- 1);
481 store_long_parameter (buf
+ 5, 1);
482 buf
[9] = last_pc_addr_data
[0] & 0x7f;
488 send_two_arg_cmd (SDI_WRITE_CPU_REG
, SDI_REG_BPC
, pc_addr
);
495 send_two_arg_cmd (SDI_WRITE_CPU_REG
, SDI_REG_PBP
, pc_addr
| 1);
500 send_two_arg_cmd (SDI_WRITE_CPU_REG
, SDI_REG_PBP
, 0x00000000);
503 if (use_ib_breakpoints
)
504 ib_breakpoints
= max_ib_breakpoints
;
508 /* Set ib breakpoints. */
509 for (i
= 0; i
< ib_breakpoints
; i
++)
511 bp_addr
= bp_address
[i
];
513 if (bp_addr
== 0xffffffff)
517 if (gdbarch_byte_order (current_gdbarch
) == BFD_ENDIAN_BIG
)
518 send_three_arg_cmd (SDI_WRITE_MEMORY
, 0xffff8000 + 4 * i
, 4,
521 send_three_arg_cmd (SDI_WRITE_MEMORY
, 0xffff8000 + 4 * i
, 4,
524 send_three_arg_cmd (SDI_WRITE_MEMORY
, 0xffff8080 + 4 * i
, 4, bp_addr
);
527 /* Set dbt breakpoints. */
528 for (i
= ib_breakpoints
; i
< MAX_BREAKPOINTS
; i
++)
530 bp_addr
= bp_address
[i
];
532 if (bp_addr
== 0xffffffff)
536 bp_addr
&= 0x7fffffff;
538 /* Write DBT instruction. */
539 buf
[0] = SDI_WRITE_MEMORY
;
540 store_long_parameter (buf
+ 1, (bp_addr
& 0xfffffffc));
541 store_long_parameter (buf
+ 5, 4);
542 if ((bp_addr
& 2) == 0 && bp_addr
!= (pc_addr
& 0xfffffffc))
544 if (gdbarch_byte_order (current_gdbarch
) == BFD_ENDIAN_BIG
)
546 buf
[9] = dbt_bp_entry
[0];
547 buf
[10] = dbt_bp_entry
[1];
548 buf
[11] = dbt_bp_entry
[2];
549 buf
[12] = dbt_bp_entry
[3];
553 buf
[9] = dbt_bp_entry
[3];
554 buf
[10] = dbt_bp_entry
[2];
555 buf
[11] = dbt_bp_entry
[1];
556 buf
[12] = dbt_bp_entry
[0];
561 if (gdbarch_byte_order (current_gdbarch
) == BFD_ENDIAN_BIG
)
563 if ((bp_addr
& 2) == 0)
565 buf
[9] = dbt_bp_entry
[0];
566 buf
[10] = dbt_bp_entry
[1];
567 buf
[11] = bp_data
[i
][2] & 0x7f;
568 buf
[12] = bp_data
[i
][3];
572 buf
[9] = bp_data
[i
][0];
573 buf
[10] = bp_data
[i
][1];
574 buf
[11] = dbt_bp_entry
[0];
575 buf
[12] = dbt_bp_entry
[1];
580 if ((bp_addr
& 2) == 0)
582 buf
[9] = bp_data
[i
][0];
583 buf
[10] = bp_data
[i
][1] & 0x7f;
584 buf
[11] = dbt_bp_entry
[1];
585 buf
[12] = dbt_bp_entry
[0];
589 buf
[9] = dbt_bp_entry
[1];
590 buf
[10] = dbt_bp_entry
[0];
591 buf
[11] = bp_data
[i
][2];
592 buf
[12] = bp_data
[i
][3];
599 /* Set access breaks. */
600 for (i
= 0; i
< max_access_breaks
; i
++)
602 ab_addr
= ab_address
[i
];
604 if (ab_addr
== 0x00000000)
608 if (gdbarch_byte_order (current_gdbarch
) == BFD_ENDIAN_BIG
)
612 case 0: /* write watch */
613 send_three_arg_cmd (SDI_WRITE_MEMORY
, 0xffff8100 + 4 * i
, 4,
616 case 1: /* read watch */
617 send_three_arg_cmd (SDI_WRITE_MEMORY
, 0xffff8100 + 4 * i
, 4,
620 case 2: /* access watch */
621 send_three_arg_cmd (SDI_WRITE_MEMORY
, 0xffff8100 + 4 * i
, 4,
630 case 0: /* write watch */
631 send_three_arg_cmd (SDI_WRITE_MEMORY
, 0xffff8100 + 4 * i
, 4,
634 case 1: /* read watch */
635 send_three_arg_cmd (SDI_WRITE_MEMORY
, 0xffff8100 + 4 * i
, 4,
638 case 2: /* access watch */
639 send_three_arg_cmd (SDI_WRITE_MEMORY
, 0xffff8100 + 4 * i
, 4,
646 send_three_arg_cmd (SDI_WRITE_MEMORY
, 0xffff8180 + 4 * i
, 4, ab_addr
);
649 send_three_arg_cmd (SDI_WRITE_MEMORY
, 0xffff8200 + 4 * i
, 4,
653 send_three_arg_cmd (SDI_WRITE_MEMORY
, 0xffff8280 + 4 * i
, 4,
657 send_three_arg_cmd (SDI_WRITE_MEMORY
, 0xffff8300 + 4 * i
, 4,
661 /* Resume program. */
662 send_cmd (SDI_EXEC_CPU
);
664 /* Without this, some commands which require an active target (such as kill)
665 won't work. This variable serves (at least) double duty as both the pid
666 of the target process (if it has such), and as a flag indicating that a
667 target is active. These functions should be split out into seperate
668 variables, especially since GDB will someday have a notion of debugging
669 several processes. */
670 inferior_ptid
= pid_to_ptid (32);
675 /* Wait until the remote machine stops, then return,
676 storing status in STATUS just as `wait' would. */
679 gdb_cntrl_c (int signo
)
682 fprintf_unfiltered (gdb_stdlog
, "interrupt\n");
687 m32r_wait (ptid_t ptid
, struct target_waitstatus
*status
)
689 static RETSIGTYPE (*prev_sigint
) ();
690 unsigned long bp_addr
, pc_addr
;
693 unsigned char buf
[13];
698 fprintf_unfiltered (gdb_stdlog
, "m32r_wait()\n");
700 status
->kind
= TARGET_WAITKIND_EXITED
;
701 status
->value
.sig
= 0;
704 prev_sigint
= signal (SIGINT
, gdb_cntrl_c
);
707 buf
[0] = SDI_WAIT_FOR_READY
;
708 if (serial_write (sdi_desc
, buf
, 1) != 0)
709 error (_("Remote connection closed"));
713 c
= serial_readchar (sdi_desc
, SDI_TIMEOUT
);
715 error (_("Remote connection closed"));
717 if (c
== '-') /* error */
719 status
->kind
= TARGET_WAITKIND_STOPPED
;
720 status
->value
.sig
= TARGET_SIGNAL_HUP
;
721 return inferior_ptid
;
723 else if (c
== '+') /* stopped */
727 ret
= serial_write (sdi_desc
, "!", 1); /* packet to interrupt */
729 ret
= serial_write (sdi_desc
, ".", 1); /* packet to wait */
731 error (_("Remote connection closed"));
734 status
->kind
= TARGET_WAITKIND_STOPPED
;
736 status
->value
.sig
= TARGET_SIGNAL_INT
;
738 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
741 signal (SIGINT
, prev_sigint
);
745 /* Recover parallel bit. */
746 if (last_pc_addr
!= 0xffffffff)
748 buf
[0] = SDI_WRITE_MEMORY
;
749 if (gdbarch_byte_order (current_gdbarch
) == BFD_ENDIAN_BIG
)
750 store_long_parameter (buf
+ 1, last_pc_addr
);
752 store_long_parameter (buf
+ 1, last_pc_addr
- 1);
753 store_long_parameter (buf
+ 5, 1);
754 buf
[9] = last_pc_addr_data
[0];
756 last_pc_addr
= 0xffffffff;
759 if (use_ib_breakpoints
)
760 ib_breakpoints
= max_ib_breakpoints
;
764 /* Set back pc by 2 if m32r is stopped with dbt. */
765 last_pc_addr
= 0xffffffff;
766 send_one_arg_cmd (SDI_READ_CPU_REG
, SDI_REG_BPC
);
767 pc_addr
= recv_long_data () - 2;
768 for (i
= ib_breakpoints
; i
< MAX_BREAKPOINTS
; i
++)
770 if (pc_addr
== bp_address
[i
])
772 send_two_arg_cmd (SDI_WRITE_CPU_REG
, SDI_REG_BPC
, pc_addr
);
774 /* If there is a parallel instruction with +2 offset at pc
775 address, we have to take care of it later. */
776 if ((pc_addr
& 0x2) != 0)
778 if (gdbarch_byte_order (current_gdbarch
) == BFD_ENDIAN_BIG
)
780 if ((bp_data
[i
][2] & 0x80) != 0)
782 last_pc_addr
= pc_addr
;
783 last_pc_addr_data
[0] = bp_data
[i
][2];
784 last_pc_addr_data
[1] = bp_data
[i
][3];
789 if ((bp_data
[i
][1] & 0x80) != 0)
791 last_pc_addr
= pc_addr
;
792 last_pc_addr_data
[0] = bp_data
[i
][1];
793 last_pc_addr_data
[1] = bp_data
[i
][0];
801 /* Remove ib breakpoints. */
802 for (i
= 0; i
< ib_breakpoints
; i
++)
804 if (bp_address
[i
] != 0xffffffff)
805 send_three_arg_cmd (SDI_WRITE_MEMORY
, 0xffff8000 + 4 * i
, 4,
808 /* Remove dbt breakpoints. */
809 for (i
= ib_breakpoints
; i
< MAX_BREAKPOINTS
; i
++)
811 bp_addr
= bp_address
[i
];
812 if (bp_addr
!= 0xffffffff)
815 bp_addr
&= 0x7fffffff;
816 buf
[0] = SDI_WRITE_MEMORY
;
817 store_long_parameter (buf
+ 1, bp_addr
& 0xfffffffc);
818 store_long_parameter (buf
+ 5, 4);
819 buf
[9] = bp_data
[i
][0];
820 buf
[10] = bp_data
[i
][1];
821 buf
[11] = bp_data
[i
][2];
822 buf
[12] = bp_data
[i
][3];
827 /* Remove access breaks. */
828 hit_watchpoint_addr
= 0;
829 for (i
= 0; i
< max_access_breaks
; i
++)
831 if (ab_address
[i
] != 0x00000000)
833 buf
[0] = SDI_READ_MEMORY
;
834 store_long_parameter (buf
+ 1, 0xffff8100 + 4 * i
);
835 store_long_parameter (buf
+ 5, 4);
836 serial_write (sdi_desc
, buf
, 9);
837 c
= serial_readchar (sdi_desc
, SDI_TIMEOUT
);
838 if (c
!= '-' && recv_data (buf
, 4) != -1)
840 if (gdbarch_byte_order (current_gdbarch
) == BFD_ENDIAN_BIG
)
842 if ((buf
[3] & 0x1) == 0x1)
843 hit_watchpoint_addr
= ab_address
[i
];
847 if ((buf
[0] & 0x1) == 0x1)
848 hit_watchpoint_addr
= ab_address
[i
];
852 send_three_arg_cmd (SDI_WRITE_MEMORY
, 0xffff8100 + 4 * i
, 4,
858 fprintf_unfiltered (gdb_stdlog
, "pc => 0x%lx\n", pc_addr
);
860 return inferior_ptid
;
863 /* Terminate the open connection to the remote debugger.
864 Use this when you want to detach and do something else
867 m32r_detach (char *args
, int from_tty
)
870 fprintf_unfiltered (gdb_stdlog
, "m32r_detach(%d)\n", from_tty
);
872 m32r_resume (inferior_ptid
, 0, 0);
874 /* calls m32r_close to do the real work */
877 fprintf_unfiltered (gdb_stdlog
, "Ending remote %s debugging\n",
881 /* Return the id of register number REGNO. */
884 get_reg_id (int regno
)
903 /* Read the remote registers into the block REGS. */
905 static void m32r_fetch_register (struct regcache
*, int);
908 m32r_fetch_registers (struct regcache
*regcache
)
913 regno
< gdbarch_num_regs (get_regcache_arch (regcache
));
915 m32r_fetch_register (regcache
, regno
);
918 /* Fetch register REGNO, or all registers if REGNO is -1.
919 Returns errno value. */
921 m32r_fetch_register (struct regcache
*regcache
, int regno
)
923 unsigned long val
, val2
, regid
;
926 m32r_fetch_registers (regcache
);
929 char buffer
[MAX_REGISTER_SIZE
];
931 regid
= get_reg_id (regno
);
932 send_one_arg_cmd (SDI_READ_CPU_REG
, regid
);
933 val
= recv_long_data ();
935 if (regid
== SDI_REG_PSW
)
937 send_one_arg_cmd (SDI_READ_CPU_REG
, SDI_REG_BBPSW
);
938 val2
= recv_long_data ();
939 val
= ((0x00cf & val2
) << 8) | ((0xcf00 & val
) >> 8);
943 fprintf_unfiltered (gdb_stdlog
, "m32r_fetch_register(%d,0x%08lx)\n",
946 /* We got the number the register holds, but gdb expects to see a
947 value in the target byte ordering. */
948 store_unsigned_integer (buffer
, 4, val
);
949 regcache_raw_supply (regcache
, regno
, buffer
);
954 /* Store the remote registers from the contents of the block REGS. */
956 static void m32r_store_register (struct regcache
*, int);
959 m32r_store_registers (struct regcache
*regcache
)
964 regno
< gdbarch_num_regs (get_regcache_arch (regcache
));
966 m32r_store_register (regcache
, regno
);
968 registers_changed ();
971 /* Store register REGNO, or all if REGNO == 0.
972 Return errno value. */
974 m32r_store_register (struct regcache
*regcache
, int regno
)
977 ULONGEST regval
, tmp
;
980 m32r_store_registers (regcache
);
983 regcache_cooked_read_unsigned (regcache
, regno
, ®val
);
984 regid
= get_reg_id (regno
);
986 if (regid
== SDI_REG_PSW
)
988 unsigned long psw
, bbpsw
;
990 send_one_arg_cmd (SDI_READ_CPU_REG
, SDI_REG_PSW
);
991 psw
= recv_long_data ();
993 send_one_arg_cmd (SDI_READ_CPU_REG
, SDI_REG_BBPSW
);
994 bbpsw
= recv_long_data ();
996 tmp
= (0x00cf & psw
) | ((0x00cf & regval
) << 8);
997 send_two_arg_cmd (SDI_WRITE_CPU_REG
, SDI_REG_PSW
, tmp
);
999 tmp
= (0x0030 & bbpsw
) | ((0xcf00 & regval
) >> 8);
1000 send_two_arg_cmd (SDI_WRITE_CPU_REG
, SDI_REG_BBPSW
, tmp
);
1004 send_two_arg_cmd (SDI_WRITE_CPU_REG
, regid
, regval
);
1008 fprintf_unfiltered (gdb_stdlog
, "m32r_store_register(%d,0x%08lu)\n",
1009 regno
, (unsigned long) regval
);
1013 /* Get ready to modify the registers array. On machines which store
1014 individual registers, this doesn't need to do anything. On machines
1015 which store all the registers in one fell swoop, this makes sure
1016 that registers contains all the registers from the program being
1020 m32r_prepare_to_store (struct regcache
*regcache
)
1022 /* Do nothing, since we can store individual regs */
1024 fprintf_unfiltered (gdb_stdlog
, "m32r_prepare_to_store()\n");
1028 m32r_files_info (struct target_ops
*target
)
1030 char *file
= "nothing";
1034 file
= bfd_get_filename (exec_bfd
);
1035 printf_filtered ("\tAttached to %s running program %s\n",
1040 /* Read/Write memory. */
1042 m32r_xfer_memory (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
,
1044 struct mem_attrib
*attrib
, struct target_ops
*target
)
1046 unsigned long taddr
;
1047 unsigned char buf
[0x2000];
1054 if ((taddr
& 0xa0000000) == 0x80000000)
1055 taddr
&= 0x7fffffff;
1061 fprintf_unfiltered (gdb_stdlog
, "m32r_xfer_memory(%s,%d,write)\n",
1062 paddr (memaddr
), len
);
1064 fprintf_unfiltered (gdb_stdlog
, "m32r_xfer_memory(%s,%d,read)\n",
1065 paddr (memaddr
), len
);
1070 buf
[0] = SDI_WRITE_MEMORY
;
1071 store_long_parameter (buf
+ 1, taddr
);
1072 store_long_parameter (buf
+ 5, len
);
1075 memcpy (buf
+ 9, myaddr
, len
);
1076 ret
= send_data (buf
, len
+ 9) - 9;
1080 if (serial_write (sdi_desc
, buf
, 9) != 0)
1083 fprintf_unfiltered (gdb_stdlog
,
1084 "m32r_xfer_memory() failed\n");
1087 ret
= send_data (myaddr
, len
);
1092 buf
[0] = SDI_READ_MEMORY
;
1093 store_long_parameter (buf
+ 1, taddr
);
1094 store_long_parameter (buf
+ 5, len
);
1095 if (serial_write (sdi_desc
, buf
, 9) != 0)
1098 fprintf_unfiltered (gdb_stdlog
, "m32r_xfer_memory() failed\n");
1102 c
= serial_readchar (sdi_desc
, SDI_TIMEOUT
);
1103 if (c
< 0 || c
== '-')
1106 fprintf_unfiltered (gdb_stdlog
, "m32r_xfer_memory() failed\n");
1110 ret
= recv_data (myaddr
, len
);
1116 fprintf_unfiltered (gdb_stdlog
, "m32r_xfer_memory() fails\n");
1127 fprintf_unfiltered (gdb_stdlog
, "m32r_kill()\n");
1129 inferior_ptid
= null_ptid
;
1134 /* Clean up when a program exits.
1136 The program actually lives on in the remote processor's RAM, and may be
1137 run again without a download. Don't leave it full of breakpoint
1141 m32r_mourn_inferior (void)
1144 fprintf_unfiltered (gdb_stdlog
, "m32r_mourn_inferior()\n");
1146 remove_breakpoints ();
1147 generic_mourn_inferior ();
1151 m32r_insert_breakpoint (struct bp_target_info
*bp_tgt
)
1153 CORE_ADDR addr
= bp_tgt
->placed_address
;
1155 unsigned char buf
[13];
1159 fprintf_unfiltered (gdb_stdlog
, "m32r_insert_breakpoint(%s,...)\n",
1162 if (use_ib_breakpoints
)
1163 ib_breakpoints
= max_ib_breakpoints
;
1167 for (i
= 0; i
< MAX_BREAKPOINTS
; i
++)
1169 if (bp_address
[i
] == 0xffffffff)
1171 bp_address
[i
] = addr
;
1172 if (i
>= ib_breakpoints
)
1174 buf
[0] = SDI_READ_MEMORY
;
1176 store_long_parameter (buf
+ 1, addr
& 0xfffffffc);
1178 store_long_parameter (buf
+ 1, addr
& 0x7ffffffc);
1179 store_long_parameter (buf
+ 5, 4);
1180 serial_write (sdi_desc
, buf
, 9);
1181 c
= serial_readchar (sdi_desc
, SDI_TIMEOUT
);
1183 recv_data (bp_data
[i
], 4);
1189 error (_("Too many breakpoints"));
1194 m32r_remove_breakpoint (struct bp_target_info
*bp_tgt
)
1196 CORE_ADDR addr
= bp_tgt
->placed_address
;
1200 fprintf_unfiltered (gdb_stdlog
, "m32r_remove_breakpoint(%s)\n",
1203 for (i
= 0; i
< MAX_BREAKPOINTS
; i
++)
1205 if (bp_address
[i
] == addr
)
1207 bp_address
[i
] = 0xffffffff;
1216 m32r_load (char *args
, int from_tty
)
1218 struct cleanup
*old_chain
;
1225 struct timeval start_time
, end_time
;
1226 unsigned long data_count
; /* Number of bytes transferred to memory */
1228 static RETSIGTYPE (*prev_sigint
) ();
1230 /* for direct tcp connections, we can do a fast binary download */
1235 while (*args
!= '\000')
1239 while (isspace (*args
))
1244 while ((*args
!= '\000') && !isspace (*args
))
1247 if (*args
!= '\000')
1252 else if (strncmp (arg
, "-quiet", strlen (arg
)) == 0)
1254 else if (strncmp (arg
, "-nostart", strlen (arg
)) == 0)
1257 error (_("Unknown option `%s'"), arg
);
1261 filename
= get_exec_file (1);
1263 pbfd
= bfd_openr (filename
, gnutarget
);
1266 perror_with_name (filename
);
1269 old_chain
= make_cleanup_bfd_close (pbfd
);
1271 if (!bfd_check_format (pbfd
, bfd_object
))
1272 error (_("\"%s\" is not an object file: %s"), filename
,
1273 bfd_errmsg (bfd_get_error ()));
1275 gettimeofday (&start_time
, NULL
);
1279 prev_sigint
= signal (SIGINT
, gdb_cntrl_c
);
1281 for (section
= pbfd
->sections
; section
; section
= section
->next
)
1283 if (bfd_get_section_flags (pbfd
, section
) & SEC_LOAD
)
1285 bfd_vma section_address
;
1286 bfd_size_type section_size
;
1290 section_address
= bfd_section_lma (pbfd
, section
);
1291 section_size
= bfd_get_section_size (section
);
1295 if ((section_address
& 0xa0000000) == 0x80000000)
1296 section_address
&= 0x7fffffff;
1300 printf_filtered ("[Loading section %s at 0x%lx (%d bytes)]\n",
1301 bfd_get_section_name (pbfd
, section
),
1302 (unsigned long) section_address
,
1303 (int) section_size
);
1307 data_count
+= section_size
;
1310 while (section_size
> 0)
1312 char unsigned buf
[0x1000 + 9];
1315 count
= min (section_size
, 0x1000);
1317 buf
[0] = SDI_WRITE_MEMORY
;
1318 store_long_parameter (buf
+ 1, section_address
);
1319 store_long_parameter (buf
+ 5, count
);
1321 bfd_get_section_contents (pbfd
, section
, buf
+ 9, fptr
, count
);
1322 if (send_data (buf
, count
+ 9) <= 0)
1323 error (_("Error while downloading %s section."),
1324 bfd_get_section_name (pbfd
, section
));
1328 printf_unfiltered (".");
1331 printf_unfiltered ("\n");
1334 gdb_flush (gdb_stdout
);
1337 section_address
+= count
;
1339 section_size
-= count
;
1345 if (!quiet
&& !interrupted
)
1347 printf_unfiltered ("done.\n");
1348 gdb_flush (gdb_stdout
);
1354 printf_unfiltered ("Interrupted.\n");
1360 signal (SIGINT
, prev_sigint
);
1362 gettimeofday (&end_time
, NULL
);
1364 /* Make the PC point at the start address */
1366 write_pc (bfd_get_start_address (exec_bfd
));
1368 inferior_ptid
= null_ptid
; /* No process now */
1370 /* This is necessary because many things were based on the PC at the time
1371 that we attached to the monitor, which is no longer valid now that we
1372 have loaded new code (and just changed the PC). Another way to do this
1373 might be to call normal_stop, except that the stack may not be valid,
1374 and things would get horribly confused... */
1376 clear_symtab_users ();
1380 entry
= bfd_get_start_address (pbfd
);
1383 printf_unfiltered ("[Starting %s at 0x%lx]\n", filename
,
1384 (unsigned long) entry
);
1387 print_transfer_performance (gdb_stdout
, data_count
, 0, &start_time
,
1390 do_cleanups (old_chain
);
1397 fprintf_unfiltered (gdb_stdlog
, "m32r_stop()\n");
1399 send_cmd (SDI_STOP_CPU
);
1405 /* Tell whether this target can support a hardware breakpoint. CNT
1406 is the number of hardware breakpoints already installed. This
1407 implements the TARGET_CAN_USE_HARDWARE_WATCHPOINT macro. */
1410 m32r_can_use_hw_watchpoint (int type
, int cnt
, int othertype
)
1412 return sdi_desc
!= NULL
&& cnt
< max_access_breaks
;
1415 /* Set a data watchpoint. ADDR and LEN should be obvious. TYPE is 0
1416 for a write watchpoint, 1 for a read watchpoint, or 2 for a read/write
1420 m32r_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
1425 fprintf_unfiltered (gdb_stdlog
, "m32r_insert_watchpoint(%s,%d,%d)\n",
1426 paddr (addr
), len
, type
);
1428 for (i
= 0; i
< MAX_ACCESS_BREAKS
; i
++)
1430 if (ab_address
[i
] == 0x00000000)
1432 ab_address
[i
] = addr
;
1439 error (_("Too many watchpoints"));
1444 m32r_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
1449 fprintf_unfiltered (gdb_stdlog
, "m32r_remove_watchpoint(%s,%d,%d)\n",
1450 paddr (addr
), len
, type
);
1452 for (i
= 0; i
< MAX_ACCESS_BREAKS
; i
++)
1454 if (ab_address
[i
] == addr
)
1456 ab_address
[i
] = 0x00000000;
1465 m32r_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
1468 if (hit_watchpoint_addr
!= 0x00000000)
1470 *addr_p
= hit_watchpoint_addr
;
1477 m32r_stopped_by_watchpoint (void)
1480 return m32r_stopped_data_address (¤t_target
, &addr
);
1485 sdireset_command (char *args
, int from_tty
)
1488 fprintf_unfiltered (gdb_stdlog
, "m32r_sdireset()\n");
1490 send_cmd (SDI_OPEN
);
1492 inferior_ptid
= null_ptid
;
1497 sdistatus_command (char *args
, int from_tty
)
1499 unsigned char buf
[4096];
1503 fprintf_unfiltered (gdb_stdlog
, "m32r_sdireset()\n");
1508 send_cmd (SDI_STATUS
);
1509 for (i
= 0; i
< 4096; i
++)
1511 c
= serial_readchar (sdi_desc
, SDI_TIMEOUT
);
1519 printf_filtered ("%s", buf
);
1524 debug_chaos_command (char *args
, int from_tty
)
1526 unsigned char buf
[3];
1528 buf
[0] = SDI_SET_ATTR
;
1529 buf
[1] = SDI_ATTR_CACHE
;
1530 buf
[2] = SDI_CACHE_TYPE_CHAOS
;
1536 use_debug_dma_command (char *args
, int from_tty
)
1538 unsigned char buf
[3];
1540 buf
[0] = SDI_SET_ATTR
;
1541 buf
[1] = SDI_ATTR_MEM_ACCESS
;
1542 buf
[2] = SDI_MEM_ACCESS_DEBUG_DMA
;
1547 use_mon_code_command (char *args
, int from_tty
)
1549 unsigned char buf
[3];
1551 buf
[0] = SDI_SET_ATTR
;
1552 buf
[1] = SDI_ATTR_MEM_ACCESS
;
1553 buf
[2] = SDI_MEM_ACCESS_MON_CODE
;
1559 use_ib_breakpoints_command (char *args
, int from_tty
)
1561 use_ib_breakpoints
= 1;
1565 use_dbt_breakpoints_command (char *args
, int from_tty
)
1567 use_ib_breakpoints
= 0;
1571 /* Define the target subroutine names */
1573 struct target_ops m32r_ops
;
1576 init_m32r_ops (void)
1578 m32r_ops
.to_shortname
= "m32rsdi";
1579 m32r_ops
.to_longname
= "Remote M32R debugging over SDI interface";
1580 m32r_ops
.to_doc
= "Use an M32R board using SDI debugging protocol.";
1581 m32r_ops
.to_open
= m32r_open
;
1582 m32r_ops
.to_close
= m32r_close
;
1583 m32r_ops
.to_detach
= m32r_detach
;
1584 m32r_ops
.to_resume
= m32r_resume
;
1585 m32r_ops
.to_wait
= m32r_wait
;
1586 m32r_ops
.to_fetch_registers
= m32r_fetch_register
;
1587 m32r_ops
.to_store_registers
= m32r_store_register
;
1588 m32r_ops
.to_prepare_to_store
= m32r_prepare_to_store
;
1589 m32r_ops
.deprecated_xfer_memory
= m32r_xfer_memory
;
1590 m32r_ops
.to_files_info
= m32r_files_info
;
1591 m32r_ops
.to_insert_breakpoint
= m32r_insert_breakpoint
;
1592 m32r_ops
.to_remove_breakpoint
= m32r_remove_breakpoint
;
1593 m32r_ops
.to_can_use_hw_breakpoint
= m32r_can_use_hw_watchpoint
;
1594 m32r_ops
.to_insert_watchpoint
= m32r_insert_watchpoint
;
1595 m32r_ops
.to_remove_watchpoint
= m32r_remove_watchpoint
;
1596 m32r_ops
.to_stopped_by_watchpoint
= m32r_stopped_by_watchpoint
;
1597 m32r_ops
.to_stopped_data_address
= m32r_stopped_data_address
;
1598 m32r_ops
.to_kill
= m32r_kill
;
1599 m32r_ops
.to_load
= m32r_load
;
1600 m32r_ops
.to_create_inferior
= m32r_create_inferior
;
1601 m32r_ops
.to_mourn_inferior
= m32r_mourn_inferior
;
1602 m32r_ops
.to_stop
= m32r_stop
;
1603 m32r_ops
.to_log_command
= serial_log_command
;
1604 m32r_ops
.to_stratum
= process_stratum
;
1605 m32r_ops
.to_has_all_memory
= 1;
1606 m32r_ops
.to_has_memory
= 1;
1607 m32r_ops
.to_has_stack
= 1;
1608 m32r_ops
.to_has_registers
= 1;
1609 m32r_ops
.to_has_execution
= 1;
1610 m32r_ops
.to_magic
= OPS_MAGIC
;
1614 extern initialize_file_ftype _initialize_remote_m32r
;
1617 _initialize_remote_m32r (void)
1623 /* Initialize breakpoints. */
1624 for (i
= 0; i
< MAX_BREAKPOINTS
; i
++)
1625 bp_address
[i
] = 0xffffffff;
1627 /* Initialize access breaks. */
1628 for (i
= 0; i
< MAX_ACCESS_BREAKS
; i
++)
1629 ab_address
[i
] = 0x00000000;
1631 add_target (&m32r_ops
);
1633 add_com ("sdireset", class_obscure
, sdireset_command
,
1634 _("Reset SDI connection."));
1636 add_com ("sdistatus", class_obscure
, sdistatus_command
,
1637 _("Show status of SDI connection."));
1639 add_com ("debug_chaos", class_obscure
, debug_chaos_command
,
1640 _("Debug M32R/Chaos."));
1642 add_com ("use_debug_dma", class_obscure
, use_debug_dma_command
,
1643 _("Use debug DMA mem access."));
1644 add_com ("use_mon_code", class_obscure
, use_mon_code_command
,
1645 _("Use mon code mem access."));
1647 add_com ("use_ib_break", class_obscure
, use_ib_breakpoints_command
,
1648 _("Set breakpoints by IB break."));
1649 add_com ("use_dbt_break", class_obscure
, use_dbt_breakpoints_command
,
1650 _("Set breakpoints by dbt."));