Commit | Line | Data |
---|---|---|
ea6bbfba | 1 | /* front end to the simulator. |
a154eea7 | 2 | |
ea6bbfba SC |
3 | Written by Steve Chamberlain of Cygnus Support. |
4 | sac@cygnus.com | |
a154eea7 | 5 | |
ea6bbfba | 6 | This file is part of H8/300 sim |
a154eea7 | 7 | |
a154eea7 | 8 | |
ea6bbfba | 9 | THIS SOFTWARE IS NOT COPYRIGHTED |
a154eea7 | 10 | |
ea6bbfba SC |
11 | Cygnus offers the following for use in the public domain. Cygnus |
12 | makes no warranty with regard to the software or it's performance | |
13 | and the user accepts the software "AS IS" with all faults. | |
a154eea7 | 14 | |
ea6bbfba SC |
15 | CYGNUS DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD TO |
16 | THIS SOFTWARE INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
17 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
18 | ||
19 | */ | |
a154eea7 | 20 | |
0743b4ac ILT |
21 | #include "config.h" |
22 | ||
3a1d485d | 23 | #include <varargs.h> |
a415cf0a | 24 | #include <stdio.h> |
e656ecf9 | 25 | #include <signal.h> |
0743b4ac ILT |
26 | #ifdef HAVE_STDLIB_H |
27 | #include <stdlib.h> | |
28 | #endif | |
29 | #include "getopt.h" | |
a154eea7 | 30 | #include "bfd.h" |
3a1d485d | 31 | #include "remote-sim.h" |
a154eea7 | 32 | |
057af5c9 C |
33 | void usage(); |
34 | extern int optind; | |
35 | extern char *optarg; | |
36 | ||
a154eea7 | 37 | int |
1cec8dae SC |
38 | main (ac, av) |
39 | int ac; | |
40 | char **av; | |
a154eea7 SC |
41 | { |
42 | bfd *abfd; | |
43 | bfd_vma start_address; | |
44 | asection *s; | |
45 | int i; | |
46 | int verbose = 0; | |
47 | int trace = 0; | |
48 | char *name = ""; | |
e656ecf9 DE |
49 | int sigrc; |
50 | enum sim_stop reason; | |
3a1d485d | 51 | |
057af5c9 C |
52 | while ((i = getopt (ac, av, "c:htv")) != EOF) |
53 | switch (i) | |
54 | { | |
55 | case 'c': | |
56 | sim_csize (atoi (optarg)); | |
57 | break; | |
58 | case 'h': | |
3a1d485d | 59 | set_h8300h (1); |
057af5c9 C |
60 | break; |
61 | case 't': | |
62 | trace = 1; | |
63 | break; | |
64 | case 'v': | |
65 | verbose = 1; | |
66 | break; | |
67 | default: | |
68 | usage(); | |
69 | } | |
057af5c9 | 70 | |
741fd619 | 71 | if (ac - optind != 1) |
057af5c9 C |
72 | usage(); |
73 | ||
741fd619 | 74 | name = av[ac - 1]; |
7ecaa5af | 75 | |
1835992e DE |
76 | if (verbose) |
77 | printf ("run %s\n", name); | |
ce38539a | 78 | |
cf5b4aa6 | 79 | abfd = bfd_openr (name, "coff-h8300"); |
741fd619 | 80 | if (! abfd) |
cf5b4aa6 | 81 | { |
741fd619 DE |
82 | fprintf (stderr, "%s: unable to open %s\n", av[0], name); |
83 | exit (1); | |
cf5b4aa6 | 84 | } |
a154eea7 | 85 | |
741fd619 DE |
86 | if (! bfd_check_format(abfd, bfd_object)) |
87 | { | |
88 | fprintf (stderr, "%s: %s is not a valid executable\n", av[0], name); | |
89 | exit (1); | |
90 | } | |
91 | ||
88ea21e5 | 92 | if (abfd->arch_info->mach == bfd_mach_h8300h |
25b344a4 | 93 | || abfd->arch_info->mach == bfd_mach_h8300s) |
741fd619 DE |
94 | set_h8300h (1); |
95 | ||
96 | for (s = abfd->sections; s; s=s->next) | |
97 | { | |
7647e0dd JL |
98 | char *buffer; |
99 | ||
100 | if (s->flags & SEC_LOAD) | |
101 | { | |
102 | ||
103 | buffer = malloc(bfd_section_size(abfd,s)); | |
104 | bfd_get_section_contents(abfd, s, buffer, 0, | |
105 | bfd_section_size (abfd, s)); | |
106 | sim_write(s->vma, buffer, bfd_section_size (abfd, s)); | |
107 | } | |
741fd619 DE |
108 | } |
109 | ||
110 | start_address = bfd_get_start_address(abfd); | |
111 | sim_create_inferior (start_address, NULL, NULL); | |
112 | sim_resume(0,0); | |
113 | if (verbose) | |
114 | sim_info (verbose - 1); | |
115 | sim_stop_reason (&reason, &sigrc); | |
116 | /* FIXME: this test is insufficient but we can't do much | |
117 | about it until sim_stop_reason is cleaned up. */ | |
118 | if (sigrc == SIGILL) | |
119 | abort (); | |
120 | return 0; | |
a154eea7 | 121 | } |
3a1d485d | 122 | |
741fd619 DE |
123 | /* gdb callback used by simulator */ |
124 | ||
3a1d485d DE |
125 | void |
126 | printf_filtered (va_alist) | |
127 | va_dcl | |
128 | { | |
129 | char *msg; | |
130 | va_list args; | |
131 | ||
132 | va_start (args); | |
133 | msg = va_arg (args, char *); | |
134 | vfprintf (stdout, msg, args); | |
135 | va_end (args); | |
136 | } | |
057af5c9 C |
137 | |
138 | void | |
139 | usage() | |
140 | { | |
741fd619 | 141 | fprintf (stderr, "usage: run [-h] [-t] [-v] [-c csize] program\n"); |
057af5c9 C |
142 | exit (1); |
143 | } |