1 /* This file is part of the program psim.
3 Copyright (C) 1994-1996, 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 */
41 #include "../../gdb/defs.h"
43 #include "../../gdb/remote-sim.h"
44 #include "../../gdb/callback.h"
47 /* Structures used by the simulator, for gdb just have static structures */
49 static psim
*simulator
;
50 static device
*root_device
;
51 static const char *register_names
[] = REGISTER_NAMES
;
56 /* Note: The simulation is not created by sim_open() because
57 complete information is not yet available */
59 TRACE(trace_gdb
, ("sim_open(args=%s) called\n", args
? args
: "(null)"));
61 if (root_device
!= NULL
)
62 printf_filtered("Warning - re-open of simulator leaks memory\n");
63 root_device
= psim_tree();
67 char **argv
= buildargv(args
);
68 psim_options(root_device
, argv
);
72 if (ppc_trace
[trace_opts
])
78 sim_close (int quitting
)
80 TRACE(trace_gdb
, ("sim_close(quitting=%d) called\n", quitting
));
81 if (ppc_trace
[trace_print_info
] && simulator
!= NULL
)
82 psim_print_info (simulator
, ppc_trace
[trace_print_info
]);
87 sim_load (char *prog
, int from_tty
)
90 TRACE(trace_gdb
, ("sim_load(prog=%s, from_tty=%d) called\n",
94 /* parse the arguments, assume that the file is argument 0 */
95 argv
= buildargv(prog
);
96 ASSERT(argv
!= NULL
&& argv
[0] != NULL
);
98 /* create the simulator */
99 TRACE(trace_gdb
, ("sim_load() - first time, create the simulator\n"));
100 simulator
= psim_create(argv
[0], root_device
);
102 /* bring in all the data section */
103 psim_init(simulator
);
105 /* release the arguments */
108 /* `I did it my way' */
116 TRACE(trace_gdb
, ("sim_kill(void) called\n"));
117 /* do nothing, nothing to do */
122 sim_read (SIM_ADDR mem
, unsigned char *buf
, int length
)
124 int result
= psim_read_memory(simulator
, MAX_NR_PROCESSORS
,
126 TRACE(trace_gdb
, ("sim_read(mem=0x%lx, buf=0x%lx, length=%d) = %d\n",
127 (long)mem
, (long)buf
, length
, result
));
133 sim_write (SIM_ADDR mem
, unsigned char *buf
, int length
)
135 int result
= psim_write_memory(simulator
, MAX_NR_PROCESSORS
,
138 TRACE(trace_gdb
, ("sim_write(mem=0x%lx, buf=0x%lx, length=%d) = %d\n",
139 (long)mem
, (long)buf
, length
, result
));
145 sim_fetch_register (int regno
, unsigned char *buf
)
147 if (simulator
== NULL
) {
150 TRACE(trace_gdb
, ("sim_fetch_register(regno=%d(%s), buf=0x%lx)\n",
151 regno
, register_names
[regno
], (long)buf
));
152 psim_read_register(simulator
, MAX_NR_PROCESSORS
,
153 buf
, register_names
[regno
],
159 sim_store_register (int regno
, unsigned char *buf
)
161 if (simulator
== NULL
)
163 TRACE(trace_gdb
, ("sim_store_register(regno=%d(%s), buf=0x%lx)\n",
164 regno
, register_names
[regno
], (long)buf
));
165 psim_write_register(simulator
, MAX_NR_PROCESSORS
,
166 buf
, register_names
[regno
],
172 sim_info (int verbose
)
174 TRACE(trace_gdb
, ("sim_info(verbose=%d) called\n", verbose
));
175 psim_print_info (simulator
, verbose
);
180 sim_create_inferior (SIM_ADDR start_address
, char **argv
, char **envp
)
182 unsigned_word entry_point
= start_address
;
184 TRACE(trace_gdb
, ("sim_create_inferior(start_address=0x%x, ...)\n",
187 psim_init(simulator
);
188 psim_stack(simulator
, argv
, envp
);
190 psim_write_register(simulator
, -1 /* all start at same PC */,
191 &entry_point
, "pc", cooked_transfer
);
195 static volatile int sim_should_run
;
198 sim_stop_reason (enum sim_stop
*reason
, int *sigrc
)
200 psim_status status
= psim_get_status(simulator
);
202 switch (CURRENT_ENVIRONMENT
) {
204 case USER_ENVIRONMENT
:
205 case VIRTUAL_ENVIRONMENT
:
206 switch (status
.reason
) {
208 *reason
= sim_stopped
;
210 if (sim_should_run
) {
211 error("sim_stop_reason() unknown reason for halt\n");
215 *reason
= sim_stopped
;
219 *reason
= sim_exited
;
223 *reason
= sim_signalled
;
224 *sigrc
= status
.signal
;
229 case OPERATING_ENVIRONMENT
:
230 *reason
= sim_stopped
;
235 error("sim_stop_reason() - unknown environment\n");
239 TRACE(trace_gdb
, ("sim_stop_reason(reason=0x%lx(%ld), sigrc=0x%lx(%ld))\n",
240 (long)reason
, (long)*reason
, (long)sigrc
, (long)*sigrc
));
245 /* Run (or resume) the program. */
253 sim_resume (int step
, int siggnal
)
257 TRACE(trace_gdb
, ("sim_resume(step=%d, siggnal=%d)\n",
260 prev
= signal(SIGINT
, sim_ctrl_c
);
264 psim_step(simulator
);
266 psim_run_until_stop(simulator
, &sim_should_run
);
268 signal(SIGINT
, prev
);
272 sim_do_command (char *cmd
)
274 TRACE(trace_gdb
, ("sim_do_commands(cmd=%s) called\n",
275 cmd
? cmd
: "(null)"));
277 char **argv
= buildargv(cmd
);
278 psim_options(root_device
, argv
);
284 sim_set_callbacks (host_callback
*callback
)
286 TRACE(trace_gdb
, ("sim_set_callbacks called\n"));
294 void *memory
= (void*)xmalloc(size
);
296 error("xmalloc failed\n");
297 memset(memory
, 0, size
);
301 void zfree(void *data
)
306 void flush_stdoutput(void)
308 gdb_flush (gdb_stdout
);