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
);
110 ARMul_Debug (ARMul_State
* state
, ARMword pc
, ARMword instr
)
116 sim_write (sd
, addr
, buffer
, size
)
119 unsigned char *buffer
;
124 for (i
= 0; i
< size
; i
++)
126 ARMul_WriteByte (state
, addr
+i
, buffer
[i
]);
132 sim_read (sd
, addr
, buffer
, size
)
135 unsigned char *buffer
;
140 for (i
= 0; i
< size
; i
++)
142 buffer
[i
] = ARMul_ReadByte (state
, addr
+ i
);
151 (*sim_callback
->printf_filtered
) (sim_callback
, "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 */
254 state
->MemSize
= strtoul(*env
+ sizeof("MEMSIZE=")-1, &end_of_num
, 0);
264 sim_info (sd
, verbose
)
272 frommem (state
, memory
)
273 struct ARMul_State
*state
;
274 unsigned char *memory
;
276 if (state
->bigendSig
== HIGH
)
278 return (memory
[0] << 24)
285 return (memory
[3] << 24)
294 tomem (state
, memory
, val
)
295 struct ARMul_State
*state
;
296 unsigned char *memory
;
299 if (state
->bigendSig
== HIGH
)
301 memory
[0] = val
>> 24;
302 memory
[1] = val
>> 16;
303 memory
[2] = val
>> 8;
304 memory
[3] = val
>> 0;
308 memory
[3] = val
>> 24;
309 memory
[2] = val
>> 16;
310 memory
[1] = val
>> 8;
311 memory
[0] = val
>> 0;
316 sim_store_register (sd
, rn
, memory
, length
)
319 unsigned char *memory
;
323 ARMul_SetReg(state
, state
->Mode
, rn
, frommem (state
, memory
));
328 sim_fetch_register (sd
, rn
, memory
, length
)
331 unsigned char *memory
;
338 regval
= ARMul_GetReg(state
, state
->Mode
, rn
);
339 else if (rn
== 25) /* FIXME: use PS_REGNUM from gdb/config/arm/tm-arm.h */
340 regval
= ARMul_GetCPSR(state
);
342 regval
= 0; /* FIXME: should report an error */
343 tomem (state
, memory
, regval
);
348 sim_open (kind
, ptr
, abfd
, argv
)
358 /* Decide upon the endian-ness of the processor.
359 If we can, get the information from the bfd itself.
360 Otherwise look to see if we have been given a command
361 line switch that tells us. Otherwise default to little endian. */
363 big_endian
= bfd_big_endian (abfd
);
364 else if (argv
[1] != NULL
)
368 /* Scan for endian-ness switch. */
369 for (i
= 0; (argv
[i
] != NULL
) && (argv
[i
][0] != 0); i
++)
370 if (argv
[i
][0] == '-' && argv
[i
][1] == 'E')
374 if ((c
= argv
[i
][2]) == 0)
383 sim_callback
->printf_filtered
384 (sim_callback
, "No argument to -E option provided\n");
398 sim_callback
->printf_filtered
399 (sim_callback
, "Unrecognised argument to -E option\n");
409 sim_close (sd
, quitting
)
417 sim_load (sd
, prog
, abfd
, from_tty
)
423 extern bfd
*sim_load_file (); /* ??? Don't know where this should live. */
426 prog_bfd
= sim_load_file (sd
, myname
, sim_callback
, prog
, abfd
,
427 sim_kind
== SIM_OPEN_DEBUG
,
429 if (prog_bfd
== NULL
)
431 ARMul_SetPC (state
, bfd_get_start_address (prog_bfd
));
433 bfd_close (prog_bfd
);
438 sim_stop_reason (sd
, reason
, sigrc
)
440 enum sim_stop
*reason
;
445 *reason
= sim_stopped
;
448 else if (state
->EndCondition
== 0)
450 *reason
= sim_exited
;
451 *sigrc
= state
->Reg
[0] & 255;
455 *reason
= sim_stopped
;
456 if (state
->EndCondition
== RDIError_BreakpointReached
)
464 sim_do_command (sd
, cmd
)
468 (*sim_callback
->printf_filtered
) (sim_callback
, "This simulator does not accept any commands.\n");
473 sim_set_callbacks (ptr
)