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 */
42 #include "../../gdb/defs.h"
46 #include "../../gdb/remote-sim.h"
47 #include "../../gdb/callback.h"
50 /* Structures used by the simulator, for gdb just have static structures */
52 static psim
*simulator
;
53 static char *register_names
[] = REGISTER_NAMES
;
54 static int print_info
= 0;
60 TRACE(trace_gdb
, ("sim_open(args=%s) called\n", args
? args
: "(null)"));
63 char **argv
= buildargv(args
);
66 for (argc
= 0; argv
[argc
]; argc
++);
69 if (*argv
[argp
] != '-')
70 error ("Argument is not an option '%s'", argv
[argp
]);
73 /* check arguments -- note, main.c also contains argument processing
74 code for the standalone emulator. */
75 char *p
= argv
[argp
] + 1;
79 printf_filtered("Usage:\n\ttarget sim [ -t <trace-option> ] [-m model] [-i] [-I]\n");
88 if (argv
[argp
] == NULL
)
89 error("Missing <trace> option for -t\n");
91 trace_option(argv
[argp
]);
99 if (argv
[argp
] == NULL
)
100 error("Missing <trace> option for -t\n");
102 model_set(argv
[argp
]);
109 current_model_issue
= MODEL_ISSUE_PROCESS
;
120 if (ppc_trace
[trace_opts
])
124 TRACE(trace_tbd
, ("sim_open() - TBD - should parse the arguments\n"));
125 TRACE(trace_tbd
, ("sim_open() - TBD - can not create simulator here as do not have description of it\n"));
130 sim_close (int quitting
)
132 TRACE(trace_gdb
, ("sim_close(quitting=%d) called\n", quitting
));
134 psim_print_info (simulator
, print_info
);
141 sim_load (char *prog
, int from_tty
)
144 TRACE(trace_gdb
, ("sim_load(prog=%s, from_tty=%d) called\n",
146 ASSERT(prog
!= NULL
);
148 /* parse the arguments, assume that the file is argument 0 */
149 argv
= buildargv(prog
);
150 ASSERT(argv
!= NULL
&& argv
[0] != NULL
);
152 /* create the simulator */
153 TRACE(trace_gdb
, ("sim_load() - first time, create the simulator\n"));
154 simulator
= psim_create(argv
[0]);
156 /* bring in all the data section */
157 psim_init(simulator
);
159 /* release the arguments */
162 /* `I did it my way' */
170 TRACE(trace_gdb
, ("sim_kill(void) called\n"));
171 /* do nothing, nothing to do */
176 sim_read (SIM_ADDR mem
, unsigned char *buf
, int length
)
178 int result
= psim_read_memory(simulator
, MAX_NR_PROCESSORS
,
180 TRACE(trace_gdb
, ("sim_read(mem=0x%lx, buf=0x%lx, length=%d) = %d\n",
181 (long)mem
, (long)buf
, length
, result
));
187 sim_write (SIM_ADDR mem
, unsigned char *buf
, int length
)
189 int result
= psim_write_memory(simulator
, MAX_NR_PROCESSORS
,
192 TRACE(trace_gdb
, ("sim_write(mem=0x%lx, buf=0x%lx, length=%d) = %d\n",
193 (long)mem
, (long)buf
, length
, result
));
199 sim_fetch_register (int regno
, unsigned char *buf
)
201 if (simulator
== NULL
) {
204 TRACE(trace_gdb
, ("sim_fetch_register(regno=%d(%s), buf=0x%lx)\n",
205 regno
, register_names
[regno
], (long)buf
));
206 psim_read_register(simulator
, MAX_NR_PROCESSORS
,
207 buf
, register_names
[regno
],
213 sim_store_register (int regno
, unsigned char *buf
)
215 if (simulator
== NULL
)
217 TRACE(trace_gdb
, ("sim_store_register(regno=%d(%s), buf=0x%lx)\n",
218 regno
, register_names
[regno
], (long)buf
));
219 psim_write_register(simulator
, MAX_NR_PROCESSORS
,
220 buf
, register_names
[regno
],
226 sim_info (int verbose
)
228 TRACE(trace_gdb
, ("sim_info(verbose=%d) called\n", verbose
));
229 psim_print_info (simulator
, verbose
);
234 sim_create_inferior (SIM_ADDR start_address
, char **argv
, char **envp
)
236 unsigned_word entry_point
= start_address
;
238 TRACE(trace_gdb
, ("sim_create_inferior(start_address=0x%x, ...)\n",
241 psim_init(simulator
);
242 psim_stack(simulator
, argv
, envp
);
244 psim_write_register(simulator
, -1 /* all start at same PC */,
245 &entry_point
, "pc", cooked_transfer
);
249 static volatile int sim_should_run
;
252 sim_stop_reason (enum sim_stop
*reason
, int *sigrc
)
254 psim_status status
= psim_get_status(simulator
);
256 switch (CURRENT_ENVIRONMENT
) {
258 case USER_ENVIRONMENT
:
259 case VIRTUAL_ENVIRONMENT
:
260 switch (status
.reason
) {
262 *reason
= sim_stopped
;
264 if (sim_should_run
) {
265 error("sim_stop_reason() unknown reason for halt\n");
269 *reason
= sim_stopped
;
273 *reason
= sim_exited
;
277 *reason
= sim_signalled
;
278 *sigrc
= status
.signal
;
283 case OPERATING_ENVIRONMENT
:
284 *reason
= sim_stopped
;
289 error("sim_stop_reason() - unknown environment\n");
293 TRACE(trace_gdb
, ("sim_stop_reason(reason=0x%lx(%ld), sigrc=0x%lx(%ld))\n",
294 (long)reason
, (long)*reason
, (long)sigrc
, (long)*sigrc
));
299 /* Run (or resume) the program. */
307 sim_resume (int step
, int siggnal
)
311 TRACE(trace_gdb
, ("sim_resume(step=%d, siggnal=%d)\n",
314 prev
= signal(SIGINT
, sim_ctrl_c
);
318 psim_step(simulator
);
320 psim_run_until_stop(simulator
, &sim_should_run
);
322 signal(SIGINT
, prev
);
326 sim_do_command(char *cmd
)
328 TRACE(trace_gdb
, ("sim_do_commands(cmd=%s) called\n", cmd
));
332 sim_set_callbacks (host_callback
*callback
)
334 TRACE(trace_gdb
, ("sim_set_callbacks called\n"));
342 void *memory
= (void*)xmalloc(size
);
344 error("xmalloc failed\n");
345 memset(memory
, 0, size
);
349 void zfree(void *data
)