Add support for setting model name and other things
[deliverable/binutils-gdb.git] / sim / ppc / sim_calls.c
1 /* This file is part of the program psim.
2
3 Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
4
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.
9
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.
14
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.
18
19 */
20
21
22 #include <signal.h> /* FIXME - should be machine dependant version */
23 #include <stdarg.h>
24 #include <ctype.h>
25
26 #include "cpu.h"
27 #include "psim.h"
28 #include "options.h"
29
30 #ifdef HAVE_STDLIB_H
31 #include <stdlib.h>
32 #endif
33
34 #ifdef HAVE_STRING_H
35 #include <string.h>
36 #else
37 #ifdef HAVE_STRINGS_H
38 #include <strings.h>
39 #endif
40 #endif
41
42 #include "../../gdb/defs.h"
43
44 #include "devices.h"
45
46 #include "../../gdb/remote-sim.h"
47 #include "../../gdb/callback.h"
48
49
50 /* Structures used by the simulator, for gdb just have static structures */
51
52 static psim *simulator;
53 static char *register_names[] = REGISTER_NAMES;
54 static int print_info = 0;
55
56 void
57 sim_open (char *args)
58 {
59 /* trace the call */
60 TRACE(trace_gdb, ("sim_open(args=%s) called\n", args ? args : "(null)"));
61
62 if (args) {
63 char **argv = buildargv(args);
64 int argp = 0;
65 int argc;
66 for (argc = 0; argv[argc]; argc++);
67
68 while (argp < argc) {
69 if (*argv[argp] != '-')
70 error ("Argument is not an option '%s'", argv[argp]);
71
72 else {
73 /* check arguments -- note, main.c also contains argument processing
74 code for the standalone emulator. */
75 char *p = argv[argp] + 1;
76 while (*p != '\0') {
77 switch (*p) {
78 default:
79 printf_filtered("Usage:\n\ttarget sim [ -t <trace-option> ] [-m model] [-i] [-I]\n");
80 trace_usage();
81 error ("");
82 break;
83 case 't':
84 if (p[1])
85 trace_option(p+1);
86 else {
87 argp += 1;
88 if (argv[argp] == NULL)
89 error("Missing <trace> option for -t\n");
90 else
91 trace_option(argv[argp]);
92 }
93 break;
94 case 'm':
95 if (p[1])
96 model_set(p+1);
97 else {
98 argp += 1;
99 if (argv[argp] == NULL)
100 error("Missing <trace> option for -t\n");
101 else
102 model_set(argv[argp]);
103 }
104 break;
105 case 'i':
106 print_info = 1;
107 break;
108 case 'I':
109 print_info = 2;
110 break;
111 }
112 p += 1;
113 }
114 }
115 argp += 1;
116 }
117 }
118
119 if (ppc_trace[trace_opts])
120 print_options ();
121
122 /* do something */
123 TRACE(trace_tbd, ("sim_open() - TBD - should parse the arguments\n"));
124 TRACE(trace_tbd, ("sim_open() - TBD - can not create simulator here as do not have description of it\n"));
125 }
126
127
128 void
129 sim_close (int quitting)
130 {
131 TRACE(trace_gdb, ("sim_close(quitting=%d) called\n", quitting));
132 if (print_info)
133 psim_print_info (simulator, print_info);
134
135 /* nothing to do */
136 }
137
138
139 int
140 sim_load (char *prog, int from_tty)
141 {
142 char **argv;
143 TRACE(trace_gdb, ("sim_load(prog=%s, from_tty=%d) called\n",
144 prog, from_tty));
145 ASSERT(prog != NULL);
146
147 /* parse the arguments, assume that the file is argument 0 */
148 argv = buildargv(prog);
149 ASSERT(argv != NULL && argv[0] != NULL);
150
151 /* create the simulator */
152 TRACE(trace_gdb, ("sim_load() - first time, create the simulator\n"));
153 simulator = psim_create(argv[0]);
154
155 /* bring in all the data section */
156 psim_init(simulator);
157
158 /* release the arguments */
159 freeargv(argv);
160
161 /* `I did it my way' */
162 return 0;
163 }
164
165
166 void
167 sim_kill (void)
168 {
169 TRACE(trace_gdb, ("sim_kill(void) called\n"));
170 /* do nothing, nothing to do */
171 }
172
173
174 int
175 sim_read (SIM_ADDR mem, unsigned char *buf, int length)
176 {
177 int result = psim_read_memory(simulator, MAX_NR_PROCESSORS,
178 buf, mem, length);
179 TRACE(trace_gdb, ("sim_read(mem=0x%lx, buf=0x%lx, length=%d) = %d\n",
180 (long)mem, (long)buf, length, result));
181 return result;
182 }
183
184
185 int
186 sim_write (SIM_ADDR mem, unsigned char *buf, int length)
187 {
188 int result = psim_write_memory(simulator, MAX_NR_PROCESSORS,
189 buf, mem, length,
190 1/*violate_ro*/);
191 TRACE(trace_gdb, ("sim_write(mem=0x%lx, buf=0x%lx, length=%d) = %d\n",
192 (long)mem, (long)buf, length, result));
193 return result;
194 }
195
196
197 void
198 sim_fetch_register (int regno, unsigned char *buf)
199 {
200 if (simulator == NULL) {
201 return;
202 }
203 TRACE(trace_gdb, ("sim_fetch_register(regno=%d(%s), buf=0x%lx)\n",
204 regno, register_names[regno], (long)buf));
205 psim_read_register(simulator, MAX_NR_PROCESSORS,
206 buf, register_names[regno],
207 raw_transfer);
208 }
209
210
211 void
212 sim_store_register (int regno, unsigned char *buf)
213 {
214 if (simulator == NULL)
215 return;
216 TRACE(trace_gdb, ("sim_store_register(regno=%d(%s), buf=0x%lx)\n",
217 regno, register_names[regno], (long)buf));
218 psim_write_register(simulator, MAX_NR_PROCESSORS,
219 buf, register_names[regno],
220 raw_transfer);
221 }
222
223
224 void
225 sim_info (int verbose)
226 {
227 TRACE(trace_gdb, ("sim_info(verbose=%d) called\n", verbose));
228 psim_print_info (simulator, verbose);
229 }
230
231
232 void
233 sim_create_inferior (SIM_ADDR start_address, char **argv, char **envp)
234 {
235 unsigned_word entry_point = start_address;
236
237 TRACE(trace_gdb, ("sim_create_inferior(start_address=0x%x, ...)\n",
238 start_address));
239
240 psim_init(simulator);
241 psim_stack(simulator, argv, envp);
242
243 psim_write_register(simulator, -1 /* all start at same PC */,
244 &entry_point, "pc", cooked_transfer);
245 }
246
247
248 static volatile int sim_should_run;
249
250 void
251 sim_stop_reason (enum sim_stop *reason, int *sigrc)
252 {
253 psim_status status = psim_get_status(simulator);
254
255 switch (CURRENT_ENVIRONMENT) {
256
257 case USER_ENVIRONMENT:
258 case VIRTUAL_ENVIRONMENT:
259 switch (status.reason) {
260 case was_continuing:
261 *reason = sim_stopped;
262 *sigrc = SIGTRAP;
263 if (sim_should_run) {
264 error("sim_stop_reason() unknown reason for halt\n");
265 }
266 break;
267 case was_trap:
268 *reason = sim_stopped;
269 *sigrc = SIGTRAP;
270 break;
271 case was_exited:
272 *reason = sim_exited;
273 *sigrc = 0;
274 break;
275 case was_signalled:
276 *reason = sim_signalled;
277 *sigrc = status.signal;
278 break;
279 }
280 break;
281
282 case OPERATING_ENVIRONMENT:
283 *reason = sim_stopped;
284 *sigrc = SIGTRAP;
285 break;
286
287 default:
288 error("sim_stop_reason() - unknown environment\n");
289
290 }
291
292 TRACE(trace_gdb, ("sim_stop_reason(reason=0x%lx(%ld), sigrc=0x%lx(%ld))\n",
293 (long)reason, (long)*reason, (long)sigrc, (long)*sigrc));
294 }
295
296
297
298 /* Run (or resume) the program. */
299 static void
300 sim_ctrl_c()
301 {
302 sim_should_run = 0;
303 }
304
305 void
306 sim_resume (int step, int siggnal)
307 {
308 void (*prev) ();
309
310 TRACE(trace_gdb, ("sim_resume(step=%d, siggnal=%d)\n",
311 step, siggnal));
312
313 prev = signal(SIGINT, sim_ctrl_c);
314 sim_should_run = 1;
315
316 if (step)
317 psim_step(simulator);
318 else
319 psim_run_until_stop(simulator, &sim_should_run);
320
321 signal(SIGINT, prev);
322 }
323
324 void
325 sim_do_command(char *cmd)
326 {
327 TRACE(trace_gdb, ("sim_do_commands(cmd=%s) called\n", cmd));
328 }
329
330 void
331 sim_set_callbacks (host_callback *callback)
332 {
333 TRACE(trace_gdb, ("sim_set_callbacks called\n"));
334 }
335
336 /****/
337
338 void *
339 zalloc(long size)
340 {
341 void *memory = (void*)xmalloc(size);
342 if (memory == NULL)
343 error("xmalloc failed\n");
344 bzero(memory, size);
345 return memory;
346 }
347
348 void zfree(void *data)
349 {
350 mfree(NULL, data);
351 }
This page took 0.036637 seconds and 5 git commands to generate.