]>
Commit | Line | Data |
---|---|---|
2494eaf6 SC |
1 | /* run front end support for ARM |
2 | Copyright (C) 1996 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of ARM 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 | |
6d8e15cb DE |
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. */ | |
2494eaf6 SC |
19 | |
20 | /* Steve Chamberlain | |
21 | [email protected] */ | |
22 | ||
23 | #include <stdio.h> | |
24 | #include <varargs.h> | |
25 | #include "bfd.h" | |
6d8e15cb | 26 | #include "getopt.h" |
2494eaf6 SC |
27 | #include "remote-sim.h" |
28 | ||
6d8e15cb | 29 | static void usage(); |
2494eaf6 SC |
30 | |
31 | int target_byte_order; | |
32 | ||
33 | int | |
34 | main (ac, av) | |
35 | int ac; | |
36 | char **av; | |
37 | { | |
38 | bfd *abfd; | |
39 | bfd_vma start_address; | |
40 | asection *s; | |
41 | int i; | |
2494eaf6 | 42 | int trace = 0; |
6d8e15cb DE |
43 | int verbose = 0; |
44 | char *name; | |
2494eaf6 SC |
45 | |
46 | while ((i = getopt (ac, av, "m:p:s:tv")) != EOF) | |
47 | switch (i) | |
48 | { | |
49 | case 'm': | |
6d8e15cb | 50 | arm_sim_set_mem_size (atoi (optarg)); |
2494eaf6 | 51 | break; |
6d8e15cb DE |
52 | case 'p': /* FIXME: unused */ |
53 | arm_sim_set_profile (atoi (optarg)); | |
2494eaf6 | 54 | break; |
6d8e15cb DE |
55 | case 's': /* FIXME: unused */ |
56 | arm_sim_set_profile_size (atoi (optarg)); | |
2494eaf6 SC |
57 | break; |
58 | case 't': | |
59 | trace = 1; | |
60 | break; | |
61 | case 'v': | |
62 | verbose = 1; | |
6d8e15cb | 63 | arm_sim_set_verbosity (1); |
2494eaf6 SC |
64 | break; |
65 | default: | |
66 | usage(); | |
67 | } | |
68 | ac -= optind; | |
69 | av += optind; | |
70 | ||
71 | if (ac != 1) | |
72 | usage(); | |
73 | ||
74 | name = *av; | |
75 | ||
76 | if (verbose) | |
77 | { | |
78 | printf ("run %s\n", name); | |
79 | } | |
6d8e15cb | 80 | |
2494eaf6 SC |
81 | abfd = bfd_openr (name, 0); |
82 | if (abfd) | |
83 | { | |
84 | if (bfd_check_format (abfd, bfd_object)) | |
85 | { | |
2494eaf6 SC |
86 | for (s = abfd->sections; s; s = s->next) |
87 | { | |
6d8e15cb DE |
88 | if (s->flags & SEC_LOAD) |
89 | { | |
90 | unsigned char *buffer = malloc (bfd_section_size (abfd, s)); | |
91 | bfd_get_section_contents (abfd, | |
92 | s, | |
93 | buffer, | |
94 | 0, | |
95 | bfd_section_size (abfd, s)); | |
96 | sim_write (s->vma, buffer, bfd_section_size (abfd, s)); | |
97 | free (buffer); | |
98 | } | |
2494eaf6 SC |
99 | } |
100 | ||
101 | start_address = bfd_get_start_address (abfd); | |
102 | sim_create_inferior (start_address, NULL, NULL); | |
103 | ||
104 | target_byte_order = abfd->xvec->byteorder_big_p ? 4321 : 1234; | |
105 | ||
106 | if (trace) | |
107 | { | |
108 | int done = 0; | |
109 | while (!done) | |
110 | { | |
111 | done = sim_trace (); | |
112 | } | |
113 | } | |
114 | else | |
115 | { | |
116 | sim_resume (0, 0); | |
117 | } | |
118 | if (verbose) | |
119 | sim_info (0); | |
120 | ||
121 | /* Assume we left through the exit system call, | |
c8aea29b | 122 | in which case r0 has the exit code */ |
6d8e15cb | 123 | /* FIXME: byte order dependent? */ |
2494eaf6 SC |
124 | { |
125 | unsigned char b[4]; | |
c8aea29b SC |
126 | sim_fetch_register (0, b); |
127 | return b[0]; | |
2494eaf6 | 128 | } |
2494eaf6 SC |
129 | } |
130 | } | |
131 | ||
132 | return 1; | |
133 | } | |
134 | ||
6d8e15cb | 135 | static void |
2494eaf6 SC |
136 | usage() |
137 | { | |
138 | fprintf (stderr, "usage: run [-tv] program\n"); | |
139 | exit (1); | |
140 | } | |
141 | ||
142 | \f | |
143 | /* Callbacks used by the simulator proper. */ | |
144 | ||
145 | void | |
146 | printf_filtered (va_alist) | |
147 | va_dcl | |
148 | { | |
149 | va_list args; | |
150 | char *format; | |
151 | ||
152 | va_start (args); | |
153 | format = va_arg (args, char *); | |
154 | ||
155 | vfprintf (stdout, format, args); | |
156 | va_end (args); | |
157 | } |