1 /* This file is part of the program psim.
3 Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include <signal.h> /* FIXME - should be machine dependant version */
31 #include "../../gdb/defs.h"
35 #include "../../gdb/remote-sim.h"
38 /* Structures used by the simulator, for gdb just have static structures */
40 static psim *simulator;
42 static char *register_names[] = REGISTER_NAMES;
43 static int print_info = 0;
51 TRACE(trace_gdb, ("sim_open(args=%s) called\n", args ? args : "(null)"));
54 char *buf = (char *)alloca (strlen (args) + 1);
58 p = strtok (args, " \t");
59 while (p != (char *)0) {
61 error ("Argument is not an option '%s'", p);
64 /* check arguments -- note, main.c also contains argument processing
65 code for the standalone emulator. */
66 while (*++p != '\0') {
69 error ("Usage: target sim [ -a -p -c -C -s -i -I -t ]\n");
72 for (i = 0; i < nr_trace; i++)
76 trace[trace_cpu] = trace[trace_semantics] = 1;
79 trace[trace_core] = 1;
82 trace[trace_console_device] = 1;
85 trace[trace_create_stack] = 1;
88 trace[trace_icu_device] = 1;
94 trace[trace_device_tree] = 1;
100 p = strtok ((char *)0, " \t");
105 TRACE(trace_tbd, ("sim_open() - TBD - should parse the arguments\n"));
106 TRACE(trace_tbd, ("sim_open() - TBD - can not create simulator here as do not have description of it\n"));
111 sim_close (int quitting)
113 TRACE(trace_gdb, ("sim_close(quitting=%d) called\n", quitting));
115 psim_print_info (simulator, 1);
122 sim_load (char *prog, int from_tty)
124 TRACE(trace_gdb, ("sim_load(prog=%s, from_tty=%d) called\n",
129 error ("sim_load() - TBD - read stan shebs e-mail about how to find the program name?\n");
132 TRACE(trace_tbd, ("sim_load() - TBD - parse that prog stripping things like quotes\n"));
134 /* create the simulator */
135 TRACE(trace_gdb, ("sim_load() - first time, create the simulator\n"));
136 nr_cpus = (WITH_SMP ? WITH_SMP : 1);
137 simulator = psim_create(prog, nr_cpus);
139 /* bring in all the data section */
140 psim_load(simulator);
149 TRACE(trace_gdb, ("sim_kill(void) called\n"));
150 /* do nothing, nothing to do */
155 sim_read (SIM_ADDR mem, unsigned char *buf, int length)
157 return psim_read_memory(simulator, nr_cpus, buf, mem, length,
163 sim_write (SIM_ADDR mem, unsigned char *buf, int length)
165 return psim_write_memory(simulator, nr_cpus, buf, mem, length,
166 raw_transfer, 1/*violate_ro*/);
171 sim_fetch_register (int regno, unsigned char *buf)
173 if (simulator == NULL) {
177 psim_read_register(simulator, nr_cpus, buf, register_names[regno],
183 sim_store_register (int regno, unsigned char *buf)
185 if (simulator == NULL)
188 psim_write_register(simulator, nr_cpus, buf, register_names[regno],
194 sim_info (int verbose)
196 TRACE(trace_gdb, ("sim_info(verbose=%d) called\n", verbose));
197 psim_print_info (simulator, verbose);
202 sim_create_inferior (SIM_ADDR start_address, char **argv, char **envp)
204 unsigned_word entry_point = start_address;
206 TRACE(trace_gdb, ("sim_create_inferior(start_address=0x%x, ...)\n",
209 psim_load(simulator);
210 psim_stack(simulator, argv, envp);
212 psim_write_register(simulator, -1 /* all start at same PC */,
213 &entry_point, "pc", cooked_transfer);
217 static volatile int sim_should_run;
220 sim_stop_reason (enum sim_stop *reason, int *sigrc)
222 psim_status status = psim_get_status(simulator);
224 switch (CURRENT_ENVIRONMENT) {
226 case VIRTUAL_ENVIRONMENT:
227 switch (status.reason) {
229 *reason = sim_stopped;
231 if (sim_should_run) {
232 error("sim_stop_reason() unknown reason for halt\n");
236 *reason = sim_stopped;
240 *reason = sim_exited;
244 *reason = sim_signalled;
245 *sigrc = status.signal;
250 case OPERATING_ENVIRONMENT:
251 *reason = sim_stopped;
256 error("sim_stop_reason() - unknown environment\n");
263 /* Run (or resume) the program. */
271 sim_resume (int step, int siggnal)
274 unsigned_word program_counter;
276 prev = signal(SIGINT, sim_ctrl_c);
280 psim_step(simulator);
282 psim_run_until_stop(simulator, &sim_should_run);
284 signal(SIGINT, prev);
288 sim_do_command(char *cmd)
290 TRACE(trace_gdb, ("sim_do_commands(cmd=%s) called\n", cmd));
298 void *memory = (void*)xmalloc(size);
300 error("xmalloc failed\n");
305 void zfree(void *data)