* compile.c (sim_resume): Watch for calls to abort.
[deliverable/binutils-gdb.git] / sim / h8300 / run.c
CommitLineData
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
33void usage();
34extern int optind;
35extern char *optarg;
36
a154eea7 37int
1cec8dae
SC
38main (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 }
70 ac -= optind;
71 av += optind;
72
73 if (ac != 1)
74 usage();
75
76 name = *av;
7ecaa5af 77
1835992e
DE
78 if (verbose)
79 printf ("run %s\n", name);
ce38539a 80
cf5b4aa6
DE
81 abfd = bfd_openr (name, "coff-h8300");
82 if (abfd)
83 {
84 if (bfd_check_format(abfd, bfd_object))
ce38539a 85 {
cf5b4aa6 86 if (abfd->arch_info->mach == bfd_mach_h8300h)
3a1d485d 87 set_h8300h (1);
ce38539a 88
cf5b4aa6
DE
89 for (s = abfd->sections; s; s=s->next)
90 {
91 char *buffer = malloc(bfd_section_size(abfd,s));
92 bfd_get_section_contents(abfd, s, buffer, 0, bfd_section_size(abfd,s));
93 sim_write(s->vma, buffer, bfd_section_size(abfd,s));
ce38539a 94 }
cf5b4aa6
DE
95
96 start_address = bfd_get_start_address(abfd);
3a1d485d 97 sim_create_inferior (start_address, NULL, NULL);
cf5b4aa6
DE
98 sim_resume(0,0);
99 if (verbose)
3a1d485d 100 sim_info (verbose - 1);
e656ecf9
DE
101 sim_stop_reason (&reason, &sigrc);
102 /* FIXME: this test is insufficient but we can't do much
103 about it until sim_stop_reason is cleaned up. */
104 if (sigrc == SIGILL)
105 abort ();
cf5b4aa6 106 return 0;
1cec8dae 107 }
cf5b4aa6 108 }
a154eea7
SC
109
110 return 1;
111}
3a1d485d
DE
112
113void
114printf_filtered (va_alist)
115 va_dcl
116{
117 char *msg;
118 va_list args;
119
120 va_start (args);
121 msg = va_arg (args, char *);
122 vfprintf (stdout, msg, args);
123 va_end (args);
124}
057af5c9
C
125
126void
127usage()
128{
129 fprintf (stderr, "usage: run [-tv] program\n");
130 exit (1);
131}
This page took 0.130134 seconds and 4 git commands to generate.