* Contribute CGEN simulator build support code.
[binutils-gdb.git] / sim / w65 / run.c
blob2d966eeddaebd62753e1a56b56d75587e5ac9ef7
1 /* run front end support for W65
2 Copyright (C) 1995 Free Software Foundation, Inc.
4 This file is part of W65 SIM
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.
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.
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. */
21 /* Steve Chamberlain
22 sac@cygnus.com */
24 #include "config.h"
26 #include <stdio.h>
27 #ifdef HAVE_STDLIB_H
28 #include <stdlib.h>
29 #endif
30 #include "getopt.h"
31 #include "bfd.h"
33 #ifdef NEED_DECLARATION_PRINTF
34 extern int printf ();
35 #endif
37 void usage();
38 extern int optind;
40 int
41 main (ac, av)
42 int ac;
43 char **av;
45 bfd *abfd;
46 bfd_vma start_address;
47 asection *s;
48 int i;
49 int verbose = 0;
50 int trace = 0;
51 char *name = "";
53 while ((i = getopt (ac, av, "tv")) != EOF)
54 switch (i)
56 case 't':
57 trace = 1;
58 break;
59 case 'v':
60 verbose = 1;
61 break;
62 default:
63 usage();
65 ac -= optind;
66 av += optind;
68 if (ac != 1)
69 usage();
71 name = *av;
73 if (verbose)
75 printf ("run %s\n", name);
77 abfd = bfd_openr (name, "coff-w65");
78 if (abfd)
81 if (bfd_check_format (abfd, bfd_object))
84 for (s = abfd->sections; s; s = s->next)
86 unsigned char *buffer = malloc (bfd_section_size (abfd, s));
87 bfd_get_section_contents (abfd,
89 buffer,
91 bfd_section_size (abfd, s));
92 sim_write (s->vma, buffer, bfd_section_size (abfd, s));
93 free (buffer);
96 start_address = bfd_get_start_address (abfd);
97 sim_set_pc (start_address);
98 if (trace)
100 int done = 0;
101 while (!done)
103 done = sim_trace ();
106 else
108 sim_resume (0, 0);
110 if (verbose)
111 sim_info (printf, 0);
113 /* Find out what was in r0 and return that */
115 unsigned char b[4];
116 sim_fetch_register(0, b, 4);
117 return b[3];
123 return 1;
126 void
127 usage()
129 fprintf (stderr, "usage: run [-tv] program\n");
130 exit (1);