1 /* run front end support for arm
2 Copyright (C) 1995, 1996, 1997, 2000 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. */
30 #include "remote-sim.h"
36 host_callback *sim_callback;
38 static struct ARMul_State *state;
40 /* Who is using the simulator. */
41 static SIM_OPEN_KIND sim_kind;
46 /* Memory size in bytes. */
47 static int mem_size = (1 << 21);
49 /* Non-zero to display start up banner, and maybe other things. */
52 /* Non-zero to set big endian mode. */
53 static int big_endian;
65 state = ARMul_NewState ();
66 state->bigendSig = (big_endian ? HIGH : LOW);
67 ARMul_MemoryInit (state, mem_size);
69 ARMul_CoProInit (state);
70 state->verbose = verbosity;
75 /* Set verbosity level of simulator.
76 This is not intended to produce detailed tracing or debugging information.
78 /* FIXME: common/run.c doesn't do this yet. */
87 /* Set the memory size to SIZE bytes.
88 Must be called before initializing simulator. */
89 /* FIXME: Rename to sim_set_mem_size. */
99 ARMul_ConsolePrint (ARMul_State * state, const char *format, ...)
105 va_start (ap, format);
106 vprintf (format, ap);
112 ARMul_Debug (ARMul_State * state ATTRIBUTE_UNUSED, ARMword pc ATTRIBUTE_UNUSED, ARMword instr ATTRIBUTE_UNUSED)
117 int SWI_vector_installed = FALSE;
120 sim_write (sd, addr, buffer, size)
121 SIM_DESC sd ATTRIBUTE_UNUSED;
123 unsigned char *buffer;
130 if ((addr <= 0x8) && ((addr + size) >= 0x8))
131 SWI_vector_installed = TRUE;
133 for (i = 0; i < size; i++)
134 ARMul_WriteByte (state, addr + i, buffer[i]);
140 sim_read (sd, addr, buffer, size)
141 SIM_DESC sd ATTRIBUTE_UNUSED;
143 unsigned char *buffer;
148 for (i = 0; i < size; i++)
150 buffer[i] = ARMul_ReadByte (state, addr + i);
157 SIM_DESC sd ATTRIBUTE_UNUSED;
159 (*sim_callback->printf_filtered) (sim_callback,
160 "This simulator does not support tracing\n");
166 SIM_DESC sd ATTRIBUTE_UNUSED;
168 state->Emulate = STOP;
174 sim_resume (sd, step, siggnal)
175 SIM_DESC sd ATTRIBUTE_UNUSED;
177 int siggnal ATTRIBUTE_UNUSED;
179 state->EndCondition = 0;
184 state->Reg[15] = ARMul_DoInstr (state);
185 if (state->EndCondition == 0)
186 state->EndCondition = RDIError_BreakpointReached;
191 state->NextInstr = RESUME; /* treat as PC change */
193 state->Reg[15] = ARMul_DoProg (state);
200 sim_create_inferior (sd, abfd, argv, env)
201 SIM_DESC sd ATTRIBUTE_UNUSED;
211 ARMul_SetPC (state, bfd_get_start_address (abfd));
213 ARMul_SetPC (state, 0); /* ??? */
215 mach = bfd_get_mach (abfd);
220 (*sim_callback->printf_filtered) (sim_callback,
221 "Unknown machine type; please update sim_create_inferior.\n");
225 /* We wouldn't set the machine type with earlier toolchains, so we
226 explicitly select a processor capable of supporting all ARMs in
229 case bfd_mach_arm_5T:
230 ARMul_SelectProcessor (state, ARM_v5_Prop);
233 case bfd_mach_arm_5TE:
234 ARMul_SelectProcessor (state, ARM_v5_Prop | ARM_v5e_Prop);
237 case bfd_mach_arm_XScale:
238 ARMul_SelectProcessor (state, ARM_v5_Prop | ARM_v5e_Prop | ARM_XScale_Prop);
242 case bfd_mach_arm_4T:
243 ARMul_SelectProcessor (state, ARM_v4_Prop);
247 case bfd_mach_arm_3M:
248 ARMul_SelectProcessor (state, ARM_Lock_Prop);
252 case bfd_mach_arm_2a:
253 ARMul_SelectProcessor (state, ARM_Fix26_Prop);
259 /* Reset mode to ARM. A gdb user may rerun a program that had entered
260 THUMB mode from the start and cause the ARM-mode startup code to be
261 executed in THUMB mode. */
262 ARMul_SetCPSR (state, USER32MODE);
268 ** Set up the command line (by laboriously stringing together the
269 ** environment carefully picked apart by our caller...)
271 /* Free any old stuff */
272 if (state->CommandLine != NULL)
274 free (state->CommandLine);
275 state->CommandLine = NULL;
278 /* See how much we need */
279 for (arg = argv; *arg != NULL; arg++)
280 argvlen += strlen (*arg) + 1;
283 state->CommandLine = malloc (argvlen + 1);
284 if (state->CommandLine != NULL)
287 state->CommandLine[0] = '\0';
288 for (arg = argv; *arg != NULL; arg++)
290 strcat (state->CommandLine, *arg);
291 strcat (state->CommandLine, " ");
298 /* Now see if there's a MEMSIZE spec in the environment */
301 if (strncmp (*env, "MEMSIZE=", sizeof ("MEMSIZE=") - 1) == 0)
305 /* Set up memory limit */
307 strtoul (*env + sizeof ("MEMSIZE=") - 1, &end_of_num, 0);
317 sim_info (sd, verbose)
318 SIM_DESC sd ATTRIBUTE_UNUSED;
319 int verbose ATTRIBUTE_UNUSED;
325 frommem (state, memory)
326 struct ARMul_State *state;
327 unsigned char *memory;
329 if (state->bigendSig == HIGH)
331 return (memory[0] << 24)
332 | (memory[1] << 16) | (memory[2] << 8) | (memory[3] << 0);
336 return (memory[3] << 24)
337 | (memory[2] << 16) | (memory[1] << 8) | (memory[0] << 0);
343 tomem (state, memory, val)
344 struct ARMul_State *state;
345 unsigned char *memory;
348 if (state->bigendSig == HIGH)
350 memory[0] = val >> 24;
351 memory[1] = val >> 16;
352 memory[2] = val >> 8;
353 memory[3] = val >> 0;
357 memory[3] = val >> 24;
358 memory[2] = val >> 16;
359 memory[1] = val >> 8;
360 memory[0] = val >> 0;
365 sim_store_register (sd, rn, memory, length)
366 SIM_DESC sd ATTRIBUTE_UNUSED;
368 unsigned char *memory;
369 int length ATTRIBUTE_UNUSED;
375 state->Cpsr = frommem (state, memory);
376 ARMul_CPSRAltered (state);
379 ARMul_SetReg (state, state->Mode, rn, frommem (state, memory));
384 sim_fetch_register (sd, rn, memory, length)
385 SIM_DESC sd ATTRIBUTE_UNUSED;
387 unsigned char *memory;
388 int length ATTRIBUTE_UNUSED;
395 regval = ARMul_GetReg (state, state->Mode, rn);
396 else if (rn == 25) /* FIXME: use PS_REGNUM from gdb/config/arm/tm-arm.h */
397 regval = ARMul_GetCPSR (state);
399 regval = 0; /* FIXME: should report an error */
400 tomem (state, memory, regval);
405 sim_open (kind, ptr, abfd, argv)
412 if (myname) free (myname);
413 myname = (char *) xstrdup (argv[0]);
416 /* Decide upon the endian-ness of the processor.
417 If we can, get the information from the bfd itself.
418 Otherwise look to see if we have been given a command
419 line switch that tells us. Otherwise default to little endian. */
421 big_endian = bfd_big_endian (abfd);
422 else if (argv[1] != NULL)
426 /* Scan for endian-ness switch. */
427 for (i = 0; (argv[i] != NULL) && (argv[i][0] != 0); i++)
428 if (argv[i][0] == '-' && argv[i][1] == 'E')
432 if ((c = argv[i][2]) == 0)
441 sim_callback->printf_filtered
442 (sim_callback, "No argument to -E option provided\n");
456 sim_callback->printf_filtered
457 (sim_callback, "Unrecognised argument to -E option\n");
467 sim_close (sd, quitting)
468 SIM_DESC sd ATTRIBUTE_UNUSED;
469 int quitting ATTRIBUTE_UNUSED;
471 if (myname) free (myname);
476 sim_load (sd, prog, abfd, from_tty)
480 int from_tty ATTRIBUTE_UNUSED;
482 extern bfd *sim_load_file (); /* ??? Don't know where this should live. */
485 prog_bfd = sim_load_file (sd, myname, sim_callback, prog, abfd,
486 sim_kind == SIM_OPEN_DEBUG, 0, sim_write);
487 if (prog_bfd == NULL)
489 ARMul_SetPC (state, bfd_get_start_address (prog_bfd));
491 bfd_close (prog_bfd);
496 sim_stop_reason (sd, reason, sigrc)
497 SIM_DESC sd ATTRIBUTE_UNUSED;
498 enum sim_stop *reason;
503 *reason = sim_stopped;
506 else if (state->EndCondition == 0)
508 *reason = sim_exited;
509 *sigrc = state->Reg[0] & 255;
513 *reason = sim_stopped;
514 if (state->EndCondition == RDIError_BreakpointReached)
522 sim_do_command (sd, cmd)
523 SIM_DESC sd ATTRIBUTE_UNUSED;
524 char *cmd ATTRIBUTE_UNUSED;
526 (*sim_callback->printf_filtered) (sim_callback,
527 "This simulator does not accept any commands.\n");
532 sim_set_callbacks (ptr)