]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/arm/wrapper.c
NUMBERS_WITH_SUFFIX *doesn't* want to handle 'x', since that is valid
[thirdparty/binutils-gdb.git] / sim / arm / wrapper.c
CommitLineData
c906108c
SS
1/* run front end support for arm
2 Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
3
4This file is part of ARM SIM.
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU CC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20/* This file provides the interface between the simulator and run.c and gdb
21 (when the simulator is linked with gdb).
22 All simulator interaction should go through this file. */
23
24#include <stdio.h>
25#include <stdarg.h>
26#include <bfd.h>
27#include <signal.h>
28#include "callback.h"
29#include "remote-sim.h"
30#include "armdefs.h"
31#include "armemu.h"
32#include "dbg_rdi.h"
33
34host_callback *sim_callback;
35
36static struct ARMul_State *state;
37
38/* Who is using the simulator. */
39static SIM_OPEN_KIND sim_kind;
40
41/* argv[0] */
42static char *myname;
43
44/* Memory size in bytes. */
45static int mem_size = (1 << 21);
46
47/* Non-zero to display start up banner, and maybe other things. */
48static int verbosity;
49
50/* Non-zero to set big endian mode. */
51static int big_endian;
52
7a292a7a
SS
53int stop_simulator;
54
dfcd3bfb 55static void
c906108c
SS
56init ()
57{
58 static int done;
59
60 if (!done)
61 {
dfcd3bfb 62 ARMul_EmulateInit ();
c906108c
SS
63 state = ARMul_NewState ();
64 state->bigendSig = (big_endian ? HIGH : LOW);
dfcd3bfb
JM
65 ARMul_MemoryInit (state, mem_size);
66 ARMul_OSInit (state);
67 ARMul_CoProInit (state);
c906108c
SS
68 state->verbose = verbosity;
69 done = 1;
70 }
71}
72
73/* Set verbosity level of simulator.
74 This is not intended to produce detailed tracing or debugging information.
75 Just summaries. */
76/* FIXME: common/run.c doesn't do this yet. */
77
78void
79sim_set_verbose (v)
80 int v;
81{
82 verbosity = v;
83}
84
85/* Set the memory size to SIZE bytes.
dfcd3bfb 86 Must be called before initializing simulator. */
c906108c
SS
87/* FIXME: Rename to sim_set_mem_size. */
88
dfcd3bfb 89void
c906108c
SS
90sim_size (size)
91 int size;
92{
93 mem_size = size;
94}
95
dfcd3bfb
JM
96void
97ARMul_ConsolePrint (ARMul_State * state, const char *format, ...)
c906108c
SS
98{
99 va_list ap;
100
101 if (state->verbose)
102 {
103 va_start (ap, format);
104 vprintf (format, ap);
105 va_end (ap);
106 }
107}
108
dfcd3bfb 109ARMword ARMul_Debug (ARMul_State * state, ARMword pc, ARMword instr)
c906108c
SS
110{
111
112}
113
114int
115sim_write (sd, addr, buffer, size)
116 SIM_DESC sd;
117 SIM_ADDR addr;
118 unsigned char *buffer;
119 int size;
120{
121 int i;
122 init ();
123 for (i = 0; i < size; i++)
124 {
dfcd3bfb 125 ARMul_WriteByte (state, addr + i, buffer[i]);
c906108c
SS
126 }
127 return size;
128}
129
130int
131sim_read (sd, addr, buffer, size)
132 SIM_DESC sd;
133 SIM_ADDR addr;
134 unsigned char *buffer;
135 int size;
136{
137 int i;
138 init ();
139 for (i = 0; i < size; i++)
140 {
141 buffer[i] = ARMul_ReadByte (state, addr + i);
142 }
143 return size;
144}
145
146int
147sim_trace (sd)
148 SIM_DESC sd;
dfcd3bfb
JM
149{
150 (*sim_callback->printf_filtered) (sim_callback,
151 "This simulator does not support tracing\n");
c906108c
SS
152 return 1;
153}
154
155int
156sim_stop (sd)
157 SIM_DESC sd;
158{
7a292a7a
SS
159 state->Emulate = STOP;
160 stop_simulator = 1;
161 return 1;
c906108c
SS
162}
163
164void
165sim_resume (sd, step, siggnal)
166 SIM_DESC sd;
167 int step, siggnal;
168{
169 state->EndCondition = 0;
7a292a7a 170 stop_simulator = 0;
c906108c
SS
171
172 if (step)
173 {
174 state->Reg[15] = ARMul_DoInstr (state);
175 if (state->EndCondition == 0)
176 state->EndCondition = RDIError_BreakpointReached;
177 }
178 else
179 {
dfcd3bfb
JM
180#if 1 /* JGS */
181 state->NextInstr = RESUME; /* treat as PC change */
c906108c
SS
182#endif
183 state->Reg[15] = ARMul_DoProg (state);
184 }
185
186 FLUSHPIPE;
187}
188
189SIM_RC
190sim_create_inferior (sd, abfd, argv, env)
191 SIM_DESC sd;
192 struct _bfd *abfd;
193 char **argv;
194 char **env;
195{
dfcd3bfb 196 int argvlen = 0;
c906108c
SS
197 char **arg;
198
199 if (abfd != NULL)
200 ARMul_SetPC (state, bfd_get_start_address (abfd));
201 else
dfcd3bfb 202 ARMul_SetPC (state, 0); /* ??? */
c906108c 203
dfcd3bfb 204#if 1 /* JGS */
c906108c
SS
205 /* We explicitly select a processor capable of supporting the ARM
206 32bit mode, and then we force the simulated CPU into the 32bit
207 User mode: */
dfcd3bfb
JM
208 ARMul_SelectProcessor (state, ARM600);
209 ARMul_SetCPSR (state, USER32MODE);
c906108c
SS
210#endif
211
212 if (argv != NULL)
213 {
214 /*
dfcd3bfb
JM
215 ** Set up the command line (by laboriously stringing together the
216 ** environment carefully picked apart by our caller...)
217 */
c906108c
SS
218 /* Free any old stuff */
219 if (state->CommandLine != NULL)
220 {
dfcd3bfb 221 free (state->CommandLine);
c906108c
SS
222 state->CommandLine = NULL;
223 }
dfcd3bfb 224
c906108c
SS
225 /* See how much we need */
226 for (arg = argv; *arg != NULL; arg++)
dfcd3bfb
JM
227 argvlen += strlen (*arg) + 1;
228
c906108c 229 /* allocate it... */
dfcd3bfb 230 state->CommandLine = malloc (argvlen + 1);
c906108c
SS
231 if (state->CommandLine != NULL)
232 {
233 arg = argv;
dfcd3bfb 234 state->CommandLine[0] = '\0';
c906108c
SS
235 for (arg = argv; *arg != NULL; arg++)
236 {
dfcd3bfb
JM
237 strcat (state->CommandLine, *arg);
238 strcat (state->CommandLine, " ");
c906108c
SS
239 }
240 }
241 }
242
243 if (env != NULL)
244 {
245 /* Now see if there's a MEMSIZE spec in the environment */
246 while (*env)
247 {
dfcd3bfb 248 if (strncmp (*env, "MEMSIZE=", sizeof ("MEMSIZE=") - 1) == 0)
c906108c
SS
249 {
250 unsigned long top_of_memory;
251 char *end_of_num;
dfcd3bfb 252
c906108c 253 /* Set up memory limit */
dfcd3bfb
JM
254 state->MemSize =
255 strtoul (*env + sizeof ("MEMSIZE=") - 1, &end_of_num, 0);
c906108c
SS
256 }
257 env++;
258 }
259 }
260
261 return SIM_RC_OK;
262}
263
264void
265sim_info (sd, verbose)
266 SIM_DESC sd;
267 int verbose;
268{
269}
270
271
dfcd3bfb 272static int
c906108c
SS
273frommem (state, memory)
274 struct ARMul_State *state;
275 unsigned char *memory;
276{
277 if (state->bigendSig == HIGH)
278 {
279 return (memory[0] << 24)
dfcd3bfb 280 | (memory[1] << 16) | (memory[2] << 8) | (memory[3] << 0);
c906108c
SS
281 }
282 else
283 {
284 return (memory[3] << 24)
dfcd3bfb 285 | (memory[2] << 16) | (memory[1] << 8) | (memory[0] << 0);
c906108c
SS
286 }
287}
288
289
290static void
dfcd3bfb 291tomem (state, memory, val)
c906108c
SS
292 struct ARMul_State *state;
293 unsigned char *memory;
294 int val;
295{
296 if (state->bigendSig == HIGH)
297 {
298 memory[0] = val >> 24;
299 memory[1] = val >> 16;
300 memory[2] = val >> 8;
301 memory[3] = val >> 0;
302 }
303 else
304 {
305 memory[3] = val >> 24;
306 memory[2] = val >> 16;
307 memory[1] = val >> 8;
308 memory[0] = val >> 0;
309 }
310}
311
312int
313sim_store_register (sd, rn, memory, length)
314 SIM_DESC sd;
315 int rn;
316 unsigned char *memory;
317 int length;
318{
319 init ();
dfcd3bfb 320 ARMul_SetReg (state, state->Mode, rn, frommem (state, memory));
c906108c
SS
321 return -1;
322}
323
324int
325sim_fetch_register (sd, rn, memory, length)
326 SIM_DESC sd;
327 int rn;
328 unsigned char *memory;
329 int length;
330{
331 ARMword regval;
332
333 init ();
334 if (rn < 16)
dfcd3bfb
JM
335 regval = ARMul_GetReg (state, state->Mode, rn);
336 else if (rn == 25) /* FIXME: use PS_REGNUM from gdb/config/arm/tm-arm.h */
337 regval = ARMul_GetCPSR (state);
c906108c 338 else
dfcd3bfb 339 regval = 0; /* FIXME: should report an error */
c906108c
SS
340 tomem (state, memory, regval);
341 return -1;
342}
343
344SIM_DESC
345sim_open (kind, ptr, abfd, argv)
346 SIM_OPEN_KIND kind;
347 host_callback *ptr;
348 struct _bfd *abfd;
349 char **argv;
350{
351 sim_kind = kind;
352 myname = argv[0];
353 sim_callback = ptr;
dfcd3bfb 354
c906108c
SS
355 /* Decide upon the endian-ness of the processor.
356 If we can, get the information from the bfd itself.
357 Otherwise look to see if we have been given a command
358 line switch that tells us. Otherwise default to little endian. */
359 if (abfd != NULL)
360 big_endian = bfd_big_endian (abfd);
361 else if (argv[1] != NULL)
362 {
363 int i;
dfcd3bfb 364
c906108c
SS
365 /* Scan for endian-ness switch. */
366 for (i = 0; (argv[i] != NULL) && (argv[i][0] != 0); i++)
dfcd3bfb
JM
367 if (argv[i][0] == '-' && argv[i][1] == 'E')
368 {
369 char c;
370
371 if ((c = argv[i][2]) == 0)
372 {
373 ++i;
374 c = argv[i][0];
375 }
376
377 switch (c)
378 {
379 case 0:
380 sim_callback->printf_filtered
381 (sim_callback, "No argument to -E option provided\n");
382 break;
383
384 case 'b':
385 case 'B':
386 big_endian = 1;
387 break;
388
389 case 'l':
390 case 'L':
391 big_endian = 0;
392 break;
393
394 default:
395 sim_callback->printf_filtered
396 (sim_callback, "Unrecognised argument to -E option\n");
397 break;
398 }
399 }
c906108c
SS
400 }
401
402 return (SIM_DESC) 1;
403}
404
405void
406sim_close (sd, quitting)
407 SIM_DESC sd;
408 int quitting;
409{
410 /* nothing to do */
411}
412
413SIM_RC
414sim_load (sd, prog, abfd, from_tty)
415 SIM_DESC sd;
416 char *prog;
417 bfd *abfd;
418 int from_tty;
419{
dfcd3bfb 420 extern bfd *sim_load_file (); /* ??? Don't know where this should live. */
c906108c
SS
421 bfd *prog_bfd;
422
423 prog_bfd = sim_load_file (sd, myname, sim_callback, prog, abfd,
dfcd3bfb 424 sim_kind == SIM_OPEN_DEBUG, 0, sim_write);
c906108c
SS
425 if (prog_bfd == NULL)
426 return SIM_RC_FAIL;
427 ARMul_SetPC (state, bfd_get_start_address (prog_bfd));
428 if (abfd == NULL)
429 bfd_close (prog_bfd);
430 return SIM_RC_OK;
431}
432
433void
434sim_stop_reason (sd, reason, sigrc)
435 SIM_DESC sd;
436 enum sim_stop *reason;
437 int *sigrc;
438{
7a292a7a
SS
439 if (stop_simulator)
440 {
441 *reason = sim_stopped;
442 *sigrc = SIGINT;
443 }
444 else if (state->EndCondition == 0)
c906108c
SS
445 {
446 *reason = sim_exited;
447 *sigrc = state->Reg[0] & 255;
448 }
449 else
450 {
451 *reason = sim_stopped;
452 if (state->EndCondition == RDIError_BreakpointReached)
453 *sigrc = SIGTRAP;
454 else
455 *sigrc = 0;
456 }
457}
458
459void
460sim_do_command (sd, cmd)
461 SIM_DESC sd;
462 char *cmd;
dfcd3bfb
JM
463{
464 (*sim_callback->printf_filtered) (sim_callback,
465 "This simulator does not accept any commands.\n");
c906108c
SS
466}
467
468
469void
470sim_set_callbacks (ptr)
471 host_callback *ptr;
472{
473 sim_callback = ptr;
474}