1 /* run front end support for all the simulators.
2 Copyright (C) 1992, 1993 1994, 1995 Free Software Foundation, Inc.
4 GNU CC is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 GNU CC is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 #include "remote-sim.h"
29 #define SIGQUIT SIGTERM
38 int target_byte_order
;
40 extern host_callback default_callback
;
47 bfd_vma start_address
;
56 while ((i
= getopt (ac
, av
, "m:p:s:tv")) != EOF
)
60 sim_size (atoi (optarg
));
63 sim_set_profile (atoi (optarg
));
66 sim_set_profile_size (atoi (optarg
));
87 printf ("run %s\n", name
);
90 exec_bfd
= abfd
= bfd_openr (name
, 0);
93 fprintf (stderr
, "run: can't open %s: %s\n",
94 name
, bfd_errmsg(bfd_get_error()));
98 if (!bfd_check_format (abfd
, bfd_object
))
100 fprintf (stderr
, "run: can't load %s: %s\n",
101 name
, bfd_errmsg(bfd_get_error()));
105 sim_set_callbacks (&default_callback
);
106 default_callback
.init (&default_callback
);
108 /* Ensure that any run-time initialisation that needs to be
109 performed by the simulator can occur. */
112 for (s
= abfd
->sections
; s
; s
= s
->next
)
113 if (abfd
&& (s
->flags
& SEC_LOAD
))
115 unsigned char *buffer
= (unsigned char *)malloc ((size_t)(bfd_section_size (abfd
, s
)));
118 bfd_get_section_contents (abfd
,
122 bfd_section_size (abfd
, s
));
123 sim_write (s
->vma
, buffer
, bfd_section_size (abfd
, s
));
127 fprintf (stderr
, "run: failed to allocate section buffer: %s\n",
128 bfd_errmsg(bfd_get_error()));
133 start_address
= bfd_get_start_address (abfd
);
134 sim_create_inferior (start_address
, NULL
, NULL
);
136 target_byte_order
= bfd_big_endian (abfd
) ? 4321 : 1234;
153 sim_stop_reason (&reason
, &sigrc
);
157 /* Why did we stop? */
162 fprintf (stderr
, "program stopped with signal %d.\n", sigrc
);
169 /* If reason is sim_exited, then sigrc holds the exit code which we want
170 to return. If reason is sim_stopped or sim_signalled, then sigrc holds
171 the signal that the simulator received; we want to return that to
179 fprintf (stderr
, "usage: run [-tv][-m size] program\n");