Commit | Line | Data |
---|---|---|
6834d493 JW |
1 | /* run front end support for all the simulators. |
2 | Copyright (C) 1992, 1993 1994, 1995 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of SH SIM | |
5 | ||
6 | GNU CC is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2, or (at your option) | |
9 | any later version. | |
10 | ||
11 | GNU CC is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, 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 | ||
34 | void usage(); | |
35 | extern int optind; | |
36 | extern char *optarg; | |
37 | ||
38 | int target_byte_order; | |
39 | ||
40 | extern host_callback default_callback; | |
41 | int | |
42 | main (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 | } | |
89 | abfd = bfd_openr (name, 0); | |
90 | sim_set_callbacks (&default_callback); | |
91 | default_callback.init (&default_callback); | |
92 | if (abfd) | |
93 | { | |
94 | if (bfd_check_format (abfd, bfd_object)) | |
95 | { | |
96 | ||
97 | for (s = abfd->sections; s; s = s->next) | |
98 | { | |
99 | unsigned char *buffer = (unsigned char *)malloc (bfd_section_size (abfd, s)); | |
100 | bfd_get_section_contents (abfd, | |
101 | s, | |
102 | buffer, | |
103 | 0, | |
104 | bfd_section_size (abfd, s)); | |
105 | sim_write (s->vma, buffer, bfd_section_size (abfd, s)); | |
106 | } | |
107 | ||
108 | start_address = bfd_get_start_address (abfd); | |
109 | sim_create_inferior (start_address, NULL, NULL); | |
110 | ||
111 | target_byte_order = abfd->xvec->byteorder_big_p ? 4321 : 1234; | |
112 | ||
113 | if (trace) | |
114 | { | |
115 | int done = 0; | |
116 | while (!done) | |
117 | { | |
118 | done = sim_trace (); | |
119 | } | |
120 | } | |
121 | else | |
122 | { | |
123 | sim_resume (0, 0); | |
124 | } | |
125 | if (verbose) | |
126 | sim_info (0); | |
127 | ||
128 | sim_stop_reason (&reason, &sigrc); | |
129 | ||
130 | if (sigrc == SIGQUIT) | |
131 | { | |
132 | return sim_get_quit_code(); | |
133 | } | |
134 | else | |
135 | return sigrc; | |
136 | } | |
137 | } | |
138 | ||
139 | return 1; | |
140 | } | |
141 | ||
142 | void | |
143 | usage() | |
144 | { | |
145 | fprintf (stderr, "usage: run [-tv][-m size] program\n"); | |
146 | exit (1); | |
147 | } | |
148 | ||
149 |