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. */
58 state = ARMul_NewState ();
59 ARMul_MemoryInit(state, mem_size);
61 ARMul_CoProInit(state);
62 state->verbose = verbosity;
67 /* Set verbosity level of simulator.
68 This is not intended to produce detailed tracing or debugging information.
70 /* FIXME: common/run.c doesn't do this yet. */
79 /* Set the memory size to SIZE bytes.
80 Must be called before initializing simulator. */
81 /* FIXME: Rename to sim_set_mem_size. */
91 ARMul_ConsolePrint (ARMul_State * state, const char *format,...)
97 va_start (ap, format);
104 ARMul_Debug (ARMul_State * state, ARMword pc, ARMword instr)
110 sim_write (sd, addr, buffer, size)
113 unsigned char *buffer;
118 for (i = 0; i < size; i++)
120 ARMul_WriteByte (state, addr+i, buffer[i]);
126 sim_read (sd, addr, buffer, size)
129 unsigned char *buffer;
134 for (i = 0; i < size; i++)
136 buffer[i] = ARMul_ReadByte (state, addr + i);
145 (*sim_callback->printf_filtered) (sim_callback, "This simulator does not support tracing\n");
157 sim_resume (sd, step, siggnal)
161 state->EndCondition = 0;
165 state->Reg[15] = ARMul_DoInstr (state);
166 if (state->EndCondition == 0)
167 state->EndCondition = RDIError_BreakpointReached;
171 state->Reg[15] = ARMul_DoProg (state);
178 sim_create_inferior (sd, abfd, argv, env)
188 /* We explicitly select a processor capable of supporting the ARM
189 32bit mode, and then we force the simulated CPU into the 32bit
191 ARMul_SelectProcessor(state, ARM600);
192 ARMul_SetCPSR(state, USER32MODE);
198 ** Set up the command line (by laboriously stringing together the
199 ** environment carefully picked apart by our caller...)
201 /* Free any old stuff */
202 if (state->CommandLine != NULL)
204 free(state->CommandLine);
205 state->CommandLine = NULL;
208 /* See how much we need */
209 for (arg = argv; *arg != NULL; arg++)
210 argvlen += strlen(*arg)+1;
213 state->CommandLine = malloc(argvlen+1);
214 if (state->CommandLine != NULL)
217 state->CommandLine[0]='\0';
218 for (arg = argv; *arg != NULL; arg++)
220 strcat(state->CommandLine, *arg);
221 strcat(state->CommandLine, " ");
228 /* Now see if there's a MEMSIZE spec in the environment */
231 if (strncmp(*env, "MEMSIZE=", sizeof("MEMSIZE=")-1)==0)
233 unsigned long top_of_memory;
236 /* Set up memory limit */
237 state->MemSize = strtoul(*env + sizeof("MEMSIZE=")-1, &end_of_num, 0);
247 sim_info (sd, verbose)
255 frommem (state, memory)
256 struct ARMul_State *state;
257 unsigned char *memory;
259 if (state->bigendSig == HIGH)
261 return (memory[0] << 24)
268 return (memory[3] << 24)
277 tomem (state, memory, val)
278 struct ARMul_State *state;
279 unsigned char *memory;
282 if (state->bigendSig == HIGH)
284 memory[0] = val >> 24;
285 memory[1] = val >> 16;
286 memory[2] = val >> 8;
287 memory[3] = val >> 0;
291 memory[3] = val >> 24;
292 memory[2] = val >> 16;
293 memory[1] = val >> 8;
294 memory[0] = val >> 0;
299 sim_store_register (sd, rn, memory)
302 unsigned char *memory;
305 ARMul_SetReg(state, state->Mode, rn, frommem (state, memory));
309 sim_fetch_register (sd, rn, memory)
312 unsigned char *memory;
315 tomem (state, memory, ARMul_GetReg(state, state->Mode, rn));
322 sim_open (kind, ptr, abfd, argv)
335 sim_close (sd, quitting)
343 sim_load (sd, prog, abfd, from_tty)
349 extern bfd *sim_load_file (); /* ??? Don't know where this should live. */
352 prog_bfd = sim_load_file (sd, myname, sim_callback, prog, abfd,
353 sim_kind == SIM_OPEN_DEBUG,
355 if (prog_bfd == NULL)
358 bfd_close (prog_bfd);
363 sim_stop_reason (sd, reason, sigrc)
365 enum sim_stop *reason;
368 if (state->EndCondition == 0)
370 *reason = sim_exited;
371 *sigrc = state->Reg[0] & 255;
375 *reason = sim_stopped;
376 if (state->EndCondition == RDIError_BreakpointReached)
384 sim_do_command (sd, cmd)
388 (*sim_callback->printf_filtered) (sim_callback, "This simulator does not accept any commands.\n");
393 sim_set_callbacks (ptr)