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
)
118 sim_write (sd
, addr
, buffer
, size
)
119 SIM_DESC sd ATTRIBUTE_UNUSED
;
121 unsigned char *buffer
;
128 for (i
= 0; i
< size
; i
++)
129 ARMul_WriteByte (state
, addr
+ i
, buffer
[i
]);
135 sim_read (sd
, addr
, buffer
, size
)
136 SIM_DESC sd ATTRIBUTE_UNUSED
;
138 unsigned char *buffer
;
143 for (i
= 0; i
< size
; i
++)
145 buffer
[i
] = ARMul_ReadByte (state
, addr
+ i
);
152 SIM_DESC sd ATTRIBUTE_UNUSED
;
154 (*sim_callback
->printf_filtered
) (sim_callback
,
155 "This simulator does not support tracing\n");
161 SIM_DESC sd ATTRIBUTE_UNUSED
;
163 state
->Emulate
= STOP
;
169 sim_resume (sd
, step
, siggnal
)
170 SIM_DESC sd ATTRIBUTE_UNUSED
;
172 int siggnal ATTRIBUTE_UNUSED
;
174 state
->EndCondition
= 0;
179 state
->Reg
[15] = ARMul_DoInstr (state
);
180 if (state
->EndCondition
== 0)
181 state
->EndCondition
= RDIError_BreakpointReached
;
186 state
->NextInstr
= RESUME
; /* treat as PC change */
188 state
->Reg
[15] = ARMul_DoProg (state
);
195 sim_create_inferior (sd
, abfd
, argv
, env
)
196 SIM_DESC sd ATTRIBUTE_UNUSED
;
206 ARMul_SetPC (state
, bfd_get_start_address (abfd
));
208 ARMul_SetPC (state
, 0); /* ??? */
210 mach
= bfd_get_mach (abfd
);
215 (*sim_callback
->printf_filtered
) (sim_callback
,
216 "Unknown machine type; please update sim_create_inferior.\n");
220 /* We wouldn't set the machine type with earlier toolchains, so we
221 explicitly select a processor capable of supporting all ARM
229 if (mach
== 7 || mach
== 8)
230 ARMul_SelectProcessor (state
, ARM_v5_Prop
);
232 ARMul_SelectProcessor (state
, ARM_v4_Prop
);
233 /* Reset mode to ARM. A gdb user may rerun a program that had entered
234 THUMB mode from the start and cause the ARM-mode startup code to be
235 executed in THUMB mode. */
236 ARMul_SetCPSR (state
, USER32MODE
);
241 ARMul_SelectProcessor (state
, ARM_Lock_Prop
);
246 ARMul_SelectProcessor (state
, ARM_Fix26_Prop
);
253 ** Set up the command line (by laboriously stringing together the
254 ** environment carefully picked apart by our caller...)
256 /* Free any old stuff */
257 if (state
->CommandLine
!= NULL
)
259 free (state
->CommandLine
);
260 state
->CommandLine
= NULL
;
263 /* See how much we need */
264 for (arg
= argv
; *arg
!= NULL
; arg
++)
265 argvlen
+= strlen (*arg
) + 1;
268 state
->CommandLine
= malloc (argvlen
+ 1);
269 if (state
->CommandLine
!= NULL
)
272 state
->CommandLine
[0] = '\0';
273 for (arg
= argv
; *arg
!= NULL
; arg
++)
275 strcat (state
->CommandLine
, *arg
);
276 strcat (state
->CommandLine
, " ");
283 /* Now see if there's a MEMSIZE spec in the environment */
286 if (strncmp (*env
, "MEMSIZE=", sizeof ("MEMSIZE=") - 1) == 0)
290 /* Set up memory limit */
292 strtoul (*env
+ sizeof ("MEMSIZE=") - 1, &end_of_num
, 0);
302 sim_info (sd
, verbose
)
303 SIM_DESC sd ATTRIBUTE_UNUSED
;
304 int verbose ATTRIBUTE_UNUSED
;
310 frommem (state
, memory
)
311 struct ARMul_State
*state
;
312 unsigned char *memory
;
314 if (state
->bigendSig
== HIGH
)
316 return (memory
[0] << 24)
317 | (memory
[1] << 16) | (memory
[2] << 8) | (memory
[3] << 0);
321 return (memory
[3] << 24)
322 | (memory
[2] << 16) | (memory
[1] << 8) | (memory
[0] << 0);
328 tomem (state
, memory
, val
)
329 struct ARMul_State
*state
;
330 unsigned char *memory
;
333 if (state
->bigendSig
== HIGH
)
335 memory
[0] = val
>> 24;
336 memory
[1] = val
>> 16;
337 memory
[2] = val
>> 8;
338 memory
[3] = val
>> 0;
342 memory
[3] = val
>> 24;
343 memory
[2] = val
>> 16;
344 memory
[1] = val
>> 8;
345 memory
[0] = val
>> 0;
350 sim_store_register (sd
, rn
, memory
, length
)
351 SIM_DESC sd ATTRIBUTE_UNUSED
;
353 unsigned char *memory
;
354 int length ATTRIBUTE_UNUSED
;
359 state
->Cpsr
= frommem (state
, memory
);
360 ARMul_CPSRAltered (state
);
363 ARMul_SetReg (state
, state
->Mode
, rn
, frommem (state
, memory
));
368 sim_fetch_register (sd
, rn
, memory
, length
)
369 SIM_DESC sd ATTRIBUTE_UNUSED
;
371 unsigned char *memory
;
372 int length ATTRIBUTE_UNUSED
;
378 regval
= ARMul_GetReg (state
, state
->Mode
, rn
);
379 else if (rn
== 25) /* FIXME: use PS_REGNUM from gdb/config/arm/tm-arm.h */
380 regval
= ARMul_GetCPSR (state
);
382 regval
= 0; /* FIXME: should report an error */
383 tomem (state
, memory
, regval
);
388 sim_open (kind
, ptr
, abfd
, argv
)
395 if (myname
) free (myname
);
396 myname
= (char *) xstrdup (argv
[0]);
399 /* Decide upon the endian-ness of the processor.
400 If we can, get the information from the bfd itself.
401 Otherwise look to see if we have been given a command
402 line switch that tells us. Otherwise default to little endian. */
404 big_endian
= bfd_big_endian (abfd
);
405 else if (argv
[1] != NULL
)
409 /* Scan for endian-ness switch. */
410 for (i
= 0; (argv
[i
] != NULL
) && (argv
[i
][0] != 0); i
++)
411 if (argv
[i
][0] == '-' && argv
[i
][1] == 'E')
415 if ((c
= argv
[i
][2]) == 0)
424 sim_callback
->printf_filtered
425 (sim_callback
, "No argument to -E option provided\n");
439 sim_callback
->printf_filtered
440 (sim_callback
, "Unrecognised argument to -E option\n");
450 sim_close (sd
, quitting
)
451 SIM_DESC sd ATTRIBUTE_UNUSED
;
452 int quitting ATTRIBUTE_UNUSED
;
454 if (myname
) free (myname
);
459 sim_load (sd
, prog
, abfd
, from_tty
)
463 int from_tty ATTRIBUTE_UNUSED
;
465 extern bfd
*sim_load_file (); /* ??? Don't know where this should live. */
468 prog_bfd
= sim_load_file (sd
, myname
, sim_callback
, prog
, abfd
,
469 sim_kind
== SIM_OPEN_DEBUG
, 0, sim_write
);
470 if (prog_bfd
== NULL
)
472 ARMul_SetPC (state
, bfd_get_start_address (prog_bfd
));
474 bfd_close (prog_bfd
);
479 sim_stop_reason (sd
, reason
, sigrc
)
480 SIM_DESC sd ATTRIBUTE_UNUSED
;
481 enum sim_stop
*reason
;
486 *reason
= sim_stopped
;
489 else if (state
->EndCondition
== 0)
491 *reason
= sim_exited
;
492 *sigrc
= state
->Reg
[0] & 255;
496 *reason
= sim_stopped
;
497 if (state
->EndCondition
== RDIError_BreakpointReached
)
505 sim_do_command (sd
, cmd
)
506 SIM_DESC sd ATTRIBUTE_UNUSED
;
507 char *cmd ATTRIBUTE_UNUSED
;
509 (*sim_callback
->printf_filtered
) (sim_callback
,
510 "This simulator does not accept any commands.\n");
515 sim_set_callbacks (ptr
)