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;
61 state = ARMul_NewState ();
62 state->bigendSig = (big_endian ? HIGH : LOW);
63 ARMul_MemoryInit(state, mem_size);
65 ARMul_CoProInit(state);
66 state->verbose = verbosity;
71 /* Set verbosity level of simulator.
72 This is not intended to produce detailed tracing or debugging information.
74 /* FIXME: common/run.c doesn't do this yet. */
83 /* Set the memory size to SIZE bytes.
84 Must be called before initializing simulator. */
85 /* FIXME: Rename to sim_set_mem_size. */
95 ARMul_ConsolePrint (ARMul_State * state, const char *format,...)
101 va_start (ap, format);
102 vprintf (format, ap);
108 ARMul_Debug (ARMul_State * state, ARMword pc, ARMword instr)
114 sim_write (sd, addr, buffer, size)
117 unsigned char *buffer;
122 for (i = 0; i < size; i++)
124 ARMul_WriteByte (state, addr+i, buffer[i]);
130 sim_read (sd, addr, buffer, size)
133 unsigned char *buffer;
138 for (i = 0; i < size; i++)
140 buffer[i] = ARMul_ReadByte (state, addr + i);
149 (*sim_callback->printf_filtered) (sim_callback, "This simulator does not support tracing\n");
161 sim_resume (sd, step, siggnal)
165 state->EndCondition = 0;
169 state->Reg[15] = ARMul_DoInstr (state);
170 if (state->EndCondition == 0)
171 state->EndCondition = RDIError_BreakpointReached;
176 state->NextInstr = RESUME; /* treat as PC change */
178 state->Reg[15] = ARMul_DoProg (state);
185 sim_create_inferior (sd, abfd, argv, env)
195 ARMul_SetPC (state, bfd_get_start_address (abfd));
197 ARMul_SetPC (state, 0); /* ??? */
200 /* We explicitly select a processor capable of supporting the ARM
201 32bit mode, and then we force the simulated CPU into the 32bit
203 ARMul_SelectProcessor(state, ARM600);
204 ARMul_SetCPSR(state, USER32MODE);
210 ** Set up the command line (by laboriously stringing together the
211 ** environment carefully picked apart by our caller...)
213 /* Free any old stuff */
214 if (state->CommandLine != NULL)
216 free(state->CommandLine);
217 state->CommandLine = NULL;
220 /* See how much we need */
221 for (arg = argv; *arg != NULL; arg++)
222 argvlen += strlen(*arg)+1;
225 state->CommandLine = malloc(argvlen+1);
226 if (state->CommandLine != NULL)
229 state->CommandLine[0]='\0';
230 for (arg = argv; *arg != NULL; arg++)
232 strcat(state->CommandLine, *arg);
233 strcat(state->CommandLine, " ");
240 /* Now see if there's a MEMSIZE spec in the environment */
243 if (strncmp(*env, "MEMSIZE=", sizeof("MEMSIZE=")-1)==0)
245 unsigned long top_of_memory;
248 /* Set up memory limit */
249 state->MemSize = strtoul(*env + sizeof("MEMSIZE=")-1, &end_of_num, 0);
259 sim_info (sd, verbose)
267 frommem (state, memory)
268 struct ARMul_State *state;
269 unsigned char *memory;
271 if (state->bigendSig == HIGH)
273 return (memory[0] << 24)
280 return (memory[3] << 24)
289 tomem (state, memory, val)
290 struct ARMul_State *state;
291 unsigned char *memory;
294 if (state->bigendSig == HIGH)
296 memory[0] = val >> 24;
297 memory[1] = val >> 16;
298 memory[2] = val >> 8;
299 memory[3] = val >> 0;
303 memory[3] = val >> 24;
304 memory[2] = val >> 16;
305 memory[1] = val >> 8;
306 memory[0] = val >> 0;
311 sim_store_register (sd, rn, memory, length)
314 unsigned char *memory;
318 ARMul_SetReg(state, state->Mode, rn, frommem (state, memory));
323 sim_fetch_register (sd, rn, memory, length)
326 unsigned char *memory;
333 regval = ARMul_GetReg(state, state->Mode, rn);
334 else if (rn == 25) /* FIXME: use PS_REGNUM from gdb/config/arm/tm-arm.h */
335 regval = ARMul_GetCPSR(state);
337 regval = 0; /* FIXME: should report an error */
338 tomem (state, memory, regval);
343 sim_open (kind, ptr, abfd, argv)
353 /* Decide upon the endian-ness of the processor.
354 If we can, get the information from the bfd itself.
355 Otherwise look to see if we have been given a command
356 line switch that tells us. Otherwise default to little endian. */
358 big_endian = bfd_big_endian (abfd);
359 else if (argv[1] != NULL)
363 /* Scan for endian-ness switch. */
364 for (i = 0; (argv[i] != NULL) && (argv[i][0] != 0); i++)
365 if (argv[i][0] == '-' && argv[i][1] == 'E')
369 if ((c = argv[i][2]) == 0)
378 sim_callback->printf_filtered
379 (sim_callback, "No argument to -E option provided\n");
393 sim_callback->printf_filtered
394 (sim_callback, "Unrecognised argument to -E option\n");
404 sim_close (sd, quitting)
412 sim_load (sd, prog, abfd, from_tty)
418 extern bfd *sim_load_file (); /* ??? Don't know where this should live. */
421 prog_bfd = sim_load_file (sd, myname, sim_callback, prog, abfd,
422 sim_kind == SIM_OPEN_DEBUG,
424 if (prog_bfd == NULL)
426 ARMul_SetPC (state, bfd_get_start_address (prog_bfd));
428 bfd_close (prog_bfd);
433 sim_stop_reason (sd, reason, sigrc)
435 enum sim_stop *reason;
438 if (state->EndCondition == 0)
440 *reason = sim_exited;
441 *sigrc = state->Reg[0] & 255;
445 *reason = sim_stopped;
446 if (state->EndCondition == RDIError_BreakpointReached)
454 sim_do_command (sd, cmd)
458 (*sim_callback->printf_filtered) (sim_callback, "This simulator does not accept any commands.\n");
463 sim_set_callbacks (ptr)