1 /* Remote debugging interface for SPARC64 Simulator.
2 Copyright 1992 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 simif_xxx are internal objects that describe top level interfaces to the
40 simulator (simif for SIMulator InterFace).
42 sim_xxx are external counterparts to the simif_xxx objects that must be
43 provided by the simulator. */
45 /* Forward data declarations */
46 extern struct target_ops simif_ops
;
48 int simif_verbose
= 0; /* available to the simulator to use */
50 static int program_loaded
= 0;
52 static void dump_mem ();
55 simif_fetch_register (regno
)
61 printf_filtered ("simif_fetch_register: %d\n", regno
);
62 for (regno
= 0; regno
< 16; regno
++)
63 simif_fetch_register (regno
);
67 char buf
[MAX_REGISTER_RAW_SIZE
];
69 sim_fetch_register (regno
, buf
);
70 supply_register (regno
, buf
);
73 printf_filtered ("simif_fetch_register: %d", regno
);
74 dump_mem (buf
, sizeof (REGISTER_TYPE
));
80 simif_store_register (regno
)
86 printf_filtered ("simif_store_register: %d\n", regno
);
87 for (regno
= 0; regno
< 16; regno
++)
88 simif_store_register (regno
);
92 char value
[sizeof (REGISTER_TYPE
)];
94 read_register_gen (regno
, value
);
95 SWAP_TARGET_AND_HOST (value
, sizeof (REGISTER_TYPE
));
96 sim_store_register (regno
, value
);
99 printf_filtered ("simif_store_register: %d", regno
);
100 dump_mem (value
, sizeof (REGISTER_TYPE
));
106 simif_kill (arg
,from_tty
)
111 printf_filtered ("simif_kill: arg \"%s\"\n", arg
);
113 sim_kill (); /* close fd's, remove mappings */
117 /* Download a file specified in 'args', to the sim. */
120 simif_load (args
, fromtty
)
127 printf_filtered ("simif_load: args \"%s\"\n", args
);
131 /* FIXME: a.out should be a config parm and/or an arg. */
132 abfd
= bfd_openr (args
,"a.out-sunos-big");
135 error ("Unable to open file %s.", args
);
137 if (bfd_check_format (abfd
, bfd_object
) ==0)
138 error ("File is not an object file.");
140 if (sim_load (abfd
, args
) != 0)
145 /* It is sim_load()'s job to set this. */
146 /*sim_set_pc (abfd->start_address); - can't do 'cus we use RMTVaddr */
149 /* This is called not only when we first attach, but also when the
150 user types "run" after having attached. */
153 simif_create_inferior (exec_file
, args
, env
)
159 char *arg_buf
,**argv
;
161 if (! program_loaded
)
162 error ("No program loaded.");
165 printf_filtered ("simif_create_inferior: exec_file \"%s\", args \"%s\"\n",
168 if (exec_file
== 0 || exec_bfd
== 0)
169 error ("No exec file specified.");
171 entry_pt
= (int) bfd_get_start_address (exec_bfd
);
173 simif_kill (NULL
, NULL
);
174 remove_breakpoints ();
175 init_wait_for_inferior ();
177 len
= 5 + strlen (exec_file
) + 1 + strlen (args
) + 1 + /*slop*/ 10;
178 arg_buf
= (char *) alloca (len
);
180 strcat (arg_buf
, exec_file
);
181 strcat (arg_buf
, " ");
182 strcat (arg_buf
, args
);
183 argv
= buildargv (arg_buf
);
184 make_cleanup (freeargv
, (char *) argv
);
185 sim_set_args (argv
, env
);
188 insert_breakpoints (); /* Needed to get correct instruction in cache */
189 proceed (entry_pt
, -1, 0);
192 /* Called when selecting the simulator. EG: (gdb) target sim name.
193 NAME unused at present. */
196 simif_open (name
, from_tty
)
201 printf_filtered ("simif_open: name \"%s\"\n", name
);
203 if (sim_init (name
) != 0)
205 error ("Unable to initialize simulator (insufficient memory?).");
209 push_target (&simif_ops
);
210 target_fetch_registers (-1);
212 printf_filtered ("Connected to the simulator.\n");
215 /* Close out all files and local state before this target loses control. */
218 simif_close (quitting
)
222 printf_filtered ("simif_close: quitting %d\n", quitting
);
226 /* FIXME: Need to call sim_close() to close all files and
227 delete all mappings. */
230 /* Terminate the open connection to the remote debugger.
231 Use this when you want to detach and do something else
235 simif_detach (args
,from_tty
)
240 printf_filtered ("simif_detach: args \"%s\"\n", args
);
242 pop_target (); /* calls simif_close to do the real work */
244 printf_filtered ("Ending simulator %s debugging\n", target_shortname
);
247 /* Tell the remote machine to resume. */
248 /* FIXME: What are A and B? */
254 printf_filtered ("simif_resume: %d/%d\n", a
, b
);
259 /* Wait until the remote machine stops, then return,
260 storing status in STATUS just as `wait' would. */
267 printf_filtered ("simif_wait: ");
269 *status
= sim_stop_signal ();
271 WSETSTOP (*status
, sim_stop_signal ());
274 printf_filtered ("status %d\n", *status
);
278 /* Get ready to modify the registers array. On machines which store
279 individual registers, this doesn't need to do anything. On machines
280 which store all the registers in one fell swoop, this makes sure
281 that registers contains all the registers from the program being
285 simif_prepare_to_store ()
287 /* Do nothing, since we can store individual regs */
291 simif_xfer_inferior_memory (memaddr
, myaddr
, len
, write
, target
)
296 struct target_ops
*target
; /* ignored */
300 printf_filtered ("simif_xfer_inferior_memory: myaddr 0x%x, memaddr 0x%x, len %d, write %d\n",
301 myaddr
, memaddr
, len
, write
);
302 if (simif_verbose
&& write
)
303 dump_mem(myaddr
, len
);
306 if (! program_loaded
)
307 error ("No program loaded.");
311 len
= sim_write (memaddr
, myaddr
, len
);
315 len
= sim_read (memaddr
, myaddr
, len
);
316 if (simif_verbose
&& len
> 0)
317 dump_mem(myaddr
, len
);
325 char *file
= "nothing";
328 file
= bfd_get_filename (exec_bfd
);
331 printf_filtered ("simif_files_info: file \"%s\"\n", file
);
334 printf_filtered ("\tAttached to %s running program %s\n",
335 target_shortname
, file
);
338 /* Clear the sims notion of what the break points are */
343 printf_filtered ("simif_mourn:\n");
345 remove_breakpoints ();
346 generic_mourn_inferior ();
349 /* Define the target subroutine names */
351 struct target_ops simif_ops
=
353 "sim", "SPARC64 Simulator",
354 "Use the SPARC64 Simulator",
355 simif_open
, simif_close
,
356 0, simif_detach
, simif_resume
, simif_wait
, /* attach */
357 simif_fetch_register
, simif_store_register
,
358 simif_prepare_to_store
,
359 simif_xfer_inferior_memory
,
361 0, 0, /* Breakpoints */
362 0, 0, 0, 0, 0, /* Terminal handling */
363 simif_kill
, /* FIXME, kill */
365 0, /* lookup_symbol */
366 simif_create_inferior
, /* create_inferior */
367 simif_mourn
, /* mourn_inferior FIXME */
369 0, /* notice_signals */
370 process_stratum
, 0, /* next */
371 1, 1, 1, 1, 1, /* all mem, mem, stack, regs, exec */
372 0, 0, /* Section pointers */
373 OPS_MAGIC
, /* Always the last thing */
379 simif_verbose
= ! simif_verbose
;
381 printf_filtered ("Snoop enabled\n");
383 printf_filtered ("Snoop disabled\n");
387 /***********************************************************************/
390 _initialize_remote_sim ()
392 add_target (&simif_ops
);
393 add_com ("snoop", class_obscure
, simif_snoop
,
394 "Show what commands are going to the simulator");
404 if (len
== 8 || len
== 4)
407 memcpy (l
, buf
, len
);
408 printf_filtered ("\t0x%x", l
[0]);
409 printf_filtered (len
== 8 ? " 0x%x\n" : "\n", l
[1]);
414 printf_filtered ("\t");
415 for (i
= 0; i
< len
; i
++)
416 printf_filtered ("0x%x ", buf
[i
]);
417 printf_filtered ("\n");