]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/arm/run.c
Update FSF address.
[thirdparty/binutils-gdb.git] / sim / arm / run.c
CommitLineData
2494eaf6
SC
1/* run front end support for ARM
2 Copyright (C) 1996 Free Software Foundation, Inc.
3
4This file is part of ARM SIM
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
17along with GNU CC; see the file COPYING. If not, write to
6c9638b4 18Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
2494eaf6
SC
19
20
21/* Steve Chamberlain
22 sac@cygnus.com */
23
24#include <stdio.h>
25#include <varargs.h>
26#include "bfd.h"
27#include "sysdep.h"
28#include "remote-sim.h"
29
30void usage();
31extern int optind;
32extern char *optarg;
33
34int target_byte_order;
35
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 = "";
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,
c8aea29b 120 in which case r0 has the exit code */
2494eaf6
SC
121 {
122 unsigned char b[4];
c8aea29b
SC
123 sim_fetch_register (0, b);
124 return b[0];
2494eaf6
SC
125 }
126
127 }
128 }
129
130 return 1;
131}
132
133void
134usage()
135{
136 fprintf (stderr, "usage: run [-tv] program\n");
137 exit (1);
138}
139
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}