From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20784 invoked by alias); 14 Oct 2003 07:53:33 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 20766 invoked from network); 14 Oct 2003 07:53:30 -0000 Received: from unknown (HELO mail02.idc.renesas.com) (202.234.163.13) by sources.redhat.com with SMTP; 14 Oct 2003 07:53:30 -0000 Received: from mail02.idc.renesas.com (localhost [127.0.0.1]) by mail02.idc.renesas.com with ESMTP id h9E7r6p0021502 for ; Tue, 14 Oct 2003 16:53:11 +0900 (JST) Received: from guardian01.idc.renesas.com ([172.20.8.132]) by mail02.idc.renesas.com with ESMTP id h9E7qlYV021444; Tue, 14 Oct 2003 16:52:51 +0900 (JST) Received: (from root@localhost) by guardian01.idc.renesas.com with id h9E7qgo9025457; Tue, 14 Oct 2003 16:52:42 +0900 (JST) Received: from unknown [172.20.8.68] by guardian01.idc.renesas.com with SMTP id SAA25456 ; Tue, 14 Oct 2003 16:52:42 +0900 Received: from mta01.idc.renesas.com (localhost [127.0.0.1]) by mta01.idc.renesas.com with ESMTP id h9E7qeEW003626; Tue, 14 Oct 2003 16:52:40 +0900 (JST) Received: from rnsmtp01.hoku_r.renesas.com ([10.145.246.51]) by mta01.idc.renesas.com with ESMTP id h9E7qeO5003621; Tue, 14 Oct 2003 16:52:40 +0900 (JST) Received: from mrkaisv.hoku.renesas.com ([10.145.105.245]) by rnsmtp01.hoku_r.renesas.com (8.9.3/3.7W) with ESMTP id QAA20528; Tue, 14 Oct 2003 16:52:39 +0900 (JST) Received: from KEI (unknown [10.145.105.81]) by mrkaisv.hoku.renesas.com (Postfix) with SMTP id 34781798501; Tue, 14 Oct 2003 16:52:39 +0900 (JST) Message-ID: <032401c39228$378ab450$5169910a@KEI> From: "Kei Sakamoto" To: "Andrew Cagney" Cc: References: <02e201c35a5e$883a8cb0$5169910a@KEI> <20030817210347.GF11300@nevyn.them.org> <3F6EA141.7020502@redhat.com> <00bc01c3888d$39639660$5169910a@KEI> <3F860E3D.9000506@redhat.com> Subject: Re: [patch] New m32r remote target, m32rsdi Date: Tue, 14 Oct 2003 07:53:00 -0000 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0321_01C39273.A7586BB0" X-Priority: 3 X-MSMail-Priority: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-SW-Source: 2003-10/txt/msg00443.txt.bz2 This is a multi-part message in MIME format. ------=_NextPart_000_0321_01C39273.A7586BB0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-length: 741 > Can you post what you've got, without worrying about the ASYNC part. > > Andrew I attached the revised patch. It is different from the last one as the following: - use serial.[ch] functions instead of socket library - documented (doc/gdb.texinfo) - add an entry in NEWS Kei === ChangeLog: 2003-10-14 Kei Sakamoto * remote-m32r-sdi.c : New file, interface to m32r on-chip debug interface, SDI (Scalable Debug Interface). * NEWS: Mention m32r SDI protocol was supported. * Makefile.in (remote-m32r-sdi.o): Add build rule. * config/m32r/m32r.mt (TDEPFILES) : Add remote-m32r-sdi.o. doc/ChangeLog: 2003-10-14 Kei Sakamoto * gdb.texinfo (M32R/D): Mention m32rsdi target. ------=_NextPart_000_0321_01C39273.A7586BB0 Content-Type: application/octet-stream; name="diffs" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="diffs" Content-length: 3412 Index: Makefile.in=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvs/src/src/gdb/Makefile.in,v=0A= retrieving revision 1.456=0A= diff -u -r1.456 Makefile.in=0A= --- Makefile.in 11 Oct 2003 15:22:39 -0000 1.456=0A= +++ Makefile.in 14 Oct 2003 07:32:46 -0000=0A= @@ -1287,7 +1287,7 @@=0A= ppcnbsd-nat.o ppcnbsd-tdep.o \=0A= procfs.c \=0A= remote-e7000.c \=0A= - remote-hms.c remote-mips.c \=0A= + remote-hms.c remote-m32r-sdi.c remote-mips.c \=0A= remote-rdp.c remote-sim.c \=0A= remote-st.c remote-utils.c dcache.c \=0A= remote-vx.c \=0A= @@ -2161,6 +2161,8 @@=0A= $(remote_fileio_h)=0A= remote-hms.o: remote-hms.c $(defs_h) $(gdbcore_h) $(target_h) $(monitor_h)= \=0A= $(serial_h) $(regcache_h)=0A= +remote-m32r-sdi.o: remote-m32r-sdi.c $(defs_h) $(gdbcmd_h) $(gdbcore_h) \= =0A= + $(inferior_h) $(target_h) $(regcache_h) $(gdb_string_h) $(serial_h)=0A= remote-mips.o: remote-mips.c $(defs_h) $(inferior_h) $(bfd_h) $(symfile_h)= \=0A= $(gdbcmd_h) $(gdbcore_h) $(serial_h) $(target_h) $(remote_utils_h) \=0A= $(gdb_string_h) $(gdb_stat_h) $(regcache_h)=0A= Index: NEWS=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvs/src/src/gdb/NEWS,v=0A= retrieving revision 1.124=0A= diff -u -r1.124 NEWS=0A= --- NEWS 10 Oct 2003 07:13:10 -0000 1.124=0A= +++ NEWS 14 Oct 2003 07:32:46 -0000=0A= @@ -3,6 +3,10 @@=0A= =20=0A= *** Changes since GDB 6.0:=0A= =20=0A= +* New debugging protocols=0A= +=0A= +M32R with SDI protocol m32r-*-elf*=0A= +=0A= * "set prompt-escape-char" command deleted.=0A= =20=0A= The command "set prompt-escape-char" has been deleted. This command,=0A= Index: config/m32r/m32r.mt=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvs/src/src/gdb/config/m32r/m32r.mt,v=0A= retrieving revision 1.6=0A= diff -u -r1.6 m32r.mt=0A= --- config/m32r/m32r.mt 1 Aug 2003 21:14:33 -0000 1.6=0A= +++ config/m32r/m32r.mt 14 Oct 2003 07:32:46 -0000=0A= @@ -1,4 +1,4 @@=0A= # Target: Renesas m32r processor=0A= -TDEPFILES=3D m32r-tdep.o monitor.o m32r-rom.o dsrec.o=0A= +TDEPFILES=3D m32r-tdep.o monitor.o m32r-rom.o dsrec.o remote-m32r-sdi.o=0A= SIM_OBS =3D remote-sim.o=0A= SIM =3D ../sim/m32r/libsim.a=0A= Index: doc/gdb.texinfo=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v=0A= retrieving revision 1.179=0A= diff -u -r1.179 gdb.texinfo=0A= --- doc/gdb.texinfo 13 Oct 2003 16:11:57 -0000 1.179=0A= +++ doc/gdb.texinfo 14 Oct 2003 07:32:48 -0000=0A= @@ -12046,6 +12046,10 @@=0A= @item target m32r @var{dev}=0A= Renesas M32R/D ROM monitor.=0A= =20=0A= +@kindex target m32rsdi=0A= +@item target m32rsdi @var{dev}=0A= +Renesas M32R SDI server, connected via parallel port to the board.=0A= +=0A= @end table=0A= =20=0A= @node M68K=0A= ------=_NextPart_000_0321_01C39273.A7586BB0 Content-Type: application/octet-stream; name="remote-m32r-sdi.c" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="remote-m32r-sdi.c" Content-length: 46402 /* Remote debugging interface for M32R/SDI.=0A= =0A= Copyright (C) 2003 Free Software Foundation, Inc.=0A= =0A= Contributed by Renesas Technology Co.=0A= Written by Kei Sakamoto .=0A= =0A= This file is part of GDB.=0A= =0A= This program is free software; you can redistribute it and/or modify=0A= it under the terms of the GNU General Public License as published by=0A= the Free Software Foundation; either version 2 of the License, or=0A= (at your option) any later version.=0A= =0A= This program is distributed in the hope that it will be useful,=0A= but WITHOUT ANY WARRANTY; without even the implied warranty of=0A= MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the=0A= GNU General Public License for more details.=0A= =0A= You should have received a copy of the GNU General Public License=0A= along with this program; if not, write to the Free Software=0A= Foundation, Inc., 59 Temple Place - Suite 330,=0A= Boston, MA 02111-1307, USA. */=0A= =0A= #include "defs.h"=0A= #include "gdbcmd.h"=0A= #include "gdbcore.h"=0A= #include "inferior.h"=0A= #include "target.h"=0A= #include "regcache.h"=0A= #include "gdb_string.h"=0A= #include =0A= #include =0A= #include =0A= #include =0A= #include =0A= #include =0A= #include =0A= =0A= =0A= #include "serial.h"=0A= =0A= /* Descriptor for I/O to remote machine. */=0A= =0A= static struct serial *sdi_desc =3D NULL;=0A= =0A= #define SDI_TIMEOUT 30=0A= =0A= =0A= #define SDIPORT 3232=0A= =0A= static char chip_name[64];=0A= =0A= static int step_mode;=0A= static unsigned long last_pc_addr =3D 0xffffffff;=0A= static unsigned char last_pc_addr_data[2];=0A= =0A= static int mmu_on =3D 0;=0A= =0A= static int use_ib_breakpoints =3D 1;=0A= =0A= #define MAX_BREAKPOINTS 1024=0A= static int max_ib_breakpoints;=0A= static unsigned long bp_address[MAX_BREAKPOINTS];=0A= static unsigned char bp_data[MAX_BREAKPOINTS][4];=0A= static const unsigned char ib_bp_entry_enable[] =3D {=0A= 0x00, 0x00, 0x00, 0x06=0A= };=0A= static const unsigned char ib_bp_entry_disable[] =3D {=0A= 0x00, 0x00, 0x00, 0x00=0A= };=0A= =0A= /* dbt -> nop */=0A= static const unsigned char dbt_bp_entry[] =3D {=0A= 0x10, 0xe0, 0x70, 0x00=0A= };=0A= =0A= #define MAX_ACCESS_BREAKS 4=0A= static int max_access_breaks;=0A= static unsigned long ab_address[MAX_ACCESS_BREAKS];=0A= static unsigned int ab_type[MAX_ACCESS_BREAKS];=0A= static unsigned int ab_size[MAX_ACCESS_BREAKS];=0A= static CORE_ADDR hit_watchpoint_addr =3D 0;=0A= =0A= static int interrupted =3D 0;=0A= =0A= /* Forward data declarations */=0A= extern struct target_ops m32r_ops;=0A= =0A= =0A= /* Commands */=0A= #define SDI_OPEN 1=0A= #define SDI_CLOSE 2=0A= #define SDI_RELEASE 3=0A= #define SDI_READ_CPU_REG 4=0A= #define SDI_WRITE_CPU_REG 5=0A= #define SDI_READ_MEMORY 6=0A= #define SDI_WRITE_MEMORY 7=0A= #define SDI_EXEC_CPU 8=0A= #define SDI_STOP_CPU 9=0A= #define SDI_WAIT_FOR_READY 10=0A= #define SDI_GET_ATTR 11=0A= #define SDI_SET_ATTR 12=0A= #define SDI_STATUS 13=0A= =0A= /* Attributes */=0A= #define SDI_ATTR_NAME 1=0A= #define SDI_ATTR_BRK 2=0A= #define SDI_ATTR_ABRK 3=0A= #define SDI_ATTR_CACHE 4=0A= #define SDI_CACHE_TYPE_M32102 0=0A= #define SDI_CACHE_TYPE_CHAOS 1=0A= #define SDI_ATTR_MEM_ACCESS 5=0A= #define SDI_MEM_ACCESS_DEBUG_DMA 0=0A= #define SDI_MEM_ACCESS_MON_CODE 1=0A= =0A= /* Registers */=0A= #define SDI_REG_R0 0=0A= #define SDI_REG_R1 1=0A= #define SDI_REG_R2 2=0A= #define SDI_REG_R3 3=0A= #define SDI_REG_R4 4=0A= #define SDI_REG_R5 5=0A= #define SDI_REG_R6 6=0A= #define SDI_REG_R7 7=0A= #define SDI_REG_R8 8=0A= #define SDI_REG_R9 9=0A= #define SDI_REG_R10 10=0A= #define SDI_REG_R11 11=0A= #define SDI_REG_R12 12=0A= #define SDI_REG_FP 13=0A= #define SDI_REG_LR 14=0A= #define SDI_REG_SP 15=0A= #define SDI_REG_PSW 16=0A= #define SDI_REG_CBR 17=0A= #define SDI_REG_SPI 18=0A= #define SDI_REG_SPU 19=0A= #define SDI_REG_CR4 20=0A= #define SDI_REG_EVB 21=0A= #define SDI_REG_BPC 22=0A= #define SDI_REG_CR7 23=0A= #define SDI_REG_BBPSW 24=0A= #define SDI_REG_CR9 25=0A= #define SDI_REG_CR10 26=0A= #define SDI_REG_CR11 27=0A= #define SDI_REG_CR12 28=0A= #define SDI_REG_WR 29=0A= #define SDI_REG_BBPC 30=0A= #define SDI_REG_PBP 31=0A= #define SDI_REG_ACCH 32=0A= #define SDI_REG_ACCL 33=0A= #define SDI_REG_ACC1H 34=0A= #define SDI_REG_ACC1L 35=0A= =0A= =0A= /* Low level communication functions */=0A= =0A= /* Check an ack packet from the target */=0A= static int=0A= get_ack (void)=0A= {=0A= int c;=0A= =0A= if (!sdi_desc)=20=0A= return -1;=0A= =0A= c =3D serial_readchar (sdi_desc, SDI_TIMEOUT);=0A= =0A= if (c < 0)=0A= return -1;=0A= =0A= if (c !=3D '+') /* error */=0A= return -1;=0A= =0A= return 0;=0A= }=0A= =0A= /* Send data to the target and check an ack packet */=0A= static int=0A= send_data (void *buf, int len)=0A= {=0A= int ret;=0A= =0A= if (!sdi_desc)=20=0A= return -1;=0A= =0A= if (serial_write (sdi_desc, buf, len) !=3D 0)=0A= return -1;=0A= =0A= if (get_ack () =3D=3D -1)=0A= return -1;=0A= =0A= return len;=0A= }=0A= =0A= /* Receive data from the target */=0A= static int=0A= recv_data (void *buf, int len)=0A= {=0A= int total =3D 0;=0A= int c;=0A= =0A= if (!sdi_desc)=20=0A= return -1;=0A= =0A= while (total < len)=0A= {=0A= c =3D serial_readchar (sdi_desc, SDI_TIMEOUT);=0A= =0A= if (c < 0)=0A= return -1;=0A= =0A= ((unsigned char *) buf)[total++] =3D c;=0A= }=0A= =0A= return len;=0A= }=0A= =0A= /* Store unsigned long parameter on packet */=0A= static void=0A= store_long_parameter (void *buf, long val)=0A= {=0A= val =3D htonl (val);=0A= memcpy (buf, &val, 4);=0A= }=0A= =0A= /* Check if MMU is on */=0A= static void=0A= check_mmu_status (void)=0A= {=0A= unsigned long val;=0A= unsigned char buf[2];=0A= =0A= /* Read PC address */=0A= buf[0] =3D SDI_READ_CPU_REG;=0A= buf[1] =3D SDI_REG_BPC;=0A= if (send_data (buf, 2) =3D=3D -1)=0A= return;=0A= recv_data (&val, 4);=0A= val =3D ntohl (val);=0A= if ((val & 0xc0000000) =3D=3D 0x80000000)=0A= {=0A= mmu_on =3D 1;=0A= return;=0A= }=0A= =0A= /* Read EVB address */=0A= buf[0] =3D SDI_READ_CPU_REG;=0A= buf[1] =3D SDI_REG_EVB;=0A= if (send_data (buf, 2) =3D=3D -1)=0A= return;=0A= recv_data (&val, 4);=0A= val =3D ntohl (val);=0A= if ((val & 0xc0000000) =3D=3D 0x80000000)=0A= {=0A= mmu_on =3D 1;=0A= return;=0A= }=0A= =0A= mmu_on =3D 0;=0A= }=0A= =0A= =0A= /* This is called not only when we first attach, but also when the=0A= user types "run" after having attached. */=0A= static void=0A= m32r_create_inferior (char *execfile, char *args, char **env)=0A= {=0A= CORE_ADDR entry_pt;=0A= =0A= if (args && *args)=0A= error ("Cannot pass arguments to remote STDEBUG process");=0A= =0A= if (execfile =3D=3D 0 || exec_bfd =3D=3D 0)=0A= error ("No executable file specified");=0A= =0A= if (remote_debug)=0A= fprintf_unfiltered (gdb_stdlog, "m32r_create_inferior(%s,%s)\n", execfi= le,=0A= args);=0A= =0A= entry_pt =3D bfd_get_start_address (exec_bfd);=0A= =0A= /* The "process" (board) is already stopped awaiting our commands, and=0A= the program is already downloaded. We just set its PC and go. */=0A= =0A= clear_proceed_status ();=0A= =0A= /* Tell wait_for_inferior that we've started a new process. */=0A= init_wait_for_inferior ();=0A= =0A= /* Set up the "saved terminal modes" of the inferior=0A= based on what modes we are starting it with. */=0A= target_terminal_init ();=0A= =0A= /* Install inferior's terminal modes. */=0A= target_terminal_inferior ();=0A= =0A= proceed (entry_pt, TARGET_SIGNAL_DEFAULT, 0);=0A= }=0A= =0A= /* Open a connection to a remote debugger.=0A= NAME is the filename used for communication. */=0A= =0A= static void=0A= m32r_open (char *args, int from_tty)=0A= {=0A= struct hostent *host_ent;=0A= struct sockaddr_in server_addr;=0A= char *port_str, hostname[256];=0A= int port;=0A= unsigned char buf[2];=0A= int i, n;=0A= int yes =3D 1;=0A= =0A= if (remote_debug)=0A= fprintf_unfiltered (gdb_stdlog, "m32r_open(%d)\n", from_tty);=0A= =0A= target_preopen (from_tty);=0A= =0A= push_target (&m32r_ops);=0A= =0A= if (args =3D=3D NULL)=0A= sprintf (hostname, "localhost:%d", SDIPORT);=0A= else=0A= {=0A= port_str =3D strchr (args, ':');=0A= if (port_str =3D=3D NULL)=0A= sprintf (hostname, "%s:%d", args, SDIPORT);=0A= else=0A= strcpy (hostname, args);=0A= }=0A= =0A= sdi_desc =3D serial_open (hostname);=0A= if (!sdi_desc)=0A= error ("Connection refused\n");=0A= =0A= if (get_ack () =3D=3D -1)=0A= error ("Cannot connect to SDI target\n");=0A= =0A= buf[0] =3D SDI_OPEN;=0A= if (send_data (buf, 1) =3D=3D -1)=0A= error ("Cannot connect to SDI target\n");=0A= =0A= /* Get maximum number of ib breakpoints */=0A= buf[0] =3D SDI_GET_ATTR;=0A= buf[1] =3D SDI_ATTR_BRK;=0A= send_data (buf, 2);=0A= recv_data (buf, 1);=0A= max_ib_breakpoints =3D buf[0];=0A= if (remote_debug)=0A= printf_filtered ("Max IB Breakpoints =3D %d\n", max_ib_breakpoints);=0A= =0A= /* Initialize breakpoints. */=0A= for (i =3D 0; i < MAX_BREAKPOINTS; i++)=0A= bp_address[i] =3D 0xffffffff;=0A= =0A= /* Get maximum number of access breaks. */=0A= buf[0] =3D SDI_GET_ATTR;=0A= buf[1] =3D SDI_ATTR_ABRK;=0A= send_data (buf, 2);=0A= recv_data (buf, 1);=0A= max_access_breaks =3D buf[0];=0A= if (remote_debug)=0A= printf_filtered ("Max Access Breaks =3D %d\n", max_access_breaks);=0A= =0A= /* Initialize access breask. */=0A= for (i =3D 0; i < MAX_ACCESS_BREAKS; i++)=0A= ab_address[i] =3D 0x00000000;=0A= =0A= check_mmu_status ();=0A= =0A= /* Get the name of chip on target board. */=0A= buf[0] =3D SDI_GET_ATTR;=0A= buf[1] =3D SDI_ATTR_NAME;=0A= send_data (buf, 2);=0A= recv_data (chip_name, 64);=0A= =0A= if (from_tty)=0A= printf_filtered ("Remote %s connected to %s\n", target_shortname,=0A= chip_name);=0A= }=0A= =0A= /* Close out all files and local state before this target loses control. */= =0A= =0A= static void=0A= m32r_close (int quitting)=0A= {=0A= unsigned char buf[1];=0A= =0A= if (remote_debug)=0A= fprintf_unfiltered (gdb_stdlog, "m32r_close(%d)\n", quitting);=0A= =0A= if (sdi_desc)=0A= {=0A= buf[0] =3D SDI_CLOSE;=0A= send_data (buf, 1);=0A= serial_close (sdi_desc);=0A= sdi_desc =3D NULL;=0A= }=0A= =0A= inferior_ptid =3D null_ptid;=0A= return;=0A= }=0A= =0A= /* Tell the remote machine to resume. */=0A= =0A= static void=0A= m32r_resume (ptid_t ptid, int step, enum target_signal sig)=0A= {=0A= unsigned long pc_addr, bp_addr, ab_addr;=0A= unsigned char buf[13];=0A= int i;=0A= =0A= if (remote_debug)=0A= {=0A= if (step)=0A= fprintf_unfiltered (gdb_stdlog, "\nm32r_resume(step)\n");=0A= else=0A= fprintf_unfiltered (gdb_stdlog, "\nm32r_resume(cont)\n");=0A= }=0A= =0A= check_mmu_status ();=0A= =0A= pc_addr =3D read_pc ();=0A= if (remote_debug)=0A= fprintf_unfiltered (gdb_stdlog, "pc <=3D 0x%lx\n", pc_addr);=0A= =0A= /* At pc address there is a parallel instruction with +2 offset,=0A= so we have to make it a serial instruction or avoid it. */=0A= if (pc_addr =3D=3D last_pc_addr)=0A= {=0A= /* Avoid a parallel nop. */=0A= if (last_pc_addr_data[0] =3D=3D 0xf0 && last_pc_addr_data[1] =3D=3D 0= x00)=0A= {=0A= pc_addr +=3D 2;=0A= /* Now we can forget this instruction. */=0A= last_pc_addr =3D 0xffffffff;=0A= }=0A= /* Clear a parallel bit. */=0A= else=0A= {=0A= buf[0] =3D SDI_WRITE_MEMORY;=0A= if (TARGET_BYTE_ORDER =3D=3D BFD_ENDIAN_BIG)=0A= store_long_parameter (buf + 1, pc_addr);=0A= else=0A= store_long_parameter (buf + 1, pc_addr - 1);=0A= store_long_parameter (buf + 5, 1);=0A= buf[9] =3D last_pc_addr_data[0] & 0x7f;=0A= send_data (buf, 10);=0A= }=0A= }=0A= =0A= /* Set PC. */=0A= buf[0] =3D SDI_WRITE_CPU_REG;=0A= buf[1] =3D SDI_REG_BPC;=0A= store_long_parameter (buf + 2, pc_addr);=0A= send_data (buf, 6);=0A= =0A= /* step mode. */=0A= step_mode =3D step;=0A= if (step)=0A= {=0A= /* Set PBP. */=0A= buf[0] =3D SDI_WRITE_CPU_REG;=0A= buf[1] =3D SDI_REG_PBP;=0A= store_long_parameter (buf + 2, pc_addr | 1);=0A= send_data (buf, 6);=0A= }=0A= else=0A= {=0A= int ib_breakpoints;=0A= =0A= if (use_ib_breakpoints)=0A= ib_breakpoints =3D max_ib_breakpoints;=0A= else=0A= ib_breakpoints =3D 0;=0A= =0A= /* Set ib breakpoints. */=0A= for (i =3D 0; i < ib_breakpoints; i++)=0A= {=0A= bp_addr =3D bp_address[i];=0A= if (bp_addr !=3D 0xffffffff && bp_addr !=3D pc_addr)=0A= {=0A= /* Set PBP. */=0A= buf[0] =3D SDI_WRITE_MEMORY;=0A= store_long_parameter (buf + 1, 0xffff8000 + 4 * i);=0A= store_long_parameter (buf + 5, 4);=0A= if (TARGET_BYTE_ORDER =3D=3D BFD_ENDIAN_BIG)=0A= {=0A= buf[9] =3D ib_bp_entry_enable[0];=0A= buf[10] =3D ib_bp_entry_enable[1];=0A= buf[11] =3D ib_bp_entry_enable[2];=0A= buf[12] =3D ib_bp_entry_enable[3];=0A= }=0A= else=0A= {=0A= buf[9] =3D ib_bp_entry_enable[3];=0A= buf[10] =3D ib_bp_entry_enable[2];=0A= buf[11] =3D ib_bp_entry_enable[1];=0A= buf[12] =3D ib_bp_entry_enable[0];=0A= }=0A= send_data (buf, 13);=0A= =0A= buf[0] =3D SDI_WRITE_MEMORY;=0A= store_long_parameter (buf + 1, 0xffff8080 + 4 * i);=0A= store_long_parameter (buf + 5, 4);=0A= store_unsigned_integer (buf + 9, 4, bp_addr);=0A= send_data (buf, 13);=0A= }=0A= }=0A= =0A= /* Set dbt breakpoints. */=0A= for (i =3D ib_breakpoints; i < MAX_BREAKPOINTS; i++)=0A= {=0A= bp_addr =3D bp_address[i];=0A= if (bp_addr !=3D 0xffffffff && bp_addr !=3D pc_addr)=0A= {=0A= if (!mmu_on)=0A= bp_addr &=3D 0x7fffffff;=0A= =0A= /* Write DBT instruction. */=0A= buf[0] =3D SDI_WRITE_MEMORY;=0A= if ((bp_addr & 2) =3D=3D 0 && bp_addr !=3D (pc_addr & 0xfffffffc))= =0A= {=0A= store_long_parameter (buf + 1, bp_addr);=0A= store_long_parameter (buf + 5, 4);=0A= if (TARGET_BYTE_ORDER =3D=3D BFD_ENDIAN_BIG)=0A= {=0A= buf[9] =3D dbt_bp_entry[0];=0A= buf[10] =3D dbt_bp_entry[1];=0A= buf[11] =3D dbt_bp_entry[2];=0A= buf[12] =3D dbt_bp_entry[3];=0A= }=0A= else=0A= {=0A= buf[9] =3D dbt_bp_entry[3];=0A= buf[10] =3D dbt_bp_entry[2];=0A= buf[11] =3D dbt_bp_entry[1];=0A= buf[12] =3D dbt_bp_entry[0];=0A= }=0A= send_data (buf, 13);=0A= }=0A= else=0A= {=0A= if (TARGET_BYTE_ORDER =3D=3D BFD_ENDIAN_BIG)=0A= store_long_parameter (buf + 1, bp_addr);=0A= else if ((bp_addr & 2) =3D=3D 0)=0A= store_long_parameter (buf + 1, bp_addr + 2);=0A= else=0A= store_long_parameter (buf + 1, bp_addr - 2);=0A= store_long_parameter (buf + 5, 2);=0A= if (TARGET_BYTE_ORDER =3D=3D BFD_ENDIAN_BIG)=0A= {=0A= buf[9] =3D dbt_bp_entry[0];=0A= buf[10] =3D dbt_bp_entry[1];=0A= }=0A= else=0A= {=0A= buf[9] =3D dbt_bp_entry[1];=0A= buf[10] =3D dbt_bp_entry[0];=0A= }=0A= send_data (buf, 11);=0A= }=0A= }=0A= }=0A= =0A= /* Set access breaks. */=0A= for (i =3D 0; i < max_access_breaks; i++)=0A= {=0A= ab_addr =3D ab_address[i];=0A= if (ab_addr !=3D 0x00000000)=0A= {=0A= /* DBC register */=0A= buf[0] =3D SDI_WRITE_MEMORY;=0A= store_long_parameter (buf + 1, 0xffff8100 + 4 * i);=0A= store_long_parameter (buf + 5, 4);=0A= if (TARGET_BYTE_ORDER =3D=3D BFD_ENDIAN_BIG)=0A= {=0A= buf[9] =3D 0x00;=0A= buf[10] =3D 0x00;=0A= buf[11] =3D 0x00;=0A= switch (ab_type[i])=0A= {=0A= case 0: /* write watch */=0A= buf[12] =3D 0x86;=0A= break;=0A= case 1: /* read watch */=0A= buf[12] =3D 0x46;=0A= break;=0A= case 2: /* access watch */=0A= buf[12] =3D 0x06;=0A= break;=0A= }=0A= }=0A= else=0A= {=0A= switch (ab_type[i])=0A= {=0A= case 0: /* write watch */=0A= buf[9] =3D 0x86;=0A= break;=0A= case 1: /* read watch */=0A= buf[9] =3D 0x46;=0A= break;=0A= case 2: /* access watch */=0A= buf[9] =3D 0x06;=0A= break;=0A= }=0A= buf[10] =3D 0x00;=0A= buf[11] =3D 0x00;=0A= buf[12] =3D 0x00;=0A= }=0A= send_data (buf, 13);=0A= =0A= /* DBAH register */=0A= buf[0] =3D SDI_WRITE_MEMORY;=0A= store_long_parameter (buf + 1, 0xffff8180 + 4 * i);=0A= store_long_parameter (buf + 5, 4);=0A= store_unsigned_integer (buf + 9, 4, ab_addr);=0A= send_data (buf, 13);=0A= =0A= /* DBAL register */=0A= buf[0] =3D SDI_WRITE_MEMORY;=0A= store_long_parameter (buf + 1, 0xffff8200 + 4 * i);=0A= store_long_parameter (buf + 5, 4);=0A= store_long_parameter (buf + 9, 0xffffffff);=0A= send_data (buf, 13);=0A= =0A= /* DBD register */=0A= buf[0] =3D SDI_WRITE_MEMORY;=0A= store_long_parameter (buf + 1, 0xffff8280 + 4 * i);=0A= store_long_parameter (buf + 5, 4);=0A= store_long_parameter (buf + 9, 0x00000000);=0A= send_data (buf, 13);=0A= =0A= /* DBDM register */=0A= buf[0] =3D SDI_WRITE_MEMORY;=0A= store_long_parameter (buf + 1, 0xffff8300 + 4 * i);=0A= store_long_parameter (buf + 5, 4);=0A= store_long_parameter (buf + 9, 0x00000000);=0A= send_data (buf, 13);=0A= }=0A= }=0A= =0A= /* Unset PBP. */=0A= buf[0] =3D SDI_WRITE_CPU_REG;=0A= buf[1] =3D SDI_REG_PBP;=0A= store_long_parameter (buf + 2, 0x00000000);=0A= send_data (buf, 6);=0A= }=0A= =0A= buf[0] =3D SDI_EXEC_CPU;=0A= send_data (buf, 1);=0A= =0A= /* Without this, some commands which require an active target (such as ki= ll)=0A= won't work. This variable serves (at least) double duty as both the p= id=0A= of the target process (if it has such), and as a flag indicating that = a=0A= target is active. These functions should be split out into seperate= =0A= variables, especially since GDB will someday have a notion of debuggin= g=0A= several processes. */=0A= inferior_ptid =3D pid_to_ptid (32);=0A= =0A= return;=0A= }=0A= =0A= /* Wait until the remote machine stops, then return,=0A= storing status in STATUS just as `wait' would. */=0A= =0A= static void=0A= gdb_cntrl_c (int signo)=0A= {=0A= if (remote_debug)=0A= fprintf_unfiltered (gdb_stdlog, "interrupt\n");=0A= interrupted =3D 1;=0A= }=0A= =0A= static ptid_t=0A= m32r_wait (ptid_t ptid, struct target_waitstatus *status)=0A= {=0A= static RETSIGTYPE (*prev_sigint) ();=0A= unsigned long bp_addr, pc_addr;=0A= long i;=0A= unsigned char buf[13];=0A= unsigned long val;=0A= int ret, c;=0A= =0A= if (remote_debug)=0A= fprintf_unfiltered (gdb_stdlog, "m32r_wait()\n");=0A= =0A= status->kind =3D TARGET_WAITKIND_EXITED;=0A= status->value.sig =3D 0;=0A= =0A= interrupted =3D 0;=0A= prev_sigint =3D signal (SIGINT, gdb_cntrl_c);=0A= =0A= /* Wait for ready */=0A= buf[0] =3D SDI_WAIT_FOR_READY;=0A= if (serial_write (sdi_desc, buf, 1) !=3D 0)=0A= error ("Remote connection closed");=0A= =0A= while (1)=0A= {=0A= c =3D serial_readchar (sdi_desc, SDI_TIMEOUT);=0A= if (c < 0)=0A= error ("Remote connection closed");=0A= =0A= if (c =3D=3D '-') /* error */=0A= {=0A= status->kind =3D TARGET_WAITKIND_STOPPED;=0A= status->value.sig =3D TARGET_SIGNAL_HUP;=0A= return inferior_ptid;=0A= }=0A= else if (c =3D=3D '+') /* stopped */=0A= break;=0A= =0A= if (interrupted)=0A= ret =3D serial_write (sdi_desc, "!", 1); /* packet to interrupt */=0A= else=0A= ret =3D serial_write (sdi_desc, ".", 1); /* packet to wait */=0A= if (ret !=3D 0)=0A= error ("Remote connection closed");=0A= }=0A= =0A= status->kind =3D TARGET_WAITKIND_STOPPED;=0A= if (interrupted)=0A= status->value.sig =3D TARGET_SIGNAL_INT;=0A= else=0A= status->value.sig =3D TARGET_SIGNAL_TRAP;=0A= =0A= interrupted =3D 0;=0A= signal (SIGINT, prev_sigint);=0A= =0A= check_mmu_status ();=0A= =0A= /* Recover parallel bit. */=0A= if (last_pc_addr !=3D 0xffffffff)=0A= {=0A= buf[0] =3D SDI_WRITE_MEMORY;=0A= if (TARGET_BYTE_ORDER =3D=3D BFD_ENDIAN_BIG)=0A= store_long_parameter (buf + 1, last_pc_addr);=0A= else=0A= store_long_parameter (buf + 1, last_pc_addr - 1);=0A= store_long_parameter (buf + 5, 1);=0A= buf[9] =3D last_pc_addr_data[0];=0A= send_data (buf, 10);=0A= last_pc_addr =3D 0xffffffff;=0A= }=0A= =0A= /* Breakpoints are inserted only for "next" command */=0A= if (!step_mode)=0A= {=0A= int ib_breakpoints;=0A= =0A= if (use_ib_breakpoints)=0A= ib_breakpoints =3D max_ib_breakpoints;=0A= else=0A= ib_breakpoints =3D 0;=0A= =0A= /* Set back pc by 2 if m32r is stopped with dbt. */=0A= buf[0] =3D SDI_READ_CPU_REG;=0A= buf[1] =3D SDI_REG_BPC;=0A= send_data (buf, 2);=0A= recv_data (&val, 4);=0A= pc_addr =3D ntohl (val) - 2;=0A= for (i =3D ib_breakpoints; i < MAX_BREAKPOINTS; i++)=0A= {=0A= if (pc_addr =3D=3D bp_address[i])=0A= {=0A= buf[0] =3D SDI_WRITE_CPU_REG;=0A= buf[1] =3D SDI_REG_BPC;=0A= store_long_parameter (buf + 2, pc_addr);=0A= send_data (buf, 6);=0A= =0A= /* If there is a parallel instruction with +2 offset at pc=0A= address, we have to take care of it later. */=0A= if ((pc_addr & 0x2) !=3D 0)=0A= {=0A= if (TARGET_BYTE_ORDER =3D=3D BFD_ENDIAN_BIG)=0A= {=0A= if ((bp_data[i][2] & 0x80) !=3D 0)=0A= {=0A= last_pc_addr =3D pc_addr;=0A= last_pc_addr_data[0] =3D bp_data[i][2];=0A= last_pc_addr_data[1] =3D bp_data[i][3];=0A= }=0A= }=0A= else=0A= {=0A= if ((bp_data[i][1] & 0x80) !=3D 0)=0A= {=0A= last_pc_addr =3D pc_addr;=0A= last_pc_addr_data[0] =3D bp_data[i][1];=0A= last_pc_addr_data[1] =3D bp_data[i][0];=0A= }=0A= }=0A= }=0A= break;=0A= }=0A= }=0A= =0A= /* Remove ib breakpoints. */=0A= for (i =3D 0; i < ib_breakpoints; i++)=0A= {=0A= if (bp_address[i] !=3D 0xffffffff)=0A= {=0A= buf[0] =3D SDI_WRITE_MEMORY;=0A= store_long_parameter (buf + 1, 0xffff8000 + 4 * i);=0A= store_long_parameter (buf + 5, 4);=0A= buf[9] =3D ib_bp_entry_disable[0];=0A= buf[10] =3D ib_bp_entry_disable[1];=0A= buf[11] =3D ib_bp_entry_disable[2];=0A= buf[12] =3D ib_bp_entry_disable[3];=0A= send_data (buf, 13);=0A= }=0A= }=0A= /* Remove dbt breakpoints. */=0A= for (i =3D ib_breakpoints; i < MAX_BREAKPOINTS; i++)=0A= {=0A= bp_addr =3D bp_address[i];=0A= if (bp_addr !=3D 0xffffffff)=0A= {=0A= if (!mmu_on)=0A= bp_addr &=3D 0x7fffffff;=0A= buf[0] =3D SDI_WRITE_MEMORY;=0A= store_long_parameter (buf + 1, bp_addr & 0xfffffffc);=0A= store_long_parameter (buf + 5, 4);=0A= buf[9] =3D bp_data[i][0];=0A= buf[10] =3D bp_data[i][1];=0A= buf[11] =3D bp_data[i][2];=0A= buf[12] =3D bp_data[i][3];=0A= send_data (buf, 13);=0A= }=0A= }=0A= =0A= /* Remove access breaks. */=0A= hit_watchpoint_addr =3D 0;=0A= for (i =3D 0; i < max_access_breaks; i++)=0A= {=0A= if (ab_address[i] !=3D 0x00000000)=0A= {=0A= buf[0] =3D SDI_READ_MEMORY;=0A= store_long_parameter (buf + 1, 0xffff8100 + 4 * i);=0A= store_long_parameter (buf + 5, 4);=0A= serial_write (sdi_desc, buf, 9);=0A= c =3D serial_readchar (sdi_desc, SDI_TIMEOUT);=0A= if (c !=3D '-' && recv_data (buf, 4) !=3D -1)=0A= {=0A= if (TARGET_BYTE_ORDER =3D=3D BFD_ENDIAN_BIG)=0A= {=0A= if ((buf[3] & 0x1) =3D=3D 0x1)=0A= hit_watchpoint_addr =3D ab_address[i];=0A= }=0A= else=0A= {=0A= if ((buf[0] & 0x1) =3D=3D 0x1)=0A= hit_watchpoint_addr =3D ab_address[i];=0A= }=0A= }=0A= =0A= buf[0] =3D SDI_WRITE_MEMORY;=0A= store_long_parameter (buf + 1, 0xffff8100 + 4 * i);=0A= store_long_parameter (buf + 5, 4);=0A= store_long_parameter (buf + 9, 0x00000000);=0A= send_data (buf, 13);=0A= }=0A= }=0A= =0A= if (remote_debug)=0A= fprintf_unfiltered (gdb_stdlog, "pc =3D> 0x%lx\n", pc_addr);=0A= }=0A= else=0A= last_pc_addr =3D 0xffffffff;=0A= =0A= return inferior_ptid;=0A= }=0A= =0A= /* Terminate the open connection to the remote debugger.=0A= Use this when you want to detach and do something else=0A= with your gdb. */=0A= static void=0A= m32r_detach (char *args, int from_tty)=0A= {=0A= if (remote_debug)=0A= fprintf_unfiltered (gdb_stdlog, "m32r_detach(%d)\n", from_tty);=0A= =0A= m32r_resume (inferior_ptid, 0, 0);=0A= =0A= /* calls m32r_close to do the real work */=0A= pop_target ();=0A= if (from_tty)=0A= fprintf_unfiltered (gdb_stdlog, "Ending remote %s debugging\n",=0A= target_shortname);=0A= }=0A= =0A= /* Return the id of register number REGNO. */=0A= =0A= static int=0A= get_reg_id (int regno)=0A= {=0A= switch (regno)=0A= {=0A= case 20:=0A= return SDI_REG_BBPC;=0A= case 21:=0A= return SDI_REG_BPC;=0A= case 22:=0A= return SDI_REG_ACCL;=0A= case 23:=0A= return SDI_REG_ACCH;=0A= case 24:=0A= return SDI_REG_EVB;=0A= }=0A= =0A= return regno;=0A= }=0A= =0A= /* Read the remote registers into the block REGS. */=0A= =0A= static void m32r_fetch_register (int);=0A= =0A= static void=0A= m32r_fetch_registers (void)=0A= {=0A= int regno;=0A= =0A= for (regno =3D 0; regno < NUM_REGS; regno++)=0A= m32r_fetch_register (regno);=0A= }=0A= =0A= /* Fetch register REGNO, or all registers if REGNO is -1.=0A= Returns errno value. */=0A= static void=0A= m32r_fetch_register (int regno)=0A= {=0A= unsigned long val, val2, regid;=0A= unsigned char buf[2];=0A= =0A= if (regno =3D=3D -1)=0A= m32r_fetch_registers ();=0A= else=0A= {=0A= char buffer[MAX_REGISTER_SIZE];=0A= =0A= regid =3D get_reg_id (regno);=0A= buf[0] =3D SDI_READ_CPU_REG;=0A= buf[1] =3D regid;=0A= send_data (buf, 2);=0A= recv_data (&val, 4);=0A= val =3D ntohl (val);=0A= =0A= if (regid =3D=3D SDI_REG_PSW)=0A= {=0A= buf[0] =3D SDI_READ_CPU_REG;=0A= buf[1] =3D SDI_REG_BBPSW;=0A= send_data (buf, 2);=0A= recv_data (&val2, 4);=0A= val2 =3D ntohl (val2);=0A= val =3D ((0x00c1 & val2) << 8) | ((0xc100 & val) >> 8);=0A= }=0A= =0A= if (remote_debug)=0A= fprintf_unfiltered (gdb_stdlog, "m32r_fetch_register(%d,0x%08lx)\n",=0A= regno, val);=0A= =0A= /* We got the number the register holds, but gdb expects to see a=0A= value in the target byte ordering. */=0A= store_unsigned_integer (buffer, 4, val);=0A= supply_register (regno, buffer);=0A= }=0A= return;=0A= }=0A= =0A= /* Store the remote registers from the contents of the block REGS. */=0A= =0A= static void m32r_store_register (int);=0A= =0A= static void=0A= m32r_store_registers (void)=0A= {=0A= int regno;=0A= =0A= for (regno =3D 0; regno < NUM_REGS; regno++)=0A= m32r_store_register (regno);=0A= =0A= registers_changed ();=0A= }=0A= =0A= /* Store register REGNO, or all if REGNO =3D=3D 0.=0A= Return errno value. */=0A= static void=0A= m32r_store_register (int regno)=0A= {=0A= int regid;=0A= ULONGEST regval, tmp;=0A= unsigned char buf[6];=0A= =0A= if (regno =3D=3D -1)=0A= m32r_store_registers ();=0A= else=0A= {=0A= regcache_cooked_read_unsigned (current_regcache, regno, ®val);=0A= regid =3D get_reg_id (regno);=0A= =0A= if (regid =3D=3D SDI_REG_PSW)=0A= {=0A= unsigned long psw, bbpsw;=0A= =0A= buf[0] =3D SDI_READ_CPU_REG;=0A= buf[1] =3D SDI_REG_PSW;=0A= send_data (buf, 2);=0A= recv_data (&psw, 4);=0A= psw =3D ntohl (psw);=0A= =0A= buf[0] =3D SDI_READ_CPU_REG;=0A= buf[1] =3D SDI_REG_BBPSW;=0A= send_data (buf, 2);=0A= recv_data (&bbpsw, 4);=0A= bbpsw =3D ntohl (bbpsw);=0A= =0A= tmp =3D (0x00c1 & psw) | ((0x00c1 & regval) << 8);=0A= buf[0] =3D SDI_WRITE_CPU_REG;=0A= buf[1] =3D SDI_REG_PSW;=0A= store_long_parameter (buf + 2, tmp);=0A= send_data (buf, 6);=0A= =0A= tmp =3D (0x0030 & bbpsw) | ((0xc100 & regval) >> 8);=0A= buf[0] =3D SDI_WRITE_CPU_REG;=0A= buf[1] =3D SDI_REG_BBPSW;=0A= store_long_parameter (buf + 2, tmp);=0A= send_data (buf, 6);=0A= }=0A= else=0A= {=0A= buf[0] =3D SDI_WRITE_CPU_REG;=0A= buf[1] =3D regid;=0A= store_long_parameter (buf + 2, regval);=0A= send_data (buf, 6);=0A= }=0A= =0A= if (remote_debug)=0A= fprintf_unfiltered (gdb_stdlog, "m32r_store_register(%d,0x%08lu)\n",=0A= regno, (unsigned long) regval);=0A= }=0A= }=0A= =0A= /* Get ready to modify the registers array. On machines which store=0A= individual registers, this doesn't need to do anything. On machines=0A= which store all the registers in one fell swoop, this makes sure=0A= that registers contains all the registers from the program being=0A= debugged. */=0A= =0A= static void=0A= m32r_prepare_to_store (void)=0A= {=0A= /* Do nothing, since we can store individual regs */=0A= if (remote_debug)=0A= fprintf_unfiltered (gdb_stdlog, "m32r_prepare_to_store()\n");=0A= }=0A= =0A= static void=0A= m32r_files_info (struct target_ops *target)=0A= {=0A= char *file =3D "nothing";=0A= =0A= if (exec_bfd)=0A= {=0A= file =3D bfd_get_filename (exec_bfd);=0A= printf_filtered ("\tAttached to %s running program %s\n",=0A= chip_name, file);=0A= }=0A= }=0A= =0A= /* Read/Write memory. */=0A= static int=0A= m32r_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len,=0A= int write,=0A= struct mem_attrib *attrib, struct target_ops *target)=0A= {=0A= unsigned long taddr;=0A= unsigned char buf[0x2000];=0A= int ret, c;=0A= =0A= taddr =3D memaddr;=0A= =0A= if (!mmu_on)=0A= {=0A= if ((taddr & 0xa0000000) =3D=3D 0x80000000)=0A= taddr &=3D 0x7fffffff;=0A= }=0A= =0A= if (remote_debug)=0A= {=0A= if (write)=0A= fprintf_unfiltered (gdb_stdlog, "m32r_xfer_memory(%08lx,%d,write)\n",=0A= memaddr, len);=0A= else=0A= fprintf_unfiltered (gdb_stdlog, "m32r_xfer_memory(%08lx,%d,read)\n",=0A= memaddr, len);=0A= }=0A= =0A= if (write)=0A= {=0A= buf[0] =3D SDI_WRITE_MEMORY;=0A= store_long_parameter (buf + 1, taddr);=0A= store_long_parameter (buf + 5, len);=0A= if (len < 0x1000)=0A= {=0A= memcpy (buf + 9, myaddr, len);=0A= ret =3D send_data (buf, len + 9) - 9;=0A= }=0A= else=0A= {=0A= if (serial_write (sdi_desc, buf, 9) !=3D 0)=0A= {=0A= if (remote_debug)=0A= fprintf_unfiltered (gdb_stdlog,=0A= "m32r_xfer_memory() failed\n");=0A= return 0;=0A= }=0A= ret =3D send_data (myaddr, len);=0A= }=0A= }=0A= else=0A= {=0A= buf[0] =3D SDI_READ_MEMORY;=0A= store_long_parameter (buf + 1, taddr);=0A= store_long_parameter (buf + 5, len);=0A= if (serial_write (sdi_desc, buf, 9) !=3D 0)=0A= {=0A= if (remote_debug)=0A= fprintf_unfiltered (gdb_stdlog, "m32r_xfer_memory() failed\n");=0A= return 0;=0A= }=0A= =0A= c =3D serial_readchar (sdi_desc, SDI_TIMEOUT);=0A= if (c < 0 || c =3D=3D '-')=0A= {=0A= if (remote_debug)=0A= fprintf_unfiltered (gdb_stdlog, "m32r_xfer_memory() failed\n");=0A= return 0;=0A= }=0A= =0A= ret =3D recv_data (myaddr, len);=0A= }=0A= =0A= if (ret <=3D 0)=0A= {=0A= if (remote_debug)=0A= fprintf_unfiltered (gdb_stdlog, "m32r_xfer_memory() fails\n");=0A= return 0;=0A= }=0A= =0A= return ret;=0A= }=0A= =0A= static void=0A= m32r_kill (void)=0A= {=0A= if (remote_debug)=0A= fprintf_unfiltered (gdb_stdlog, "m32r_kill()\n");=0A= =0A= inferior_ptid =3D null_ptid;=0A= =0A= return;=0A= }=0A= =0A= /* Clean up when a program exits.=0A= =0A= The program actually lives on in the remote processor's RAM, and may be= =0A= run again without a download. Don't leave it full of breakpoint=0A= instructions. */=0A= =0A= static void=0A= m32r_mourn_inferior (void)=0A= {=0A= if (remote_debug)=0A= fprintf_unfiltered (gdb_stdlog, "m32r_mourn_inferior()\n");=0A= =0A= remove_breakpoints ();=0A= generic_mourn_inferior ();=0A= }=0A= =0A= static int=0A= m32r_insert_breakpoint (CORE_ADDR addr, char *shadow)=0A= {=0A= int ib_breakpoints;=0A= unsigned char buf[13];=0A= int i, c;=0A= =0A= if (remote_debug)=0A= fprintf_unfiltered (gdb_stdlog, "m32r_insert_breakpoint(%08lx,\"%s\")\n= ",=0A= addr, shadow);=0A= =0A= if (use_ib_breakpoints)=0A= ib_breakpoints =3D max_ib_breakpoints;=0A= else=0A= ib_breakpoints =3D 0;=0A= =0A= for (i =3D 0; i < MAX_BREAKPOINTS; i++)=0A= {=0A= if (bp_address[i] =3D=3D 0xffffffff)=0A= {=0A= bp_address[i] =3D addr;=0A= if (i >=3D ib_breakpoints)=0A= {=0A= buf[0] =3D SDI_READ_MEMORY;=0A= if (mmu_on)=0A= store_long_parameter (buf + 1, addr & 0xfffffffc);=0A= else=0A= store_long_parameter (buf + 1, addr & 0x7ffffffc);=0A= store_long_parameter (buf + 5, 4);=0A= serial_write (sdi_desc, buf, 9);=0A= c =3D serial_readchar (sdi_desc, SDI_TIMEOUT);=0A= if (c !=3D '-')=0A= recv_data (bp_data[i], 4);=0A= }=0A= return 0;=0A= }=0A= }=0A= =0A= error ("Too many breakpoints");=0A= return 1;=0A= }=0A= =0A= static int=0A= m32r_remove_breakpoint (CORE_ADDR addr, char *shadow)=0A= {=0A= int i;=0A= =0A= if (remote_debug)=0A= fprintf_unfiltered (gdb_stdlog, "m32r_remove_breakpoint(%08lx,\"%s\")\n= ",=0A= addr, shadow);=0A= =0A= for (i =3D 0; i < MAX_BREAKPOINTS; i++)=0A= {=0A= if (bp_address[i] =3D=3D addr)=0A= {=0A= bp_address[i] =3D 0xffffffff;=0A= break;=0A= }=0A= }=0A= =0A= return 0;=0A= }=0A= =0A= static void=0A= m32r_load (char *args, int from_tty)=0A= {=0A= struct cleanup *old_chain;=0A= asection *section;=0A= bfd *pbfd;=0A= bfd_vma entry;=0A= char *filename;=0A= int quiet;=0A= int nostart;=0A= time_t start_time, end_time; /* Start and end times of download */=0A= unsigned long data_count; /* Number of bytes transferred to memory */=0A= int ret;=0A= static RETSIGTYPE (*prev_sigint) ();=0A= =0A= /* for direct tcp connections, we can do a fast binary download */=0A= quiet =3D 0;=0A= nostart =3D 0;=0A= filename =3D NULL;=0A= =0A= while (*args !=3D '\000')=0A= {=0A= char *arg;=0A= =0A= while (isspace (*args))=0A= args++;=0A= =0A= arg =3D args;=0A= =0A= while ((*args !=3D '\000') && !isspace (*args))=0A= args++;=0A= =0A= if (*args !=3D '\000')=0A= *args++ =3D '\000';=0A= =0A= if (*arg !=3D '-')=0A= filename =3D arg;=0A= else if (strncmp (arg, "-quiet", strlen (arg)) =3D=3D 0)=0A= quiet =3D 1;=0A= else if (strncmp (arg, "-nostart", strlen (arg)) =3D=3D 0)=0A= nostart =3D 1;=0A= else=0A= error ("Unknown option `%s'", arg);=0A= }=0A= =0A= if (!filename)=0A= filename =3D get_exec_file (1);=0A= =0A= pbfd =3D bfd_openr (filename, gnutarget);=0A= if (pbfd =3D=3D NULL)=0A= {=0A= perror_with_name (filename);=0A= return;=0A= }=0A= old_chain =3D make_cleanup_bfd_close (pbfd);=0A= =0A= if (!bfd_check_format (pbfd, bfd_object))=0A= error ("\"%s\" is not an object file: %s", filename,=0A= bfd_errmsg (bfd_get_error ()));=0A= =0A= start_time =3D time (NULL);=0A= data_count =3D 0;=0A= =0A= interrupted =3D 0;=0A= prev_sigint =3D signal (SIGINT, gdb_cntrl_c);=0A= =0A= for (section =3D pbfd->sections; section; section =3D section->next)=0A= {=0A= if (bfd_get_section_flags (pbfd, section) & SEC_LOAD)=0A= {=0A= bfd_vma section_address;=0A= bfd_size_type section_size;=0A= file_ptr fptr;=0A= int n;=0A= =0A= section_address =3D bfd_section_lma (pbfd, section);=0A= section_size =3D bfd_get_section_size_before_reloc (section);=0A= =0A= if (!mmu_on)=0A= {=0A= if ((section_address & 0xa0000000) =3D=3D 0x80000000)=0A= section_address &=3D 0x7fffffff;=0A= }=0A= =0A= if (!quiet)=0A= printf_filtered ("[Loading section %s at 0x%lx (%d bytes)]\n",=0A= bfd_get_section_name (pbfd, section),=0A= section_address, (int) section_size);=0A= =0A= fptr =3D 0;=0A= =0A= data_count +=3D section_size;=0A= =0A= n =3D 0;=0A= while (section_size > 0)=0A= {=0A= char unsigned buf[0x1000 + 9];=0A= int count;=0A= =0A= count =3D min (section_size, 0x1000);=0A= =0A= buf[0] =3D SDI_WRITE_MEMORY;=0A= store_long_parameter (buf + 1, section_address);=0A= store_long_parameter (buf + 5, count);=0A= =0A= bfd_get_section_contents (pbfd, section, buf + 9, fptr, count);=0A= if (send_data (buf, count + 9) <=3D 0)=0A= error ("Error while downloading %s section.",=0A= bfd_get_section_name (pbfd, section));=0A= =0A= if (!quiet)=0A= {=0A= printf_unfiltered (".");=0A= if (n++ > 60)=0A= {=0A= printf_unfiltered ("\n");=0A= n =3D 0;=0A= }=0A= gdb_flush (gdb_stdout);=0A= }=0A= =0A= section_address +=3D count;=0A= fptr +=3D count;=0A= section_size -=3D count;=0A= =0A= if (interrupted)=0A= break;=0A= }=0A= =0A= if (!quiet && !interrupted)=0A= {=0A= printf_unfiltered ("done.\n");=0A= gdb_flush (gdb_stdout);=0A= }=0A= }=0A= =0A= if (interrupted)=0A= {=0A= printf_unfiltered ("Interrupted.\n");=0A= break;=0A= }=0A= }=0A= =0A= interrupted =3D 0;=0A= signal (SIGINT, prev_sigint);=0A= =0A= end_time =3D time (NULL);=0A= =0A= /* Make the PC point at the start address */=0A= if (exec_bfd)=0A= write_pc (bfd_get_start_address (exec_bfd));=0A= =0A= inferior_ptid =3D null_ptid; /* No process now */=0A= =0A= /* This is necessary because many things were based on the PC at the time= =0A= that we attached to the monitor, which is no longer valid now that we= =0A= have loaded new code (and just changed the PC). Another way to do thi= s=0A= might be to call normal_stop, except that the stack may not be valid,= =0A= and things would get horribly confused... */=0A= =0A= clear_symtab_users ();=0A= =0A= if (!nostart)=0A= {=0A= entry =3D bfd_get_start_address (pbfd);=0A= =0A= if (!quiet)=0A= printf_unfiltered ("[Starting %s at 0x%lx]\n", filename, entry);=0A= }=0A= =0A= print_transfer_performance (gdb_stdout, data_count, 0,=0A= end_time - start_time);=0A= =0A= do_cleanups (old_chain);=0A= }=0A= =0A= static void=0A= m32r_stop (void)=0A= {=0A= unsigned char buf[1];=0A= =0A= if (remote_debug)=0A= fprintf_unfiltered (gdb_stdlog, "m32r_stop()\n");=0A= =0A= buf[0] =3D SDI_STOP_CPU;=0A= send_data (buf, 1);=0A= =0A= return;=0A= }=0A= =0A= =0A= /* Tell whether this target can support a hardware breakpoint.=20=0A= This implements the TARGET_CAN_USE_HARDWARE_WATCHPOINT macro. */=0A= =0A= int=0A= m32r_can_use_hardware_watchpoint (void)=0A= {=0A= return max_access_breaks;=0A= }=0A= =0A= /* Set a data watchpoint. ADDR and LEN should be obvious. TYPE is 0=0A= for a write watchpoint, 1 for a read watchpoint, or 2 for a read/write= =0A= watchpoint. */=0A= =0A= int=0A= m32r_set_watchpoint (CORE_ADDR addr, int len, int type)=0A= {=0A= int i;=0A= =0A= if (remote_debug)=0A= fprintf_unfiltered (gdb_stdlog, "m32r_set_watchpoint(%08lx,%d,%d)\n",= =0A= addr, len, type);=0A= =0A= for (i =3D 0; i < MAX_ACCESS_BREAKS; i++)=0A= {=0A= if (ab_address[i] =3D=3D 0x00000000)=0A= {=0A= ab_address[i] =3D addr;=0A= ab_size[i] =3D len;=0A= ab_type[i] =3D type;=0A= return 0;=0A= }=0A= }=0A= =0A= error ("Too many watchpoints");=0A= return 1;=0A= }=0A= =0A= int=0A= m32r_remove_watchpoint (CORE_ADDR addr, int len, int type)=0A= {=0A= int i;=0A= =0A= if (remote_debug)=0A= fprintf_unfiltered (gdb_stdlog, "m32r_remove_watchpoint(%08lx,%d,%d)\n"= ,=0A= addr, len, type);=0A= =0A= for (i =3D 0; i < MAX_ACCESS_BREAKS; i++)=0A= {=0A= if (ab_address[i] =3D=3D addr)=0A= {=0A= ab_address[i] =3D 0x00000000;=0A= break;=0A= }=0A= }=0A= =0A= return 0;=0A= }=0A= =0A= CORE_ADDR=0A= m32r_stopped_data_address (void)=0A= {=0A= return hit_watchpoint_addr;=0A= }=0A= =0A= int=0A= m32r_stopped_by_watchpoint (void)=0A= {=0A= return (hit_watchpoint_addr !=3D 0x00000000);=0A= }=0A= =0A= =0A= static void=0A= sdireset_command (char *args, int from_tty)=0A= {=0A= unsigned char buf[1];=0A= =0A= if (remote_debug)=0A= fprintf_unfiltered (gdb_stdlog, "m32r_sdireset()\n");=0A= =0A= buf[0] =3D SDI_OPEN;=0A= send_data (buf, 1);=0A= =0A= inferior_ptid =3D null_ptid;=0A= }=0A= =0A= =0A= static void=0A= sdistatus_command (char *args, int from_tty)=0A= {=0A= unsigned char buf[4096];=0A= int i, c;=0A= =0A= if (remote_debug)=0A= fprintf_unfiltered (gdb_stdlog, "m32r_sdireset()\n");=0A= =0A= if (!sdi_desc)=0A= return;=0A= =0A= buf[0] =3D SDI_STATUS;=0A= send_data (buf, 1);=0A= for (i =3D 0; i < 4096; i++)=0A= {=0A= c =3D serial_readchar (sdi_desc, SDI_TIMEOUT);=0A= if (c < 0)=0A= return;=0A= buf[i] =3D c;=0A= if (c =3D=3D 0)=0A= break;=0A= }=20=20=20=20=0A= =0A= printf_filtered ("%s", buf);=0A= }=0A= =0A= =0A= static void=0A= debug_chaos_command (char *args, int from_tty)=0A= {=0A= unsigned char buf[3];=0A= =0A= buf[0] =3D SDI_SET_ATTR;=0A= buf[1] =3D SDI_ATTR_CACHE;=0A= buf[2] =3D SDI_CACHE_TYPE_CHAOS;=0A= send_data (buf, 3);=0A= }=0A= =0A= =0A= static void=0A= use_debug_dma_command (char *args, int from_tty)=0A= {=0A= unsigned char buf[3];=0A= =0A= buf[0] =3D SDI_SET_ATTR;=0A= buf[1] =3D SDI_ATTR_MEM_ACCESS;=0A= buf[2] =3D SDI_MEM_ACCESS_DEBUG_DMA;=0A= send_data (buf, 3);=0A= }=0A= =0A= static void=0A= use_mon_code_command (char *args, int from_tty)=0A= {=0A= unsigned char buf[3];=0A= =0A= buf[0] =3D SDI_SET_ATTR;=0A= buf[1] =3D SDI_ATTR_MEM_ACCESS;=0A= buf[2] =3D SDI_MEM_ACCESS_MON_CODE;=0A= send_data (buf, 3);=0A= }=0A= =0A= =0A= static void=0A= use_ib_breakpoints_command (char *args, int from_tty)=0A= {=0A= use_ib_breakpoints =3D 1;=0A= }=0A= =0A= static void=0A= use_dbt_breakpoints_command (char *args, int from_tty)=0A= {=0A= use_ib_breakpoints =3D 0;=0A= }=0A= =0A= =0A= /* Define the target subroutine names */=0A= =0A= struct target_ops m32r_ops;=0A= =0A= static void=0A= init_m32r_ops (void)=0A= {=0A= m32r_ops.to_shortname =3D "m32rsdi";=0A= m32r_ops.to_longname =3D "Remote M32R debugging over SDI interface";=0A= m32r_ops.to_doc =3D "Use an M32R board using SDI debugging protocol.";=0A= m32r_ops.to_open =3D m32r_open;=0A= m32r_ops.to_close =3D m32r_close;=0A= m32r_ops.to_detach =3D m32r_detach;=0A= m32r_ops.to_resume =3D m32r_resume;=0A= m32r_ops.to_wait =3D m32r_wait;=0A= m32r_ops.to_fetch_registers =3D m32r_fetch_register;=0A= m32r_ops.to_store_registers =3D m32r_store_register;=0A= m32r_ops.to_prepare_to_store =3D m32r_prepare_to_store;=0A= m32r_ops.to_xfer_memory =3D m32r_xfer_memory;=0A= m32r_ops.to_files_info =3D m32r_files_info;=0A= m32r_ops.to_insert_breakpoint =3D m32r_insert_breakpoint;=0A= m32r_ops.to_remove_breakpoint =3D m32r_remove_breakpoint;=0A= m32r_ops.to_kill =3D m32r_kill;=0A= m32r_ops.to_load =3D m32r_load;=0A= m32r_ops.to_create_inferior =3D m32r_create_inferior;=0A= m32r_ops.to_mourn_inferior =3D m32r_mourn_inferior;=0A= m32r_ops.to_stop =3D m32r_stop;=0A= m32r_ops.to_stratum =3D process_stratum;=0A= m32r_ops.to_has_all_memory =3D 1;=0A= m32r_ops.to_has_memory =3D 1;=0A= m32r_ops.to_has_stack =3D 1;=0A= m32r_ops.to_has_registers =3D 1;=0A= m32r_ops.to_has_execution =3D 1;=0A= m32r_ops.to_magic =3D OPS_MAGIC;=0A= };=0A= =0A= =0A= extern initialize_file_ftype _initialize_remote_m32r;=0A= =0A= void=0A= _initialize_remote_m32r (void)=0A= {=0A= int i;=0A= =0A= init_m32r_ops ();=0A= =0A= /* Initialize breakpoints. */=0A= for (i =3D 0; i < MAX_BREAKPOINTS; i++)=0A= bp_address[i] =3D 0xffffffff;=0A= =0A= /* Initialize access breaks. */=0A= for (i =3D 0; i < MAX_ACCESS_BREAKS; i++)=0A= ab_address[i] =3D 0x00000000;=0A= =0A= add_target (&m32r_ops);=0A= =0A= add_com ("sdireset", class_obscure, sdireset_command,=0A= "Reset SDI connection.");=0A= =0A= add_com ("sdistatus", class_obscure, sdistatus_command,=0A= "Show status of SDI connection.");=0A= =0A= add_com ("debug_chaos", class_obscure, debug_chaos_command,=0A= "Debug M32R/Chaos.");=0A= =0A= add_com ("use_debug_dma", class_obscure, use_debug_dma_command,=0A= "Use debug DMA mem access.");=0A= add_com ("use_mon_code", class_obscure, use_mon_code_command,=0A= "Use mon code mem access.");=0A= =0A= add_com ("use_ib_break", class_obscure, use_ib_breakpoints_command,=0A= "Set breakpoints by IB break.");=0A= add_com ("use_dbt_break", class_obscure, use_dbt_breakpoints_command,=0A= "Set breakpoints by dbt.");=0A= }=0A= ------=_NextPart_000_0321_01C39273.A7586BB0--