1 /* main.c --- main function for stand-alone RL78 simulator.
4 Free Software Foundation, Inc.
5 Contributed by Red Hat, Inc.
7 This file is part of the GNU simulators.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
38 #include "libiberty.h"
46 static int disassemble = 0;
47 static const char * dump_counts_filename = NULL;
54 printf ("Exit code: %d\n", exit_code);
55 printf ("total clocks: %lld\n", total_clocks);
57 if (dump_counts_filename)
58 dump_counts_per_insn (dump_counts_filename);
63 main (int argc, char **argv)
70 xmalloc_set_program_name (argv[0]);
72 while ((o = getopt (argc, argv, "tvdr:D:")) != -1)
86 mem_ram_size (atoi (optarg));
89 dump_counts_filename = optarg;
94 "usage: run [options] program [arguments]\n");
96 "\t-v\t\t- increase verbosity.\n"
98 "\t-d\t\t- disassemble.\n"
99 "\t-r <bytes>\t- ram size.\n"
100 "\t-D <filename>\t- dump cycle count histogram\n");
106 prog = bfd_openr (argv[optind], 0);
109 fprintf (stderr, "Can't read %s\n", argv[optind]);
113 if (!bfd_check_format (prog, bfd_object))
115 fprintf (stderr, "%s not a rl78 program\n", argv[optind]);
124 rl78_load (prog, 0, argv[0]);
127 sim_disasm_init (prog);
129 rc = setjmp (decode_jmp_buf);
133 if (!trace && !disassemble)
135 /* This will longjmp to the above if an exception
150 rc = decode_opcode ();
153 trace_register_changes ();
157 if (RL78_HIT_BREAK (rc))
159 else if (RL78_EXITED (rc))
160 done (RL78_EXIT_STATUS (rc));
161 else if (RL78_STOPPED (rc))
164 printf ("Stopped on signal %d\n", RL78_STOP_SIG (rc));