summaryrefslogtreecommitdiff
path: root/tools/4.10/gdb/gdb-7.11-erc32-common-run.diff
blob: e59cd7859681dd5281ddbc3cef256b24af851896 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
diff -rNuw gdb-7.11.orig2/sim/erc32/Makefile.in gdb-7.11/sim/erc32/Makefile.in
--- gdb-7.11.orig2/sim/erc32/Makefile.in	2016-03-16 14:20:34.556597040 +1100
+++ gdb-7.11/sim/erc32/Makefile.in	2016-03-16 14:21:45.736598841 +1100
@@ -22,7 +22,7 @@
 READLINE_LIB = @READLINE@
 
 SIM_OBJS = exec.o erc32.o func.o help.o float.o interf.o
-SIM_RUN_OBJS = sis.o
+SIM_RUN_OBJS = run.o
 SIM_EXTRA_LIBS = $(READLINE_LIB) $(TERMCAP_LIB) -lm
 SIM_EXTRA_ALL = sis
 SIM_EXTRA_INSTALL = install-sis
@@ -56,4 +56,3 @@
 	  srcdir=. ; export srcdir ; \
 	else true ; fi ; \
 	(cd $${srcdir}; autoconf --localdir=../common)
-
diff -rNuw gdb-7.11.orig2/sim/erc32/run.c gdb-7.11/sim/erc32/run.c
--- gdb-7.11.orig2/sim/erc32/run.c	1970-01-01 10:00:00.000000000 +1000
+++ gdb-7.11/sim/erc32/run.c	2016-03-16 14:21:21.556598229 +1100
@@ -0,0 +1,354 @@
+/* run front end support for all the simulators.
+   Copyright (C) 1992-2015 Free Software Foundation, Inc.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Steve Chamberlain sac@cygnus.com,
+   and others at Cygnus.  */
+
+#include "config.h"
+
+#include <signal.h>
+#include <stdio.h>
+#ifdef __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#else
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+#endif
+
+#include "libiberty.h"
+#include "bfd.h"
+#include "gdb/callback.h"
+#include "gdb/remote-sim.h"
+#include "ansidecl.h"
+#include "run-sim.h"
+#include "version.h"
+
+static void usage (int help);
+static void print_version (void);
+extern int optind;
+extern char *optarg;
+
+extern host_callback default_callback;
+
+static char *myname;
+
+extern int getopt ();
+
+#ifdef NEED_UI_LOOP_HOOK
+/* Gdb foolery. This is only needed for gdb using a gui.  */
+int (*deprecated_ui_loop_hook) (int signo);
+#endif
+
+static SIM_DESC sd;
+
+static RETSIGTYPE
+cntrl_c (int sig ATTRIBUTE_UNUSED)
+{
+  if (! sim_stop (sd))
+    {
+      fprintf (stderr, "Quit!\n");
+      exit (1);
+    }
+}
+
+int
+main (ac, av)
+     int ac;
+     char **av;
+{
+  RETSIGTYPE (*prev_sigint) ();
+  bfd *abfd;
+  int i;
+  int verbose = 0;
+  int trace = 0;
+#ifdef SIM_HAVE_ENVIRONMENT
+  int operating_p = 0;
+#endif
+  char *name;
+  static char *no_args[4];
+  char **sim_argv = &no_args[0];
+  char **prog_args;
+  enum sim_stop reason;
+  int sigrc;
+
+  myname = av[0] + strlen (av[0]);
+  while (myname > av[0] && myname[-1] != '/')
+    --myname;
+
+  /* The first element of sim_open's argv is the program name.  */
+  no_args[0] = av[0];
+#ifdef SIM_HAVE_BIENDIAN
+  no_args[1] = "-E";
+  no_args[2] = "set-later";
+#endif
+
+  /* FIXME: This is currently being migrated into sim_open.
+     Simulators that use functions such as sim_size() still require
+     this.  */
+  default_callback.init (&default_callback);
+  //sim_set_callbacks (&default_callback);
+
+#ifdef SIM_TARGET_SWITCHES
+  ac = sim_target_parse_command_line (ac, av);
+#endif
+
+  for (i = 1; av[i]; ++i)
+    {
+      if (strcmp (av[i], "--help") == 0)
+        {
+          usage (1);
+        }
+      else if (strcmp (av[i], "--version") == 0)
+        {
+          print_version ();
+          return 0;
+        }
+    }
+
+  /* FIXME: This is currently being rewritten to have each simulator
+     do all argv processing.  */
+
+  while ((i = getopt (ac, av, "a:c:m:op:s:tv")) != EOF)
+    switch (i)
+      {
+      case 'a':
+	/* FIXME: Temporary hack.  */
+	{
+	  int len = strlen (av[0]) + strlen (optarg);
+	  char *argbuf = (char *) alloca (len + 2 + 50);
+	  sprintf (argbuf, "%s %s", av[0], optarg);
+#ifdef SIM_HAVE_BIENDIAN
+	  /* The desired endianness must be passed to sim_open.
+	     The value for "set-later" is set when we know what it is.
+	     -E support isn't yet part of the published interface.  */
+	  strcat (argbuf, " -E set-later");
+#endif
+	  sim_argv = buildargv (argbuf);
+	}
+	break;
+#ifdef SIM_HAVE_SIMCACHE
+      case 'c':
+	sim_set_simcache_size (atoi (optarg));
+	break;
+#endif
+      case 'm':
+	/* FIXME: Rename to sim_set_mem_size.  */
+	//sim_size (atoi (optarg));
+	break;
+#ifdef SIM_HAVE_ENVIRONMENT
+      case 'o':
+	/* Operating enironment where any signals are delivered to the
+           target.  */
+	operating_p = 1;
+	break;
+#endif
+#ifdef SIM_HAVE_PROFILE
+      case 'p':
+	sim_set_profile (atoi (optarg));
+	break;
+      case 's':
+	sim_set_profile_size (atoi (optarg));
+	break;
+#endif
+      case 't':
+	trace = 1;
+	break;
+      case 'v':
+	/* Things that are printed with -v are the kinds of things that
+	   gcc -v prints.  This is not meant to include detailed tracing
+	   or debugging information, just summaries.  */
+	verbose = 1;
+	/* sim_set_verbose (1); */
+	break;
+	/* FIXME: Quick hack, to be replaced by more general facility.  */
+      default:
+	usage (0);
+      }
+
+  ac -= optind;
+  av += optind;
+  if (ac <= 0)
+    usage (0);
+
+  name = *av;
+  prog_args = av;
+
+  if (verbose)
+    {
+      printf ("%s %s\n", myname, name);
+    }
+
+  abfd = bfd_openr (name, 0);
+  if (!abfd)
+    {
+      fprintf (stderr, "%s: can't open %s: %s\n",
+	       myname, name, bfd_errmsg (bfd_get_error ()));
+      exit (1);
+    }
+
+  if (!bfd_check_format (abfd, bfd_object))
+    {
+      fprintf (stderr, "%s: can't load %s: %s\n",
+	       myname, name, bfd_errmsg (bfd_get_error ()));
+      exit (1);
+    }
+
+#ifdef SIM_HAVE_BIENDIAN
+  /* The endianness must be passed to sim_open because one may wish to
+     examine/set registers before calling sim_load [which is the other
+     place where one can determine endianness].  We previously passed the
+     endianness via global `target_byte_order' but that's not a clean
+     interface.  */
+  for (i = 1; sim_argv[i + 1] != NULL; ++i)
+    continue;
+  if (bfd_big_endian (abfd))
+    sim_argv[i] = "big";
+  else
+    sim_argv[i] = "little";
+#endif
+
+  /* Ensure that any run-time initialisation that needs to be
+     performed by the simulator can occur.  */
+  sd = sim_open (SIM_OPEN_STANDALONE, &default_callback, abfd, sim_argv);
+  if (sd == 0)
+    exit (1);
+
+  if (sim_load (sd, name, abfd, 0) == SIM_RC_FAIL)
+    exit (1);
+
+  if (sim_create_inferior (sd, abfd, prog_args, NULL) == SIM_RC_FAIL)
+    exit (1);
+
+#ifdef SIM_HAVE_ENVIRONMENT
+  /* NOTE: An old simulator supporting the operating environment MUST
+     provide sim_set_trace() and not sim_trace(). That way
+     sim_stop_reason() can be used to determine any stop reason.  */
+  if (trace)
+    sim_set_trace ();
+  sigrc = 0;
+  do
+    {
+      prev_sigint = signal (SIGINT, cntrl_c);
+      sim_resume (sd, 0, sigrc);
+      signal (SIGINT, prev_sigint);
+      sim_stop_reason (sd, &reason, &sigrc);
+    }
+  while (operating_p && reason == sim_stopped && sigrc != SIGINT);
+#else
+  if (trace)
+    {
+      int done = 0;
+      prev_sigint = signal (SIGINT, cntrl_c);
+      while (!done)
+	{
+	  // done = sim_trace (sd);
+	}
+      signal (SIGINT, prev_sigint);
+      sim_stop_reason (sd, &reason, &sigrc);
+    }
+  else
+    {
+      prev_sigint = signal (SIGINT, cntrl_c);
+      sigrc = 0;
+      sim_resume (sd, 0, sigrc);
+      signal (SIGINT, prev_sigint);
+      sim_stop_reason (sd, &reason, &sigrc);
+    }
+#endif
+
+  if (verbose)
+    sim_info (sd, 0);
+  sim_close (sd, 0);
+
+  /* If reason is sim_exited, then sigrc holds the exit code which we want
+     to return.  If reason is sim_stopped or sim_signalled, then sigrc holds
+     the signal that the simulator received; we want to return that to
+     indicate failure.  */
+
+  /* Why did we stop? */
+  switch (reason)
+    {
+    case sim_signalled:
+    case sim_stopped:
+      if (sigrc != 0)
+	fprintf (stderr, "program stopped with signal %d.\n", sigrc);
+      break;
+
+    case sim_exited:
+      break;
+
+    case sim_running:
+    case sim_polling: /* These indicate a serious problem.  */
+      abort ();
+      break;
+
+    }
+
+  return sigrc;
+}
+
+static void
+usage (int help)
+{
+  FILE *stream = help ? stdout : stderr;
+
+  fprintf (stream, "Usage: %s [options] program [program args]\n", myname);
+  fprintf (stream, "Options:\n");
+  fprintf (stream, "-a args         Pass `args' to simulator.\n");
+#ifdef SIM_HAVE_SIMCACHE
+  fprintf (stream, "-c size         Set simulator cache size to `size'.\n");
+#endif
+  fprintf (stream, "-m size         Set memory size of simulator, in bytes.\n");
+#ifdef SIM_HAVE_ENVIRONMENT
+  fprintf (stream, "-o              Select operating (kernel) environment.\n");
+#endif
+#ifdef SIM_HAVE_PROFILE
+  fprintf (stream, "-p freq         Set profiling frequency.\n");
+  fprintf (stream, "-s size         Set profiling size.\n");
+#endif
+  fprintf (stream, "-t              Perform instruction tracing.\n");
+  fprintf (stream, "                Note: Very few simulators support tracing.\n");
+  fprintf (stream, "-v              Verbose output.\n");
+  fprintf (stream, "\n");
+  fprintf (stream, "program args    Arguments to pass to simulated program.\n");
+  fprintf (stream, "                Note: Very few simulators support this.\n");
+#ifdef SIM_TARGET_SWITCHES
+  fprintf (stream, "\nTarget specific options:\n");
+  sim_target_display_usage (help);
+#endif
+
+  if (help && REPORT_BUGS_TO[0])
+    printf ("Report bugs to %s\n", REPORT_BUGS_TO);
+
+  exit (help ? 0 : 1);
+}
+
+static void
+print_version ()
+{
+  printf ("GNU simulator %s%s\n", PKGVERSION, version);
+}
diff -rNuw gdb-7.11.orig2/sim/erc32/run-sim.h gdb-7.11/sim/erc32/run-sim.h
--- gdb-7.11.orig2/sim/erc32/run-sim.h	1970-01-01 10:00:00.000000000 +1000
+++ gdb-7.11/sim/erc32/run-sim.h	2016-03-16 14:22:00.512599215 +1100
@@ -0,0 +1,93 @@
+/* This file defines the part of the interface between the standalone
+   simaulator program - run - and simulator library - libsim.a - that
+   is not used by GDB.  The GDB part is described in include/remote-sim.h.
+
+   Copyright 2002-2015 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef RUN_SIM_H
+#define RUN_SIM_H
+
+#ifdef SIM_TARGET_SWITCHES
+  /* Parse the command line, extracting any target specific switches
+     before the generic simulator code gets a chance to complain
+     about them.  Returns the adjusted value of argc.  */
+int sim_target_parse_command_line (int, char **);
+
+  /* Display a list of target specific switches supported by this
+     target.  */
+void sim_target_display_usage (int help);
+
+#endif
+
+/* Provide simulator with a default (global) host_callback_struct.
+   THIS PROCEDURE IS DEPRECATED.
+   GDB and NRUN do not use this interface.
+   This procedure does not take a SIM_DESC argument as it is
+   used before sim_open. */
+
+void sim_set_callbacks (struct host_callback_struct *);
+
+
+/* Set the size of the simulator memory array.
+   THIS PROCEDURE IS DEPRECATED.
+   GDB and NRUN do not use this interface.
+   This procedure does not take a SIM_DESC argument as it is
+   used before sim_open. */
+
+void sim_size (int i);
+
+
+/* Single-step simulator with tracing enabled.
+   THIS PROCEDURE IS DEPRECATED.
+   THIS PROCEDURE IS EVEN MORE DEPRECATED THAN SIM_SET_TRACE
+   GDB and NRUN do not use this interface.
+   This procedure returns: ``0'' indicating that the simulator should
+   be continued using sim_trace() calls; ``1'' indicating that the
+   simulation has finished. */
+
+int sim_trace (SIM_DESC sd);
+
+
+/* Enable tracing.
+   THIS PROCEDURE IS DEPRECATED.
+   GDB and NRUN do not use this interface.
+   This procedure returns: ``0'' indicating that the simulator should
+   be continued using sim_trace() calls; ``1'' indicating that the
+   simulation has finished. */
+
+void sim_set_trace (void);
+
+
+/* Configure the size of the profile buffer.
+   THIS PROCEDURE IS DEPRECATED.
+   GDB and NRUN do not use this interface.
+   This procedure does not take a SIM_DESC argument as it is
+   used before sim_open. */
+
+void sim_set_profile_size (int n);
+
+
+/* Kill the running program.
+   THIS PROCEDURE IS DEPRECATED.
+   GDB and NRUN do not use this interface.
+   This procedure will be replaced as part of the introduction of
+   multi-cpu simulators. */
+
+void sim_kill (SIM_DESC sd);
+
+#endif