1 /* run front end support for arm
2 Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
4 This file is part of ARM SIM.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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. */
29 #include "remote-sim.h"
34 host_callback *sim_callback;
36 static struct ARMul_State *state;
38 /* Who is using the simulator. */
39 static SIM_OPEN_KIND sim_kind;
44 /* Memory size in bytes. */
45 static int mem_size = (1 << 21);
47 /* Non-zero to display start up banner, and maybe other things. */
50 /* Non-zero to set big endian mode. */
51 static int big_endian;
63 state = ARMul_NewState ();
64 state->bigendSig = (big_endian ? HIGH : LOW);
65 ARMul_MemoryInit (state, mem_size);
67 ARMul_CoProInit (state);
68 state->verbose = verbosity;
73 /* Set verbosity level of simulator.
74 This is not intended to produce detailed tracing or debugging information.
76 /* FIXME: common/run.c doesn't do this yet. */
85 /* Set the memory size to SIZE bytes.
86 Must be called before initializing simulator. */
87 /* FIXME: Rename to sim_set_mem_size. */
97 ARMul_ConsolePrint (ARMul_State * state, const char *format, ...)
103 va_start (ap, format);
104 vprintf (format, ap);
109 ARMword ARMul_Debug (ARMul_State * state, ARMword pc, ARMword instr)
115 sim_write (sd, addr, buffer, size)
118 unsigned char *buffer;
123 for (i = 0; i < size; i++)
125 ARMul_WriteByte (state, addr + i, buffer[i]);
131 sim_read (sd, addr, buffer, size)
134 unsigned char *buffer;
139 for (i = 0; i < size; i++)
141 buffer[i] = ARMul_ReadByte (state, addr + i);
150 (*sim_callback->printf_filtered) (sim_callback,
151 "This simulator does not support tracing\n");
159 state->Emulate = STOP;
165 sim_resume (sd, step, siggnal)
169 state->EndCondition = 0;
174 state->Reg[15] = ARMul_DoInstr (state);
175 if (state->EndCondition == 0)
176 state->EndCondition = RDIError_BreakpointReached;
181 state->NextInstr = RESUME; /* treat as PC change */
183 state->Reg[15] = ARMul_DoProg (state);
190 sim_create_inferior (sd, abfd, argv, env)
200 ARMul_SetPC (state, bfd_get_start_address (abfd));
202 ARMul_SetPC (state, 0); /* ??? */
205 /* We explicitly select a processor capable of supporting the ARM
206 32bit mode, and then we force the simulated CPU into the 32bit
208 ARMul_SelectProcessor (state, ARM600);
209 ARMul_SetCPSR (state, USER32MODE);
215 ** Set up the command line (by laboriously stringing together the
216 ** environment carefully picked apart by our caller...)
218 /* Free any old stuff */
219 if (state->CommandLine != NULL)
221 free (state->CommandLine);
222 state->CommandLine = NULL;
225 /* See how much we need */
226 for (arg = argv; *arg != NULL; arg++)
227 argvlen += strlen (*arg) + 1;
230 state->CommandLine = malloc (argvlen + 1);
231 if (state->CommandLine != NULL)
234 state->CommandLine[0] = '\0';
235 for (arg = argv; *arg != NULL; arg++)
237 strcat (state->CommandLine, *arg);
238 strcat (state->CommandLine, " ");
245 /* Now see if there's a MEMSIZE spec in the environment */
248 if (strncmp (*env, "MEMSIZE=", sizeof ("MEMSIZE=") - 1) == 0)
250 unsigned long top_of_memory;
253 /* Set up memory limit */
255 strtoul (*env + sizeof ("MEMSIZE=") - 1, &end_of_num, 0);
265 sim_info (sd, verbose)
273 frommem (state, memory)
274 struct ARMul_State *state;
275 unsigned char *memory;
277 if (state->bigendSig == HIGH)
279 return (memory[0] << 24)
280 | (memory[1] << 16) | (memory[2] << 8) | (memory[3] << 0);
284 return (memory[3] << 24)
285 | (memory[2] << 16) | (memory[1] << 8) | (memory[0] << 0);
291 tomem (state, memory, val)
292 struct ARMul_State *state;
293 unsigned char *memory;
296 if (state->bigendSig == HIGH)
298 memory[0] = val >> 24;
299 memory[1] = val >> 16;
300 memory[2] = val >> 8;
301 memory[3] = val >> 0;
305 memory[3] = val >> 24;
306 memory[2] = val >> 16;
307 memory[1] = val >> 8;
308 memory[0] = val >> 0;
313 sim_store_register (sd, rn, memory, length)
316 unsigned char *memory;
320 ARMul_SetReg (state, state->Mode, rn, frommem (state, memory));
325 sim_fetch_register (sd, rn, memory, length)
328 unsigned char *memory;
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);
339 regval = 0; /* FIXME: should report an error */
340 tomem (state, memory, regval);
345 sim_open (kind, ptr, abfd, argv)
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. */
360 big_endian = bfd_big_endian (abfd);
361 else if (argv[1] != NULL)
365 /* Scan for endian-ness switch. */
366 for (i = 0; (argv[i] != NULL) && (argv[i][0] != 0); i++)
367 if (argv[i][0] == '-' && argv[i][1] == 'E')
371 if ((c = argv[i][2]) == 0)
380 sim_callback->printf_filtered
381 (sim_callback, "No argument to -E option provided\n");
395 sim_callback->printf_filtered
396 (sim_callback, "Unrecognised argument to -E option\n");
406 sim_close (sd, quitting)
414 sim_load (sd, prog, abfd, from_tty)
420 extern bfd *sim_load_file (); /* ??? Don't know where this should live. */
423 prog_bfd = sim_load_file (sd, myname, sim_callback, prog, abfd,
424 sim_kind == SIM_OPEN_DEBUG, 0, sim_write);
425 if (prog_bfd == NULL)
427 ARMul_SetPC (state, bfd_get_start_address (prog_bfd));
429 bfd_close (prog_bfd);
434 sim_stop_reason (sd, reason, sigrc)
436 enum sim_stop *reason;
441 *reason = sim_stopped;
444 else if (state->EndCondition == 0)
446 *reason = sim_exited;
447 *sigrc = state->Reg[0] & 255;
451 *reason = sim_stopped;
452 if (state->EndCondition == RDIError_BreakpointReached)
460 sim_do_command (sd, cmd)
464 (*sim_callback->printf_filtered) (sim_callback,
465 "This simulator does not accept any commands.\n");
470 sim_set_callbacks (ptr)