]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/w65/run.c
Initial creation of sourceware repository
[thirdparty/binutils-gdb.git] / sim / w65 / run.c
CommitLineData
c906108c
SS
1/* run front end support for W65
2 Copyright (C) 1995 Free Software Foundation, Inc.
3
4This file is part of W65 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 "config.h"
25
26#include <stdio.h>
27#ifdef HAVE_STDLIB_H
28#include <stdlib.h>
29#endif
30#include "getopt.h"
31#include "bfd.h"
32
33#ifdef NEED_DECLARATION_PRINTF
34extern int printf ();
35#endif
36
37void usage();
38extern int optind;
39
40int
41main (ac, av)
42 int ac;
43 char **av;
44{
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 = "";
52
53 while ((i = getopt (ac, av, "tv")) != EOF)
54 switch (i)
55 {
56 case 't':
57 trace = 1;
58 break;
59 case 'v':
60 verbose = 1;
61 break;
62 default:
63 usage();
64 }
65 ac -= optind;
66 av += optind;
67
68 if (ac != 1)
69 usage();
70
71 name = *av;
72
73 if (verbose)
74 {
75 printf ("run %s\n", name);
76 }
77 abfd = bfd_openr (name, "coff-w65");
78 if (abfd)
79 {
80
81 if (bfd_check_format (abfd, bfd_object))
82 {
83
84 for (s = abfd->sections; s; s = s->next)
85 {
86 unsigned char *buffer = malloc (bfd_section_size (abfd, s));
87 bfd_get_section_contents (abfd,
88 s,
89 buffer,
90 0,
91 bfd_section_size (abfd, s));
92 sim_write (s->vma, buffer, bfd_section_size (abfd, s));
93 free (buffer);
94 }
95
96 start_address = bfd_get_start_address (abfd);
97 sim_set_pc (start_address);
98 if (trace)
99 {
100 int done = 0;
101 while (!done)
102 {
103 done = sim_trace ();
104 }
105 }
106 else
107 {
108 sim_resume (0, 0);
109 }
110 if (verbose)
111 sim_info (printf, 0);
112
113 /* Find out what was in r0 and return that */
114 {
115 unsigned char b[4];
116 sim_fetch_register(0, b, 4);
117 return b[3];
118 }
119
120 }
121 }
122
123 return 1;
124}
125
126void
127usage()
128{
129 fprintf (stderr, "usage: run [-tv] program\n");
130 exit (1);
131}