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