* ieee.c (ieee_vec): Set symbol_leading_char field to '_'.
[deliverable/binutils-gdb.git] / sim / common / run.c
CommitLineData
6834d493
JW
1/* run front end support for all the simulators.
2 Copyright (C) 1992, 1993 1994, 1995 Free Software Foundation, Inc.
3
4This file is part of SH SIM
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU CC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20
21/* Steve Chamberlain
22 sac@cygnus.com */
23
24#include <signal.h>
25#include <stdio.h>
26#include <varargs.h>
27#include "bfd.h"
28#include "remote-sim.h"
29#include "callback.h"
30#ifndef SIGQUIT
31#define SIGQUIT SIGTERM
32#endif
33
34void usage();
35extern int optind;
36extern char *optarg;
37
38int target_byte_order;
39
40extern host_callback default_callback;
41int
42main (ac, av)
43 int ac;
44 char **av;
45{
46 bfd *abfd;
47 bfd_vma start_address;
48 asection *s;
49 int i;
50 int verbose = 0;
51 int trace = 0;
52 char *name = "";
53 enum sim_stop reason;
54 int sigrc;
55
56 while ((i = getopt (ac, av, "m:p:s:tv")) != EOF)
57 switch (i)
58 {
59 case 'm':
60 sim_size (atoi (optarg));
61 break;
62 case 'p':
63 sim_set_profile (atoi (optarg));
64 break;
65 case 's':
66 sim_set_profile_size (atoi (optarg));
67 break;
68 case 't':
69 trace = 1;
70 break;
71 case 'v':
72 verbose = 1;
73 break;
74 default:
75 usage();
76 }
77 ac -= optind;
78 av += optind;
79
80 if (ac != 1)
81 usage();
82
83 name = *av;
84
85 if (verbose)
86 {
87 printf ("run %s\n", name);
88 }
3be50301 89
6834d493 90 abfd = bfd_openr (name, 0);
3be50301
JW
91 if (!abfd)
92 {
93 fprintf (stderr, "run: can't open %s: %s\n",
94 name, bfd_errmsg(bfd_get_error()));
95 exit (1);
96 }
97
98 if (!bfd_check_format (abfd, bfd_object))
99 {
100 fprintf (stderr, "run: can't load %s: %s\n",
101 name, bfd_errmsg(bfd_get_error()));
102 exit (1);
103 }
104
105
6834d493
JW
106 sim_set_callbacks (&default_callback);
107 default_callback.init (&default_callback);
3be50301
JW
108
109 for (s = abfd->sections; s; s = s->next)
6834d493
JW
110 if (abfd)
111 {
3be50301
JW
112 unsigned char *buffer = (unsigned char *)malloc (bfd_section_size (abfd, s));
113 bfd_get_section_contents (abfd,
114 s,
115 buffer,
116 0,
117 bfd_section_size (abfd, s));
118 sim_write (s->vma, buffer, bfd_section_size (abfd, s));
119 }
120
121 start_address = bfd_get_start_address (abfd);
122 sim_create_inferior (start_address, NULL, NULL);
123
124 target_byte_order = abfd->xvec->byteorder_big_p ? 4321 : 1234;
6834d493 125
3be50301
JW
126 if (trace)
127 {
128 int done = 0;
129 while (!done)
130 {
131 done = sim_trace ();
6834d493
JW
132 }
133 }
3be50301
JW
134 else
135 {
136 sim_resume (0, 0);
137 }
138 if (verbose)
139 sim_info (0);
140
141 sim_stop_reason (&reason, &sigrc);
6834d493 142
3be50301
JW
143 /* If reason is sim_exited, then sigrc holds the exit code which we want
144 to return. If reason is sim_stopped or sim_signalled, then sigrc holds
145 the signal that the simulator received; we want to return that to
146 indicate failure. */
147 return sigrc;
6834d493
JW
148}
149
150void
151usage()
152{
153 fprintf (stderr, "usage: run [-tv][-m size] program\n");
154 exit (1);
155}
156
157
This page took 0.054573 seconds and 4 git commands to generate.