1 /* main.c --- main function for stand-alone RX simulator.
3 Copyright (C) 2005, 2007, 2008, 2009, 2010, 2011
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/>. */
48 static int disassemble
= 0;
50 /* This must be higher than any other option index. */
53 #define ACT(E,A) (OPT_ACT + SIM_ERR_##E * SIM_ERRACTION_NUM_ACTIONS + SIM_ERRACTION_##A)
55 static struct option sim_options
[] =
57 { "end-sim-args", 0, NULL
, 'E' },
58 { "exit-null-deref", 0, NULL
, ACT(NULL_POINTER_DEREFERENCE
,EXIT
) },
59 { "warn-null-deref", 0, NULL
, ACT(NULL_POINTER_DEREFERENCE
,WARN
) },
60 { "ignore-null-deref", 0, NULL
, ACT(NULL_POINTER_DEREFERENCE
,IGNORE
) },
61 { "exit-unwritten-pages", 0, NULL
, ACT(READ_UNWRITTEN_PAGES
,EXIT
) },
62 { "warn-unwritten-pages", 0, NULL
, ACT(READ_UNWRITTEN_PAGES
,WARN
) },
63 { "ignore-unwritten-pages", 0, NULL
, ACT(READ_UNWRITTEN_PAGES
,IGNORE
) },
64 { "exit-unwritten-bytes", 0, NULL
, ACT(READ_UNWRITTEN_BYTES
,EXIT
) },
65 { "warn-unwritten-bytes", 0, NULL
, ACT(READ_UNWRITTEN_BYTES
,WARN
) },
66 { "ignore-unwritten-bytes", 0, NULL
, ACT(READ_UNWRITTEN_BYTES
,IGNORE
) },
67 { "exit-corrupt-stack", 0, NULL
, ACT(CORRUPT_STACK
,EXIT
) },
68 { "warn-corrupt-stack", 0, NULL
, ACT(CORRUPT_STACK
,WARN
) },
69 { "ignore-corrupt-stack", 0, NULL
, ACT(CORRUPT_STACK
,IGNORE
) },
80 /* Only use comma separated numbers when being very verbose.
81 Comma separated numbers are hard to parse in awk scripts. */
83 printf ("insns: %14s\n", comma (rx_cycles
));
85 printf ("insns: %u\n", rx_cycles
);
93 main (int argc
, char **argv
)
100 /* By default, we exit when an execution error occurs. */
101 execution_error_init_standalone ();
103 while ((o
= getopt_long (argc
, argv
, "tvdeEwi", sim_options
, NULL
)) != -1)
106 /* Stop processing the command line. This is so that any remaining
107 words on the command line that look like arguments will be passed
108 on to the program being simulated. */
116 e
= o
/ SIM_ERRACTION_NUM_ACTIONS
;
117 a
= o
% SIM_ERRACTION_NUM_ACTIONS
;
118 execution_error_set_action (e
, a
);
132 execution_error_init_standalone ();
135 execution_error_warn_all ();
138 execution_error_ignore_all ();
144 "usage: run [options] program [arguments]\n");
146 "\t-v\t- increase verbosity.\n"
148 "\t-d\t- disassemble.\n"
149 "\t-E\t- stop processing sim args\n"
150 "\t-e\t- exit on all execution errors.\n"
151 "\t-w\t- warn (do not exit) on all execution errors.\n"
152 "\t-i\t- ignore all execution errors.\n");
153 for (i
=0; sim_options
[i
].name
; i
++)
154 fprintf (stderr
, "\t--%s\n", sim_options
[i
].name
);
160 prog
= bfd_openr (argv
[optind
], 0);
163 fprintf (stderr
, "Can't read %s\n", argv
[optind
]);
167 if (!bfd_check_format (prog
, bfd_object
))
169 fprintf (stderr
, "%s not a rx program\n", argv
[optind
]);
181 sim_disasm_init (prog
);
183 enable_counting
= verbose
;
185 rc
= setjmp (decode_jmp_buf
);
189 if (!trace
&& !disassemble
)
191 /* This will longjmp to the above if an exception
207 enable_counting
= verbose
;
210 rc
= decode_opcode ();
213 trace_register_changes ();
217 if (RX_HIT_BREAK (rc
))
219 else if (RX_EXITED (rc
))
220 done (RX_EXIT_STATUS (rc
));
221 else if (RX_STOPPED (rc
))
224 printf("Stopped on signal %d\n", RX_STOP_SIG (rc
));