* printcmd.c (disassemble_command): Adjust low function bound
[deliverable/binutils-gdb.git] / gdb / remote-sim.c
CommitLineData
40b92220 1/* Generic remote debugging interface for simulators.
286f83b4 2 Copyright 1993, 1994, 1996, 1997 Free Software Foundation, Inc.
40b92220 3 Contributed by Cygnus Support.
47424e79 4 Steve Chamberlain (sac@cygnus.com).
ec25d19b
SC
5
6This file is part of GDB.
7
8This program is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2 of the License, or
11(at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
6c9638b4 20Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
ec25d19b
SC
21
22#include "defs.h"
23#include "inferior.h"
24#include "wait.h"
25#include "value.h"
2b576293 26#include "gdb_string.h"
ec25d19b
SC
27#include <ctype.h>
28#include <fcntl.h>
29#include <signal.h>
30#include <setjmp.h>
31#include <errno.h>
32#include "terminal.h"
33#include "target.h"
34#include "gdbcore.h"
4da8b2a5 35#include "callback.h"
59c2be48 36#include "remote-sim.h"
f1e7bafc 37#include "remote-utils.h"
40b92220 38
8501c742
SG
39/* Prototypes */
40
41static void dump_mem PARAMS ((char *buf, int len));
42
4da8b2a5
DE
43static void init_callbacks PARAMS ((void));
44
45static void end_callbacks PARAMS ((void));
46
47static int gdb_os_write_stdout PARAMS ((host_callback *, const char *, int));
48
48ae8057
AC
49static void gdb_os_flush_stdout PARAMS ((host_callback *));
50
51static int gdb_os_write_stderr PARAMS ((host_callback *, const char *, int));
52
53static void gdb_os_flush_stderr PARAMS ((host_callback *));
54
8517f62b
AC
55static int gdb_os_poll_quit PARAMS ((host_callback *));
56
48ae8057 57/* printf_filtered is depreciated */
4da8b2a5
DE
58static void gdb_os_printf_filtered PARAMS ((host_callback *, const char *, ...));
59
8902803f 60static void gdb_os_vprintf_filtered PARAMS ((host_callback *, const char *, va_list));
48ae8057 61
8902803f 62static void gdb_os_evprintf_filtered PARAMS ((host_callback *, const char *, va_list));
48ae8057 63
163a75af
DE
64static void gdb_os_error PARAMS ((host_callback *, const char *, ...));
65
8501c742
SG
66static void gdbsim_fetch_register PARAMS ((int regno));
67
68static void gdbsim_store_register PARAMS ((int regno));
69
70static void gdbsim_kill PARAMS ((void));
71
72static void gdbsim_load PARAMS ((char *prog, int fromtty));
73
74static void gdbsim_create_inferior PARAMS ((char *exec_file, char *args, char **env));
75
76static void gdbsim_open PARAMS ((char *args, int from_tty));
77
78static void gdbsim_close PARAMS ((int quitting));
79
80static void gdbsim_detach PARAMS ((char *args, int from_tty));
81
82static void gdbsim_resume PARAMS ((int pid, int step, enum target_signal siggnal));
83
84static int gdbsim_wait PARAMS ((int pid, struct target_waitstatus *status));
85
86static void gdbsim_prepare_to_store PARAMS ((void));
87
88static int gdbsim_xfer_inferior_memory PARAMS ((CORE_ADDR memaddr,
89 char *myaddr, int len,
90 int write,
91 struct target_ops *target));
92
93static void gdbsim_files_info PARAMS ((struct target_ops *target));
94
95static void gdbsim_mourn_inferior PARAMS ((void));
96
8517f62b
AC
97static void gdbsim_stop PARAMS ((void));
98
8501c742
SG
99static void simulator_command PARAMS ((char *args, int from_tty));
100
40b92220
JK
101/* Naming convention:
102
103 sim_* are the interface to the simulator (see remote-sim.h).
40b92220 104 gdbsim_* are stuff which is internal to gdb. */
ec25d19b
SC
105
106/* Forward data declarations */
40b92220 107extern struct target_ops gdbsim_ops;
ec25d19b 108
40b92220
JK
109static int program_loaded = 0;
110
d9ad8adf
DE
111/* We must keep track of whether the simulator has been opened or not because
112 GDB can call a target's close routine twice, but sim_close doesn't allow
286f83b4
DE
113 this. We also need to record the result of sim_open so we can pass it
114 back to the other sim_foo routines. */
115static SIM_DESC gdbsim_desc = 0;
d9ad8adf 116
40b92220
JK
117static void
118dump_mem (buf, len)
119 char *buf;
ec25d19b
SC
120 int len;
121{
40b92220
JK
122 if (len <= 8)
123 {
124 if (len == 8 || len == 4)
125 {
126 long l[2];
127 memcpy (l, buf, len);
128 printf_filtered ("\t0x%x", l[0]);
129 printf_filtered (len == 8 ? " 0x%x\n" : "\n", l[1]);
130 }
131 else
132 {
133 int i;
134 printf_filtered ("\t");
135 for (i = 0; i < len; i++)
136 printf_filtered ("0x%x ", buf[i]);
137 printf_filtered ("\n");
138 }
139 }
140}
141
4da8b2a5
DE
142static host_callback gdb_callback;
143static int callbacks_initialized = 0;
144
145/* Initialize gdb_callback. */
146
147static void
148init_callbacks ()
149{
150 if (! callbacks_initialized)
151 {
152 gdb_callback = default_callback;
163a75af
DE
153 gdb_callback.init (&gdb_callback);
154 gdb_callback.write_stdout = gdb_os_write_stdout;
48ae8057
AC
155 gdb_callback.flush_stdout = gdb_os_flush_stdout;
156 gdb_callback.write_stderr = gdb_os_write_stderr;
157 gdb_callback.flush_stderr = gdb_os_flush_stderr;
163a75af 158 gdb_callback.printf_filtered = gdb_os_printf_filtered;
48ae8057
AC
159 gdb_callback.vprintf_filtered = gdb_os_vprintf_filtered;
160 gdb_callback.evprintf_filtered = gdb_os_evprintf_filtered;
1387cba1 161 gdb_callback.error = gdb_os_error;
8517f62b
AC
162 gdb_callback.poll_quit = gdb_os_poll_quit;
163 gdb_callback.magic = HOST_CALLBACK_MAGIC;
286f83b4 164 sim_set_callbacks (gdbsim_desc, &gdb_callback);
8517f62b 165
4da8b2a5
DE
166 callbacks_initialized = 1;
167 }
168}
169
170/* Release callbacks (free resources used by them). */
171
172static void
173end_callbacks ()
174{
175 if (callbacks_initialized)
176 {
177 gdb_callback.shutdown (&gdb_callback);
178 callbacks_initialized = 0;
179 }
180}
181
182/* GDB version of os_write_stdout callback. */
183
184static int
185gdb_os_write_stdout (p, buf, len)
186 host_callback *p;
187 const char *buf;
188 int len;
189{
190 int i;
191 char b[2];
192
193 for (i = 0; i < len; i++)
194 {
195 b[0] = buf[i];
196 b[1] = 0;
197 if (target_output_hook)
198 target_output_hook (b);
199 else
200 fputs_filtered (b, gdb_stdout);
201 }
202 return len;
203}
204
48ae8057
AC
205/* GDB version of os_flush_stdout callback. */
206
207static void
208gdb_os_flush_stdout (p)
209 host_callback *p;
210{
211 gdb_flush (gdb_stdout);
212}
213
214/* GDB version of os_write_stderr callback. */
215
216static int
217gdb_os_write_stderr (p, buf, len)
218 host_callback *p;
219 const char *buf;
220 int len;
221{
222 int i;
223 char b[2];
224
225 for (i = 0; i < len; i++)
226 {
227 b[0] = buf[i];
228 b[1] = 0;
229 if (target_output_hook)
230 target_output_hook (b);
231 else
232 fputs_filtered (b, gdb_stderr);
233 }
234 return len;
235}
236
237/* GDB version of os_flush_stderr callback. */
238
239static void
240gdb_os_flush_stderr (p)
241 host_callback *p;
242{
243 gdb_flush (gdb_stderr);
244}
245
8517f62b
AC
246/* GDB version of os_poll_quit callback.
247 Taken from gdb/util.c - should be in a library */
248
249static int
250gdb_os_poll_quit (p)
251 host_callback *p;
252{
253 notice_quit ();
254 if (quit_flag)
255 {
256 quit_flag = 0; /* we've stolen it */
257 return 1;
258 }
259 else if (immediate_quit)
260 {
261 return 1;
262 }
263 return 0;
264}
265
4da8b2a5
DE
266/* GDB version of printf_filtered callback. */
267
268/* VARARGS */
269static void
270#ifdef ANSI_PROTOTYPES
271gdb_os_printf_filtered (host_callback *p, const char *format, ...)
272#else
273gdb_os_printf_filtered (p, va_alist)
274 host_callback *p;
275 va_dcl
276#endif
277{
278 va_list args;
279#ifdef ANSI_PROTOTYPES
280 va_start (args, format);
281#else
282 char *format;
283
284 va_start (args);
285 format = va_arg (args, char *);
286#endif
287
163a75af 288 vfprintf_filtered (gdb_stdout, format, args);
4da8b2a5
DE
289
290 va_end (args);
291}
292
48ae8057
AC
293/* GDB version of error vprintf_filtered. */
294
295/* VARARGS */
296static void
297#ifdef ANSI_PROTOTYPES
8902803f 298gdb_os_vprintf_filtered (host_callback *p, const char *format, va_list ap)
48ae8057 299#else
011fa671 300gdb_os_vprintf_filtered (p, format, ap)
48ae8057 301 host_callback *p;
011fa671 302 char *format;
8902803f 303 va_list ap;
48ae8057
AC
304#endif
305{
8902803f 306 vfprintf_filtered (gdb_stdout, format, ap);
48ae8057
AC
307}
308
309/* GDB version of error evprintf_filtered. */
310
311/* VARARGS */
312static void
313#ifdef ANSI_PROTOTYPES
8902803f 314gdb_os_evprintf_filtered (host_callback *p, const char *format, va_list ap)
48ae8057 315#else
011fa671 316gdb_os_evprintf_filtered (p, format, ap)
48ae8057 317 host_callback *p;
011fa671 318 char *format;
8902803f 319 va_list ap;
48ae8057
AC
320#endif
321{
8902803f 322 vfprintf_filtered (gdb_stderr, format, ap);
48ae8057
AC
323}
324
163a75af
DE
325/* GDB version of error callback. */
326
327/* VARARGS */
328static void
329#ifdef ANSI_PROTOTYPES
330gdb_os_error (host_callback *p, const char *format, ...)
331#else
332gdb_os_error (p, va_alist)
333 host_callback *p;
334 va_dcl
335#endif
336{
337 if (error_hook)
338 (*error_hook) ();
339 else
340 {
341 va_list args;
342#ifdef ANSI_PROTOTYPES
343 va_start (args, format);
344#else
345 char *format;
346
347 va_start (args);
348 format = va_arg (args, char *);
349#endif
350
351 error_begin ();
352 vfprintf_filtered (gdb_stderr, format, args);
353 fprintf_filtered (gdb_stderr, "\n");
354 va_end (args);
355 return_to_top_level (RETURN_ERROR);
356 }
357}
358
40b92220
JK
359static void
360gdbsim_fetch_register (regno)
361int regno;
362{
363 if (regno == -1)
364 {
365 for (regno = 0; regno < NUM_REGS; regno++)
366 gdbsim_fetch_register (regno);
367 }
368 else
369 {
370 char buf[MAX_REGISTER_RAW_SIZE];
371
286f83b4 372 sim_fetch_register (gdbsim_desc, regno, buf);
40b92220
JK
373 supply_register (regno, buf);
374 if (sr_get_debug ())
375 {
376 printf_filtered ("gdbsim_fetch_register: %d", regno);
377 /* FIXME: We could print something more intelligible. */
378 dump_mem (buf, REGISTER_RAW_SIZE (regno));
379 }
380 }
ec25d19b
SC
381}
382
6b009ef6 383
a944e79a 384static void
40b92220 385gdbsim_store_register (regno)
ec25d19b
SC
386int regno;
387{
388 if (regno == -1)
40b92220
JK
389 {
390 for (regno = 0; regno < NUM_REGS; regno++)
391 gdbsim_store_register (regno);
392 }
393 else
394 {
395 /* FIXME: Until read_register() returns LONGEST, we have this. */
3beff94e
SC
396 char tmp[MAX_REGISTER_RAW_SIZE];
397 read_register_gen (regno, tmp);
286f83b4 398 sim_store_register (gdbsim_desc, regno, tmp);
40b92220
JK
399 if (sr_get_debug ())
400 {
401 printf_filtered ("gdbsim_store_register: %d", regno);
402 /* FIXME: We could print something more intelligible. */
3beff94e 403 dump_mem (tmp, REGISTER_RAW_SIZE (regno));
40b92220
JK
404 }
405 }
ec25d19b
SC
406}
407
47424e79
DE
408/* Kill the running program. This may involve closing any open files
409 and releasing other resources acquired by the simulated program. */
410
40b92220
JK
411static void
412gdbsim_kill ()
413{
414 if (sr_get_debug ())
415 printf_filtered ("gdbsim_kill\n");
416
286f83b4 417 sim_kill (gdbsim_desc); /* close fd's, remove mappings, etc. */
40b92220
JK
418 inferior_pid = 0;
419}
420
421/* Load an executable file into the target process. This is expected to
422 not only bring new code into the target process, but also to update
423 GDB's symbol tables to match. */
ec25d19b 424
ec25d19b 425static void
40b92220
JK
426gdbsim_load (prog, fromtty)
427 char *prog;
428 int fromtty;
ec25d19b 429{
40b92220
JK
430 if (sr_get_debug ())
431 printf_filtered ("gdbsim_load: prog \"%s\"\n", prog);
ec25d19b 432
47424e79
DE
433 inferior_pid = 0;
434
44cd79e4
DE
435 /* FIXME: We will print two messages on error.
436 Need error to either not print anything if passed NULL or need
437 another routine that doesn't take any arguments. */
438 if (sim_load (gdbsim_desc, prog, NULL, fromtty) == SIM_RC_FAIL)
439 error ("unable to load program");
47424e79 440
44cd79e4 441 program_loaded = 1;
40b92220
JK
442}
443
ec25d19b 444
40b92220
JK
445/* Start an inferior process and set inferior_pid to its pid.
446 EXEC_FILE is the file to run.
163a75af 447 ARGS is a string containing the arguments to the program.
40b92220
JK
448 ENV is the environment vector to pass. Errors reported with error().
449 On VxWorks and various standalone systems, we ignore exec_file. */
ec25d19b
SC
450/* This is called not only when we first attach, but also when the
451 user types "run" after having attached. */
40b92220
JK
452
453static void
454gdbsim_create_inferior (exec_file, args, env)
455 char *exec_file;
ec25d19b
SC
456 char *args;
457 char **env;
458{
47424e79 459 int len;
40b92220 460 char *arg_buf,**argv;
47424e79 461 CORE_ADDR entry_pt;
ec25d19b 462
40b92220
JK
463 if (! program_loaded)
464 error ("No program loaded.");
ec25d19b 465
40b92220
JK
466 if (sr_get_debug ())
467 printf_filtered ("gdbsim_create_inferior: exec_file \"%s\", args \"%s\"\n",
468 exec_file, args);
469
470 if (exec_file == 0 || exec_bfd == 0)
471 error ("No exec file specified.");
ec25d19b 472
47424e79 473 entry_pt = (CORE_ADDR) bfd_get_start_address (exec_bfd);
40b92220 474
8501c742 475 gdbsim_kill ();
40b92220 476 remove_breakpoints ();
ec25d19b 477 init_wait_for_inferior ();
ec25d19b 478
163a75af 479 len = strlen (exec_file) + 1 + strlen (args) + 1 + /*slop*/ 10;
40b92220
JK
480 arg_buf = (char *) alloca (len);
481 arg_buf[0] = '\0';
482 strcat (arg_buf, exec_file);
483 strcat (arg_buf, " ");
484 strcat (arg_buf, args);
485 argv = buildargv (arg_buf);
486 make_cleanup (freeargv, (char *) argv);
44cd79e4 487 sim_create_inferior (gdbsim_desc, argv, env);
40b92220
JK
488
489 inferior_pid = 42;
490 insert_breakpoints (); /* Needed to get correct instruction in cache */
45dc9be3 491 proceed (entry_pt, TARGET_SIGNAL_DEFAULT, 0);
40b92220 492}
ec25d19b 493
40b92220
JK
494/* The open routine takes the rest of the parameters from the command,
495 and (if successful) pushes a new target onto the stack.
496 Targets should supply this routine, if only to provide an error message. */
497/* Called when selecting the simulator. EG: (gdb) target sim name. */
ec25d19b 498
a944e79a 499static void
40b92220
JK
500gdbsim_open (args, from_tty)
501 char *args;
ec25d19b
SC
502 int from_tty;
503{
286f83b4
DE
504 int len;
505 char *arg_buf;
506 char **argv;
507
40b92220 508 if (sr_get_debug ())
47424e79 509 printf_filtered ("gdbsim_open: args \"%s\"\n", args ? args : "(null)");
7a29d686 510
d9ad8adf
DE
511 /* Remove current simulator if one exists. Only do this if the simulator
512 has been opened because sim_close requires it.
513 This is important because the call to push_target below will cause
514 sim_close to be called if the simulator is already open, but push_target
515 is called after sim_open! We can't move the call to push_target before
516 the call to sim_open because sim_open may invoke `error'. */
286f83b4 517 if (gdbsim_desc != NULL)
d9ad8adf
DE
518 unpush_target (&gdbsim_ops);
519
4da8b2a5 520 init_callbacks ();
7a29d686 521
44cd79e4 522 len = 7 + 1 + (args ? strlen (args) : 0) + 50;
286f83b4 523 arg_buf = (char *) alloca (len);
0c4cec9f
DE
524 sprintf (arg_buf, "gdbsim%s%s",
525 args ? " " : "", args ? args : "");
526#ifdef TARGET_BYTE_ORDER_SELECTABLE
527 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
528 strcat (arg_buf, " -E big");
529 else
530 strcat (arg_buf, " -E little");
531#endif
286f83b4
DE
532 argv = buildargv (arg_buf);
533 if (argv == NULL)
534 error ("Insufficient memory available to allocate simulator arg list.");
535 make_cleanup (freeargv, (char *) argv);
536
99097077
DE
537 gdbsim_desc = sim_open (SIM_OPEN_DEBUG, argv);
538 if (gdbsim_desc == 0)
539 error ("unable to create simulator instance");
3e38efa0 540
40b92220
JK
541 push_target (&gdbsim_ops);
542 target_fetch_registers (-1);
40b92220 543 printf_filtered ("Connected to the simulator.\n");
ec25d19b
SC
544}
545
40b92220
JK
546/* Does whatever cleanup is required for a target that we are no longer
547 going to be calling. Argument says whether we are quitting gdb and
548 should not get hung in case of errors, or whether we want a clean
549 termination even if it takes a while. This routine is automatically
550 always called just before a routine is popped off the target stack.
551 Closing file descriptors and freeing memory are typical things it should
552 do. */
ec25d19b
SC
553/* Close out all files and local state before this target loses control. */
554
a944e79a 555static void
40b92220 556gdbsim_close (quitting)
ec25d19b
SC
557 int quitting;
558{
40b92220
JK
559 if (sr_get_debug ())
560 printf_filtered ("gdbsim_close: quitting %d\n", quitting);
561
562 program_loaded = 0;
563
286f83b4 564 if (gdbsim_desc != NULL)
d9ad8adf 565 {
286f83b4
DE
566 sim_close (gdbsim_desc, quitting);
567 gdbsim_desc = NULL;
d9ad8adf 568 }
4da8b2a5
DE
569
570 end_callbacks ();
ec25d19b
SC
571}
572
40b92220
JK
573/* Takes a program previously attached to and detaches it.
574 The program may resume execution (some targets do, some don't) and will
575 no longer stop on signals, etc. We better not have left any breakpoints
576 in the program or it'll die when it hits one. ARGS is arguments
577 typed by the user (e.g. a signal to send the process). FROM_TTY
578 says whether to be verbose or not. */
ec25d19b 579/* Terminate the open connection to the remote debugger.
40b92220
JK
580 Use this when you want to detach and do something else with your gdb. */
581
582static void
583gdbsim_detach (args,from_tty)
ec25d19b
SC
584 char *args;
585 int from_tty;
586{
40b92220
JK
587 if (sr_get_debug ())
588 printf_filtered ("gdbsim_detach: args \"%s\"\n", args);
a944e79a 589
40b92220
JK
590 pop_target (); /* calls gdbsim_close to do the real work */
591 if (from_tty)
592 printf_filtered ("Ending simulator %s debugging\n", target_shortname);
ec25d19b
SC
593}
594
40b92220
JK
595/* Resume execution of the target process. STEP says whether to single-step
596 or to run free; SIGGNAL is the signal value (e.g. SIGINT) to be given
597 to the target, or zero for no signal. */
598
8517f62b
AC
599static enum target_signal resume_siggnal;
600static int resume_step;
601
40b92220
JK
602static void
603gdbsim_resume (pid, step, siggnal)
67ac9759
JK
604 int pid, step;
605 enum target_signal siggnal;
40b92220 606{
6bafbdfb
JL
607 if (inferior_pid != 42)
608 error ("The program is not being run.");
609
40b92220
JK
610 if (sr_get_debug ())
611 printf_filtered ("gdbsim_resume: step %d, signal %d\n", step, siggnal);
ec25d19b 612
8517f62b
AC
613 resume_siggnal = siggnal;
614 resume_step = step;
615}
616
617/* Notify the simulator of an asynchronous request to stop.
618 Since some simulators can not stop, help them out.
619 When stepping, need to also notify the client that it
620 too should quit */
621
622static void
623gdbsim_stop ()
624{
625 if (! sim_stop (gdbsim_desc))
626 {
627 error ("gdbsim_stop: simulator failed to stop!\n");
628 }
40b92220 629}
ec25d19b 630
40b92220
JK
631/* Wait for inferior process to do something. Return pid of child,
632 or -1 in case of error; store status through argument pointer STATUS,
8517f62b
AC
633 just as `wait' would. */
634
635static void (*prev_sigint) ();
636
637static void
638gdbsim_cntrl_c (int signo)
639{
640 gdbsim_stop ();
641}
ec25d19b 642
40b92220 643static int
de43d7d0
SG
644gdbsim_wait (pid, status)
645 int pid;
67ac9759 646 struct target_waitstatus *status;
ec25d19b 647{
8517f62b
AC
648 int sigrc = 0;
649 enum sim_stop reason = sim_running;
592f517a 650
40b92220 651 if (sr_get_debug ())
67ac9759
JK
652 printf_filtered ("gdbsim_wait\n");
653
8517f62b
AC
654 prev_sigint = signal (SIGINT, gdbsim_cntrl_c);
655 sim_resume (gdbsim_desc, resume_step,
656 target_signal_to_host (resume_siggnal));
657 signal (SIGINT, prev_sigint);
658 resume_step = 0;
659
286f83b4 660 sim_stop_reason (gdbsim_desc, &reason, &sigrc);
8517f62b 661
67ac9759
JK
662 switch (reason)
663 {
664 case sim_exited:
665 status->kind = TARGET_WAITKIND_EXITED;
666 status->value.integer = sigrc;
667 break;
668 case sim_stopped:
8517f62b
AC
669 switch (sigrc)
670 {
671 case SIGABRT:
672 quit ();
673 break;
674 case SIGINT:
675 case SIGTRAP:
676 default:
677 status->kind = TARGET_WAITKIND_STOPPED;
678 /* The signal in sigrc is a host signal. That probably
679 should be fixed. */
680 status->value.sig = target_signal_from_host (sigrc);
681 break;
682 }
67ac9759
JK
683 break;
684 case sim_signalled:
685 status->kind = TARGET_WAITKIND_SIGNALLED;
686 /* The signal in sigrc is a host signal. That probably
687 should be fixed. */
688 status->value.sig = target_signal_from_host (sigrc);
689 break;
690 }
691
3f0184ac 692 return inferior_pid;
ec25d19b
SC
693}
694
40b92220
JK
695/* Get ready to modify the registers array. On machines which store
696 individual registers, this doesn't need to do anything. On machines
697 which store all the registers in one fell swoop, this makes sure
698 that registers contains all the registers from the program being
699 debugged. */
700
ec25d19b 701static void
40b92220 702gdbsim_prepare_to_store ()
ec25d19b 703{
40b92220 704 /* Do nothing, since we can store individual regs */
ec25d19b
SC
705}
706
40b92220
JK
707static int
708gdbsim_xfer_inferior_memory (memaddr, myaddr, len, write, target)
ec25d19b
SC
709 CORE_ADDR memaddr;
710 char *myaddr;
711 int len;
712 int write;
713 struct target_ops *target; /* ignored */
714{
40b92220
JK
715 if (! program_loaded)
716 error ("No program loaded.");
717
718 if (sr_get_debug ())
719 {
720 printf_filtered ("gdbsim_xfer_inferior_memory: myaddr 0x%x, memaddr 0x%x, len %d, write %d\n",
721 myaddr, memaddr, len, write);
722 if (sr_get_debug () && write)
723 dump_mem(myaddr, len);
724 }
725
ec25d19b 726 if (write)
40b92220 727 {
286f83b4 728 len = sim_write (gdbsim_desc, memaddr, myaddr, len);
40b92220 729 }
ec25d19b 730 else
40b92220 731 {
286f83b4 732 len = sim_read (gdbsim_desc, memaddr, myaddr, len);
40b92220
JK
733 if (sr_get_debug () && len > 0)
734 dump_mem(myaddr, len);
735 }
ec25d19b
SC
736 return len;
737}
738
40b92220
JK
739static void
740gdbsim_files_info (target)
741 struct target_ops *target;
742{
743 char *file = "nothing";
ec25d19b 744
40b92220
JK
745 if (exec_bfd)
746 file = bfd_get_filename (exec_bfd);
ec25d19b 747
40b92220
JK
748 if (sr_get_debug ())
749 printf_filtered ("gdbsim_files_info: file \"%s\"\n", file);
750
751 if (exec_bfd)
752 {
753 printf_filtered ("\tAttached to %s running program %s\n",
754 target_shortname, file);
286f83b4 755 sim_info (gdbsim_desc, 0);
40b92220 756 }
ec25d19b
SC
757}
758
fb506180 759/* Clear the simulator's notion of what the break points are. */
ec25d19b 760
40b92220
JK
761static void
762gdbsim_mourn_inferior ()
763{
764 if (sr_get_debug ())
765 printf_filtered ("gdbsim_mourn_inferior:\n");
ec25d19b 766
40b92220
JK
767 remove_breakpoints ();
768 generic_mourn_inferior ();
ec25d19b 769}
40b92220 770
07997f65
SS
771/* Pass the command argument through to the simulator verbatim. The
772 simulator must do any command interpretation work. */
ec25d19b 773
fb506180
SS
774static void
775simulator_command (args, from_tty)
776 char *args;
777 int from_tty;
ec25d19b 778{
07997f65
SS
779 /* The user may give a command before the simulator is opened, so
780 ensure that the callbacks have been set up. */
4da8b2a5 781 init_callbacks ();
07997f65 782
286f83b4
DE
783 /* Note that if the simulator hasn't been opened, gdbsim_desc == NULL
784 which is correct (??? assuming of course one wishes to continue to
785 allow commands to be sent to unopened simulators, which isn't entirely
12967062
FF
786 unreasonable). Simulators should be prepared to deal with any
787 combination of NULL or empty args. */
286f83b4 788 sim_do_command (gdbsim_desc, args);
fb506180
SS
789}
790
791/* Define the target subroutine names */
792
793struct target_ops gdbsim_ops = {
794 "sim", /* to_shortname */
795 "simulator", /* to_longname */
796 "Use the compiled-in simulator.", /* to_doc */
797 gdbsim_open, /* to_open */
798 gdbsim_close, /* to_close */
799 NULL, /* to_attach */
800 gdbsim_detach, /* to_detach */
801 gdbsim_resume, /* to_resume */
802 gdbsim_wait, /* to_wait */
803 gdbsim_fetch_register, /* to_fetch_registers */
804 gdbsim_store_register, /* to_store_registers */
805 gdbsim_prepare_to_store, /* to_prepare_to_store */
806 gdbsim_xfer_inferior_memory, /* to_xfer_memory */
807 gdbsim_files_info, /* to_files_info */
808 memory_insert_breakpoint, /* to_insert_breakpoint */
809 memory_remove_breakpoint, /* to_remove_breakpoint */
810 NULL, /* to_terminal_init */
811 NULL, /* to_terminal_inferior */
812 NULL, /* to_terminal_ours_for_output */
813 NULL, /* to_terminal_ours */
814 NULL, /* to_terminal_info */
815 gdbsim_kill, /* to_kill */
816 gdbsim_load, /* to_load */
817 NULL, /* to_lookup_symbol */
818 gdbsim_create_inferior, /* to_create_inferior */
819 gdbsim_mourn_inferior, /* to_mourn_inferior */
820 0, /* to_can_run */
821 0, /* to_notice_signals */
43fc25c8 822 0, /* to_thread_alive */
8517f62b 823 gdbsim_stop, /* to_stop */
fb506180
SS
824 process_stratum, /* to_stratum */
825 NULL, /* to_next */
826 1, /* to_has_all_memory */
827 1, /* to_has_memory */
828 1, /* to_has_stack */
829 1, /* to_has_registers */
830 1, /* to_has_execution */
831 NULL, /* sections */
832 NULL, /* sections_end */
833 OPS_MAGIC, /* to_magic */
ec25d19b
SC
834};
835
ec25d19b
SC
836void
837_initialize_remote_sim ()
838{
40b92220 839 add_target (&gdbsim_ops);
fb506180
SS
840
841 add_com ("sim <command>", class_obscure, simulator_command,
842 "Send a command to the simulator.");
ec25d19b 843}
This page took 0.286361 seconds and 4 git commands to generate.