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"
36 #include "../../gdb/callback.h"
39 /* Structures used by the simulator, for gdb just have static structures */
41 static psim
*simulator
;
43 static char *register_names
[] = REGISTER_NAMES
;
44 static int print_info
= 0;
52 TRACE(trace_gdb
, ("sim_open(args=%s) called\n", args
? args
: "(null)"));
55 char *buf
= (char *)alloca (strlen (args
) + 1);
59 p
= strtok (args
, " \t");
60 while (p
!= (char *)0) {
62 error ("Argument is not an option '%s'", p
);
65 /* check arguments -- note, main.c also contains argument processing
66 code for the standalone emulator. */
67 while (*++p
!= '\0') {
70 error ("Usage: target sim [ -a -p -c -C -s -i -I -t ]\n");
73 for (i
= 0; i
< nr_trace
; i
++)
77 trace
[trace_cpu
] = trace
[trace_semantics
] = 1;
80 trace
[trace_core
] = 1;
83 trace
[trace_console_device
] = 1;
86 trace
[trace_create_stack
] = 1;
89 trace
[trace_icu_device
] = 1;
95 trace
[trace_device_tree
] = 1;
101 p
= strtok ((char *)0, " \t");
106 TRACE(trace_tbd
, ("sim_open() - TBD - should parse the arguments\n"));
107 TRACE(trace_tbd
, ("sim_open() - TBD - can not create simulator here as do not have description of it\n"));
112 sim_close (int quitting
)
114 TRACE(trace_gdb
, ("sim_close(quitting=%d) called\n", quitting
));
116 psim_print_info (simulator
, 1);
123 sim_load (char *prog
, int from_tty
)
125 TRACE(trace_gdb
, ("sim_load(prog=%s, from_tty=%d) called\n",
130 error ("sim_load() - TBD - read stan shebs e-mail about how to find the program name?\n");
133 TRACE(trace_tbd
, ("sim_load() - TBD - parse that prog stripping things like quotes\n"));
135 /* create the simulator */
136 TRACE(trace_gdb
, ("sim_load() - first time, create the simulator\n"));
137 nr_cpus
= (WITH_SMP
? WITH_SMP
: 1);
138 simulator
= psim_create(prog
, nr_cpus
);
140 /* bring in all the data section */
141 psim_load(simulator
);
150 TRACE(trace_gdb
, ("sim_kill(void) called\n"));
151 /* do nothing, nothing to do */
156 sim_read (SIM_ADDR mem
, unsigned char *buf
, int length
)
158 return psim_read_memory(simulator
, nr_cpus
, buf
, mem
, length
,
164 sim_write (SIM_ADDR mem
, unsigned char *buf
, int length
)
166 return psim_write_memory(simulator
, nr_cpus
, buf
, mem
, length
,
167 raw_transfer
, 1/*violate_ro*/);
172 sim_fetch_register (int regno
, unsigned char *buf
)
174 if (simulator
== NULL
) {
178 psim_read_register(simulator
, nr_cpus
, buf
, register_names
[regno
],
184 sim_store_register (int regno
, unsigned char *buf
)
186 if (simulator
== NULL
)
189 psim_write_register(simulator
, nr_cpus
, buf
, register_names
[regno
],
195 sim_info (int verbose
)
197 TRACE(trace_gdb
, ("sim_info(verbose=%d) called\n", verbose
));
198 psim_print_info (simulator
, verbose
);
203 sim_create_inferior (SIM_ADDR start_address
, char **argv
, char **envp
)
205 unsigned_word entry_point
= start_address
;
207 TRACE(trace_gdb
, ("sim_create_inferior(start_address=0x%x, ...)\n",
210 psim_load(simulator
);
211 psim_stack(simulator
, argv
, envp
);
213 psim_write_register(simulator
, -1 /* all start at same PC */,
214 &entry_point
, "pc", cooked_transfer
);
218 static volatile int sim_should_run
;
221 sim_stop_reason (enum sim_stop
*reason
, int *sigrc
)
223 psim_status status
= psim_get_status(simulator
);
225 switch (CURRENT_ENVIRONMENT
) {
227 case VIRTUAL_ENVIRONMENT
:
228 switch (status
.reason
) {
230 *reason
= sim_stopped
;
232 if (sim_should_run
) {
233 error("sim_stop_reason() unknown reason for halt\n");
237 *reason
= sim_stopped
;
241 *reason
= sim_exited
;
245 *reason
= sim_signalled
;
246 *sigrc
= status
.signal
;
251 case OPERATING_ENVIRONMENT
:
252 *reason
= sim_stopped
;
257 error("sim_stop_reason() - unknown environment\n");
264 /* Run (or resume) the program. */
272 sim_resume (int step
, int siggnal
)
275 unsigned_word program_counter
;
277 prev
= signal(SIGINT
, sim_ctrl_c
);
281 psim_step(simulator
);
283 psim_run_until_stop(simulator
, &sim_should_run
);
285 signal(SIGINT
, prev
);
289 sim_do_command(char *cmd
)
291 TRACE(trace_gdb
, ("sim_do_commands(cmd=%s) called\n", cmd
));
295 sim_set_callbacks (host_callback
*callback
)
297 TRACE(trace_gdb
, ("sim_set_callbacks called\n"));
305 void *memory
= (void*)xmalloc(size
);
307 error("xmalloc failed\n");
312 void zfree(void *data
)