GDB (API)
/home/stan/gdb/src/gdb/m32r-rom.c
Go to the documentation of this file.
00001 /* Remote debugging interface to m32r and mon2000 ROM monitors for GDB, 
00002    the GNU debugger.
00003 
00004    Copyright (C) 1996-2013 Free Software Foundation, Inc.
00005 
00006    Adapted by Michael Snyder of Cygnus Support.
00007 
00008    This file is part of GDB.
00009 
00010    This program is free software; you can redistribute it and/or modify
00011    it under the terms of the GNU General Public License as published by
00012    the Free Software Foundation; either version 3 of the License, or
00013    (at your option) any later version.
00014 
00015    This program is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018    GNU General Public License for more details.
00019 
00020    You should have received a copy of the GNU General Public License
00021    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00022 
00023 /* This module defines communication with the Renesas m32r monitor.  */
00024 
00025 #include "defs.h"
00026 #include "gdbcore.h"
00027 #include "target.h"
00028 #include "exceptions.h"
00029 #include "monitor.h"
00030 #include "serial.h"
00031 #include "symtab.h"
00032 #include "command.h"
00033 #include "gdbcmd.h"
00034 #include "symfile.h"            /* for generic load */
00035 #include <sys/time.h>
00036 #include <time.h>               /* for time_t */
00037 #include "gdb_string.h"
00038 #include "objfiles.h"           /* for ALL_OBJFILES etc.  */
00039 #include "inferior.h"
00040 #include <ctype.h>
00041 #include "regcache.h"
00042 #include "gdb_bfd.h"
00043 #include "cli/cli-utils.h"
00044 
00045 /*
00046  * All this stuff just to get my host computer's IP address!
00047  */
00048 #ifdef __MINGW32__
00049 #include <winsock2.h>
00050 #else
00051 #include <sys/types.h>
00052 #include <netdb.h>              /* for hostent */
00053 #include <netinet/in.h>         /* for struct in_addr */
00054 #if 1
00055 #include <arpa/inet.h>          /* for inet_ntoa */
00056 #endif
00057 #endif
00058 
00059 static char *board_addr;        /* user-settable IP address for M32R-EVA */
00060 static char *server_addr;       /* user-settable IP address for gdb host */
00061 static char *download_path;     /* user-settable path for SREC files     */
00062 
00063 
00064 /* REGNUM */
00065 #define PSW_REGNUM      16
00066 #define SPI_REGNUM      18
00067 #define SPU_REGNUM      19
00068 #define ACCL_REGNUM     22
00069 #define ACCH_REGNUM     23
00070 
00071 
00072 /* 
00073  * Function: m32r_load_1 (helper function)
00074  */
00075 
00076 static void
00077 m32r_load_section (bfd *abfd, asection *s, void *obj)
00078 {
00079   unsigned int *data_count = obj;
00080   if (s->flags & SEC_LOAD)
00081     {
00082       int addr_size = gdbarch_addr_bit (target_gdbarch ()) / 8;
00083       bfd_size_type section_size = bfd_section_size (abfd, s);
00084       bfd_vma section_base = bfd_section_lma (abfd, s);
00085       unsigned int buffer, i;
00086 
00087       *data_count += section_size;
00088 
00089       printf_filtered ("Loading section %s, size 0x%lx lma ",
00090                        bfd_section_name (abfd, s),
00091                        (unsigned long) section_size);
00092       fputs_filtered (paddress (target_gdbarch (), section_base), gdb_stdout);
00093       printf_filtered ("\n");
00094       gdb_flush (gdb_stdout);
00095       monitor_printf ("%s mw\r", phex_nz (section_base, addr_size));
00096       for (i = 0; i < section_size; i += 4)
00097         {
00098           QUIT;
00099           monitor_expect (" -> ", NULL, 0);
00100           bfd_get_section_contents (abfd, s, (char *) &buffer, i, 4);
00101           monitor_printf ("%x\n", buffer);
00102         }
00103       monitor_expect (" -> ", NULL, 0);
00104       monitor_printf ("q\n");
00105       monitor_expect_prompt (NULL, 0);
00106     }
00107 }
00108 
00109 static int
00110 m32r_load_1 (void *dummy)
00111 {
00112   int data_count = 0;
00113 
00114   bfd_map_over_sections ((bfd *) dummy, m32r_load_section, &data_count);
00115   return data_count;
00116 }
00117 
00118 /* 
00119  * Function: m32r_load (an alternate way to load) 
00120  */
00121 
00122 static void
00123 m32r_load (char *filename, int from_tty)
00124 {
00125   bfd *abfd;
00126   unsigned int data_count = 0;
00127   struct timeval start_time, end_time;
00128   struct cleanup *cleanup;
00129 
00130   if (filename == NULL || filename[0] == 0)
00131     filename = get_exec_file (1);
00132 
00133   abfd = gdb_bfd_open (filename, NULL, -1);
00134   if (!abfd)
00135     error (_("Unable to open file %s."), filename);
00136   cleanup = make_cleanup_bfd_unref (abfd);
00137   if (bfd_check_format (abfd, bfd_object) == 0)
00138     error (_("File is not an object file."));
00139   gettimeofday (&start_time, NULL);
00140 #if 0
00141   for (s = abfd->sections; s; s = s->next)
00142     if (s->flags & SEC_LOAD)
00143       {
00144         bfd_size_type section_size = bfd_section_size (abfd, s);
00145         bfd_vma section_base = bfd_section_vma (abfd, s);
00146         unsigned int buffer;
00147 
00148         data_count += section_size;
00149 
00150         printf_filtered ("Loading section %s, size 0x%lx vma ",
00151                          bfd_section_name (abfd, s), section_size);
00152         fputs_filtered (paddress (target_gdbarch (), section_base), gdb_stdout);
00153         printf_filtered ("\n");
00154         gdb_flush (gdb_stdout);
00155         monitor_printf ("%x mw\r", section_base);
00156         for (i = 0; i < section_size; i += 4)
00157           {
00158             monitor_expect (" -> ", NULL, 0);
00159             bfd_get_section_contents (abfd, s, (char *) &buffer, i, 4);
00160             monitor_printf ("%x\n", buffer);
00161           }
00162         monitor_expect (" -> ", NULL, 0);
00163         monitor_printf ("q\n");
00164         monitor_expect_prompt (NULL, 0);
00165       }
00166 #else
00167   if (!(catch_errors (m32r_load_1, abfd, "Load aborted!\n", RETURN_MASK_ALL)))
00168     {
00169       monitor_printf ("q\n");
00170       do_cleanups (cleanup);
00171       return;
00172     }
00173 #endif
00174   gettimeofday (&end_time, NULL);
00175   printf_filtered ("Start address 0x%lx\n",
00176                    (unsigned long) bfd_get_start_address (abfd));
00177   print_transfer_performance (gdb_stdout, data_count, 0, &start_time,
00178                               &end_time);
00179 
00180   /* Finally, make the PC point at the start address.  */
00181   if (exec_bfd)
00182     regcache_write_pc (get_current_regcache (),
00183                        bfd_get_start_address (exec_bfd));
00184 
00185   inferior_ptid = null_ptid;    /* No process now.  */
00186 
00187   /* This is necessary because many things were based on the PC at the
00188      time that we attached to the monitor, which is no longer valid
00189      now that we have loaded new code (and just changed the PC).
00190      Another way to do this might be to call normal_stop, except that
00191      the stack may not be valid, and things would get horribly
00192      confused...  */
00193 
00194   clear_symtab_users (0);
00195   do_cleanups (cleanup);
00196 }
00197 
00198 static void
00199 m32r_load_gen (char *filename, int from_tty)
00200 {
00201   generic_load (filename, from_tty);
00202 }
00203 
00204 static void m32r_open (char *args, int from_tty);
00205 static void mon2000_open (char *args, int from_tty);
00206 
00207 /* This array of registers needs to match the indexes used by GDB.  The
00208    whole reason this exists is because the various ROM monitors use
00209    different names than GDB does, and don't support all the registers
00210    either.  So, typing "info reg sp" becomes an "A7".  */
00211 
00212 static char *m32r_regnames[] =
00213   { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
00214   "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
00215   "psw", "cbr", "spi", "spu", "bpc", "pc", "accl", "acch",
00216 };
00217 
00218 static void
00219 m32r_supply_register (struct regcache *regcache, char *regname,
00220                       int regnamelen, char *val, int vallen)
00221 {
00222   int regno;
00223   int num_regs = sizeof (m32r_regnames) / sizeof (m32r_regnames[0]);
00224   struct gdbarch *gdbarch = get_regcache_arch (regcache);
00225 
00226   for (regno = 0; regno < num_regs; regno++)
00227     if (strncmp (regname, m32r_regnames[regno], regnamelen) == 0)
00228       break;
00229 
00230   if (regno >= num_regs)
00231     return;                     /* no match */
00232 
00233   if (regno == ACCL_REGNUM)
00234     {                           /* Special handling for 64-bit acc reg.  */
00235       monitor_supply_register (regcache, ACCH_REGNUM, val);
00236       val = strchr (val, ':');  /* Skip past ':' to get 2nd word.  */
00237       if (val != NULL)
00238         monitor_supply_register (regcache, ACCL_REGNUM, val + 1);
00239     }
00240   else
00241     {
00242       monitor_supply_register (regcache, regno, val);
00243       if (regno == PSW_REGNUM)
00244         {
00245 #if (defined SM_REGNUM || defined BSM_REGNUM || defined IE_REGNUM \
00246      || defined BIE_REGNUM || defined COND_REGNUM  || defined CBR_REGNUM \
00247      || defined BPC_REGNUM || defined BCARRY_REGNUM)
00248           unsigned long psw = strtoul (val, NULL, 16);
00249           char *zero = "00000000", *one = "00000001";
00250 #endif
00251 
00252 #ifdef SM_REGNUM
00253           /* Stack mode bit */
00254           monitor_supply_register (regcache, SM_REGNUM,
00255                                    (psw & 0x80) ? one : zero);
00256 #endif
00257 #ifdef BSM_REGNUM
00258           /* Backup stack mode bit */
00259           monitor_supply_register (regcache, BSM_REGNUM,
00260                                    (psw & 0x8000) ? one : zero);
00261 #endif
00262 #ifdef IE_REGNUM
00263           /* Interrupt enable bit */
00264           monitor_supply_register (regcache, IE_REGNUM,
00265                                    (psw & 0x40) ? one : zero);
00266 #endif
00267 #ifdef BIE_REGNUM
00268           /* Backup interrupt enable bit */
00269           monitor_supply_register (regcache, BIE_REGNUM,
00270                                    (psw & 0x4000) ? one : zero);
00271 #endif
00272 #ifdef COND_REGNUM
00273           /* Condition bit (carry etc.) */
00274           monitor_supply_register (regcache, COND_REGNUM,
00275                                    (psw & 0x1) ? one : zero);
00276 #endif
00277 #ifdef CBR_REGNUM
00278           monitor_supply_register (regcache, CBR_REGNUM,
00279                                    (psw & 0x1) ? one : zero);
00280 #endif
00281 #ifdef BPC_REGNUM
00282           monitor_supply_register (regcache, BPC_REGNUM,
00283                                    zero);       /* KLUDGE:   (???????) */
00284 #endif
00285 #ifdef BCARRY_REGNUM
00286           monitor_supply_register (regcache, BCARRY_REGNUM,
00287                                    zero);       /* KLUDGE: (??????) */
00288 #endif
00289         }
00290 
00291       if (regno == SPI_REGNUM || regno == SPU_REGNUM)
00292         {       /* special handling for stack pointer (spu or spi).  */
00293           ULONGEST stackmode, psw;
00294           regcache_cooked_read_unsigned (regcache, PSW_REGNUM, &psw);
00295           stackmode = psw & 0x80;
00296 
00297           if (regno == SPI_REGNUM && !stackmode)        /* SP == SPI */
00298             monitor_supply_register (regcache,
00299                                      gdbarch_sp_regnum (gdbarch), val);
00300           else if (regno == SPU_REGNUM && stackmode)    /* SP == SPU */
00301             monitor_supply_register (regcache,
00302                                      gdbarch_sp_regnum (gdbarch), val);
00303         }
00304     }
00305 }
00306 
00307 /* m32r RevC board monitor */
00308 
00309 static struct target_ops m32r_ops;
00310 
00311 static char *m32r_inits[] = { "\r", NULL };
00312 
00313 static struct monitor_ops m32r_cmds;
00314 
00315 static void
00316 init_m32r_cmds (void)
00317 {
00318   m32r_cmds.flags = MO_CLR_BREAK_USES_ADDR | MO_REGISTER_VALUE_FIRST;
00319   m32r_cmds.init = m32r_inits;  /* Init strings */
00320   m32r_cmds.cont = "go\r";      /* continue command */
00321   m32r_cmds.step = "step\r";    /* single step */
00322   m32r_cmds.stop = NULL;        /* interrupt command */
00323   m32r_cmds.set_break = "%x +bp\r";     /* set a breakpoint */
00324   m32r_cmds.clr_break = "%x -bp\r";     /* clear a breakpoint */
00325   m32r_cmds.clr_all_break = "bpoff\r";  /* clear all breakpoints */
00326   m32r_cmds.fill = "%x %x %x fill\r";   /* fill (start length val) */
00327   m32r_cmds.setmem.cmdb = "%x 1 %x fill\r";     /* setmem.cmdb (addr, value) */
00328   m32r_cmds.setmem.cmdw = "%x 1 %x fillh\r";    /* setmem.cmdw (addr, value) */
00329   m32r_cmds.setmem.cmdl = "%x 1 %x fillw\r";    /* setmem.cmdl (addr, value) */
00330   m32r_cmds.setmem.cmdll = NULL;        /* setmem.cmdll (addr, value) */
00331   m32r_cmds.setmem.resp_delim = NULL;   /* setmem.resp_delim */
00332   m32r_cmds.setmem.term = NULL; /* setmem.term */
00333   m32r_cmds.setmem.term_cmd = NULL;     /* setmem.term_cmd */
00334   m32r_cmds.getmem.cmdb = "%x %x dump\r";       /* getmem.cmdb (addr, len) */
00335   m32r_cmds.getmem.cmdw = NULL; /* getmem.cmdw (addr, len) */
00336   m32r_cmds.getmem.cmdl = NULL; /* getmem.cmdl (addr, len) */
00337   m32r_cmds.getmem.cmdll = NULL;        /* getmem.cmdll (addr, len) */
00338   m32r_cmds.getmem.resp_delim = ": ";   /* getmem.resp_delim */
00339   m32r_cmds.getmem.term = NULL; /* getmem.term */
00340   m32r_cmds.getmem.term_cmd = NULL;     /* getmem.term_cmd */
00341   m32r_cmds.setreg.cmd = "%x to %%%s\r";        /* setreg.cmd (name, value) */
00342   m32r_cmds.setreg.resp_delim = NULL;   /* setreg.resp_delim */
00343   m32r_cmds.setreg.term = NULL; /* setreg.term */
00344   m32r_cmds.setreg.term_cmd = NULL;     /* setreg.term_cmd */
00345   m32r_cmds.getreg.cmd = NULL;  /* getreg.cmd (name) */
00346   m32r_cmds.getreg.resp_delim = NULL;   /* getreg.resp_delim */
00347   m32r_cmds.getreg.term = NULL; /* getreg.term */
00348   m32r_cmds.getreg.term_cmd = NULL;     /* getreg.term_cmd */
00349   m32r_cmds.dump_registers = ".reg\r";  /* dump_registers */
00350                                         /* register_pattern */
00351   m32r_cmds.register_pattern = "\\(\\w+\\) += \\([0-9a-fA-F]+\\b\\)";
00352   m32r_cmds.supply_register = m32r_supply_register;
00353   m32r_cmds.load = NULL;        /* download command */
00354   m32r_cmds.loadresp = NULL;    /* load response */
00355   m32r_cmds.prompt = "ok ";     /* monitor command prompt */
00356   m32r_cmds.line_term = "\r";   /* end-of-line terminator */
00357   m32r_cmds.cmd_end = NULL;     /* optional command terminator */
00358   m32r_cmds.target = &m32r_ops; /* target operations */
00359   m32r_cmds.stopbits = SERIAL_1_STOPBITS;       /* number of stop bits */
00360   m32r_cmds.regnames = m32r_regnames;   /* registers names */
00361   m32r_cmds.magic = MONITOR_OPS_MAGIC;  /* magic */
00362 }                               /* init_m32r_cmds */
00363 
00364 static void
00365 m32r_open (char *args, int from_tty)
00366 {
00367   monitor_open (args, &m32r_cmds, from_tty);
00368 }
00369 
00370 /* Mon2000 monitor (MSA2000 board) */
00371 
00372 static struct target_ops mon2000_ops;
00373 static struct monitor_ops mon2000_cmds;
00374 
00375 static void
00376 init_mon2000_cmds (void)
00377 {
00378   mon2000_cmds.flags = MO_CLR_BREAK_USES_ADDR | MO_REGISTER_VALUE_FIRST;
00379   mon2000_cmds.init = m32r_inits;       /* Init strings */
00380   mon2000_cmds.cont = "go\r";   /* continue command */
00381   mon2000_cmds.step = "step\r"; /* single step */
00382   mon2000_cmds.stop = NULL;     /* interrupt command */
00383   mon2000_cmds.set_break = "%x +bp\r";  /* set a breakpoint */
00384   mon2000_cmds.clr_break = "%x -bp\r";  /* clear a breakpoint */
00385   mon2000_cmds.clr_all_break = "bpoff\r";       /* clear all breakpoints */
00386   mon2000_cmds.fill = "%x %x %x fill\r";        /* fill (start length val) */
00387   mon2000_cmds.setmem.cmdb = "%x 1 %x fill\r";  /* setmem.cmdb (addr, value) */
00388   mon2000_cmds.setmem.cmdw = "%x 1 %x fillh\r"; /* setmem.cmdw (addr, value) */
00389   mon2000_cmds.setmem.cmdl = "%x 1 %x fillw\r"; /* setmem.cmdl (addr, value) */
00390   mon2000_cmds.setmem.cmdll = NULL;     /* setmem.cmdll (addr, value) */
00391   mon2000_cmds.setmem.resp_delim = NULL;        /* setmem.resp_delim */
00392   mon2000_cmds.setmem.term = NULL;      /* setmem.term */
00393   mon2000_cmds.setmem.term_cmd = NULL;  /* setmem.term_cmd */
00394   mon2000_cmds.getmem.cmdb = "%x %x dump\r";    /* getmem.cmdb (addr, len) */
00395   mon2000_cmds.getmem.cmdw = NULL;      /* getmem.cmdw (addr, len) */
00396   mon2000_cmds.getmem.cmdl = NULL;      /* getmem.cmdl (addr, len) */
00397   mon2000_cmds.getmem.cmdll = NULL;     /* getmem.cmdll (addr, len) */
00398   mon2000_cmds.getmem.resp_delim = ": ";        /* getmem.resp_delim */
00399   mon2000_cmds.getmem.term = NULL;      /* getmem.term */
00400   mon2000_cmds.getmem.term_cmd = NULL;  /* getmem.term_cmd */
00401   mon2000_cmds.setreg.cmd = "%x to %%%s\r";     /* setreg.cmd (name, value) */
00402   mon2000_cmds.setreg.resp_delim = NULL;        /* setreg.resp_delim */
00403   mon2000_cmds.setreg.term = NULL;      /* setreg.term */
00404   mon2000_cmds.setreg.term_cmd = NULL;  /* setreg.term_cmd */
00405   mon2000_cmds.getreg.cmd = NULL;       /* getreg.cmd (name) */
00406   mon2000_cmds.getreg.resp_delim = NULL;        /* getreg.resp_delim */
00407   mon2000_cmds.getreg.term = NULL;      /* getreg.term */
00408   mon2000_cmds.getreg.term_cmd = NULL;  /* getreg.term_cmd */
00409   mon2000_cmds.dump_registers = ".reg\r";       /* dump_registers */
00410                                                 /* register_pattern */
00411   mon2000_cmds.register_pattern = "\\(\\w+\\) += \\([0-9a-fA-F]+\\b\\)";
00412   mon2000_cmds.supply_register = m32r_supply_register;
00413   mon2000_cmds.load = NULL;     /* download command */
00414   mon2000_cmds.loadresp = NULL; /* load response */
00415   mon2000_cmds.prompt = "Mon2000>";     /* monitor command prompt */
00416   mon2000_cmds.line_term = "\r";        /* end-of-line terminator */
00417   mon2000_cmds.cmd_end = NULL;  /* optional command terminator */
00418   mon2000_cmds.target = &mon2000_ops;   /* target operations */
00419   mon2000_cmds.stopbits = SERIAL_1_STOPBITS;    /* number of stop bits */
00420   mon2000_cmds.regnames = m32r_regnames;        /* registers names */
00421   mon2000_cmds.magic = MONITOR_OPS_MAGIC;       /* magic */
00422 }                               /* init_mon2000_cmds */
00423 
00424 static void
00425 mon2000_open (char *args, int from_tty)
00426 {
00427   monitor_open (args, &mon2000_cmds, from_tty);
00428 }
00429 
00430 static void
00431 m32r_upload_command (char *args, int from_tty)
00432 {
00433   bfd *abfd;
00434   asection *s;
00435   struct timeval start_time, end_time;
00436   int resp_len, data_count = 0;
00437   char buf[1024];
00438   struct hostent *hostent;
00439   struct in_addr inet_addr;
00440   struct cleanup *cleanup;
00441 
00442   /* First check to see if there's an ethernet port!  */
00443   monitor_printf ("ust\r");
00444   resp_len = monitor_expect_prompt (buf, sizeof (buf));
00445   if (!strchr (buf, ':'))
00446     error (_("No ethernet connection!"));
00447 
00448   if (board_addr == 0)
00449     {
00450       /* Scan second colon in the output from the "ust" command.  */
00451       char *myIPaddress = strchr (strchr (buf, ':') + 1, ':') + 1;
00452 
00453       myIPaddress = skip_spaces (myIPaddress);
00454 
00455       if (!strncmp (myIPaddress, "0.0.", 4))    /* empty */
00456         error (_("Please use 'set board-address' to "
00457                  "set the M32R-EVA board's IP address."));
00458       if (strchr (myIPaddress, '('))
00459         *(strchr (myIPaddress, '(')) = '\0';    /* delete trailing junk */
00460       board_addr = xstrdup (myIPaddress);
00461     }
00462   if (server_addr == 0)
00463     {
00464 #ifdef __MINGW32__
00465       WSADATA wd;
00466       /* Winsock initialization.  */
00467       if (WSAStartup (MAKEWORD (1, 1), &wd))
00468         error (_("Couldn't initialize WINSOCK."));
00469 #endif
00470 
00471       buf[0] = 0;
00472       gethostname (buf, sizeof (buf));
00473       if (buf[0] != 0)
00474         {
00475           hostent = gethostbyname (buf);
00476           if (hostent != 0)
00477             {
00478 #if 1
00479               memcpy (&inet_addr.s_addr, hostent->h_addr,
00480                       sizeof (inet_addr.s_addr));
00481               server_addr = (char *) inet_ntoa (inet_addr);
00482 #else
00483               server_addr = (char *) inet_ntoa (hostent->h_addr);
00484 #endif
00485             }
00486         }
00487       if (server_addr == 0)     /* failed?  */
00488         error (_("Need to know gdb host computer's "
00489                  "IP address (use 'set server-address')"));
00490     }
00491 
00492   if (args == 0 || args[0] == 0)        /* No args: upload the current
00493                                            file.  */
00494     args = get_exec_file (1);
00495 
00496   if (args[0] != '/' && download_path == 0)
00497     {
00498       if (current_directory)
00499         download_path = xstrdup (current_directory);
00500       else
00501         error (_("Need to know default download "
00502                  "path (use 'set download-path')"));
00503     }
00504 
00505   gettimeofday (&start_time, NULL);
00506   monitor_printf ("uhip %s\r", server_addr);
00507   resp_len = monitor_expect_prompt (buf, sizeof (buf)); /* parse result?  */
00508   monitor_printf ("ulip %s\r", board_addr);
00509   resp_len = monitor_expect_prompt (buf, sizeof (buf)); /* parse result?  */
00510   if (args[0] != '/')
00511     monitor_printf ("up %s\r", download_path);  /* use default path */
00512   else
00513     monitor_printf ("up\r");    /* rooted filename/path */
00514   resp_len = monitor_expect_prompt (buf, sizeof (buf)); /* parse result?  */
00515 
00516   if (strrchr (args, '.') && !strcmp (strrchr (args, '.'), ".srec"))
00517     monitor_printf ("ul %s\r", args);
00518   else                          /* add ".srec" suffix */
00519     monitor_printf ("ul %s.srec\r", args);
00520   resp_len = monitor_expect_prompt (buf, sizeof (buf)); /* parse result?  */
00521 
00522   if (buf[0] == 0 || strstr (buf, "complete") == 0)
00523     error (_("Upload file not found: %s.srec\n"
00524              "Check IP addresses and download path."),
00525            args);
00526   else
00527     printf_filtered (" -- Ethernet load complete.\n");
00528 
00529   gettimeofday (&end_time, NULL);
00530   abfd = gdb_bfd_open (args, NULL, -1);
00531   cleanup = make_cleanup_bfd_unref (abfd);
00532   if (abfd != NULL)
00533     {           /* Download is done -- print section statistics.  */
00534       if (bfd_check_format (abfd, bfd_object) == 0)
00535         {
00536           printf_filtered ("File is not an object file\n");
00537         }
00538       for (s = abfd->sections; s; s = s->next)
00539         if (s->flags & SEC_LOAD)
00540           {
00541             bfd_size_type section_size = bfd_section_size (abfd, s);
00542             bfd_vma section_base = bfd_section_lma (abfd, s);
00543 
00544             data_count += section_size;
00545 
00546             printf_filtered ("Loading section %s, size 0x%lx lma ",
00547                              bfd_section_name (abfd, s),
00548                              (unsigned long) section_size);
00549             fputs_filtered (paddress (target_gdbarch (), section_base),
00550                             gdb_stdout);
00551             printf_filtered ("\n");
00552             gdb_flush (gdb_stdout);
00553           }
00554       /* Finally, make the PC point at the start address.  */
00555       regcache_write_pc (get_current_regcache (),
00556                          bfd_get_start_address (abfd));
00557       printf_filtered ("Start address 0x%lx\n", 
00558                        (unsigned long) bfd_get_start_address (abfd));
00559       print_transfer_performance (gdb_stdout, data_count, 0, &start_time,
00560                                   &end_time);
00561     }
00562   inferior_ptid = null_ptid;    /* No process now.  */
00563 
00564   /* This is necessary because many things were based on the PC at the
00565      time that we attached to the monitor, which is no longer valid
00566      now that we have loaded new code (and just changed the PC).
00567      Another way to do this might be to call normal_stop, except that
00568      the stack may not be valid, and things would get horribly
00569      confused...  */
00570 
00571   clear_symtab_users (0);
00572   do_cleanups (cleanup);
00573 }
00574 
00575 /* Provide a prototype to silence -Wmissing-prototypes.  */
00576 extern initialize_file_ftype _initialize_m32r_rom;
00577 
00578 void
00579 _initialize_m32r_rom (void)
00580 {
00581   /* Initialize m32r RevC monitor target.  */
00582   init_m32r_cmds ();
00583   init_monitor_ops (&m32r_ops);
00584 
00585   m32r_ops.to_shortname = "m32r";
00586   m32r_ops.to_longname = "m32r monitor";
00587   m32r_ops.to_load = m32r_load_gen;     /* Monitor lacks a download
00588                                            command.  */
00589   m32r_ops.to_doc = "Debug via the m32r monitor.\n\
00590 Specify the serial device it is connected to (e.g. /dev/ttya).";
00591   m32r_ops.to_open = m32r_open;
00592   add_target (&m32r_ops);
00593 
00594   /* Initialize mon2000 monitor target */
00595   init_mon2000_cmds ();
00596   init_monitor_ops (&mon2000_ops);
00597 
00598   mon2000_ops.to_shortname = "mon2000";
00599   mon2000_ops.to_longname = "Mon2000 monitor";
00600   mon2000_ops.to_load = m32r_load_gen;  /* Monitor lacks a download
00601                                            command.  */
00602   mon2000_ops.to_doc = "Debug via the Mon2000 monitor.\n\
00603 Specify the serial device it is connected to (e.g. /dev/ttya).";
00604   mon2000_ops.to_open = mon2000_open;
00605   add_target (&mon2000_ops);
00606 
00607   add_setshow_string_cmd ("download-path", class_obscure, &download_path, _("\
00608 Set the default path for downloadable SREC files."), _("\
00609 Show the default path for downloadable SREC files."), _("\
00610 Determines the default path for downloadable SREC files."),
00611                           NULL,
00612                           NULL, /* FIXME: i18n: The default path for
00613                                    downloadable SREC files is %s.  */
00614                           &setlist, &showlist);
00615 
00616   add_setshow_string_cmd ("board-address", class_obscure, &board_addr, _("\
00617 Set IP address for M32R-EVA target board."), _("\
00618 Show IP address for M32R-EVA target board."), _("\
00619 Determine the IP address for M32R-EVA target board."),
00620                           NULL,
00621                           NULL, /* FIXME: i18n: IP address for
00622                                    M32R-EVA target board is %s.  */
00623                           &setlist, &showlist);
00624 
00625   add_setshow_string_cmd ("server-address", class_obscure, &server_addr, _("\
00626 Set IP address for download server (GDB's host computer)."), _("\
00627 Show IP address for download server (GDB's host computer)."), _("\
00628 Determine the IP address for download server (GDB's host computer)."),
00629                           NULL,
00630                           NULL, /* FIXME: i18n: IP address for
00631                                    download server (GDB's host
00632                                    computer) is %s.  */
00633                           &setlist, &showlist);
00634 
00635   add_com ("upload", class_obscure, m32r_upload_command, _("\
00636 Upload the srec file via the monitor's Ethernet upload capability."));
00637 
00638   add_com ("tload", class_obscure, m32r_load, _("test upload command."));
00639 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines