Add switch processing in gdb.
[deliverable/binutils-gdb.git] / sim / ppc / sim_calls.c
CommitLineData
8eab189b
MM
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 <stdlib.h>
25#include <string.h>
26#include <ctype.h>
27
28#include "basics.h"
29#include "psim.h"
30
31#include "../../gdb/defs.h"
32
33#include "devices.h"
34
35#include "../../gdb/remote-sim.h"
36
37
38/* Structures used by the simulator, for gdb just have static structures */
39
40static psim *simulator;
41static int nr_cpus;
42static char *register_names[] = REGISTER_NAMES;
43
44void
45sim_open (char *args)
46{
47 int i;
48
49 /* trace the call */
50 TRACE(trace_gdb, ("sim_open(args=%s) called\n", args ? args : "(null)"));
51
52 if (args) {
53 char *buf = (char *)alloca (strlen (args) + 1);
54 char *p;
55 strcpy (buf, args);
56
57 p = strtok (args, " \t");
58 while (p != (char *)0) {
59 if (*p != '-')
60 error ("Argument is not an option '%s'", p);
61
62 else {
63 /* check arguments -- note, main.c also contains argument processing
64 code for the standalone emulator. */
65 while (*++p != '\0') {
66 switch (*p) {
67 default:
68 error ("Usage: target sim [ -a -p -c -C -s -i -t ]\n");
69 break;
70 case 'a':
71 for (i = 0; i < nr_trace; i++)
72 trace[i] = 1;
73 break;
74 case 'p':
75 trace[trace_cpu] = trace[trace_semantics] = 1;
76 break;
77 case 'c':
78 trace[trace_core] = 1;
79 break;
80 case 'C':
81 trace[trace_console_device] = 1;
82 break;
83 case 's':
84 trace[trace_create_stack] = 1;
85 break;
86 case 'i':
87 trace[trace_icu_device] = 1;
88 break;
89 case 't':
90 trace[trace_device_tree] = 1;
91 break;
92 }
93 }
94 }
95
96 p = strtok ((char *)0, " \t");
97 }
98 }
99
100 /* do something */
101 TRACE(trace_tbd, ("sim_open() - TBD - should parse the arguments\n"));
102 TRACE(trace_tbd, ("sim_open() - TBD - can not create simulator here as do not have description of it\n"));
103}
104
105
106void
107sim_close (int quitting)
108{
109 TRACE(trace_gdb, ("sim_close(quitting=%d) called\n", quitting));
110 /* nothing to do */
111}
112
113
114int
115sim_load (char *prog, int from_tty)
116{
117 TRACE(trace_gdb, ("sim_load(prog=%s, from_tty=%d) called\n",
118 prog, from_tty));
119
120 /* sanity check */
121 if (prog == NULL) {
122 error ("sim_load() - TBD - read stan shebs e-mail about how to find the program name?\n");
123 return -1;
124 }
125 TRACE(trace_tbd, ("sim_load() - TBD - parse that prog stripping things like quotes\n"));
126
127 /* create the simulator */
128 TRACE(trace_gdb, ("sim_load() - first time, create the simulator\n"));
129 nr_cpus = (WITH_SMP ? WITH_SMP : 1);
130 simulator = psim_create(prog, nr_cpus);
131
132 /* bring in all the data section */
133 psim_load(simulator);
134
135 return 0;
136}
137
138
139void
140sim_kill (void)
141{
142 TRACE(trace_gdb, ("sim_kill(void) called\n"));
143 /* do nothing, nothing to do */
144}
145
146
147int
148sim_read (SIM_ADDR mem, unsigned char *buf, int length)
149{
150 return psim_read_memory(simulator, nr_cpus, buf, mem, length,
151 raw_transfer);
152}
153
154
155int
156sim_write (SIM_ADDR mem, unsigned char *buf, int length)
157{
158 return psim_write_memory(simulator, nr_cpus, buf, mem, length,
159 raw_transfer, 1/*violate_ro*/);
160}
161
162
163void
164sim_fetch_register (int regno, unsigned char *buf)
165{
166 if (simulator == NULL) {
167 return;
168 }
169
170 psim_read_register(simulator, nr_cpus, buf, register_names[regno],
171 raw_transfer);
172}
173
174
175void
176sim_store_register (int regno, unsigned char *buf)
177{
178 if (simulator == NULL)
179 return;
180
181 psim_write_register(simulator, nr_cpus, buf, register_names[regno],
182 raw_transfer);
183}
184
185
186void
187sim_info (int verbose)
188{
189 TRACE(trace_gdb, ("sim_info(verbose=%d) called\n", verbose));
190 TRACE(trace_tbd, ("sim_info(verbose=%d) should do something\n"));
191 /* FIXME: */
192}
193
194
195void
196sim_create_inferior (SIM_ADDR start_address, char **argv, char **envp)
197{
198 unsigned_word entry_point = start_address;
199
200 TRACE(trace_gdb, ("sim_create_inferior(start_address=0x%x, ...)\n",
201 start_address));
202
203 psim_load(simulator);
204 psim_stack(simulator, argv, envp);
205
206 psim_write_register(simulator, -1 /* all start at same PC */,
207 &entry_point, "pc", cooked_transfer);
208}
209
210
211static volatile int sim_should_run;
212
213void
214sim_stop_reason (enum sim_stop *reason, int *sigrc)
215{
216 psim_status status = psim_get_status(simulator);
217
218 switch (CURRENT_ENVIRONMENT) {
219
220 case VIRTUAL_ENVIRONMENT:
221 switch (status.reason) {
222 case was_continuing:
223 *reason = sim_stopped;
224 *sigrc = SIGTRAP;
225 if (sim_should_run) {
226 error("sim_stop_reason() unknown reason for halt\n");
227 }
228 break;
229 case was_trap:
230 *reason = sim_stopped;
231 *sigrc = SIGTRAP;
232 break;
233 case was_exited:
234 *reason = sim_exited;
235 *sigrc = 0;
236 break;
237 case was_signalled:
238 *reason = sim_signalled;
239 *sigrc = status.signal;
240 break;
241 }
242 break;
243
244 case OPERATING_ENVIRONMENT:
245 *reason = sim_stopped;
246 *sigrc = SIGTRAP;
247 break;
248
249 default:
250 error("sim_stop_reason() - unknown environment\n");
251
252 }
253}
254
255
256
257/* Run (or resume) the program. */
258static void
259sim_ctrl_c()
260{
261 sim_should_run = 0;
262}
263
264void
265sim_resume (int step, int siggnal)
266{
267 void (*prev) ();
268 unsigned_word program_counter;
269
270 prev = signal(SIGINT, sim_ctrl_c);
271 sim_should_run = 1;
272
273 if (step)
274 psim_step(simulator);
275 else
276 psim_run_until_stop(simulator, &sim_should_run);
277
278 signal(SIGINT, prev);
279}
280
281void
282sim_do_command(char *cmd)
283{
284 TRACE(trace_gdb, ("sim_do_commands(cmd=%s) called\n", cmd));
285}
286
287/****/
288
289void *
290zalloc(long size)
291{
292 void *memory = (void*)xmalloc(size);
293 if (memory == NULL)
294 error("xmalloc failed\n");
295 bzero(memory, size);
296 return memory;
297}
298
299void zfree(void *data)
300{
301 mfree(NULL, data);
302}
This page took 0.048591 seconds and 4 git commands to generate.