New sparc simulator from the ESA.
[binutils-gdb.git] / sim / erc32 / run.c
1 /*
2 * run front end support for ERC32SIM Copyright (C) 1987, 1992 Free Software
3 * Foundation, Inc.
4 *
5 * This file is part of ERC32SIM
6 *
7 * ERC32SIM is free software; you can redistribute it and/or modify it under the
8 * terms of the GNU General Public License as published by the Free Software
9 * Foundation; either version 2, or (at your option) any later version.
10 *
11 * ERC32SIM is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 * details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * ERC32SIM; see the file COPYING. If not, write to the Free Software
18 * Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include <varargs.h>
22 #include <stdio.h>
23 #include "bfd.h"
24
25 main(ac, av)
26 int ac;
27 char **av;
28 {
29 bfd *abfd;
30 bfd_vma start_address;
31 asection *s;
32 int i;
33 int verbose = 0;
34 int trace = 0;
35 char *name = "";
36 for (i = 1; i < ac; i++) {
37 if (strcmp(av[i], "-v") == 0) {
38 verbose = 1;
39 } else if (strcmp(av[i], "-t") == 0) {
40 trace = 1;
41 } else {
42 name = av[i];
43 }
44 }
45 if (verbose) {
46 printf("run %s\n", name);
47 }
48 sim_open(0);
49 abfd = bfd_openr(name, "a.out-sunos-big");
50
51 if (abfd) {
52
53 if (bfd_check_format(abfd, bfd_object)) {
54 for (s = abfd->sections; s; s = s->next) {
55 char *buffer = malloc(bfd_section_size(abfd, s));
56 bfd_get_section_contents(abfd, s, buffer, 0, bfd_section_size(abfd, s));
57 sim_write(s->vma, buffer, bfd_section_size(abfd, s));
58 }
59
60 start_address = bfd_get_start_address(abfd);
61 sim_create_inferior(start_address, NULL, NULL);
62 if (trace) {
63 int done = 0;
64 while (!done) {
65 /*
66 * done = sim_trace();
67 */
68 }
69 } else {
70 sim_resume(0, 0);
71 }
72 if (verbose) {
73 sim_info(0);
74 }
75 return 0;
76 }
77 }
78 return 1;
79 }
80
81 void
82 printf_filtered(va_alist)
83 va_dcl
84 {
85 char *msg;
86 va_list args;
87
88 va_start(args);
89 msg = va_arg(args, char *);
90 vfprintf(stdout, msg, args);
91 va_end(args);
92 }