1 /* main.c --- main function for stand-alone RL78 simulator.
3 Copyright (C) 2011-2018 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:M:")) != -1)
85 mem_ram_size (atoi (optarg
));
88 dump_counts_filename
= optarg
;
91 if (strcmp (optarg
, "g10") == 0)
96 mem_set_mirror (0, 0xf8000, 4096);
98 if (strcmp (optarg
, "g13") == 0)
104 if (strcmp (optarg
, "g14") == 0)
114 "usage: run [options] program [arguments]\n");
116 "\t-v\t\t- increase verbosity.\n"
118 "\t-d\t\t- disassemble.\n"
119 "\t-r <bytes>\t- ram size.\n"
120 "\t-M <mcu>\t- mcu type, default none, allowed: g10,g13,g14\n"
121 "\t-D <filename>\t- dump cycle count histogram\n");
127 prog
= bfd_openr (argv
[optind
], 0);
130 fprintf (stderr
, "Can't read %s\n", argv
[optind
]);
134 if (!bfd_check_format (prog
, bfd_object
))
136 fprintf (stderr
, "%s not a rl78 program\n", argv
[optind
]);
145 rl78_load (prog
, 0, argv
[0]);
148 sim_disasm_init (prog
);
150 rc
= setjmp (decode_jmp_buf
);
154 if (!trace
&& !disassemble
)
156 /* This will longjmp to the above if an exception
171 rc
= decode_opcode ();
174 trace_register_changes ();
178 if (RL78_HIT_BREAK (rc
))
180 else if (RL78_EXITED (rc
))
181 done (RL78_EXIT_STATUS (rc
));
182 else if (RL78_STOPPED (rc
))
185 printf ("Stopped on signal %d\n", RL78_STOP_SIG (rc
));