No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / gdb6 / sim / m32c / main.c
blob541bc4329208c0e5a853ef360b467605c0797a81
1 /* main.c --- main function for stand-alone M32C simulator.
3 Copyright (C) 2005 Free Software Foundation, Inc.
4 Contributed by Red Hat, Inc.
6 This file is part of the GNU simulators.
8 The GNU simulators are free software; you can redistribute them and/or
9 modify them under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version.
13 The GNU simulators are distributed in the hope that they will be
14 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with the GNU simulators; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 02110-1301, USA */
24 #include <stdio.h>
25 #include <string.h>
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include <assert.h>
29 #include <setjmp.h>
30 #include <signal.h>
32 #include "bfd.h"
34 #include "cpu.h"
35 #include "mem.h"
36 #include "misc.h"
37 #include "load.h"
38 #include "trace.h"
40 static int disassemble = 0;
41 static unsigned int cycles = 0;
43 static void
44 done (int exit_code)
46 if (verbose)
48 stack_heap_stats ();
49 mem_usage_stats ();
50 printf ("insns: %14s\n", comma (cycles));
52 exit (exit_code);
55 int
56 main (int argc, char **argv)
58 int o;
59 int save_trace;
60 bfd *prog;
62 while ((o = getopt (argc, argv, "tvdm:")) != -1)
63 switch (o)
65 case 't':
66 trace++;
67 break;
68 case 'v':
69 verbose++;
70 break;
71 case 'd':
72 disassemble++;
73 break;
74 case 'm':
75 if (strcmp (optarg, "r8c") == 0 || strcmp (optarg, "m16c") == 0)
76 default_machine = bfd_mach_m16c;
77 else if (strcmp (optarg, "m32cm") == 0
78 || strcmp (optarg, "m32c") == 0)
79 default_machine = bfd_mach_m32c;
80 else
82 fprintf (stderr, "Invalid machine: %s\n", optarg);
83 exit (1);
85 break;
86 case '?':
87 fprintf (stderr,
88 "usage: run [-v] [-t] [-d] [-m r8c|m16c|m32cm|m32c]"
89 " program\n");
90 exit (1);
93 prog = bfd_openr (argv[optind], 0);
94 if (!prog)
96 fprintf (stderr, "Can't read %s\n", argv[optind]);
97 exit (1);
100 if (!bfd_check_format (prog, bfd_object))
102 fprintf (stderr, "%s not a m32c program\n", argv[optind]);
103 exit (1);
106 save_trace = trace;
107 trace = 0;
108 m32c_load (prog);
109 trace = save_trace;
111 if (disassemble)
112 sim_disasm_init (prog);
114 while (1)
116 int rc;
118 if (trace)
119 printf ("\n");
121 if (disassemble)
122 sim_disasm_one ();
124 enable_counting = verbose;
125 cycles++;
126 rc = decode_opcode ();
127 enable_counting = 0;
129 if (M32C_HIT_BREAK (rc))
130 done (1);
131 else if (M32C_EXITED (rc))
132 done (M32C_EXIT_STATUS (rc));
133 else
134 assert (M32C_STEPPED (rc));
136 trace_register_changes ();