1 /* main.c --- main function for stand-alone RL78 simulator.
3 Copyright (C) 2011-2024 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/>.
22 /* This must come before any other includes. */
34 #include "libiberty.h"
42 static int disassemble
= 0;
43 static const char * dump_counts_filename
= NULL
;
50 printf ("Exit code: %d\n", exit_code
);
51 printf ("total clocks: %lld\n", total_clocks
);
53 if (dump_counts_filename
)
54 dump_counts_per_insn (dump_counts_filename
);
59 main (int argc
, char **argv
)
65 static const struct option longopts
[] = { { 0 } };
67 xmalloc_set_program_name (argv
[0]);
69 while ((o
= getopt_long (argc
, argv
, "tvdr:D:M:", longopts
, NULL
))
84 mem_ram_size (atoi (optarg
));
87 dump_counts_filename
= optarg
;
90 if (strcmp (optarg
, "g10") == 0)
95 mem_set_mirror (0, 0xf8000, 4096);
97 if (strcmp (optarg
, "g13") == 0)
103 if (strcmp (optarg
, "g14") == 0)
113 "usage: run [options] program [arguments]\n");
115 "\t-v\t\t- increase verbosity.\n"
117 "\t-d\t\t- disassemble.\n"
118 "\t-r <bytes>\t- ram size.\n"
119 "\t-M <mcu>\t- mcu type, default none, allowed: g10,g13,g14\n"
120 "\t-D <filename>\t- dump cycle count histogram\n");
126 prog
= bfd_openr (argv
[optind
], 0);
129 fprintf (stderr
, "Can't read %s\n", argv
[optind
]);
133 if (!bfd_check_format (prog
, bfd_object
))
135 fprintf (stderr
, "%s not a rl78 program\n", argv
[optind
]);
144 rl78_load (prog
, 0, argv
[0]);
147 sim_disasm_init (prog
);
149 rc
= setjmp (decode_jmp_buf
);
153 if (!trace
&& !disassemble
)
155 /* This will longjmp to the above if an exception
170 rc
= decode_opcode ();
173 trace_register_changes ();
177 if (RL78_HIT_BREAK (rc
))
179 else if (RL78_EXITED (rc
))
180 done (RL78_EXIT_STATUS (rc
));
181 else if (RL78_STOPPED (rc
))
184 printf ("Stopped on signal %d\n", RL78_STOP_SIG (rc
));