Commit | Line | Data |
---|---|---|
321a78a5 SC |
1 | /* run front end support for W65 |
2 | Copyright (C) 1995 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of W65 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 | |
6c9638b4 FF |
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. */ | |
321a78a5 SC |
19 | |
20 | ||
21 | /* Steve Chamberlain | |
22 | sac@cygnus.com */ | |
23 | ||
24 | #include <stdio.h> | |
25 | #include "bfd.h" | |
26 | #include "sysdep.h" | |
27 | ||
057af5c9 C |
28 | void usage(); |
29 | extern int optind; | |
321a78a5 SC |
30 | |
31 | int | |
32 | main (ac, av) | |
33 | int ac; | |
34 | char **av; | |
35 | { | |
36 | bfd *abfd; | |
37 | bfd_vma start_address; | |
38 | asection *s; | |
39 | int i; | |
40 | int verbose = 0; | |
41 | int trace = 0; | |
42 | char *name = ""; | |
057af5c9 C |
43 | |
44 | while ((i = getopt (ac, av, "tv")) != EOF) | |
45 | switch (i) | |
46 | { | |
47 | case 't': | |
48 | trace = 1; | |
49 | break; | |
50 | case 'v': | |
51 | verbose = 1; | |
52 | break; | |
53 | default: | |
54 | usage(); | |
55 | } | |
56 | ac -= optind; | |
57 | av += optind; | |
58 | ||
59 | if (ac != 1) | |
60 | usage(); | |
61 | ||
62 | name = *av; | |
63 | ||
321a78a5 SC |
64 | if (verbose) |
65 | { | |
66 | printf ("run %s\n", name); | |
67 | } | |
68 | abfd = bfd_openr (name, "coff-w65"); | |
69 | if (abfd) | |
70 | { | |
71 | ||
72 | if (bfd_check_format (abfd, bfd_object)) | |
73 | { | |
74 | ||
75 | for (s = abfd->sections; s; s = s->next) | |
76 | { | |
77 | unsigned char *buffer = malloc (bfd_section_size (abfd, s)); | |
78 | bfd_get_section_contents (abfd, | |
79 | s, | |
80 | buffer, | |
81 | 0, | |
82 | bfd_section_size (abfd, s)); | |
83 | sim_write (s->vma, buffer, bfd_section_size (abfd, s)); | |
84 | free (buffer); | |
85 | } | |
86 | ||
87 | start_address = bfd_get_start_address (abfd); | |
88 | sim_set_pc (start_address); | |
89 | if (trace) | |
90 | { | |
91 | int done = 0; | |
92 | while (!done) | |
93 | { | |
94 | done = sim_trace (); | |
95 | } | |
96 | } | |
97 | else | |
98 | { | |
99 | sim_resume (0, 0); | |
100 | } | |
101 | if (verbose) | |
102 | sim_info (printf, 0); | |
103 | ||
104 | /* Find out what was in r0 and return that */ | |
105 | { | |
106 | unsigned char b[4]; | |
107 | sim_fetch_register(0, b); | |
108 | return b[3]; | |
109 | } | |
110 | ||
111 | } | |
112 | } | |
113 | ||
114 | return 1; | |
115 | } | |
057af5c9 C |
116 | |
117 | void | |
118 | usage() | |
119 | { | |
120 | fprintf (stderr, "usage: run [-tv] program\n"); | |
121 | exit (1); | |
122 | } |