Commit | Line | Data |
---|---|---|
594266fc SC |
1 | /* run front end support for H8/500 |
2 | Copyright (C) 1987, 1992 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of H8300 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 | |
17 | along with GNU CC; see the file COPYING. If not, write to | |
18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | ||
20 | ||
21 | /* Steve Chamberlain | |
22 | sac@cygnus.com */ | |
23 | ||
c834dacd | 24 | #include <stdio.h> |
fe031f82 | 25 | #include <varargs.h> |
594266fc SC |
26 | #include "bfd.h" |
27 | #include "sysdep.h" | |
fe031f82 | 28 | #include "remote-sim.h" |
8aff8146 | 29 | |
594266fc SC |
30 | int |
31 | main (ac, av) | |
32 | int ac; | |
33 | char **av; | |
34 | { | |
35 | bfd *abfd; | |
36 | bfd_vma start_address; | |
37 | asection *s; | |
38 | int i; | |
39 | int verbose = 0; | |
40 | int trace = 0; | |
41 | char *name = ""; | |
f6fba995 | 42 | |
594266fc SC |
43 | for (i = 1; i < ac; i++) |
44 | { | |
45 | if (strcmp (av[i], "-v") == 0) | |
46 | { | |
47 | verbose = 1; | |
48 | } | |
49 | else if (strcmp (av[i], "-t") == 0) | |
50 | { | |
51 | trace = 1; | |
52 | } | |
90fe361f SC |
53 | else if (strcmp (av[i], "-p") == 0) |
54 | { | |
55 | sim_set_profile(atoi(av[i+1])); | |
56 | i++; | |
90fe361f SC |
57 | } |
58 | else if (strcmp (av[i], "-s") == 0) | |
59 | { | |
60 | sim_set_profile_size(atoi(av[i+1])); | |
f6fba995 SC |
61 | i++; |
62 | } | |
5e1ac260 SC |
63 | else if (strcmp (av[i], "-m") == 0) |
64 | { | |
65 | sim_size(atoi(av[i+1])); | |
66 | i++; | |
67 | } | |
594266fc SC |
68 | else |
69 | { | |
70 | name = av[i]; | |
71 | } | |
72 | } | |
73 | if (verbose) | |
74 | { | |
75 | printf ("run %s\n", name); | |
76 | } | |
3d3e5651 | 77 | abfd = bfd_openr (name, ""); |
594266fc SC |
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 | } | |
94 | ||
95 | start_address = bfd_get_start_address (abfd); | |
fe031f82 | 96 | sim_create_inferior (start_address, NULL, NULL); |
594266fc SC |
97 | if (trace) |
98 | { | |
99 | int done = 0; | |
100 | while (!done) | |
101 | { | |
102 | done = sim_trace (); | |
103 | } | |
104 | } | |
105 | else | |
106 | { | |
107 | sim_resume (0, 0); | |
108 | } | |
109 | if (verbose) | |
fe031f82 | 110 | sim_info (0); |
594266fc | 111 | |
f6fba995 SC |
112 | /* Find out what was in r0 and return that */ |
113 | { | |
114 | unsigned char b[4]; | |
115 | sim_fetch_register(0, b); | |
116 | return b[3]; | |
117 | } | |
118 | ||
594266fc SC |
119 | } |
120 | } | |
121 | ||
122 | return 1; | |
123 | } | |
fe031f82 DE |
124 | \f |
125 | /* Callbacks used by the simulator proper. */ | |
126 | ||
127 | void | |
128 | printf_filtered (va_alist) | |
129 | va_dcl | |
130 | { | |
131 | va_list args; | |
132 | char *format; | |
133 | ||
134 | va_start (args); | |
135 | format = va_arg (args, char *); | |
136 | ||
137 | vfprintf (stdout, format, args); | |
138 | va_end (args); | |
139 | } |