2003-08-01 Andrew Cagney <cagney@redhat.com>
[external/binutils.git] / gdb / m32r-rom.c
1 /* Remote debugging interface to m32r and mon2000 ROM monitors for GDB, 
2    the GNU debugger.
3    Copyright 1996, 1997, 1998, 1999, 2000, 2001
4    Free Software Foundation, Inc.
5
6    Adapted by Michael Snyder of Cygnus Support.
7
8    This file is part of GDB.
9
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 2 of the License, or
13    (at your option) any later version.
14
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place - Suite 330,
23    Boston, MA 02111-1307, USA.  */
24
25 /* This module defines communication with the Renesas m32r monitor */
26
27 #include "defs.h"
28 #include "gdbcore.h"
29 #include "target.h"
30 #include "monitor.h"
31 #include "serial.h"
32 #include "symtab.h"
33 #include "command.h"
34 #include "gdbcmd.h"
35 #include "symfile.h"            /* for generic load */
36 #include <time.h>               /* for time_t */
37 #include "gdb_string.h"
38 #include "objfiles.h"           /* for ALL_OBJFILES etc. */
39 #include "inferior.h"           /* for write_pc() */
40 #include <ctype.h>
41 #include "regcache.h"
42
43 /*
44  * All this stuff just to get my host computer's IP address!
45  */
46 #include <sys/types.h>
47 #include <netdb.h>              /* for hostent */
48 #include <netinet/in.h>         /* for struct in_addr */
49 #if 1
50 #include <arpa/inet.h>          /* for inet_ntoa */
51 #endif
52
53 static char *board_addr;        /* user-settable IP address for M32R-EVA */
54 static char *server_addr;       /* user-settable IP address for gdb host */
55 static char *download_path;     /* user-settable path for SREC files     */
56
57
58 /* REGNUM */
59 #define PSW_REGNUM      16
60 #define SPI_REGNUM      18
61 #define SPU_REGNUM      19
62 #define ACCL_REGNUM     22
63 #define ACCH_REGNUM     23
64
65
66 /* 
67  * Function: m32r_load_1 (helper function)
68  */
69
70 static void
71 m32r_load_section (bfd *abfd, asection *s, void *obj)
72 {
73   unsigned int *data_count = obj;
74   if (s->flags & SEC_LOAD)
75     {
76       bfd_size_type section_size = bfd_section_size (abfd, s);
77       bfd_vma section_base = bfd_section_lma (abfd, s);
78       unsigned int buffer, i;
79
80       *data_count += section_size;
81
82       printf_filtered ("Loading section %s, size 0x%lx lma ",
83                        bfd_section_name (abfd, s), section_size);
84       print_address_numeric (section_base, 1, gdb_stdout);
85       printf_filtered ("\n");
86       gdb_flush (gdb_stdout);
87       monitor_printf ("%s mw\r", paddr_nz (section_base));
88       for (i = 0; i < section_size; i += 4)
89         {
90           QUIT;
91           monitor_expect (" -> ", NULL, 0);
92           bfd_get_section_contents (abfd, s, (char *) &buffer, i, 4);
93           monitor_printf ("%x\n", buffer);
94         }
95       monitor_expect (" -> ", NULL, 0);
96       monitor_printf ("q\n");
97       monitor_expect_prompt (NULL, 0);
98     }
99 }
100
101 static int
102 m32r_load_1 (void *dummy)
103 {
104   int data_count = 0;
105
106   bfd_map_over_sections ((bfd *) dummy, m32r_load_section, &data_count);
107   return data_count;
108 }
109
110 /* 
111  * Function: m32r_load (an alternate way to load) 
112  */
113
114 static void
115 m32r_load (char *filename, int from_tty)
116 {
117   bfd *abfd;
118   asection *s;
119   unsigned int i, data_count = 0;
120   time_t start_time, end_time;  /* for timing of download */
121
122   if (filename == NULL || filename[0] == 0)
123     filename = get_exec_file (1);
124
125   abfd = bfd_openr (filename, 0);
126   if (!abfd)
127     error ("Unable to open file %s\n", filename);
128   if (bfd_check_format (abfd, bfd_object) == 0)
129     error ("File is not an object file\n");
130   start_time = time (NULL);
131 #if 0
132   for (s = abfd->sections; s; s = s->next)
133     if (s->flags & SEC_LOAD)
134       {
135         bfd_size_type section_size = bfd_section_size (abfd, s);
136         bfd_vma section_base = bfd_section_vma (abfd, s);
137         unsigned int buffer;
138
139         data_count += section_size;
140
141         printf_filtered ("Loading section %s, size 0x%lx vma ",
142                          bfd_section_name (abfd, s), section_size);
143         print_address_numeric (section_base, 1, gdb_stdout);
144         printf_filtered ("\n");
145         gdb_flush (gdb_stdout);
146         monitor_printf ("%x mw\r", section_base);
147         for (i = 0; i < section_size; i += 4)
148           {
149             monitor_expect (" -> ", NULL, 0);
150             bfd_get_section_contents (abfd, s, (char *) &buffer, i, 4);
151             monitor_printf ("%x\n", buffer);
152           }
153         monitor_expect (" -> ", NULL, 0);
154         monitor_printf ("q\n");
155         monitor_expect_prompt (NULL, 0);
156       }
157 #else
158   if (!(catch_errors (m32r_load_1, abfd, "Load aborted!\n", RETURN_MASK_ALL)))
159     {
160       monitor_printf ("q\n");
161       return;
162     }
163 #endif
164   end_time = time (NULL);
165   printf_filtered ("Start address 0x%lx\n", bfd_get_start_address (abfd));
166   print_transfer_performance (gdb_stdout, data_count, 0,
167                               end_time - start_time);
168
169   /* Finally, make the PC point at the start address */
170   if (exec_bfd)
171     write_pc (bfd_get_start_address (exec_bfd));
172
173   inferior_ptid = null_ptid;    /* No process now */
174
175   /* This is necessary because many things were based on the PC at the
176      time that we attached to the monitor, which is no longer valid
177      now that we have loaded new code (and just changed the PC).
178      Another way to do this might be to call normal_stop, except that
179      the stack may not be valid, and things would get horribly
180      confused... */
181
182   clear_symtab_users ();
183 }
184
185 static void
186 m32r_load_gen (char *filename, int from_tty)
187 {
188   generic_load (filename, from_tty);
189 }
190
191 static void m32r_open (char *args, int from_tty);
192 static void mon2000_open (char *args, int from_tty);
193
194 /* This array of registers needs to match the indexes used by GDB. The
195    whole reason this exists is because the various ROM monitors use
196    different names than GDB does, and don't support all the registers
197    either. So, typing "info reg sp" becomes an "A7". */
198
199 static char *m32r_regnames[] =
200   { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
201   "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
202   "psw", "cbr", "spi", "spu", "bpc", "pc", "accl", "acch",
203 };
204
205 static void
206 m32r_supply_register (char *regname, int regnamelen, char *val, int vallen)
207 {
208   int regno;
209   int num_regs = sizeof (m32r_regnames) / sizeof (m32r_regnames[0]);
210
211   for (regno = 0; regno < num_regs; regno++)
212     if (strncmp (regname, m32r_regnames[regno], regnamelen) == 0)
213       break;
214
215   if (regno >= num_regs)
216     return;                     /* no match */
217
218   if (regno == ACCL_REGNUM)
219     {                           /* special handling for 64-bit acc reg */
220       monitor_supply_register (ACCH_REGNUM, val);
221       val = strchr (val, ':');  /* skip past ':' to get 2nd word */
222       if (val != NULL)
223         monitor_supply_register (ACCL_REGNUM, val + 1);
224     }
225   else
226     {
227       monitor_supply_register (regno, val);
228       if (regno == PSW_REGNUM)
229         {
230           unsigned long psw = strtoul (val, NULL, 16);
231           char *zero = "00000000", *one = "00000001";
232
233 #ifdef SM_REGNUM
234           /* Stack mode bit */
235           monitor_supply_register (SM_REGNUM, (psw & 0x80) ? one : zero);
236 #endif
237 #ifdef BSM_REGNUM
238           /* Backup stack mode bit */
239           monitor_supply_register (BSM_REGNUM, (psw & 0x8000) ? one : zero);
240 #endif
241 #ifdef IE_REGNUM
242           /* Interrupt enable bit */
243           monitor_supply_register (IE_REGNUM, (psw & 0x40) ? one : zero);
244 #endif
245 #ifdef BIE_REGNUM
246           /* Backup interrupt enable bit */
247           monitor_supply_register (BIE_REGNUM, (psw & 0x4000) ? one : zero);
248 #endif
249 #ifdef COND_REGNUM
250           /* Condition bit (carry etc.) */
251           monitor_supply_register (COND_REGNUM, (psw & 0x1) ? one : zero);
252 #endif
253 #ifdef CBR_REGNUM
254           monitor_supply_register (CBR_REGNUM, (psw & 0x1) ? one : zero);
255 #endif
256 #ifdef BPC_REGNUM
257           monitor_supply_register (BPC_REGNUM, zero);   /* KLUDGE:   (???????) */
258 #endif
259 #ifdef BCARRY_REGNUM
260           monitor_supply_register (BCARRY_REGNUM, zero);        /* KLUDGE: (??????) */
261 #endif
262         }
263
264       if (regno == SPI_REGNUM || regno == SPU_REGNUM)
265         {                       /* special handling for stack pointer (spu or spi) */
266           ULONGEST stackmode, psw;
267           regcache_cooked_read_unsigned (current_regcache, PSW_REGNUM, &psw);
268           stackmode = psw & 0x80;
269
270           if (regno == SPI_REGNUM && !stackmode)        /* SP == SPI */
271             monitor_supply_register (SP_REGNUM, val);
272           else if (regno == SPU_REGNUM && stackmode)    /* SP == SPU */
273             monitor_supply_register (SP_REGNUM, val);
274         }
275     }
276 }
277
278 /* m32r RevC board monitor */
279
280 static struct target_ops m32r_ops;
281
282 static char *m32r_inits[] = { "\r", NULL };
283
284 static struct monitor_ops m32r_cmds;
285
286 static void
287 init_m32r_cmds (void)
288 {
289   m32r_cmds.flags = MO_CLR_BREAK_USES_ADDR | MO_REGISTER_VALUE_FIRST;
290   m32r_cmds.init = m32r_inits;  /* Init strings */
291   m32r_cmds.cont = "go\r";      /* continue command */
292   m32r_cmds.step = "step\r";    /* single step */
293   m32r_cmds.stop = NULL;        /* interrupt command */
294   m32r_cmds.set_break = "%x +bp\r";     /* set a breakpoint */
295   m32r_cmds.clr_break = "%x -bp\r";     /* clear a breakpoint */
296   m32r_cmds.clr_all_break = "bpoff\r";  /* clear all breakpoints */
297   m32r_cmds.fill = "%x %x %x fill\r";   /* fill (start length val) */
298   m32r_cmds.setmem.cmdb = "%x 1 %x fill\r";     /* setmem.cmdb (addr, value) */
299   m32r_cmds.setmem.cmdw = "%x 1 %x fillh\r";    /* setmem.cmdw (addr, value) */
300   m32r_cmds.setmem.cmdl = "%x 1 %x fillw\r";    /* setmem.cmdl (addr, value) */
301   m32r_cmds.setmem.cmdll = NULL;        /* setmem.cmdll (addr, value) */
302   m32r_cmds.setmem.resp_delim = NULL;   /* setmem.resp_delim */
303   m32r_cmds.setmem.term = NULL; /* setmem.term */
304   m32r_cmds.setmem.term_cmd = NULL;     /* setmem.term_cmd */
305   m32r_cmds.getmem.cmdb = "%x %x dump\r";       /* getmem.cmdb (addr, len) */
306   m32r_cmds.getmem.cmdw = NULL; /* getmem.cmdw (addr, len) */
307   m32r_cmds.getmem.cmdl = NULL; /* getmem.cmdl (addr, len) */
308   m32r_cmds.getmem.cmdll = NULL;        /* getmem.cmdll (addr, len) */
309   m32r_cmds.getmem.resp_delim = ": ";   /* getmem.resp_delim */
310   m32r_cmds.getmem.term = NULL; /* getmem.term */
311   m32r_cmds.getmem.term_cmd = NULL;     /* getmem.term_cmd */
312   m32r_cmds.setreg.cmd = "%x to %%%s\r";        /* setreg.cmd (name, value) */
313   m32r_cmds.setreg.resp_delim = NULL;   /* setreg.resp_delim */
314   m32r_cmds.setreg.term = NULL; /* setreg.term */
315   m32r_cmds.setreg.term_cmd = NULL;     /* setreg.term_cmd */
316   m32r_cmds.getreg.cmd = NULL;  /* getreg.cmd (name) */
317   m32r_cmds.getreg.resp_delim = NULL;   /* getreg.resp_delim */
318   m32r_cmds.getreg.term = NULL; /* getreg.term */
319   m32r_cmds.getreg.term_cmd = NULL;     /* getreg.term_cmd */
320   m32r_cmds.dump_registers = ".reg\r";  /* dump_registers */
321   m32r_cmds.register_pattern = "\\(\\w+\\) += \\([0-9a-fA-F]+\\b\\)";   /* register_pattern */
322   m32r_cmds.supply_register = m32r_supply_register;     /* supply_register */
323   m32r_cmds.load_routine = NULL;        /* load_routine (defaults to SRECs) */
324   m32r_cmds.load = NULL;        /* download command */
325   m32r_cmds.loadresp = NULL;    /* load response */
326   m32r_cmds.prompt = "ok ";     /* monitor command prompt */
327   m32r_cmds.line_term = "\r";   /* end-of-line terminator */
328   m32r_cmds.cmd_end = NULL;     /* optional command terminator */
329   m32r_cmds.target = &m32r_ops; /* target operations */
330   m32r_cmds.stopbits = SERIAL_1_STOPBITS;       /* number of stop bits */
331   m32r_cmds.regnames = m32r_regnames;   /* registers names */
332   m32r_cmds.magic = MONITOR_OPS_MAGIC;  /* magic */
333 }                               /* init_m32r_cmds */
334
335 static void
336 m32r_open (char *args, int from_tty)
337 {
338   monitor_open (args, &m32r_cmds, from_tty);
339 }
340
341 /* Mon2000 monitor (MSA2000 board) */
342
343 static struct target_ops mon2000_ops;
344 static struct monitor_ops mon2000_cmds;
345
346 static void
347 init_mon2000_cmds (void)
348 {
349   mon2000_cmds.flags = MO_CLR_BREAK_USES_ADDR | MO_REGISTER_VALUE_FIRST;
350   mon2000_cmds.init = m32r_inits;       /* Init strings */
351   mon2000_cmds.cont = "go\r";   /* continue command */
352   mon2000_cmds.step = "step\r"; /* single step */
353   mon2000_cmds.stop = NULL;     /* interrupt command */
354   mon2000_cmds.set_break = "%x +bp\r";  /* set a breakpoint */
355   mon2000_cmds.clr_break = "%x -bp\r";  /* clear a breakpoint */
356   mon2000_cmds.clr_all_break = "bpoff\r";       /* clear all breakpoints */
357   mon2000_cmds.fill = "%x %x %x fill\r";        /* fill (start length val) */
358   mon2000_cmds.setmem.cmdb = "%x 1 %x fill\r";  /* setmem.cmdb (addr, value) */
359   mon2000_cmds.setmem.cmdw = "%x 1 %x fillh\r"; /* setmem.cmdw (addr, value) */
360   mon2000_cmds.setmem.cmdl = "%x 1 %x fillw\r"; /* setmem.cmdl (addr, value) */
361   mon2000_cmds.setmem.cmdll = NULL;     /* setmem.cmdll (addr, value) */
362   mon2000_cmds.setmem.resp_delim = NULL;        /* setmem.resp_delim */
363   mon2000_cmds.setmem.term = NULL;      /* setmem.term */
364   mon2000_cmds.setmem.term_cmd = NULL;  /* setmem.term_cmd */
365   mon2000_cmds.getmem.cmdb = "%x %x dump\r";    /* getmem.cmdb (addr, len) */
366   mon2000_cmds.getmem.cmdw = NULL;      /* getmem.cmdw (addr, len) */
367   mon2000_cmds.getmem.cmdl = NULL;      /* getmem.cmdl (addr, len) */
368   mon2000_cmds.getmem.cmdll = NULL;     /* getmem.cmdll (addr, len) */
369   mon2000_cmds.getmem.resp_delim = ": ";        /* getmem.resp_delim */
370   mon2000_cmds.getmem.term = NULL;      /* getmem.term */
371   mon2000_cmds.getmem.term_cmd = NULL;  /* getmem.term_cmd */
372   mon2000_cmds.setreg.cmd = "%x to %%%s\r";     /* setreg.cmd (name, value) */
373   mon2000_cmds.setreg.resp_delim = NULL;        /* setreg.resp_delim */
374   mon2000_cmds.setreg.term = NULL;      /* setreg.term */
375   mon2000_cmds.setreg.term_cmd = NULL;  /* setreg.term_cmd */
376   mon2000_cmds.getreg.cmd = NULL;       /* getreg.cmd (name) */
377   mon2000_cmds.getreg.resp_delim = NULL;        /* getreg.resp_delim */
378   mon2000_cmds.getreg.term = NULL;      /* getreg.term */
379   mon2000_cmds.getreg.term_cmd = NULL;  /* getreg.term_cmd */
380   mon2000_cmds.dump_registers = ".reg\r";       /* dump_registers */
381   mon2000_cmds.register_pattern = "\\(\\w+\\) += \\([0-9a-fA-F]+\\b\\)";        /* register_pattern */
382   mon2000_cmds.supply_register = m32r_supply_register;  /* supply_register */
383   mon2000_cmds.load_routine = NULL;     /* load_routine (defaults to SRECs) */
384   mon2000_cmds.load = NULL;     /* download command */
385   mon2000_cmds.loadresp = NULL; /* load response */
386   mon2000_cmds.prompt = "Mon2000>";     /* monitor command prompt */
387   mon2000_cmds.line_term = "\r";        /* end-of-line terminator */
388   mon2000_cmds.cmd_end = NULL;  /* optional command terminator */
389   mon2000_cmds.target = &mon2000_ops;   /* target operations */
390   mon2000_cmds.stopbits = SERIAL_1_STOPBITS;    /* number of stop bits */
391   mon2000_cmds.regnames = m32r_regnames;        /* registers names */
392   mon2000_cmds.magic = MONITOR_OPS_MAGIC;       /* magic */
393 }                               /* init_mon2000_cmds */
394
395 static void
396 mon2000_open (char *args, int from_tty)
397 {
398   monitor_open (args, &mon2000_cmds, from_tty);
399 }
400
401 /* Function: set_board_address
402    Tell the BootOne monitor what it's ethernet IP address is. */
403
404 static void
405 m32r_set_board_address (char *args, int from_tty)
406 {
407   int resp_len;
408   char buf[1024];
409
410   if (args && *args)
411     {
412       monitor_printf ("ulip %s\n", args);
413       resp_len = monitor_expect_prompt (buf, sizeof (buf));
414       /* now parse the result for success */
415     }
416   else
417     error ("Requires argument (IP address for M32R-EVA board)");
418 }
419
420 /* Function: set_server_address
421    Tell the BootOne monitor what gdb's ethernet IP address is. */
422
423 static void
424 m32r_set_server_address (char *args, int from_tty)
425 {
426   int resp_len;
427   char buf[1024];
428
429   if (args && *args)
430     {
431       monitor_printf ("uhip %s\n", args);
432       resp_len = monitor_expect_prompt (buf, sizeof (buf));
433       /* now parse the result for success */
434     }
435   else
436     error ("Requires argument (IP address of GDB's host computer)");
437 }
438
439 /* Function: set_download_path
440    Tell the BootOne monitor the default path for downloadable SREC files. */
441
442 static void
443 m32r_set_download_path (char *args, int from_tty)
444 {
445   int resp_len;
446   char buf[1024];
447
448   if (args && *args)
449     {
450       monitor_printf ("up %s\n", args);
451       resp_len = monitor_expect_prompt (buf, sizeof (buf));
452       /* now parse the result for success */
453     }
454   else
455     error ("Requires argument (default path for downloadable SREC files)");
456 }
457
458 static void
459 m32r_upload_command (char *args, int from_tty)
460 {
461   bfd *abfd;
462   asection *s;
463   time_t start_time, end_time;  /* for timing of download */
464   int resp_len, data_count = 0;
465   char buf[1024];
466   struct hostent *hostent;
467   struct in_addr inet_addr;
468
469   /* first check to see if there's an ethernet port! */
470   monitor_printf ("ust\r");
471   resp_len = monitor_expect_prompt (buf, sizeof (buf));
472   if (!strchr (buf, ':'))
473     error ("No ethernet connection!");
474
475   if (board_addr == 0)
476     {
477       /* scan second colon in the output from the "ust" command */
478       char *myIPaddress = strchr (strchr (buf, ':') + 1, ':') + 1;
479
480       while (isspace (*myIPaddress))
481         myIPaddress++;
482
483       if (!strncmp (myIPaddress, "0.0.", 4))    /* empty */
484         error
485           ("Please use 'set board-address' to set the M32R-EVA board's IP address.");
486       if (strchr (myIPaddress, '('))
487         *(strchr (myIPaddress, '(')) = '\0';    /* delete trailing junk */
488       board_addr = xstrdup (myIPaddress);
489     }
490   if (server_addr == 0)
491     {
492       buf[0] = 0;
493       gethostname (buf, sizeof (buf));
494       if (buf[0] != 0)
495         {
496           hostent = gethostbyname (buf);
497           if (hostent != 0)
498             {
499 #if 1
500               memcpy (&inet_addr.s_addr, hostent->h_addr,
501                       sizeof (inet_addr.s_addr));
502               server_addr = (char *) inet_ntoa (inet_addr);
503 #else
504               server_addr = (char *) inet_ntoa (hostent->h_addr);
505 #endif
506             }
507         }
508       if (server_addr == 0)     /* failed? */
509         error
510           ("Need to know gdb host computer's IP address (use 'set server-address')");
511     }
512
513   if (args == 0 || args[0] == 0)        /* no args: upload the current file */
514     args = get_exec_file (1);
515
516   if (args[0] != '/' && download_path == 0)
517     {
518       if (current_directory)
519         download_path = xstrdup (current_directory);
520       else
521         error
522           ("Need to know default download path (use 'set download-path')");
523     }
524
525   start_time = time (NULL);
526   monitor_printf ("uhip %s\r", server_addr);
527   resp_len = monitor_expect_prompt (buf, sizeof (buf)); /* parse result? */
528   monitor_printf ("ulip %s\r", board_addr);
529   resp_len = monitor_expect_prompt (buf, sizeof (buf)); /* parse result? */
530   if (args[0] != '/')
531     monitor_printf ("up %s\r", download_path);  /* use default path */
532   else
533     monitor_printf ("up\r");    /* rooted filename/path */
534   resp_len = monitor_expect_prompt (buf, sizeof (buf)); /* parse result? */
535
536   if (strrchr (args, '.') && !strcmp (strrchr (args, '.'), ".srec"))
537     monitor_printf ("ul %s\r", args);
538   else                          /* add ".srec" suffix */
539     monitor_printf ("ul %s.srec\r", args);
540   resp_len = monitor_expect_prompt (buf, sizeof (buf)); /* parse result? */
541
542   if (buf[0] == 0 || strstr (buf, "complete") == 0)
543     error
544       ("Upload file not found: %s.srec\nCheck IP addresses and download path.",
545        args);
546   else
547     printf_filtered (" -- Ethernet load complete.\n");
548
549   end_time = time (NULL);
550   abfd = bfd_openr (args, 0);
551   if (abfd != NULL)
552     {                           /* Download is done -- print section statistics */
553       if (bfd_check_format (abfd, bfd_object) == 0)
554         {
555           printf_filtered ("File is not an object file\n");
556         }
557       for (s = abfd->sections; s; s = s->next)
558         if (s->flags & SEC_LOAD)
559           {
560             bfd_size_type section_size = bfd_section_size (abfd, s);
561             bfd_vma section_base = bfd_section_lma (abfd, s);
562             unsigned int buffer;
563
564             data_count += section_size;
565
566             printf_filtered ("Loading section %s, size 0x%lx lma ",
567                              bfd_section_name (abfd, s), section_size);
568             print_address_numeric (section_base, 1, gdb_stdout);
569             printf_filtered ("\n");
570             gdb_flush (gdb_stdout);
571           }
572       /* Finally, make the PC point at the start address */
573       write_pc (bfd_get_start_address (abfd));
574       printf_filtered ("Start address 0x%lx\n", bfd_get_start_address (abfd));
575       print_transfer_performance (gdb_stdout, data_count, 0,
576                                   end_time - start_time);
577     }
578   inferior_ptid = null_ptid;    /* No process now */
579
580   /* This is necessary because many things were based on the PC at the
581      time that we attached to the monitor, which is no longer valid
582      now that we have loaded new code (and just changed the PC).
583      Another way to do this might be to call normal_stop, except that
584      the stack may not be valid, and things would get horribly
585      confused... */
586
587   clear_symtab_users ();
588 }
589
590 void
591 _initialize_m32r_rom (void)
592 {
593   /* Initialize m32r RevC monitor target */
594   init_m32r_cmds ();
595   init_monitor_ops (&m32r_ops);
596
597   m32r_ops.to_shortname = "m32r";
598   m32r_ops.to_longname = "m32r monitor";
599   m32r_ops.to_load = m32r_load_gen;     /* monitor lacks a download command */
600   m32r_ops.to_doc = "Debug via the m32r monitor.\n\
601 Specify the serial device it is connected to (e.g. /dev/ttya).";
602   m32r_ops.to_open = m32r_open;
603   add_target (&m32r_ops);
604
605   /* Initialize mon2000 monitor target */
606   init_mon2000_cmds ();
607   init_monitor_ops (&mon2000_ops);
608
609   mon2000_ops.to_shortname = "mon2000";
610   mon2000_ops.to_longname = "Mon2000 monitor";
611   mon2000_ops.to_load = m32r_load_gen;  /* monitor lacks a download command */
612   mon2000_ops.to_doc = "Debug via the Mon2000 monitor.\n\
613 Specify the serial device it is connected to (e.g. /dev/ttya).";
614   mon2000_ops.to_open = mon2000_open;
615   add_target (&mon2000_ops);
616
617   add_setshow_cmd ("download-path", class_obscure,
618                    var_string, &download_path,
619                    "Set the default path for downloadable SREC files.",
620                    "Show the default path for downloadable SREC files.",
621                    NULL, NULL, &setlist, &showlist);
622
623   add_setshow_cmd ("board-address", class_obscure,
624                    var_string, &board_addr,
625                    "Set IP address for M32R-EVA target board.",
626                    "Show IP address for M32R-EVA target board.",
627                    NULL, NULL, &setlist, &showlist);
628
629   add_setshow_cmd ("server-address", class_obscure,
630                    var_string, &server_addr,
631                    "Set IP address for download server (GDB's host computer).",
632                    "Show IP address for download server (GDB's host computer).",
633                    NULL, NULL, &setlist, &showlist);
634
635   add_com ("upload", class_obscure, m32r_upload_command,
636            "Upload the srec file via the monitor's Ethernet upload capability.");
637
638   add_com ("tload", class_obscure, m32r_load, "test upload command.");
639 }