]> Git Repo - binutils.git/blob - sim/sh/run.c
Update FSF address.
[binutils.git] / sim / sh / run.c
1 /* run front end support for SH
2    Copyright (C) 1987, 1992 Free Software Foundation, Inc.
3
4 This file is part of SH 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 this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
19
20
21 /* Steve Chamberlain
22    [email protected] */
23
24 #include <stdio.h>
25 #include <varargs.h>
26 #include "bfd.h"
27 #include "sysdep.h"
28 #include "remote-sim.h"
29
30 void usage();
31 extern int optind;
32 extern char *optarg;
33
34 int target_byte_order;
35
36 int
37 main (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 = "";
48
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
78   if (verbose)
79     {
80       printf ("run %s\n", name);
81     }
82   abfd = bfd_openr (name, 0);
83   if (abfd)
84     {
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);
100           sim_create_inferior (start_address, NULL, NULL);
101
102           target_byte_order = abfd->xvec->byteorder_big_p ? 4321 : 1234;
103
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)
117             sim_info (0);
118
119           /* Assume we left through the exit system call,
120              in which case r5 has the exit code */
121           {
122             unsigned char b[4];
123             sim_fetch_register (5, b);
124             return b[3];
125           }
126
127         }
128     }
129
130   return 1;
131 }
132
133 void
134 usage()
135 {
136   fprintf (stderr, "usage: run [-tv] program\n");
137   exit (1);
138 }
139
140 \f
141 /* Callbacks used by the simulator proper.  */
142
143 void
144 printf_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.031479 seconds and 4 git commands to generate.