1 /* Generic remote debugging interface for simulators.
2 Copyright 1993 Free Software Foundation, Inc.
3 Contributed by Cygnus Support. Hacked from Steve Chamberlain's Z8000 work
4 by Doug Evans. (dje@cygnus.com).
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
37 /* Naming conventions:
39 sim_xxx are internal objects that describe top level interfaces to the
42 simif_xxx are external counterparts to the sim_xxx objects that must be
43 provided by the simulator (simif for SIMulator InterFace, duh...).
45 A complete list of them is:
47 --- Fetch one register and store the raw value in BUF.
49 int simif_fetch_register (int regno, char *buf);
51 --- Store VAL in one register.
53 int simif_store_register (int regno, char *val);
55 --- Complete terminate the simulator. This includes freeing all memory,
56 closing all open files, and releasing all mmap'd memory.
58 int simif_kill (void);
60 --- Load program PROG into the simulator.
62 int simif_load (bfd *abfd, char *prog);
64 --- Set the arguments and environment for the program loaded into the
65 simulator. ARGV and ENV are NULL terminated lists of pointers.
67 int simif_set_args (char **argv, char **env);
69 --- Initialize the simulator. This function is called when the simulator
70 is selected from the command line. ARGS is passed from the command line
71 and can be used to select whatever run time options the simulator provides.
72 ARGS is the raw character string and must be parsed by the simulator.
74 int simif_open (char *args);
76 --- Start running the program, or resume it after a breakpoint.
77 FIXME: What are A and B?
79 int simif_resume (int a, int b);
81 --- Fetch the reason why the program stopped running (breakpoint, signal,
84 WAITTYPE simif_stop_signal (void);
86 --- Write some data into the program's memory.
87 Result is 0 for success, nonzero for failure.
89 int simif_write (CORE_ADDR memaddr, char *myaddr, int len);
91 --- Read some data from the program's memory.
92 Result is 0 for success, nonzero for failure.
94 int simif_read (CORE_ADDR memaddr, char *myaddr, int len);
97 /* Forward data declarations */
98 extern struct target_ops sim_ops
;
100 int sim_verbose
= 0; /* available to the simulator to use */
102 static int program_loaded
= 0;
104 static void dump_mem ();
107 sim_fetch_register (regno
)
113 printf_filtered ("sim_fetch_register: %d\n", regno
);
114 /* FIXME: Where did the 16 come from and what does it need to be? */
115 for (regno
= 0; regno
< 16; regno
++)
116 sim_fetch_register (regno
);
120 char buf
[MAX_REGISTER_RAW_SIZE
];
122 simif_fetch_register (regno
, buf
);
123 supply_register (regno
, buf
);
126 printf_filtered ("sim_fetch_register: %d", regno
);
127 dump_mem (buf
, sizeof (REGISTER_TYPE
));
133 sim_store_register (regno
)
139 printf_filtered ("sim_store_register: %d\n", regno
);
141 for (regno
= 0; regno
< 16; regno
++)
142 sim_store_register (regno
);
146 char value
[sizeof (REGISTER_TYPE
)];
148 read_register_gen (regno
, value
);
149 SWAP_TARGET_AND_HOST (value
, sizeof (REGISTER_TYPE
));
150 simif_store_register (regno
, value
);
153 printf_filtered ("sim_store_register: %d", regno
);
154 dump_mem (value
, sizeof (REGISTER_TYPE
));
160 sim_kill (arg
,from_tty
)
165 printf_filtered ("sim_kill: arg \"%s\"\n", arg
);
167 simif_kill (); /* close fd's, remove mappings */
171 /* Load program PROG into the sim. */
174 sim_load (prog
, fromtty
)
181 printf_filtered ("sim_load: prog \"%s\"\n", prog
);
185 abfd
= bfd_openr (prog
, (char *) 0);
188 error ("Unable to open file %s.", prog
);
190 if (bfd_check_format (abfd
, bfd_object
) ==0)
191 error ("File is not an object file.");
193 if (simif_load (abfd
, prog
) != 0)
198 simif_set_pc (abfd
->start_address
);
201 /* This is called not only when we first attach, but also when the
202 user types "run" after having attached. */
205 sim_create_inferior (exec_file
, args
, env
)
211 char *arg_buf
,**argv
;
213 if (! program_loaded
)
214 error ("No program loaded.");
217 printf_filtered ("sim_create_inferior: exec_file \"%s\", args \"%s\"\n",
220 if (exec_file
== 0 || exec_bfd
== 0)
221 error ("No exec file specified.");
223 entry_pt
= (int) bfd_get_start_address (exec_bfd
);
225 sim_kill (NULL
, NULL
);
226 remove_breakpoints ();
227 init_wait_for_inferior ();
229 len
= 5 + strlen (exec_file
) + 1 + strlen (args
) + 1 + /*slop*/ 10;
230 arg_buf
= (char *) alloca (len
);
232 strcat (arg_buf
, exec_file
);
233 strcat (arg_buf
, " ");
234 strcat (arg_buf
, args
);
235 argv
= buildargv (arg_buf
);
236 make_cleanup (freeargv
, (char *) argv
);
237 simif_set_args (argv
, env
);
240 insert_breakpoints (); /* Needed to get correct instruction in cache */
241 proceed (entry_pt
, -1, 0);
244 /* Called when selecting the simulator. EG: (gdb) target sim name. */
247 sim_open (args
, from_tty
)
252 printf_filtered ("sim_open: args \"%s\"\n", args
);
254 if (simif_open (args
) != 0)
256 error ("Unable to initialize simulator (insufficient memory?).");
260 push_target (&sim_ops
);
261 target_fetch_registers (-1);
263 printf_filtered ("Connected to the simulator.\n");
266 /* Close out all files and local state before this target loses control. */
273 printf_filtered ("sim_close: quitting %d\n", quitting
);
277 /* FIXME: Need to call simif_close() to close all files and
278 delete all mappings. */
281 /* Terminate the open connection to the remote debugger.
282 Use this when you want to detach and do something else
286 sim_detach (args
,from_tty
)
291 printf_filtered ("sim_detach: args \"%s\"\n", args
);
293 pop_target (); /* calls sim_close to do the real work */
295 printf_filtered ("Ending simulator %s debugging\n", target_shortname
);
298 /* Tell the remote machine to resume. */
299 /* FIXME: What are A and B? */
305 printf_filtered ("sim_resume: %d/%d\n", a
, b
);
310 /* Wait until the remote machine stops, then return,
311 storing status in STATUS just as `wait' would. */
318 printf_filtered ("sim_wait: ");
320 *status
= simif_stop_signal ();
322 WSETSTOP (*status
, simif_stop_signal ());
325 printf_filtered ("status %d\n", *status
);
329 /* Get ready to modify the registers array. On machines which store
330 individual registers, this doesn't need to do anything. On machines
331 which store all the registers in one fell swoop, this makes sure
332 that registers contains all the registers from the program being
336 sim_prepare_to_store ()
338 /* Do nothing, since we can store individual regs */
342 sim_xfer_inferior_memory (memaddr
, myaddr
, len
, write
, target
)
347 struct target_ops
*target
; /* ignored */
351 printf_filtered ("sim_xfer_inferior_memory: myaddr 0x%x, memaddr 0x%x, len %d, write %d\n",
352 myaddr
, memaddr
, len
, write
);
353 if (sim_verbose
&& write
)
354 dump_mem(myaddr
, len
);
357 if (! program_loaded
)
358 error ("No program loaded.");
362 len
= simif_write (memaddr
, myaddr
, len
);
366 len
= simif_read (memaddr
, myaddr
, len
);
367 if (sim_verbose
&& len
> 0)
368 dump_mem(myaddr
, len
);
376 char *file
= "nothing";
379 file
= bfd_get_filename (exec_bfd
);
382 printf_filtered ("sim_files_info: file \"%s\"\n", file
);
385 printf_filtered ("\tAttached to %s running program %s\n",
386 target_shortname
, file
);
389 /* Clear the sims notion of what the break points are */
394 printf_filtered ("sim_mourn:\n");
396 remove_breakpoints ();
397 generic_mourn_inferior ();
400 /* Define the target subroutine names */
402 struct target_ops sim_ops
=
407 0, sim_detach
, sim_resume
, sim_wait
, /* attach */
408 sim_fetch_register
, sim_store_register
,
409 sim_prepare_to_store
,
410 sim_xfer_inferior_memory
,
412 0, 0, /* Breakpoints */
413 0, 0, 0, 0, 0, /* Terminal handling */
414 sim_kill
, /* FIXME, kill */
416 0, /* lookup_symbol */
417 sim_create_inferior
, /* create_inferior */
418 sim_mourn
, /* mourn_inferior FIXME */
420 0, /* notice_signals */
421 process_stratum
, 0, /* next */
422 1, 1, 1, 1, 1, /* all mem, mem, stack, regs, exec */
423 0, 0, /* Section pointers */
424 OPS_MAGIC
, /* Always the last thing */
430 sim_verbose
= ! sim_verbose
;
432 printf_filtered ("Snoop enabled\n");
434 printf_filtered ("Snoop disabled\n");
438 /***********************************************************************/
441 _initialize_remote_sim ()
443 add_target (&sim_ops
);
444 add_com ("snoop", class_obscure
, sim_snoop
,
445 "Show what commands are going to the simulator");
455 if (len
== 8 || len
== 4)
458 memcpy (l
, buf
, len
);
459 printf_filtered ("\t0x%x", l
[0]);
460 printf_filtered (len
== 8 ? " 0x%x\n" : "\n", l
[1]);
465 printf_filtered ("\t");
466 for (i
= 0; i
< len
; i
++)
467 printf_filtered ("0x%x ", buf
[i
]);
468 printf_filtered ("\n");
This page took 0.044209 seconds and 4 git commands to generate.