1 /* main.c --- main function for stand-alone RL78 simulator.
3 Copyright (C) 2011-2014 Free Software Foundation, Inc.
4 Contributed by Red Hat, Inc.
6 This file is part of the GNU simulators.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
37 #include "libiberty.h"
45 static int disassemble = 0;
46 static const char * dump_counts_filename = NULL;
53 printf ("Exit code: %d\n", exit_code);
54 printf ("total clocks: %lld\n", total_clocks);
56 if (dump_counts_filename)
57 dump_counts_per_insn (dump_counts_filename);
62 main (int argc, char **argv)
69 xmalloc_set_program_name (argv[0]);
71 while ((o = getopt (argc, argv, "tvdr:D:")) != -1)
85 mem_ram_size (atoi (optarg));
88 dump_counts_filename = optarg;
93 "usage: run [options] program [arguments]\n");
95 "\t-v\t\t- increase verbosity.\n"
97 "\t-d\t\t- disassemble.\n"
98 "\t-r <bytes>\t- ram size.\n"
99 "\t-D <filename>\t- dump cycle count histogram\n");
105 prog = bfd_openr (argv[optind], 0);
108 fprintf (stderr, "Can't read %s\n", argv[optind]);
112 if (!bfd_check_format (prog, bfd_object))
114 fprintf (stderr, "%s not a rl78 program\n", argv[optind]);
123 rl78_load (prog, 0, argv[0]);
126 sim_disasm_init (prog);
128 rc = setjmp (decode_jmp_buf);
132 if (!trace && !disassemble)
134 /* This will longjmp to the above if an exception
149 rc = decode_opcode ();
152 trace_register_changes ();
156 if (RL78_HIT_BREAK (rc))
158 else if (RL78_EXITED (rc))
159 done (RL78_EXIT_STATUS (rc));
160 else if (RL78_STOPPED (rc))
163 printf ("Stopped on signal %d\n", RL78_STOP_SIG (rc));