1 /* main.c --- main function for stand-alone RX simulator.
3 Copyright (C) 2005-2021 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/>. */
43 static int disassemble
= 0;
45 /* This must be higher than any other option index. */
48 #define ACT(E,A) (OPT_ACT + SIM_ERR_##E * SIM_ERRACTION_NUM_ACTIONS + SIM_ERRACTION_##A)
50 static struct option sim_options
[] =
52 { "end-sim-args", 0, NULL
, 'E' },
53 { "exit-null-deref", 0, NULL
, ACT(NULL_POINTER_DEREFERENCE
,EXIT
) },
54 { "warn-null-deref", 0, NULL
, ACT(NULL_POINTER_DEREFERENCE
,WARN
) },
55 { "ignore-null-deref", 0, NULL
, ACT(NULL_POINTER_DEREFERENCE
,IGNORE
) },
56 { "exit-unwritten-pages", 0, NULL
, ACT(READ_UNWRITTEN_PAGES
,EXIT
) },
57 { "warn-unwritten-pages", 0, NULL
, ACT(READ_UNWRITTEN_PAGES
,WARN
) },
58 { "ignore-unwritten-pages", 0, NULL
, ACT(READ_UNWRITTEN_PAGES
,IGNORE
) },
59 { "exit-unwritten-bytes", 0, NULL
, ACT(READ_UNWRITTEN_BYTES
,EXIT
) },
60 { "warn-unwritten-bytes", 0, NULL
, ACT(READ_UNWRITTEN_BYTES
,WARN
) },
61 { "ignore-unwritten-bytes", 0, NULL
, ACT(READ_UNWRITTEN_BYTES
,IGNORE
) },
62 { "exit-corrupt-stack", 0, NULL
, ACT(CORRUPT_STACK
,EXIT
) },
63 { "warn-corrupt-stack", 0, NULL
, ACT(CORRUPT_STACK
,WARN
) },
64 { "ignore-corrupt-stack", 0, NULL
, ACT(CORRUPT_STACK
,IGNORE
) },
75 /* Only use comma separated numbers when being very verbose.
76 Comma separated numbers are hard to parse in awk scripts. */
78 printf ("insns: %14s\n", comma (rx_cycles
));
80 printf ("insns: %u\n", rx_cycles
);
88 main (int argc
, char **argv
)
95 /* By default, we exit when an execution error occurs. */
96 execution_error_init_standalone ();
98 while ((o
= getopt_long (argc
, argv
, "tvdeEwi", sim_options
, NULL
)) != -1)
101 /* Stop processing the command line. This is so that any remaining
102 words on the command line that look like arguments will be passed
103 on to the program being simulated. */
111 e
= o
/ SIM_ERRACTION_NUM_ACTIONS
;
112 a
= o
% SIM_ERRACTION_NUM_ACTIONS
;
113 execution_error_set_action (e
, a
);
127 execution_error_init_standalone ();
130 execution_error_warn_all ();
133 execution_error_ignore_all ();
139 "usage: run [options] program [arguments]\n");
141 "\t-v\t- increase verbosity.\n"
143 "\t-d\t- disassemble.\n"
144 "\t-E\t- stop processing sim args\n"
145 "\t-e\t- exit on all execution errors.\n"
146 "\t-w\t- warn (do not exit) on all execution errors.\n"
147 "\t-i\t- ignore all execution errors.\n");
148 for (i
=0; sim_options
[i
].name
; i
++)
149 fprintf (stderr
, "\t--%s\n", sim_options
[i
].name
);
155 prog
= bfd_openr (argv
[optind
], 0);
158 fprintf (stderr
, "Can't read %s\n", argv
[optind
]);
162 if (!bfd_check_format (prog
, bfd_object
))
164 fprintf (stderr
, "%s not a rx program\n", argv
[optind
]);
173 rx_load (prog
, NULL
);
176 sim_disasm_init (prog
);
178 enable_counting
= verbose
;
180 rc
= setjmp (decode_jmp_buf
);
184 if (!trace
&& !disassemble
)
186 /* This will longjmp to the above if an exception
202 enable_counting
= verbose
;
205 rc
= decode_opcode ();
208 trace_register_changes ();
212 if (RX_HIT_BREAK (rc
))
214 else if (RX_EXITED (rc
))
215 done (RX_EXIT_STATUS (rc
));
216 else if (RX_STOPPED (rc
))
219 printf("Stopped on signal %d\n", RX_STOP_SIG (rc
));