]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/arm/wrapper.c
remove conflict indicator.
[thirdparty/binutils-gdb.git] / sim / arm / wrapper.c
CommitLineData
c906108c 1/* run front end support for arm
1e6b544a 2 Copyright (C) 1995, 1996, 1997, 2000 Free Software Foundation, Inc.
c906108c
SS
3
4This file is part of ARM SIM.
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU CC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
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. */
23
24#include <stdio.h>
25#include <stdarg.h>
6d358e86 26#include <string.h>
c906108c
SS
27#include <bfd.h>
28#include <signal.h>
29#include "callback.h"
30#include "remote-sim.h"
31#include "armdefs.h"
32#include "armemu.h"
33#include "dbg_rdi.h"
6d358e86 34#include "ansidecl.h"
c906108c
SS
35
36host_callback *sim_callback;
37
38static struct ARMul_State *state;
39
40/* Who is using the simulator. */
41static SIM_OPEN_KIND sim_kind;
42
43/* argv[0] */
44static char *myname;
45
46/* Memory size in bytes. */
47static int mem_size = (1 << 21);
48
49/* Non-zero to display start up banner, and maybe other things. */
50static int verbosity;
51
52/* Non-zero to set big endian mode. */
53static int big_endian;
54
7a292a7a
SS
55int stop_simulator;
56
dfcd3bfb 57static void
c906108c
SS
58init ()
59{
60 static int done;
61
62 if (!done)
63 {
dfcd3bfb 64 ARMul_EmulateInit ();
c906108c
SS
65 state = ARMul_NewState ();
66 state->bigendSig = (big_endian ? HIGH : LOW);
dfcd3bfb
JM
67 ARMul_MemoryInit (state, mem_size);
68 ARMul_OSInit (state);
69 ARMul_CoProInit (state);
c906108c
SS
70 state->verbose = verbosity;
71 done = 1;
72 }
73}
74
75/* Set verbosity level of simulator.
76 This is not intended to produce detailed tracing or debugging information.
77 Just summaries. */
78/* FIXME: common/run.c doesn't do this yet. */
79
80void
81sim_set_verbose (v)
82 int v;
83{
84 verbosity = v;
85}
86
87/* Set the memory size to SIZE bytes.
dfcd3bfb 88 Must be called before initializing simulator. */
c906108c
SS
89/* FIXME: Rename to sim_set_mem_size. */
90
dfcd3bfb 91void
c906108c
SS
92sim_size (size)
93 int size;
94{
95 mem_size = size;
96}
97
dfcd3bfb
JM
98void
99ARMul_ConsolePrint (ARMul_State * state, const char *format, ...)
c906108c
SS
100{
101 va_list ap;
102
103 if (state->verbose)
104 {
105 va_start (ap, format);
106 vprintf (format, ap);
107 va_end (ap);
108 }
109}
110
6d358e86
NC
111ARMword
112ARMul_Debug (ARMul_State * state ATTRIBUTE_UNUSED, ARMword pc ATTRIBUTE_UNUSED, ARMword instr ATTRIBUTE_UNUSED)
c906108c 113{
6d358e86 114 return 0;
c906108c
SS
115}
116
117int
118sim_write (sd, addr, buffer, size)
6d358e86 119 SIM_DESC sd ATTRIBUTE_UNUSED;
c906108c
SS
120 SIM_ADDR addr;
121 unsigned char *buffer;
122 int size;
123{
124 int i;
3943c96b 125
c906108c 126 init ();
3943c96b 127
c906108c 128 for (i = 0; i < size; i++)
3943c96b
NC
129 ARMul_WriteByte (state, addr + i, buffer[i]);
130
c906108c
SS
131 return size;
132}
133
134int
135sim_read (sd, addr, buffer, size)
6d358e86 136 SIM_DESC sd ATTRIBUTE_UNUSED;
c906108c
SS
137 SIM_ADDR addr;
138 unsigned char *buffer;
139 int size;
140{
141 int i;
142 init ();
143 for (i = 0; i < size; i++)
144 {
145 buffer[i] = ARMul_ReadByte (state, addr + i);
146 }
147 return size;
148}
149
150int
151sim_trace (sd)
6d358e86 152 SIM_DESC sd ATTRIBUTE_UNUSED;
dfcd3bfb
JM
153{
154 (*sim_callback->printf_filtered) (sim_callback,
155 "This simulator does not support tracing\n");
c906108c
SS
156 return 1;
157}
158
159int
160sim_stop (sd)
6d358e86 161 SIM_DESC sd ATTRIBUTE_UNUSED;
c906108c 162{
7a292a7a
SS
163 state->Emulate = STOP;
164 stop_simulator = 1;
165 return 1;
c906108c
SS
166}
167
168void
169sim_resume (sd, step, siggnal)
6d358e86
NC
170 SIM_DESC sd ATTRIBUTE_UNUSED;
171 int step;
172 int siggnal ATTRIBUTE_UNUSED;
c906108c
SS
173{
174 state->EndCondition = 0;
7a292a7a 175 stop_simulator = 0;
c906108c
SS
176
177 if (step)
178 {
179 state->Reg[15] = ARMul_DoInstr (state);
180 if (state->EndCondition == 0)
181 state->EndCondition = RDIError_BreakpointReached;
182 }
183 else
184 {
dfcd3bfb
JM
185#if 1 /* JGS */
186 state->NextInstr = RESUME; /* treat as PC change */
c906108c
SS
187#endif
188 state->Reg[15] = ARMul_DoProg (state);
189 }
190
191 FLUSHPIPE;
192}
193
194SIM_RC
195sim_create_inferior (sd, abfd, argv, env)
6d358e86 196 SIM_DESC sd ATTRIBUTE_UNUSED;
c906108c
SS
197 struct _bfd *abfd;
198 char **argv;
199 char **env;
200{
dfcd3bfb 201 int argvlen = 0;
1e6b544a 202 int mach;
c906108c
SS
203 char **arg;
204
205 if (abfd != NULL)
206 ARMul_SetPC (state, bfd_get_start_address (abfd));
207 else
dfcd3bfb 208 ARMul_SetPC (state, 0); /* ??? */
c906108c 209
1e6b544a
AO
210 mach = bfd_get_mach (abfd);
211
3943c96b
NC
212 switch (mach)
213 {
214 default:
215 (*sim_callback->printf_filtered) (sim_callback,
216 "Unknown machine type; please update sim_create_inferior.\n");
217 /* fall through */
218
f1129fb8 219 case 0:
3943c96b 220 /* We wouldn't set the machine type with earlier toolchains, so we
f1129fb8
NC
221 explicitly select a processor capable of supporting all ARMs in
222 32bit mode. */
223 case bfd_mach_arm_5:
224 case bfd_mach_arm_5T:
225 ARMul_SelectProcessor (state, ARM_v5_Prop);
226 break;
3943c96b 227
f1129fb8
NC
228 case bfd_mach_arm_5TE:
229 ARMul_SelectProcessor (state, ARM_v5_Prop | ARM_v5e_Prop);
230 break;
231
232 case bfd_mach_arm_XScale:
233 ARMul_SelectProcessor (state, ARM_v5_Prop | ARM_v5e_Prop | ARM_XScale_Prop);
3943c96b
NC
234 break;
235
f1129fb8
NC
236 case bfd_mach_arm_4:
237 case bfd_mach_arm_4T:
238 ARMul_SelectProcessor (state, ARM_v4_Prop);
239 break;
240
241 case bfd_mach_arm_3:
242 case bfd_mach_arm_3M:
3943c96b
NC
243 ARMul_SelectProcessor (state, ARM_Lock_Prop);
244 break;
245
f1129fb8
NC
246 case bfd_mach_arm_2:
247 case bfd_mach_arm_2a:
3943c96b
NC
248 ARMul_SelectProcessor (state, ARM_Fix26_Prop);
249 break;
250 }
251
5f7d0a33
NC
252 if ( mach != bfd_mach_arm_3
253 && mach != bfd_mach_arm_3M
254 && mach != bfd_mach_arm_2
255 && mach != bfd_mach_arm_2a)
f1129fb8
NC
256 {
257 /* Reset mode to ARM. A gdb user may rerun a program that had entered
258 THUMB mode from the start and cause the ARM-mode startup code to be
5f7d0a33
NC
259 executed in THUMB mode. */
260 ARMul_SetCPSR (state, SVC32MODE);
f1129fb8
NC
261 }
262
c906108c
SS
263 if (argv != NULL)
264 {
5f7d0a33
NC
265 /* Set up the command line by laboriously stringing together
266 the environment carefully picked apart by our caller. */
267
268 /* Free any old stuff. */
c906108c
SS
269 if (state->CommandLine != NULL)
270 {
dfcd3bfb 271 free (state->CommandLine);
c906108c
SS
272 state->CommandLine = NULL;
273 }
dfcd3bfb 274
5f7d0a33 275 /* See how much we need. */
c906108c 276 for (arg = argv; *arg != NULL; arg++)
dfcd3bfb
JM
277 argvlen += strlen (*arg) + 1;
278
5f7d0a33 279 /* Allocate it. */
dfcd3bfb 280 state->CommandLine = malloc (argvlen + 1);
c906108c
SS
281 if (state->CommandLine != NULL)
282 {
283 arg = argv;
dfcd3bfb 284 state->CommandLine[0] = '\0';
5f7d0a33 285
c906108c
SS
286 for (arg = argv; *arg != NULL; arg++)
287 {
dfcd3bfb
JM
288 strcat (state->CommandLine, *arg);
289 strcat (state->CommandLine, " ");
c906108c
SS
290 }
291 }
292 }
293
294 if (env != NULL)
295 {
5f7d0a33 296 /* Now see if there's a MEMSIZE spec in the environment. */
c906108c
SS
297 while (*env)
298 {
dfcd3bfb 299 if (strncmp (*env, "MEMSIZE=", sizeof ("MEMSIZE=") - 1) == 0)
c906108c 300 {
c906108c 301 char *end_of_num;
dfcd3bfb 302
5f7d0a33 303 /* Set up memory limit. */
dfcd3bfb
JM
304 state->MemSize =
305 strtoul (*env + sizeof ("MEMSIZE=") - 1, &end_of_num, 0);
c906108c
SS
306 }
307 env++;
308 }
309 }
310
311 return SIM_RC_OK;
312}
313
314void
315sim_info (sd, verbose)
6d358e86
NC
316 SIM_DESC sd ATTRIBUTE_UNUSED;
317 int verbose ATTRIBUTE_UNUSED;
c906108c
SS
318{
319}
320
321
dfcd3bfb 322static int
c906108c
SS
323frommem (state, memory)
324 struct ARMul_State *state;
325 unsigned char *memory;
326{
327 if (state->bigendSig == HIGH)
328 {
329 return (memory[0] << 24)
dfcd3bfb 330 | (memory[1] << 16) | (memory[2] << 8) | (memory[3] << 0);
c906108c
SS
331 }
332 else
333 {
334 return (memory[3] << 24)
dfcd3bfb 335 | (memory[2] << 16) | (memory[1] << 8) | (memory[0] << 0);
c906108c
SS
336 }
337}
338
339
340static void
dfcd3bfb 341tomem (state, memory, val)
c906108c
SS
342 struct ARMul_State *state;
343 unsigned char *memory;
344 int val;
345{
346 if (state->bigendSig == HIGH)
347 {
348 memory[0] = val >> 24;
349 memory[1] = val >> 16;
350 memory[2] = val >> 8;
351 memory[3] = val >> 0;
352 }
353 else
354 {
355 memory[3] = val >> 24;
356 memory[2] = val >> 16;
357 memory[1] = val >> 8;
358 memory[0] = val >> 0;
359 }
360}
361
362int
363sim_store_register (sd, rn, memory, length)
6d358e86 364 SIM_DESC sd ATTRIBUTE_UNUSED;
c906108c
SS
365 int rn;
366 unsigned char *memory;
6d358e86 367 int length ATTRIBUTE_UNUSED;
c906108c
SS
368{
369 init ();
f1129fb8 370
3463c3fb
NC
371 if (rn == 25)
372 {
373 state->Cpsr = frommem (state, memory);
374 ARMul_CPSRAltered (state);
375 }
376 else
377 ARMul_SetReg (state, state->Mode, rn, frommem (state, memory));
c906108c
SS
378 return -1;
379}
380
381int
382sim_fetch_register (sd, rn, memory, length)
6d358e86 383 SIM_DESC sd ATTRIBUTE_UNUSED;
c906108c
SS
384 int rn;
385 unsigned char *memory;
6d358e86 386 int length ATTRIBUTE_UNUSED;
c906108c
SS
387{
388 ARMword regval;
389
390 init ();
f1129fb8 391
c906108c 392 if (rn < 16)
dfcd3bfb
JM
393 regval = ARMul_GetReg (state, state->Mode, rn);
394 else if (rn == 25) /* FIXME: use PS_REGNUM from gdb/config/arm/tm-arm.h */
395 regval = ARMul_GetCPSR (state);
c906108c 396 else
dfcd3bfb 397 regval = 0; /* FIXME: should report an error */
c906108c
SS
398 tomem (state, memory, regval);
399 return -1;
400}
401
402SIM_DESC
403sim_open (kind, ptr, abfd, argv)
404 SIM_OPEN_KIND kind;
405 host_callback *ptr;
406 struct _bfd *abfd;
407 char **argv;
408{
409 sim_kind = kind;
6c9e0292 410 if (myname) free (myname);
c1a72ffd 411 myname = (char *) xstrdup (argv[0]);
c906108c 412 sim_callback = ptr;
dfcd3bfb 413
c906108c
SS
414 /* Decide upon the endian-ness of the processor.
415 If we can, get the information from the bfd itself.
416 Otherwise look to see if we have been given a command
417 line switch that tells us. Otherwise default to little endian. */
418 if (abfd != NULL)
419 big_endian = bfd_big_endian (abfd);
420 else if (argv[1] != NULL)
421 {
422 int i;
dfcd3bfb 423
c906108c
SS
424 /* Scan for endian-ness switch. */
425 for (i = 0; (argv[i] != NULL) && (argv[i][0] != 0); i++)
dfcd3bfb
JM
426 if (argv[i][0] == '-' && argv[i][1] == 'E')
427 {
428 char c;
429
430 if ((c = argv[i][2]) == 0)
431 {
432 ++i;
433 c = argv[i][0];
434 }
435
436 switch (c)
437 {
438 case 0:
439 sim_callback->printf_filtered
440 (sim_callback, "No argument to -E option provided\n");
441 break;
442
443 case 'b':
444 case 'B':
445 big_endian = 1;
446 break;
447
448 case 'l':
449 case 'L':
450 big_endian = 0;
451 break;
452
453 default:
454 sim_callback->printf_filtered
455 (sim_callback, "Unrecognised argument to -E option\n");
456 break;
457 }
458 }
c906108c
SS
459 }
460
461 return (SIM_DESC) 1;
462}
463
464void
465sim_close (sd, quitting)
6d358e86
NC
466 SIM_DESC sd ATTRIBUTE_UNUSED;
467 int quitting ATTRIBUTE_UNUSED;
c906108c 468{
6c9e0292
FCE
469 if (myname) free (myname);
470 myname = NULL;
c906108c
SS
471}
472
473SIM_RC
474sim_load (sd, prog, abfd, from_tty)
475 SIM_DESC sd;
476 char *prog;
477 bfd *abfd;
6d358e86 478 int from_tty ATTRIBUTE_UNUSED;
c906108c 479{
dfcd3bfb 480 extern bfd *sim_load_file (); /* ??? Don't know where this should live. */
c906108c
SS
481 bfd *prog_bfd;
482
483 prog_bfd = sim_load_file (sd, myname, sim_callback, prog, abfd,
dfcd3bfb 484 sim_kind == SIM_OPEN_DEBUG, 0, sim_write);
c906108c
SS
485 if (prog_bfd == NULL)
486 return SIM_RC_FAIL;
487 ARMul_SetPC (state, bfd_get_start_address (prog_bfd));
488 if (abfd == NULL)
489 bfd_close (prog_bfd);
490 return SIM_RC_OK;
491}
492
493void
494sim_stop_reason (sd, reason, sigrc)
6d358e86 495 SIM_DESC sd ATTRIBUTE_UNUSED;
c906108c
SS
496 enum sim_stop *reason;
497 int *sigrc;
498{
7a292a7a
SS
499 if (stop_simulator)
500 {
501 *reason = sim_stopped;
502 *sigrc = SIGINT;
503 }
504 else if (state->EndCondition == 0)
c906108c
SS
505 {
506 *reason = sim_exited;
507 *sigrc = state->Reg[0] & 255;
508 }
509 else
510 {
511 *reason = sim_stopped;
512 if (state->EndCondition == RDIError_BreakpointReached)
513 *sigrc = SIGTRAP;
514 else
515 *sigrc = 0;
516 }
517}
518
519void
520sim_do_command (sd, cmd)
6d358e86
NC
521 SIM_DESC sd ATTRIBUTE_UNUSED;
522 char *cmd ATTRIBUTE_UNUSED;
dfcd3bfb
JM
523{
524 (*sim_callback->printf_filtered) (sim_callback,
525 "This simulator does not accept any commands.\n");
c906108c
SS
526}
527
528
529void
530sim_set_callbacks (ptr)
531 host_callback *ptr;
532{
533 sim_callback = ptr;
534}