]>
Commit | Line | Data |
---|---|---|
d95a8903 AC |
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 | ||
d95a8903 AC |
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)); | |
7e3dd49e AC |
166 | print_transfer_performance (gdb_stdout, data_count, 0, |
167 | end_time - start_time); | |
d95a8903 AC |
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) */ | |
7e3dd49e AC |
266 | ULONGEST stackmode, psw; |
267 | regcache_cooked_read_unsigned (current_regcache, PSW_REGNUM, &psw); | |
268 | stackmode = psw & 0x80; | |
d95a8903 AC |
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 | ||
d95a8903 AC |
401 | static void |
402 | m32r_upload_command (char *args, int from_tty) | |
403 | { | |
404 | bfd *abfd; | |
405 | asection *s; | |
406 | time_t start_time, end_time; /* for timing of download */ | |
407 | int resp_len, data_count = 0; | |
408 | char buf[1024]; | |
409 | struct hostent *hostent; | |
410 | struct in_addr inet_addr; | |
411 | ||
412 | /* first check to see if there's an ethernet port! */ | |
413 | monitor_printf ("ust\r"); | |
414 | resp_len = monitor_expect_prompt (buf, sizeof (buf)); | |
415 | if (!strchr (buf, ':')) | |
416 | error ("No ethernet connection!"); | |
417 | ||
418 | if (board_addr == 0) | |
419 | { | |
420 | /* scan second colon in the output from the "ust" command */ | |
421 | char *myIPaddress = strchr (strchr (buf, ':') + 1, ':') + 1; | |
422 | ||
423 | while (isspace (*myIPaddress)) | |
424 | myIPaddress++; | |
425 | ||
426 | if (!strncmp (myIPaddress, "0.0.", 4)) /* empty */ | |
427 | error | |
428 | ("Please use 'set board-address' to set the M32R-EVA board's IP address."); | |
429 | if (strchr (myIPaddress, '(')) | |
430 | *(strchr (myIPaddress, '(')) = '\0'; /* delete trailing junk */ | |
431 | board_addr = xstrdup (myIPaddress); | |
432 | } | |
433 | if (server_addr == 0) | |
434 | { | |
435 | buf[0] = 0; | |
436 | gethostname (buf, sizeof (buf)); | |
437 | if (buf[0] != 0) | |
d95a8903 | 438 | { |
880bc914 AC |
439 | hostent = gethostbyname (buf); |
440 | if (hostent != 0) | |
441 | { | |
d95a8903 | 442 | #if 1 |
880bc914 AC |
443 | memcpy (&inet_addr.s_addr, hostent->h_addr, |
444 | sizeof (inet_addr.s_addr)); | |
445 | server_addr = (char *) inet_ntoa (inet_addr); | |
d95a8903 | 446 | #else |
880bc914 | 447 | server_addr = (char *) inet_ntoa (hostent->h_addr); |
d95a8903 | 448 | #endif |
880bc914 | 449 | } |
d95a8903 AC |
450 | } |
451 | if (server_addr == 0) /* failed? */ | |
452 | error | |
453 | ("Need to know gdb host computer's IP address (use 'set server-address')"); | |
454 | } | |
455 | ||
456 | if (args == 0 || args[0] == 0) /* no args: upload the current file */ | |
457 | args = get_exec_file (1); | |
458 | ||
459 | if (args[0] != '/' && download_path == 0) | |
460 | { | |
461 | if (current_directory) | |
462 | download_path = xstrdup (current_directory); | |
463 | else | |
464 | error | |
465 | ("Need to know default download path (use 'set download-path')"); | |
466 | } | |
467 | ||
468 | start_time = time (NULL); | |
469 | monitor_printf ("uhip %s\r", server_addr); | |
470 | resp_len = monitor_expect_prompt (buf, sizeof (buf)); /* parse result? */ | |
471 | monitor_printf ("ulip %s\r", board_addr); | |
472 | resp_len = monitor_expect_prompt (buf, sizeof (buf)); /* parse result? */ | |
473 | if (args[0] != '/') | |
474 | monitor_printf ("up %s\r", download_path); /* use default path */ | |
475 | else | |
476 | monitor_printf ("up\r"); /* rooted filename/path */ | |
477 | resp_len = monitor_expect_prompt (buf, sizeof (buf)); /* parse result? */ | |
478 | ||
479 | if (strrchr (args, '.') && !strcmp (strrchr (args, '.'), ".srec")) | |
480 | monitor_printf ("ul %s\r", args); | |
481 | else /* add ".srec" suffix */ | |
482 | monitor_printf ("ul %s.srec\r", args); | |
483 | resp_len = monitor_expect_prompt (buf, sizeof (buf)); /* parse result? */ | |
484 | ||
485 | if (buf[0] == 0 || strstr (buf, "complete") == 0) | |
486 | error | |
487 | ("Upload file not found: %s.srec\nCheck IP addresses and download path.", | |
488 | args); | |
489 | else | |
490 | printf_filtered (" -- Ethernet load complete.\n"); | |
491 | ||
492 | end_time = time (NULL); | |
493 | abfd = bfd_openr (args, 0); | |
494 | if (abfd != NULL) | |
495 | { /* Download is done -- print section statistics */ | |
496 | if (bfd_check_format (abfd, bfd_object) == 0) | |
497 | { | |
498 | printf_filtered ("File is not an object file\n"); | |
499 | } | |
500 | for (s = abfd->sections; s; s = s->next) | |
501 | if (s->flags & SEC_LOAD) | |
502 | { | |
503 | bfd_size_type section_size = bfd_section_size (abfd, s); | |
504 | bfd_vma section_base = bfd_section_lma (abfd, s); | |
505 | unsigned int buffer; | |
506 | ||
507 | data_count += section_size; | |
508 | ||
509 | printf_filtered ("Loading section %s, size 0x%lx lma ", | |
510 | bfd_section_name (abfd, s), section_size); | |
511 | print_address_numeric (section_base, 1, gdb_stdout); | |
512 | printf_filtered ("\n"); | |
513 | gdb_flush (gdb_stdout); | |
514 | } | |
515 | /* Finally, make the PC point at the start address */ | |
516 | write_pc (bfd_get_start_address (abfd)); | |
d95a8903 | 517 | printf_filtered ("Start address 0x%lx\n", bfd_get_start_address (abfd)); |
7e3dd49e AC |
518 | print_transfer_performance (gdb_stdout, data_count, 0, |
519 | end_time - start_time); | |
d95a8903 AC |
520 | } |
521 | inferior_ptid = null_ptid; /* No process now */ | |
522 | ||
523 | /* This is necessary because many things were based on the PC at the | |
524 | time that we attached to the monitor, which is no longer valid | |
525 | now that we have loaded new code (and just changed the PC). | |
526 | Another way to do this might be to call normal_stop, except that | |
527 | the stack may not be valid, and things would get horribly | |
528 | confused... */ | |
529 | ||
530 | clear_symtab_users (); | |
531 | } | |
532 | ||
533 | void | |
534 | _initialize_m32r_rom (void) | |
535 | { | |
536 | /* Initialize m32r RevC monitor target */ | |
537 | init_m32r_cmds (); | |
538 | init_monitor_ops (&m32r_ops); | |
539 | ||
540 | m32r_ops.to_shortname = "m32r"; | |
541 | m32r_ops.to_longname = "m32r monitor"; | |
542 | m32r_ops.to_load = m32r_load_gen; /* monitor lacks a download command */ | |
543 | m32r_ops.to_doc = "Debug via the m32r monitor.\n\ | |
544 | Specify the serial device it is connected to (e.g. /dev/ttya)."; | |
545 | m32r_ops.to_open = m32r_open; | |
546 | add_target (&m32r_ops); | |
547 | ||
548 | /* Initialize mon2000 monitor target */ | |
549 | init_mon2000_cmds (); | |
550 | init_monitor_ops (&mon2000_ops); | |
551 | ||
552 | mon2000_ops.to_shortname = "mon2000"; | |
553 | mon2000_ops.to_longname = "Mon2000 monitor"; | |
554 | mon2000_ops.to_load = m32r_load_gen; /* monitor lacks a download command */ | |
555 | mon2000_ops.to_doc = "Debug via the Mon2000 monitor.\n\ | |
556 | Specify the serial device it is connected to (e.g. /dev/ttya)."; | |
557 | mon2000_ops.to_open = mon2000_open; | |
558 | add_target (&mon2000_ops); | |
559 | ||
7e3dd49e AC |
560 | add_setshow_cmd ("download-path", class_obscure, |
561 | var_string, &download_path, | |
562 | "Set the default path for downloadable SREC files.", | |
563 | "Show the default path for downloadable SREC files.", | |
564 | NULL, NULL, &setlist, &showlist); | |
565 | ||
566 | add_setshow_cmd ("board-address", class_obscure, | |
567 | var_string, &board_addr, | |
568 | "Set IP address for M32R-EVA target board.", | |
569 | "Show IP address for M32R-EVA target board.", | |
570 | NULL, NULL, &setlist, &showlist); | |
571 | ||
572 | add_setshow_cmd ("server-address", class_obscure, | |
573 | var_string, &server_addr, | |
574 | "Set IP address for download server (GDB's host computer).", | |
575 | "Show IP address for download server (GDB's host computer).", | |
576 | NULL, NULL, &setlist, &showlist); | |
d95a8903 AC |
577 | |
578 | add_com ("upload", class_obscure, m32r_upload_command, | |
579 | "Upload the srec file via the monitor's Ethernet upload capability."); | |
580 | ||
581 | add_com ("tload", class_obscure, m32r_load, "test upload command."); | |
582 | } |