Update FSF address.
[deliverable/binutils-gdb.git] / sim / sh / run.c
CommitLineData
057af5c9 1/* run front end support for SH
594266fc
SC
2 Copyright (C) 1987, 1992 Free Software Foundation, Inc.
3
057af5c9 4This file is part of SH SIM
594266fc
SC
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU CC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
6c9638b4
FF
17along with this program; if not, write to the Free Software
18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
594266fc
SC
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
057af5c9
C
30void usage();
31extern int optind;
32extern char *optarg;
33
d2fd61a8
SC
34int target_byte_order;
35
594266fc
SC
36int
37main (ac, av)
38 int ac;
39 char **av;
40{
41 bfd *abfd;
42 bfd_vma start_address;
43 asection *s;
44 int i;
45 int verbose = 0;
46 int trace = 0;
47 char *name = "";
d2fd61a8 48
057af5c9
C
49 while ((i = getopt (ac, av, "m:p:s:tv")) != EOF)
50 switch (i)
51 {
52 case 'm':
53 sim_size (atoi (optarg));
54 break;
55 case 'p':
56 sim_set_profile (atoi (optarg));
57 break;
58 case 's':
59 sim_set_profile_size (atoi (optarg));
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;
77
594266fc
SC
78 if (verbose)
79 {
80 printf ("run %s\n", name);
81 }
d2fd61a8 82 abfd = bfd_openr (name, 0);
594266fc
SC
83 if (abfd)
84 {
594266fc
SC
85 if (bfd_check_format (abfd, bfd_object))
86 {
87
88 for (s = abfd->sections; s; s = s->next)
89 {
90 unsigned char *buffer = malloc (bfd_section_size (abfd, s));
91 bfd_get_section_contents (abfd,
92 s,
93 buffer,
94 0,
95 bfd_section_size (abfd, s));
96 sim_write (s->vma, buffer, bfd_section_size (abfd, s));
97 }
98
99 start_address = bfd_get_start_address (abfd);
fe031f82 100 sim_create_inferior (start_address, NULL, NULL);
d2fd61a8
SC
101
102 target_byte_order = abfd->xvec->byteorder_big_p ? 4321 : 1234;
103
594266fc
SC
104 if (trace)
105 {
106 int done = 0;
107 while (!done)
108 {
109 done = sim_trace ();
110 }
111 }
112 else
113 {
114 sim_resume (0, 0);
115 }
116 if (verbose)
fe031f82 117 sim_info (0);
594266fc 118
4d0be1f5
SC
119 /* Assume we left through the exit system call,
120 in which case r5 has the exit code */
f6fba995
SC
121 {
122 unsigned char b[4];
4d0be1f5 123 sim_fetch_register (5, b);
f6fba995
SC
124 return b[3];
125 }
d2fd61a8 126
594266fc
SC
127 }
128 }
129
130 return 1;
131}
057af5c9
C
132
133void
134usage()
135{
136 fprintf (stderr, "usage: run [-tv] program\n");
137 exit (1);
138}
139
fe031f82
DE
140\f
141/* Callbacks used by the simulator proper. */
142
143void
144printf_filtered (va_alist)
145 va_dcl
146{
147 va_list args;
148 char *format;
149
150 va_start (args);
151 format = va_arg (args, char *);
152
153 vfprintf (stdout, format, args);
154 va_end (args);
155}
This page took 0.163347 seconds and 4 git commands to generate.