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. */
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
;
126 for (i
= 0; i
< size
; i
++)
128 ARMul_WriteByte (state
, addr
+ i
, buffer
[i
]);
134 sim_read (sd
, addr
, buffer
, size
)
135 SIM_DESC sd ATTRIBUTE_UNUSED
;
137 unsigned char *buffer
;
142 for (i
= 0; i
< size
; i
++)
144 buffer
[i
] = ARMul_ReadByte (state
, addr
+ i
);
151 SIM_DESC sd ATTRIBUTE_UNUSED
;
153 (*sim_callback
->printf_filtered
) (sim_callback
,
154 "This simulator does not support tracing\n");
160 SIM_DESC sd ATTRIBUTE_UNUSED
;
162 state
->Emulate
= STOP
;
168 sim_resume (sd
, step
, siggnal
)
169 SIM_DESC sd ATTRIBUTE_UNUSED
;
171 int siggnal ATTRIBUTE_UNUSED
;
173 state
->EndCondition
= 0;
178 state
->Reg
[15] = ARMul_DoInstr (state
);
179 if (state
->EndCondition
== 0)
180 state
->EndCondition
= RDIError_BreakpointReached
;
185 state
->NextInstr
= RESUME
; /* treat as PC change */
187 state
->Reg
[15] = ARMul_DoProg (state
);
194 sim_create_inferior (sd
, abfd
, argv
, env
)
195 SIM_DESC sd ATTRIBUTE_UNUSED
;
204 ARMul_SetPC (state
, bfd_get_start_address (abfd
));
206 ARMul_SetPC (state
, 0); /* ??? */
208 /* We explicitly select a processor capable of supporting the ARM
210 ARMul_SelectProcessor (state
, ARM600
);
211 /* And then we force the simulated CPU into the 32bit User mode. */
212 ARMul_SetCPSR (state
, USER32MODE
);
217 ** Set up the command line (by laboriously stringing together the
218 ** environment carefully picked apart by our caller...)
220 /* Free any old stuff */
221 if (state
->CommandLine
!= NULL
)
223 free (state
->CommandLine
);
224 state
->CommandLine
= NULL
;
227 /* See how much we need */
228 for (arg
= argv
; *arg
!= NULL
; arg
++)
229 argvlen
+= strlen (*arg
) + 1;
232 state
->CommandLine
= malloc (argvlen
+ 1);
233 if (state
->CommandLine
!= NULL
)
236 state
->CommandLine
[0] = '\0';
237 for (arg
= argv
; *arg
!= NULL
; arg
++)
239 strcat (state
->CommandLine
, *arg
);
240 strcat (state
->CommandLine
, " ");
247 /* Now see if there's a MEMSIZE spec in the environment */
250 if (strncmp (*env
, "MEMSIZE=", sizeof ("MEMSIZE=") - 1) == 0)
254 /* Set up memory limit */
256 strtoul (*env
+ sizeof ("MEMSIZE=") - 1, &end_of_num
, 0);
266 sim_info (sd
, verbose
)
267 SIM_DESC sd ATTRIBUTE_UNUSED
;
268 int verbose ATTRIBUTE_UNUSED
;
274 frommem (state
, memory
)
275 struct ARMul_State
*state
;
276 unsigned char *memory
;
278 if (state
->bigendSig
== HIGH
)
280 return (memory
[0] << 24)
281 | (memory
[1] << 16) | (memory
[2] << 8) | (memory
[3] << 0);
285 return (memory
[3] << 24)
286 | (memory
[2] << 16) | (memory
[1] << 8) | (memory
[0] << 0);
292 tomem (state
, memory
, val
)
293 struct ARMul_State
*state
;
294 unsigned char *memory
;
297 if (state
->bigendSig
== HIGH
)
299 memory
[0] = val
>> 24;
300 memory
[1] = val
>> 16;
301 memory
[2] = val
>> 8;
302 memory
[3] = val
>> 0;
306 memory
[3] = val
>> 24;
307 memory
[2] = val
>> 16;
308 memory
[1] = val
>> 8;
309 memory
[0] = val
>> 0;
314 sim_store_register (sd
, rn
, memory
, length
)
315 SIM_DESC sd ATTRIBUTE_UNUSED
;
317 unsigned char *memory
;
318 int length ATTRIBUTE_UNUSED
;
323 state
->Cpsr
= frommem (state
, memory
);
324 ARMul_CPSRAltered (state
);
327 ARMul_SetReg (state
, state
->Mode
, rn
, frommem (state
, memory
));
332 sim_fetch_register (sd
, rn
, memory
, length
)
333 SIM_DESC sd ATTRIBUTE_UNUSED
;
335 unsigned char *memory
;
336 int length ATTRIBUTE_UNUSED
;
342 regval
= ARMul_GetReg (state
, state
->Mode
, rn
);
343 else if (rn
== 25) /* FIXME: use PS_REGNUM from gdb/config/arm/tm-arm.h */
344 regval
= ARMul_GetCPSR (state
);
346 regval
= 0; /* FIXME: should report an error */
347 tomem (state
, memory
, regval
);
352 sim_open (kind
, ptr
, abfd
, argv
)
359 if (myname
) free (myname
);
360 myname
= (char *) xstrdup (argv
[0]);
363 /* Decide upon the endian-ness of the processor.
364 If we can, get the information from the bfd itself.
365 Otherwise look to see if we have been given a command
366 line switch that tells us. Otherwise default to little endian. */
368 big_endian
= bfd_big_endian (abfd
);
369 else if (argv
[1] != NULL
)
373 /* Scan for endian-ness switch. */
374 for (i
= 0; (argv
[i
] != NULL
) && (argv
[i
][0] != 0); i
++)
375 if (argv
[i
][0] == '-' && argv
[i
][1] == 'E')
379 if ((c
= argv
[i
][2]) == 0)
388 sim_callback
->printf_filtered
389 (sim_callback
, "No argument to -E option provided\n");
403 sim_callback
->printf_filtered
404 (sim_callback
, "Unrecognised argument to -E option\n");
414 sim_close (sd
, quitting
)
415 SIM_DESC sd ATTRIBUTE_UNUSED
;
416 int quitting ATTRIBUTE_UNUSED
;
418 if (myname
) free (myname
);
423 sim_load (sd
, prog
, abfd
, from_tty
)
427 int from_tty ATTRIBUTE_UNUSED
;
429 extern bfd
*sim_load_file (); /* ??? Don't know where this should live. */
432 prog_bfd
= sim_load_file (sd
, myname
, sim_callback
, prog
, abfd
,
433 sim_kind
== SIM_OPEN_DEBUG
, 0, sim_write
);
434 if (prog_bfd
== NULL
)
436 ARMul_SetPC (state
, bfd_get_start_address (prog_bfd
));
438 bfd_close (prog_bfd
);
443 sim_stop_reason (sd
, reason
, sigrc
)
444 SIM_DESC sd ATTRIBUTE_UNUSED
;
445 enum sim_stop
*reason
;
450 *reason
= sim_stopped
;
453 else if (state
->EndCondition
== 0)
455 *reason
= sim_exited
;
456 *sigrc
= state
->Reg
[0] & 255;
460 *reason
= sim_stopped
;
461 if (state
->EndCondition
== RDIError_BreakpointReached
)
469 sim_do_command (sd
, cmd
)
470 SIM_DESC sd ATTRIBUTE_UNUSED
;
471 char *cmd ATTRIBUTE_UNUSED
;
473 (*sim_callback
->printf_filtered
) (sim_callback
,
474 "This simulator does not accept any commands.\n");
479 sim_set_callbacks (ptr
)