From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24235 invoked by alias); 4 Aug 2003 07:57:41 -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 24226 invoked from network); 4 Aug 2003 07:57:39 -0000 Received: from unknown (HELO mail03.idc.renesas.com) (202.234.163.13) by sources.redhat.com with SMTP; 4 Aug 2003 07:57:39 -0000 Received: from mail03.idc.renesas.com ([127.0.0.1]) by mail03.idc.renesas.com with ESMTP id h747va4p022528 for ; Mon, 4 Aug 2003 16:57:36 +0900 (JST) Received: from guardian05.idc.renesas.com ([172.20.8.136]) by mail03.idc.renesas.com with ESMTP id h747vZWA022525 for ; Mon, 4 Aug 2003 16:57:35 +0900 (JST) Received: (from root@localhost) by guardian05.idc.renesas.com with id h747vYnj006821 for gdb-patches@sources.redhat.com; Mon, 4 Aug 2003 16:57:34 +0900 (JST) Received: from unknown [172.20.8.68] by guardian05.idc.renesas.com with SMTP id SAA06820 ; Mon, 4 Aug 2003 16:57:34 +0900 Received: from mta01.idc.renesas.com (localhost [127.0.0.1]) by mta01.idc.renesas.com with ESMTP id h747vX4G004667 for ; Mon, 4 Aug 2003 16:57:34 +0900 (JST) Received: from rnsmtp01.hoku_r.renesas.com ([10.145.246.51]) by mta01.idc.renesas.com with ESMTP id h747vXZV004664 for ; Mon, 4 Aug 2003 16:57:33 +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 QAA03270 for ; Mon, 4 Aug 2003 16:57:33 +0900 (JST) Received: from KEI (unknown [10.145.105.81]) by mrkaisv.hoku.renesas.com (Postfix) with SMTP id 1C86C798568 for ; Mon, 4 Aug 2003 16:57:33 +0900 (JST) Message-ID: <02e201c35a5e$883a8cb0$5169910a@KEI> From: "Kei Sakamoto" To: Subject: [patch] New m32r remote target, m32rsdi Date: Mon, 04 Aug 2003 07:57:00 -0000 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_02DF_01C35AA9.F80B5150" X-Priority: 3 X-MSMail-Priority: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-SW-Source: 2003-08/txt/msg00026.txt.bz2 This is a multi-part message in MIME format. ------=_NextPart_000_02DF_01C35AA9.F80B5150 Content-Type: text/plain; charset="iso-2022-jp" Content-Transfer-Encoding: 7bit Content-length: 662 Hello, The attached adds a new remote target, m32rsdi, which uses m32r's on-chip debug interface, SDI (Scalable Debug Interface). In m32rsdi target mode, gdb does not control a target board directly. Instead, gdb sends commands to "sdiserver" by sockets interface. Sdiserver is a program which controls the target board using printer ports. Is this OK to commit? Kei Sakamoto ==== 2003-08-04 Kei Sakamoto * remote-m32r-sdi.c : New file, interface to m32r on-chip debug interface, SDI (Scalable Debug Interface). * Makefile.in (remote-m32r-sdi.o): Add build rule. * config/m32r/m32r.mt (TDEPFILES) : Add remote-m32r-sdi.o. ------=_NextPart_000_02DF_01C35AA9.F80B5150 Content-Type: application/octet-stream; name="diffs" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="diffs" Content-length: 1485 diff -Naur src.orig/gdb/Makefile.in src/gdb/Makefile.in=0A= --- src.orig/gdb/Makefile.in 2003-08-03 05:11:48.000000000 +0900=0A= +++ src/gdb/Makefile.in 2003-08-04 16:46:18.000000000 +0900=0A= @@ -1282,7 +1282,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= @@ -2136,6 +2136,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)=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= diff -Naur src.orig/gdb/config/m32r/m32r.mt src/gdb/config/m32r/m32r.mt=0A= --- src.orig/gdb/config/m32r/m32r.mt 2003-08-02 06:14:33.000000000 +0900=0A= +++ src/gdb/config/m32r/m32r.mt 2003-08-04 15:57:11.000000000 +0900=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= ------=_NextPart_000_02DF_01C35AA9.F80B5150 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: 47508 /* 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= #include =0A= #include =0A= #include =0A= =0A= static int sockfd =3D -1;=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= unsigned char buf[1];=0A= int n;=0A= =0A= if (sockfd =3D=3D -1)=0A= return -1;=0A= =0A= n =3D recv (sockfd, buf, 1, 0);=0A= =0A= if (n =3D=3D -1)=0A= return -1;=0A= =0A= if (buf[0] !=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 total =3D 0;=0A= int bytesleft =3D len;=0A= int n;=0A= =0A= if (sockfd =3D=3D -1)=0A= return -1;=0A= =0A= while (total < len)=0A= {=0A= n =3D send (sockfd, (unsigned char *) buf + total, bytesleft, 0);=0A= =0A= if (n =3D=3D -1)=0A= return -1;=0A= =0A= total +=3D n;=0A= bytesleft -=3D n;=0A= }=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 bytesleft =3D len;=0A= int n;=0A= =0A= if (sockfd =3D=3D -1)=0A= return -1;=0A= =0A= while (total < len)=0A= {=0A= n =3D recv (sockfd, (unsigned char *) buf + total, bytesleft, 0);=0A= =0A= if (n =3D=3D -1)=0A= return -1;=0A= =0A= total +=3D n;=0A= bytesleft -=3D n;=0A= }=0A= =0A= return len;=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= 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= 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[100];=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= {=0A= strcpy (hostname, "localhost");=0A= port =3D SDIPORT;=0A= }=0A= else=0A= {=0A= port_str =3D strchr (args, ':');=0A= if (port_str =3D=3D NULL)=0A= {=0A= strcpy (hostname, args);=0A= port =3D SDIPORT;=0A= }=0A= else=0A= {=0A= n =3D min (port_str - args, (int) sizeof hostname - 1);=0A= if (n > 0)=0A= {=0A= strncpy (hostname, args, n);=0A= hostname[n] =3D '\000';=0A= }=0A= else=0A= strcpy (hostname, "localhost");=0A= port =3D atoi (port_str + 1);=0A= }=0A= }=0A= =0A= host_ent =3D gethostbyname (hostname);=0A= if (host_ent =3D=3D NULL)=0A= error ("%s: unknown host\n", hostname);=0A= =0A= sockfd =3D socket (AF_INET, SOCK_STREAM, 0);=0A= if (sockfd =3D=3D -1)=0A= error ("Socket error\n");=0A= =0A= server_addr.sin_family =3D AF_INET;=0A= server_addr.sin_port =3D htons (port);=0A= server_addr.sin_addr =3D *((struct in_addr *) host_ent->h_addr);=0A= memset (&(server_addr.sin_zero), '\0', 8);=0A= =0A= if (connect=0A= (sockfd, (struct sockaddr *) &server_addr,=0A= sizeof (struct sockaddr)) =3D=3D -1)=0A= {=0A= close (sockfd);=0A= sockfd =3D -1;=0A= error ("Connection refused\n");=0A= }=0A= =0A= /* Speed up TCP/IP communication */=0A= setsockopt (sockfd, IPPROTO_TCP, TCP_NODELAY, (char *) &yes, sizeof (yes)= );=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 (sockfd !=3D -1)=0A= {=0A= buf[0] =3D SDI_CLOSE;=0A= send_data (buf, 1);=0A= close (sockfd);=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= *((unsigned long *) (buf + 1)) =3D pc_addr;=0A= else=0A= *((unsigned long *) (buf + 1)) =3D pc_addr - 1;=0A= *((unsigned long *) (buf + 5)) =3D 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= *((unsigned long *) (buf + 2)) =3D 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= *((unsigned long *) (buf + 2)) =3D 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= *((unsigned long *) (buf + 1)) =3D 0xffff8000 + 4 * i;=0A= *((unsigned long *) (buf + 5)) =3D 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= *((unsigned long *) (buf + 1)) =3D 0xffff8080 + 4 * i;=0A= *((unsigned long *) (buf + 5)) =3D 4;=0A= if (TARGET_BYTE_ORDER =3D=3D BFD_ENDIAN_BIG)=0A= {=0A= buf[9] =3D *(((unsigned char *) &bp_addr) + 3);=0A= buf[10] =3D *(((unsigned char *) &bp_addr) + 2);=0A= buf[11] =3D *(((unsigned char *) &bp_addr) + 1);=0A= buf[12] =3D *(((unsigned char *) &bp_addr) + 0);=0A= }=0A= else=0A= *((unsigned long *) (buf + 9)) =3D 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= *((unsigned long *) (buf + 1)) =3D bp_addr;=0A= *((unsigned long *) (buf + 5)) =3D 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= *((unsigned long *) (buf + 1)) =3D bp_addr;=0A= else if ((bp_addr & 2) =3D=3D 0)=0A= *((unsigned long *) (buf + 1)) =3D bp_addr + 2;=0A= else=0A= *((unsigned long *) (buf + 1)) =3D bp_addr - 2;=0A= *((unsigned long *) (buf + 5)) =3D 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= *((unsigned long *) (buf + 1)) =3D 0xffff8100 + 4 * i;=0A= *((unsigned long *) (buf + 5)) =3D 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= *((unsigned long *) (buf + 1)) =3D 0xffff8180 + 4 * i;=0A= *((unsigned long *) (buf + 5)) =3D 4;=0A= if (TARGET_BYTE_ORDER =3D=3D BFD_ENDIAN_BIG)=0A= {=0A= buf[9] =3D *(((unsigned char *) &ab_addr) + 3);=0A= buf[10] =3D *(((unsigned char *) &ab_addr) + 2);=0A= buf[11] =3D *(((unsigned char *) &ab_addr) + 1);=0A= buf[12] =3D *(((unsigned char *) &ab_addr) + 0);=0A= }=0A= else=0A= *((unsigned long *) (buf + 9)) =3D ab_addr;=0A= send_data (buf, 13);=0A= =0A= /* DBAL register */=0A= buf[0] =3D SDI_WRITE_MEMORY;=0A= *((unsigned long *) (buf + 1)) =3D 0xffff8200 + 4 * i;=0A= *((unsigned long *) (buf + 5)) =3D 4;=0A= *((unsigned long *) (buf + 9)) =3D 0xffffffff;=0A= send_data (buf, 13);=0A= =0A= /* DBD register */=0A= buf[0] =3D SDI_WRITE_MEMORY;=0A= *((unsigned long *) (buf + 1)) =3D 0xffff8280 + 4 * i;=0A= *((unsigned long *) (buf + 5)) =3D 4;=0A= *((unsigned long *) (buf + 9)) =3D 0x00000000;=0A= send_data (buf, 13);=0A= =0A= /* DBDM register */=0A= buf[0] =3D SDI_WRITE_MEMORY;=0A= *((unsigned long *) (buf + 1)) =3D 0xffff8300 + 4 * i;=0A= *((unsigned long *) (buf + 5)) =3D 4;=0A= *((unsigned long *) (buf + 9)) =3D 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= *((unsigned long *) (buf + 2)) =3D 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= int ret;=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 (send (sockfd, buf, 1, 0) =3D=3D -1)=0A= error ("Remote connection closed");=0A= =0A= while (1)=0A= {=0A= if (recv (sockfd, buf, 1, 0) =3D=3D -1)=0A= error ("Remote connection closed");=0A= =0A= if (buf[0] =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 (buf[0] =3D=3D '+') /* stopped */=0A= break;=0A= =0A= if (interrupted)=0A= ret =3D send (sockfd, "!", 1, 0); /* packet to interrupt */=0A= else=0A= ret =3D send (sockfd, ".", 1, 0); /* packet to wait */=0A= if (ret =3D=3D -1)=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= *((unsigned long *) (buf + 1)) =3D last_pc_addr;=0A= else=0A= *((unsigned long *) (buf + 1)) =3D last_pc_addr - 1;=0A= *((unsigned long *) (buf + 5)) =3D 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 (buf, 4);=0A= pc_addr =3D *((unsigned long *) buf) - 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= *((unsigned long *) (buf + 2)) =3D 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= *((unsigned long *) (buf + 1)) =3D 0xffff8000 + 4 * i;=0A= *((unsigned long *) (buf + 5)) =3D 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= *((unsigned long *) (buf + 1)) =3D bp_addr & 0xfffffffc;=0A= *((unsigned long *) (buf + 5)) =3D 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= unsigned long dbc;=0A= =0A= buf[0] =3D SDI_READ_MEMORY;=0A= *((unsigned long *) (buf + 1)) =3D 0xffff8100 + 4 * i;=0A= *((unsigned long *) (buf + 5)) =3D 4;=0A= send (sockfd, buf, 9, 0);=0A= recv (sockfd, buf, 1, 0);=0A= if (buf[0] !=3D '-' && recv_data (&dbc, 4) !=3D -1)=0A= {=0A= if ((dbc & 0x1) =3D=3D 0x1)=0A= hit_watchpoint_addr =3D ab_address[i];=0A= }=0A= =0A= buf[0] =3D SDI_WRITE_MEMORY;=0A= *((unsigned long *) (buf + 1)) =3D 0xffff8100 + 4 * i;=0A= *((unsigned long *) (buf + 5)) =3D 4;=0A= *((unsigned long *) (buf + 9)) =3D 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= =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= 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= =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= =0A= tmp =3D (0x00c1 & psw) | ((0x00c1 & regval) << 8);=0A= buf[0] =3D SDI_WRITE_CPU_REG;=0A= buf[1] =3D SDI_REG_PSW;=0A= *((unsigned long *) (buf + 2)) =3D 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= *((unsigned long *) (buf + 2)) =3D tmp;=0A= send_data (buf, 6);=0A= }=0A= else=0A= {=0A= buf[0] =3D SDI_WRITE_CPU_REG;=0A= buf[1] =3D regid;=0A= *((unsigned long *) (buf + 2)) =3D 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;=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= *((unsigned long *) (buf + 1)) =3D taddr;=0A= *((unsigned long *) (buf + 5)) =3D 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 (send (sockfd, buf, 9, 0) =3D=3D -1)=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= *((unsigned long *) (buf + 1)) =3D taddr;=0A= *((unsigned long *) (buf + 5)) =3D len;=0A= if (send (sockfd, buf, 9, 0) =3D=3D -1)=0A= {=0A= if (remote_debug)=0A= fprintf_unfiltered (gdb_stdlog, "m32r_xfer_memory() failed\n");=0A= return 0;=0A= }=0A= =0A= ret =3D recv (sockfd, buf, 1, 0);=0A= if (ret <=3D 0 || buf[0] =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;=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= *((unsigned long *) (buf + 1)) =3D addr & 0xfffffffc;=0A= else=0A= *((unsigned long *) (buf + 1)) =3D addr & 0x7ffffffc;=0A= *((unsigned long *) (buf + 5)) =3D 4;=0A= send (sockfd, buf, 9, 0);=0A= recv (sockfd, buf, 1, 0);=0A= if (buf[0] !=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= *((unsigned long *) (buf + 1)) =3D section_address;=0A= *((unsigned long *) (buf + 5)) =3D 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= =0A= if (remote_debug)=0A= fprintf_unfiltered (gdb_stdlog, "m32r_sdireset()\n");=0A= =0A= buf[0] =3D SDI_STATUS;=0A= send_data (buf, 1);=0A= recv (sockfd, buf, 4096, 0);=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_02DF_01C35AA9.F80B5150--