gdb/m32r-rom.c - gdb

Global variables defined

Functions defined

Macros defined

Source code

  1. /* Remote debugging interface to m32r and mon2000 ROM monitors for GDB,
  2.    the GNU debugger.

  3.    Copyright (C) 1996-2015 Free Software Foundation, Inc.

  4.    Adapted by Michael Snyder of Cygnus Support.

  5.    This file is part of GDB.

  6.    This program is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 3 of the License, or
  9.    (at your option) any later version.

  10.    This program is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.    GNU General Public License for more details.

  14.    You should have received a copy of the GNU General Public License
  15.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  16. /* This module defines communication with the Renesas m32r monitor.  */

  17. #include "defs.h"
  18. #include "gdbcore.h"
  19. #include "target.h"
  20. #include "monitor.h"
  21. #include "serial.h"
  22. #include "symtab.h"
  23. #include "command.h"
  24. #include "gdbcmd.h"
  25. #include "symfile.h"                /* for generic load */
  26. #include <sys/time.h>
  27. #include <time.h>                /* for time_t */
  28. #include "objfiles.h"                /* for ALL_OBJFILES etc.  */
  29. #include "inferior.h"
  30. #include <ctype.h>
  31. #include "regcache.h"
  32. #include "gdb_bfd.h"
  33. #include "cli/cli-utils.h"

  34. /*
  35. * All this stuff just to get my host computer's IP address!
  36. */
  37. #ifdef __MINGW32__
  38. #include <winsock2.h>
  39. #else
  40. #include <sys/types.h>
  41. #include <netdb.h>                /* for hostent */
  42. #include <netinet/in.h>                /* for struct in_addr */
  43. #if 1
  44. #include <arpa/inet.h>                /* for inet_ntoa */
  45. #endif
  46. #endif

  47. static char *board_addr;        /* user-settable IP address for M32R-EVA */
  48. static char *server_addr;        /* user-settable IP address for gdb host */
  49. static char *download_path;        /* user-settable path for SREC files     */


  50. /* REGNUM */
  51. #define PSW_REGNUM      16
  52. #define SPI_REGNUM      18
  53. #define SPU_REGNUM      19
  54. #define ACCL_REGNUM     22
  55. #define ACCH_REGNUM     23


  56. /*
  57. * Function: m32r_load_1 (helper function)
  58. */

  59. static void
  60. m32r_load_section (bfd *abfd, asection *s, void *obj)
  61. {
  62.   unsigned int *data_count = obj;
  63.   if (s->flags & SEC_LOAD)
  64.     {
  65.       int addr_size = gdbarch_addr_bit (target_gdbarch ()) / 8;
  66.       bfd_size_type section_size = bfd_section_size (abfd, s);
  67.       bfd_vma section_base = bfd_section_lma (abfd, s);
  68.       unsigned int buffer, i;

  69.       *data_count += section_size;

  70.       printf_filtered ("Loading section %s, size 0x%lx lma ",
  71.                        bfd_section_name (abfd, s),
  72.                        (unsigned long) section_size);
  73.       fputs_filtered (paddress (target_gdbarch (), section_base), gdb_stdout);
  74.       printf_filtered ("\n");
  75.       gdb_flush (gdb_stdout);
  76.       monitor_printf ("%s mw\r", phex_nz (section_base, addr_size));
  77.       for (i = 0; i < section_size; i += 4)
  78.         {
  79.           QUIT;
  80.           monitor_expect (" -> ", NULL, 0);
  81.           bfd_get_section_contents (abfd, s, (char *) &buffer, i, 4);
  82.           monitor_printf ("%x\n", buffer);
  83.         }
  84.       monitor_expect (" -> ", NULL, 0);
  85.       monitor_printf ("q\n");
  86.       monitor_expect_prompt (NULL, 0);
  87.     }
  88. }

  89. static int
  90. m32r_load_1 (void *dummy)
  91. {
  92.   int data_count = 0;

  93.   bfd_map_over_sections ((bfd *) dummy, m32r_load_section, &data_count);
  94.   return data_count;
  95. }

  96. /*
  97. * Function: m32r_load (an alternate way to load)
  98. */

  99. static void
  100. m32r_load (char *filename, int from_tty)
  101. {
  102.   bfd *abfd;
  103.   unsigned int data_count = 0;
  104.   struct timeval start_time, end_time;
  105.   struct cleanup *cleanup;

  106.   if (filename == NULL || filename[0] == 0)
  107.     filename = get_exec_file (1);

  108.   abfd = gdb_bfd_open (filename, NULL, -1);
  109.   if (!abfd)
  110.     error (_("Unable to open file %s."), filename);
  111.   cleanup = make_cleanup_bfd_unref (abfd);
  112.   if (bfd_check_format (abfd, bfd_object) == 0)
  113.     error (_("File is not an object file."));
  114.   gettimeofday (&start_time, NULL);
  115. #if 0
  116.   for (s = abfd->sections; s; s = s->next)
  117.     if (s->flags & SEC_LOAD)
  118.       {
  119.         bfd_size_type section_size = bfd_section_size (abfd, s);
  120.         bfd_vma section_base = bfd_section_vma (abfd, s);
  121.         unsigned int buffer;

  122.         data_count += section_size;

  123.         printf_filtered ("Loading section %s, size 0x%lx vma ",
  124.                          bfd_section_name (abfd, s), section_size);
  125.         fputs_filtered (paddress (target_gdbarch (), section_base), gdb_stdout);
  126.         printf_filtered ("\n");
  127.         gdb_flush (gdb_stdout);
  128.         monitor_printf ("%x mw\r", section_base);
  129.         for (i = 0; i < section_size; i += 4)
  130.           {
  131.             monitor_expect (" -> ", NULL, 0);
  132.             bfd_get_section_contents (abfd, s, (char *) &buffer, i, 4);
  133.             monitor_printf ("%x\n", buffer);
  134.           }
  135.         monitor_expect (" -> ", NULL, 0);
  136.         monitor_printf ("q\n");
  137.         monitor_expect_prompt (NULL, 0);
  138.       }
  139. #else
  140.   if (!(catch_errors (m32r_load_1, abfd, "Load aborted!\n", RETURN_MASK_ALL)))
  141.     {
  142.       monitor_printf ("q\n");
  143.       do_cleanups (cleanup);
  144.       return;
  145.     }
  146. #endif
  147.   gettimeofday (&end_time, NULL);
  148.   printf_filtered ("Start address 0x%lx\n",
  149.                    (unsigned long) bfd_get_start_address (abfd));
  150.   print_transfer_performance (gdb_stdout, data_count, 0, &start_time,
  151.                               &end_time);

  152.   /* Finally, make the PC point at the start address.  */
  153.   if (exec_bfd)
  154.     regcache_write_pc (get_current_regcache (),
  155.                        bfd_get_start_address (exec_bfd));

  156.   inferior_ptid = null_ptid;        /* No process now.  */

  157.   /* This is necessary because many things were based on the PC at the
  158.      time that we attached to the monitor, which is no longer valid
  159.      now that we have loaded new code (and just changed the PC).
  160.      Another way to do this might be to call normal_stop, except that
  161.      the stack may not be valid, and things would get horribly
  162.      confused...  */

  163.   clear_symtab_users (0);
  164.   do_cleanups (cleanup);
  165. }

  166. static void
  167. m32r_load_gen (struct target_ops *self, const char *filename, int from_tty)
  168. {
  169.   generic_load (filename, from_tty);
  170. }

  171. /* This array of registers needs to match the indexes used by GDB.  The
  172.    whole reason this exists is because the various ROM monitors use
  173.    different names than GDB does, and don't support all the registers
  174.    either.  So, typing "info reg sp" becomes an "A7".  */

  175. static char *m32r_regnames[] =
  176.   { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
  177.   "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
  178.   "psw", "cbr", "spi", "spu", "bpc", "pc", "accl", "acch",
  179. };

  180. static void
  181. m32r_supply_register (struct regcache *regcache, char *regname,
  182.                       int regnamelen, char *val, int vallen)
  183. {
  184.   int regno;
  185.   int num_regs = sizeof (m32r_regnames) / sizeof (m32r_regnames[0]);
  186.   struct gdbarch *gdbarch = get_regcache_arch (regcache);

  187.   for (regno = 0; regno < num_regs; regno++)
  188.     if (strncmp (regname, m32r_regnames[regno], regnamelen) == 0)
  189.       break;

  190.   if (regno >= num_regs)
  191.     return;                        /* no match */

  192.   if (regno == ACCL_REGNUM)
  193.     {                                /* Special handling for 64-bit acc reg.  */
  194.       monitor_supply_register (regcache, ACCH_REGNUM, val);
  195.       val = strchr (val, ':');        /* Skip past ':' to get 2nd word.  */
  196.       if (val != NULL)
  197.         monitor_supply_register (regcache, ACCL_REGNUM, val + 1);
  198.     }
  199.   else
  200.     {
  201.       monitor_supply_register (regcache, regno, val);
  202.       if (regno == PSW_REGNUM)
  203.         {
  204. #if (defined SM_REGNUM || defined BSM_REGNUM || defined IE_REGNUM \
  205.      || defined BIE_REGNUM || defined COND_REGNUM  || defined CBR_REGNUM \
  206.      || defined BPC_REGNUM || defined BCARRY_REGNUM)
  207.           unsigned long psw = strtoul (val, NULL, 16);
  208.           char *zero = "00000000", *one = "00000001";
  209. #endif

  210. #ifdef SM_REGNUM
  211.           /* Stack mode bit */
  212.           monitor_supply_register (regcache, SM_REGNUM,
  213.                                    (psw & 0x80) ? one : zero);
  214. #endif
  215. #ifdef BSM_REGNUM
  216.           /* Backup stack mode bit */
  217.           monitor_supply_register (regcache, BSM_REGNUM,
  218.                                    (psw & 0x8000) ? one : zero);
  219. #endif
  220. #ifdef IE_REGNUM
  221.           /* Interrupt enable bit */
  222.           monitor_supply_register (regcache, IE_REGNUM,
  223.                                    (psw & 0x40) ? one : zero);
  224. #endif
  225. #ifdef BIE_REGNUM
  226.           /* Backup interrupt enable bit */
  227.           monitor_supply_register (regcache, BIE_REGNUM,
  228.                                    (psw & 0x4000) ? one : zero);
  229. #endif
  230. #ifdef COND_REGNUM
  231.           /* Condition bit (carry etc.) */
  232.           monitor_supply_register (regcache, COND_REGNUM,
  233.                                    (psw & 0x1) ? one : zero);
  234. #endif
  235. #ifdef CBR_REGNUM
  236.           monitor_supply_register (regcache, CBR_REGNUM,
  237.                                    (psw & 0x1) ? one : zero);
  238. #endif
  239. #ifdef BPC_REGNUM
  240.           monitor_supply_register (regcache, BPC_REGNUM,
  241.                                    zero);        /* KLUDGE:   (???????) */
  242. #endif
  243. #ifdef BCARRY_REGNUM
  244.           monitor_supply_register (regcache, BCARRY_REGNUM,
  245.                                    zero);        /* KLUDGE: (??????) */
  246. #endif
  247.         }

  248.       if (regno == SPI_REGNUM || regno == SPU_REGNUM)
  249.         {        /* special handling for stack pointer (spu or spi).  */
  250.           ULONGEST stackmode, psw;
  251.           regcache_cooked_read_unsigned (regcache, PSW_REGNUM, &psw);
  252.           stackmode = psw & 0x80;

  253.           if (regno == SPI_REGNUM && !stackmode)        /* SP == SPI */
  254.             monitor_supply_register (regcache,
  255.                                      gdbarch_sp_regnum (gdbarch), val);
  256.           else if (regno == SPU_REGNUM && stackmode)        /* SP == SPU */
  257.             monitor_supply_register (regcache,
  258.                                      gdbarch_sp_regnum (gdbarch), val);
  259.         }
  260.     }
  261. }

  262. /* m32r RevC board monitor */

  263. static struct target_ops m32r_ops;

  264. static char *m32r_inits[] = { "\r", NULL };

  265. static struct monitor_ops m32r_cmds;

  266. static void
  267. init_m32r_cmds (void)
  268. {
  269.   m32r_cmds.flags = MO_CLR_BREAK_USES_ADDR | MO_REGISTER_VALUE_FIRST;
  270.   m32r_cmds.init = m32r_inits;        /* Init strings */
  271.   m32r_cmds.cont = "go\r";        /* continue command */
  272.   m32r_cmds.step = "step\r";        /* single step */
  273.   m32r_cmds.stop = NULL;        /* interrupt command */
  274.   m32r_cmds.set_break = "%x +bp\r";        /* set a breakpoint */
  275.   m32r_cmds.clr_break = "%x -bp\r";        /* clear a breakpoint */
  276.   m32r_cmds.clr_all_break = "bpoff\r";        /* clear all breakpoints */
  277.   m32r_cmds.fill = "%x %x %x fill\r";        /* fill (start length val) */
  278.   m32r_cmds.setmem.cmdb = "%x 1 %x fill\r";        /* setmem.cmdb (addr, value) */
  279.   m32r_cmds.setmem.cmdw = "%x 1 %x fillh\r";        /* setmem.cmdw (addr, value) */
  280.   m32r_cmds.setmem.cmdl = "%x 1 %x fillw\r";        /* setmem.cmdl (addr, value) */
  281.   m32r_cmds.setmem.cmdll = NULL;        /* setmem.cmdll (addr, value) */
  282.   m32r_cmds.setmem.resp_delim = NULL;        /* setmem.resp_delim */
  283.   m32r_cmds.setmem.term = NULL;        /* setmem.term */
  284.   m32r_cmds.setmem.term_cmd = NULL;        /* setmem.term_cmd */
  285.   m32r_cmds.getmem.cmdb = "%x %x dump\r";        /* getmem.cmdb (addr, len) */
  286.   m32r_cmds.getmem.cmdw = NULL;        /* getmem.cmdw (addr, len) */
  287.   m32r_cmds.getmem.cmdl = NULL;        /* getmem.cmdl (addr, len) */
  288.   m32r_cmds.getmem.cmdll = NULL;        /* getmem.cmdll (addr, len) */
  289.   m32r_cmds.getmem.resp_delim = ": ";        /* getmem.resp_delim */
  290.   m32r_cmds.getmem.term = NULL;        /* getmem.term */
  291.   m32r_cmds.getmem.term_cmd = NULL;        /* getmem.term_cmd */
  292.   m32r_cmds.setreg.cmd = "%x to %%%s\r";        /* setreg.cmd (name, value) */
  293.   m32r_cmds.setreg.resp_delim = NULL;        /* setreg.resp_delim */
  294.   m32r_cmds.setreg.term = NULL;        /* setreg.term */
  295.   m32r_cmds.setreg.term_cmd = NULL;        /* setreg.term_cmd */
  296.   m32r_cmds.getreg.cmd = NULL;        /* getreg.cmd (name) */
  297.   m32r_cmds.getreg.resp_delim = NULL;        /* getreg.resp_delim */
  298.   m32r_cmds.getreg.term = NULL;        /* getreg.term */
  299.   m32r_cmds.getreg.term_cmd = NULL;        /* getreg.term_cmd */
  300.   m32r_cmds.dump_registers = ".reg\r";        /* dump_registers */
  301.                                           /* register_pattern */
  302.   m32r_cmds.register_pattern = "\\(\\w+\\) += \\([0-9a-fA-F]+\\b\\)";
  303.   m32r_cmds.supply_register = m32r_supply_register;
  304.   m32r_cmds.load = NULL;        /* download command */
  305.   m32r_cmds.loadresp = NULL;        /* load response */
  306.   m32r_cmds.prompt = "ok ";        /* monitor command prompt */
  307.   m32r_cmds.line_term = "\r";        /* end-of-line terminator */
  308.   m32r_cmds.cmd_end = NULL;        /* optional command terminator */
  309.   m32r_cmds.target = &m32r_ops;        /* target operations */
  310.   m32r_cmds.stopbits = SERIAL_1_STOPBITS;        /* number of stop bits */
  311.   m32r_cmds.regnames = m32r_regnames;        /* registers names */
  312.   m32r_cmds.magic = MONITOR_OPS_MAGIC;        /* magic */
  313. }                                /* init_m32r_cmds */

  314. static void
  315. m32r_open (const char *args, int from_tty)
  316. {
  317.   monitor_open (args, &m32r_cmds, from_tty);
  318. }

  319. /* Mon2000 monitor (MSA2000 board) */

  320. static struct target_ops mon2000_ops;
  321. static struct monitor_ops mon2000_cmds;

  322. static void
  323. init_mon2000_cmds (void)
  324. {
  325.   mon2000_cmds.flags = MO_CLR_BREAK_USES_ADDR | MO_REGISTER_VALUE_FIRST;
  326.   mon2000_cmds.init = m32r_inits;        /* Init strings */
  327.   mon2000_cmds.cont = "go\r";        /* continue command */
  328.   mon2000_cmds.step = "step\r";        /* single step */
  329.   mon2000_cmds.stop = NULL;        /* interrupt command */
  330.   mon2000_cmds.set_break = "%x +bp\r";        /* set a breakpoint */
  331.   mon2000_cmds.clr_break = "%x -bp\r";        /* clear a breakpoint */
  332.   mon2000_cmds.clr_all_break = "bpoff\r";        /* clear all breakpoints */
  333.   mon2000_cmds.fill = "%x %x %x fill\r";        /* fill (start length val) */
  334.   mon2000_cmds.setmem.cmdb = "%x 1 %x fill\r";        /* setmem.cmdb (addr, value) */
  335.   mon2000_cmds.setmem.cmdw = "%x 1 %x fillh\r";        /* setmem.cmdw (addr, value) */
  336.   mon2000_cmds.setmem.cmdl = "%x 1 %x fillw\r";        /* setmem.cmdl (addr, value) */
  337.   mon2000_cmds.setmem.cmdll = NULL;        /* setmem.cmdll (addr, value) */
  338.   mon2000_cmds.setmem.resp_delim = NULL;        /* setmem.resp_delim */
  339.   mon2000_cmds.setmem.term = NULL;        /* setmem.term */
  340.   mon2000_cmds.setmem.term_cmd = NULL;        /* setmem.term_cmd */
  341.   mon2000_cmds.getmem.cmdb = "%x %x dump\r";        /* getmem.cmdb (addr, len) */
  342.   mon2000_cmds.getmem.cmdw = NULL;        /* getmem.cmdw (addr, len) */
  343.   mon2000_cmds.getmem.cmdl = NULL;        /* getmem.cmdl (addr, len) */
  344.   mon2000_cmds.getmem.cmdll = NULL;        /* getmem.cmdll (addr, len) */
  345.   mon2000_cmds.getmem.resp_delim = ": ";        /* getmem.resp_delim */
  346.   mon2000_cmds.getmem.term = NULL;        /* getmem.term */
  347.   mon2000_cmds.getmem.term_cmd = NULL;        /* getmem.term_cmd */
  348.   mon2000_cmds.setreg.cmd = "%x to %%%s\r";        /* setreg.cmd (name, value) */
  349.   mon2000_cmds.setreg.resp_delim = NULL;        /* setreg.resp_delim */
  350.   mon2000_cmds.setreg.term = NULL;        /* setreg.term */
  351.   mon2000_cmds.setreg.term_cmd = NULL;        /* setreg.term_cmd */
  352.   mon2000_cmds.getreg.cmd = NULL;        /* getreg.cmd (name) */
  353.   mon2000_cmds.getreg.resp_delim = NULL;        /* getreg.resp_delim */
  354.   mon2000_cmds.getreg.term = NULL;        /* getreg.term */
  355.   mon2000_cmds.getreg.term_cmd = NULL;        /* getreg.term_cmd */
  356.   mon2000_cmds.dump_registers = ".reg\r";        /* dump_registers */
  357.                                                 /* register_pattern */
  358.   mon2000_cmds.register_pattern = "\\(\\w+\\) += \\([0-9a-fA-F]+\\b\\)";
  359.   mon2000_cmds.supply_register = m32r_supply_register;
  360.   mon2000_cmds.load = NULL;        /* download command */
  361.   mon2000_cmds.loadresp = NULL;        /* load response */
  362.   mon2000_cmds.prompt = "Mon2000>";        /* monitor command prompt */
  363.   mon2000_cmds.line_term = "\r";        /* end-of-line terminator */
  364.   mon2000_cmds.cmd_end = NULL;        /* optional command terminator */
  365.   mon2000_cmds.target = &mon2000_ops;        /* target operations */
  366.   mon2000_cmds.stopbits = SERIAL_1_STOPBITS;        /* number of stop bits */
  367.   mon2000_cmds.regnames = m32r_regnames;        /* registers names */
  368.   mon2000_cmds.magic = MONITOR_OPS_MAGIC;        /* magic */
  369. }                                /* init_mon2000_cmds */

  370. static void
  371. mon2000_open (const char *args, int from_tty)
  372. {
  373.   monitor_open (args, &mon2000_cmds, from_tty);
  374. }

  375. static void
  376. m32r_upload_command (char *args, int from_tty)
  377. {
  378.   bfd *abfd;
  379.   asection *s;
  380.   struct timeval start_time, end_time;
  381.   int resp_len, data_count = 0;
  382.   char buf[1024];
  383.   struct hostent *hostent;
  384.   struct in_addr inet_addr;
  385.   struct cleanup *cleanup;

  386.   /* First check to see if there's an ethernet port!  */
  387.   monitor_printf ("ust\r");
  388.   resp_len = monitor_expect_prompt (buf, sizeof (buf));
  389.   if (!strchr (buf, ':'))
  390.     error (_("No ethernet connection!"));

  391.   if (board_addr == 0)
  392.     {
  393.       /* Scan second colon in the output from the "ust" command.  */
  394.       char *myIPaddress = strchr (strchr (buf, ':') + 1, ':') + 1;

  395.       myIPaddress = skip_spaces (myIPaddress);

  396.       if (!strncmp (myIPaddress, "0.0.", 4))        /* empty */
  397.         error (_("Please use 'set board-address' to "
  398.                  "set the M32R-EVA board's IP address."));
  399.       if (strchr (myIPaddress, '('))
  400.         *(strchr (myIPaddress, '(')) = '\0';        /* delete trailing junk */
  401.       board_addr = xstrdup (myIPaddress);
  402.     }
  403.   if (server_addr == 0)
  404.     {
  405. #ifdef __MINGW32__
  406.       WSADATA wd;
  407.       /* Winsock initialization.  */
  408.       if (WSAStartup (MAKEWORD (1, 1), &wd))
  409.         error (_("Couldn't initialize WINSOCK."));
  410. #endif

  411.       buf[0] = 0;
  412.       gethostname (buf, sizeof (buf));
  413.       if (buf[0] != 0)
  414.         {
  415.           hostent = gethostbyname (buf);
  416.           if (hostent != 0)
  417.             {
  418. #if 1
  419.               memcpy (&inet_addr.s_addr, hostent->h_addr,
  420.                       sizeof (inet_addr.s_addr));
  421.               server_addr = (char *) inet_ntoa (inet_addr);
  422. #else
  423.               server_addr = (char *) inet_ntoa (hostent->h_addr);
  424. #endif
  425.             }
  426.         }
  427.       if (server_addr == 0)        /* failed?  */
  428.         error (_("Need to know gdb host computer's "
  429.                  "IP address (use 'set server-address')"));
  430.     }

  431.   if (args == 0 || args[0] == 0)        /* No args: upload the current
  432.                                            file.  */
  433.     args = get_exec_file (1);

  434.   if (args[0] != '/' && download_path == 0)
  435.     {
  436.       if (current_directory)
  437.         download_path = xstrdup (current_directory);
  438.       else
  439.         error (_("Need to know default download "
  440.                  "path (use 'set download-path')"));
  441.     }

  442.   gettimeofday (&start_time, NULL);
  443.   monitor_printf ("uhip %s\r", server_addr);
  444.   resp_len = monitor_expect_prompt (buf, sizeof (buf));        /* parse result?  */
  445.   monitor_printf ("ulip %s\r", board_addr);
  446.   resp_len = monitor_expect_prompt (buf, sizeof (buf));        /* parse result?  */
  447.   if (args[0] != '/')
  448.     monitor_printf ("up %s\r", download_path);        /* use default path */
  449.   else
  450.     monitor_printf ("up\r");        /* rooted filename/path */
  451.   resp_len = monitor_expect_prompt (buf, sizeof (buf));        /* parse result?  */

  452.   if (strrchr (args, '.') && !strcmp (strrchr (args, '.'), ".srec"))
  453.     monitor_printf ("ul %s\r", args);
  454.   else                                /* add ".srec" suffix */
  455.     monitor_printf ("ul %s.srec\r", args);
  456.   resp_len = monitor_expect_prompt (buf, sizeof (buf));        /* parse result?  */

  457.   if (buf[0] == 0 || strstr (buf, "complete") == 0)
  458.     error (_("Upload file not found: %s.srec\n"
  459.              "Check IP addresses and download path."),
  460.            args);
  461.   else
  462.     printf_filtered (" -- Ethernet load complete.\n");

  463.   gettimeofday (&end_time, NULL);
  464.   abfd = gdb_bfd_open (args, NULL, -1);
  465.   cleanup = make_cleanup_bfd_unref (abfd);
  466.   if (abfd != NULL)
  467.     {                /* Download is done -- print section statistics.  */
  468.       if (bfd_check_format (abfd, bfd_object) == 0)
  469.         {
  470.           printf_filtered ("File is not an object file\n");
  471.         }
  472.       for (s = abfd->sections; s; s = s->next)
  473.         if (s->flags & SEC_LOAD)
  474.           {
  475.             bfd_size_type section_size = bfd_section_size (abfd, s);
  476.             bfd_vma section_base = bfd_section_lma (abfd, s);

  477.             data_count += section_size;

  478.             printf_filtered ("Loading section %s, size 0x%lx lma ",
  479.                              bfd_section_name (abfd, s),
  480.                              (unsigned long) section_size);
  481.             fputs_filtered (paddress (target_gdbarch (), section_base),
  482.                             gdb_stdout);
  483.             printf_filtered ("\n");
  484.             gdb_flush (gdb_stdout);
  485.           }
  486.       /* Finally, make the PC point at the start address.  */
  487.       regcache_write_pc (get_current_regcache (),
  488.                          bfd_get_start_address (abfd));
  489.       printf_filtered ("Start address 0x%lx\n",
  490.                        (unsigned long) bfd_get_start_address (abfd));
  491.       print_transfer_performance (gdb_stdout, data_count, 0, &start_time,
  492.                                   &end_time);
  493.     }
  494.   inferior_ptid = null_ptid;        /* No process now.  */

  495.   /* This is necessary because many things were based on the PC at the
  496.      time that we attached to the monitor, which is no longer valid
  497.      now that we have loaded new code (and just changed the PC).
  498.      Another way to do this might be to call normal_stop, except that
  499.      the stack may not be valid, and things would get horribly
  500.      confused...  */

  501.   clear_symtab_users (0);
  502.   do_cleanups (cleanup);
  503. }

  504. /* Provide a prototype to silence -Wmissing-prototypes.  */
  505. extern initialize_file_ftype _initialize_m32r_rom;

  506. void
  507. _initialize_m32r_rom (void)
  508. {
  509.   /* Initialize m32r RevC monitor target.  */
  510.   init_m32r_cmds ();
  511.   init_monitor_ops (&m32r_ops);

  512.   m32r_ops.to_shortname = "m32r";
  513.   m32r_ops.to_longname = "m32r monitor";
  514.   m32r_ops.to_load = m32r_load_gen;        /* Monitor lacks a download
  515.                                            command.  */
  516.   m32r_ops.to_doc = "Debug via the m32r monitor.\n\
  517. Specify the serial device it is connected to (e.g. /dev/ttya).";
  518.   m32r_ops.to_open = m32r_open;
  519.   add_target (&m32r_ops);

  520.   /* Initialize mon2000 monitor target */
  521.   init_mon2000_cmds ();
  522.   init_monitor_ops (&mon2000_ops);

  523.   mon2000_ops.to_shortname = "mon2000";
  524.   mon2000_ops.to_longname = "Mon2000 monitor";
  525.   mon2000_ops.to_load = m32r_load_gen;        /* Monitor lacks a download
  526.                                            command.  */
  527.   mon2000_ops.to_doc = "Debug via the Mon2000 monitor.\n\
  528. Specify the serial device it is connected to (e.g. /dev/ttya).";
  529.   mon2000_ops.to_open = mon2000_open;
  530.   add_target (&mon2000_ops);

  531.   add_setshow_string_cmd ("download-path", class_obscure, &download_path, _("\
  532. Set the default path for downloadable SREC files."), _("\
  533. Show the default path for downloadable SREC files."), _("\
  534. Determines the default path for downloadable SREC files."),
  535.                           NULL,
  536.                           NULL, /* FIXME: i18n: The default path for
  537.                                    downloadable SREC files is %s.  */
  538.                           &setlist, &showlist);

  539.   add_setshow_string_cmd ("board-address", class_obscure, &board_addr, _("\
  540. Set IP address for M32R-EVA target board."), _("\
  541. Show IP address for M32R-EVA target board."), _("\
  542. Determine the IP address for M32R-EVA target board."),
  543.                           NULL,
  544.                           NULL, /* FIXME: i18n: IP address for
  545.                                    M32R-EVA target board is %s.  */
  546.                           &setlist, &showlist);

  547.   add_setshow_string_cmd ("server-address", class_obscure, &server_addr, _("\
  548. Set IP address for download server (GDB's host computer)."), _("\
  549. Show IP address for download server (GDB's host computer)."), _("\
  550. Determine the IP address for download server (GDB's host computer)."),
  551.                           NULL,
  552.                           NULL, /* FIXME: i18n: IP address for
  553.                                    download server (GDB's host
  554.                                    computer) is %s.  */
  555.                           &setlist, &showlist);

  556.   add_com ("upload", class_obscure, m32r_upload_command, _("\
  557. Upload the srec file via the monitor's Ethernet upload capability."));

  558.   add_com ("tload", class_obscure, m32r_load, _("test upload command."));
  559. }