* run.c: parse arguments with getopt().
[deliverable/binutils-gdb.git] / sim / h8300 / run.c
1 /* front end to the simulator.
2
3 Written by Steve Chamberlain of Cygnus Support.
4 sac@cygnus.com
5
6 This file is part of H8/300 sim
7
8
9 THIS SOFTWARE IS NOT COPYRIGHTED
10
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.
14
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 */
20
21 #include <varargs.h>
22 #include <stdio.h>
23 #include "bfd.h"
24 #include "sysdep.h"
25 #include "remote-sim.h"
26
27 void usage();
28 extern int optind;
29 extern char *optarg;
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 = "";
43
44 while ((i = getopt (ac, av, "c:htv")) != EOF)
45 switch (i)
46 {
47 case 'c':
48 sim_csize (atoi (optarg));
49 break;
50 case 'h':
51 set_h8300h (1);
52 break;
53 case 't':
54 trace = 1;
55 break;
56 case 'v':
57 verbose = 1;
58 break;
59 default:
60 usage();
61 }
62 ac -= optind;
63 av += optind;
64
65 if (ac != 1)
66 usage();
67
68 name = *av;
69
70 if (verbose)
71 printf ("run %s\n", name);
72
73 abfd = bfd_openr (name, "coff-h8300");
74 if (abfd)
75 {
76 if (bfd_check_format(abfd, bfd_object))
77 {
78 if (abfd->arch_info->mach == bfd_mach_h8300h)
79 set_h8300h (1);
80
81 for (s = abfd->sections; s; s=s->next)
82 {
83 char *buffer = malloc(bfd_section_size(abfd,s));
84 bfd_get_section_contents(abfd, s, buffer, 0, bfd_section_size(abfd,s));
85 sim_write(s->vma, buffer, bfd_section_size(abfd,s));
86 }
87
88 start_address = bfd_get_start_address(abfd);
89 sim_create_inferior (start_address, NULL, NULL);
90 sim_resume(0,0);
91 if (verbose)
92 sim_info (verbose - 1);
93 return 0;
94 }
95 }
96
97 return 1;
98 }
99
100 void
101 printf_filtered (va_alist)
102 va_dcl
103 {
104 char *msg;
105 va_list args;
106
107 va_start (args);
108 msg = va_arg (args, char *);
109 vfprintf (stdout, msg, args);
110 va_end (args);
111 }
112
113 void
114 usage()
115 {
116 fprintf (stderr, "usage: run [-tv] program\n");
117 exit (1);
118 }
This page took 0.033044 seconds and 5 git commands to generate.