1 /* run front end support for arm
2 Copyright (C) 1995-2023 Free Software Foundation, Inc.
4 This file is part of ARM SIM.
6 This program 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 3 of the License, or
9 (at your option) any later version.
11 This program 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, see <http://www.gnu.org/licenses/>. */
19 /* This file provides the interface between the simulator and
20 run.c and gdb (when the simulator is linked with gdb).
21 All simulator interaction should go through this file. */
23 /* This must come before any other includes. */
32 #include "sim/callback.h"
35 #include "sim-options.h"
39 #include "sim/sim-arm.h"
40 #include "gdb/signals.h"
41 #include "libiberty.h"
46 /* TODO: This should get pulled from the SIM_DESC. */
47 host_callback
*sim_callback
;
49 /* TODO: This should get merged into sim_cpu. */
50 struct ARMul_State
*state
;
52 /* Memory size in bytes. */
53 /* TODO: Memory should be converted to the common memory module. */
54 static int mem_size
= (1 << 21);
60 /* TODO: Tracing should be converted to common tracing module. */
65 static struct disassemble_info info
;
66 static char opbuf
[1000];
68 static int ATTRIBUTE_PRINTF (2, 3)
69 op_printf (char *buf
, const char *fmt
, ...)
75 ret
= vsprintf (opbuf
+ strlen (opbuf
), fmt
, ap
);
80 static int ATTRIBUTE_PRINTF (3, 4)
81 op_styled_printf (char *buf
, enum disassembler_style style
,
88 ret
= vsprintf (opbuf
+ strlen (opbuf
), fmt
, ap
);
94 sim_dis_read (bfd_vma memaddr ATTRIBUTE_UNUSED
,
97 struct disassemble_info
* info
)
99 ARMword val
= (ARMword
) *((ARMword
*) info
->application_data
);
103 * ptr
++ = val
& 0xFF;
110 print_insn (ARMword instr
)
113 disassembler_ftype disassemble_fn
;
116 info
.application_data
= & instr
;
117 disassemble_fn
= disassembler (bfd_arch_arm
, 0, 0, NULL
);
118 size
= disassemble_fn (0, & info
);
119 fprintf (stderr
, " %*s\n", size
, opbuf
);
129 ARMul_EmulateInit ();
130 state
= ARMul_NewState ();
131 state
->bigendSig
= (CURRENT_TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
? HIGH
: LOW
);
132 ARMul_MemoryInit (state
, mem_size
);
133 ARMul_OSInit (state
);
140 ARMul_ConsolePrint (ARMul_State
* state
,
148 va_start (ap
, format
);
149 vprintf (format
, ap
);
155 sim_write (SIM_DESC sd ATTRIBUTE_UNUSED
,
161 const unsigned char * data
= buffer
;
165 for (i
= 0; i
< size
; i
++)
166 ARMul_SafeWriteByte (state
, addr
+ i
, data
[i
]);
172 sim_read (SIM_DESC sd ATTRIBUTE_UNUSED
,
178 unsigned char * data
= buffer
;
182 for (i
= 0; i
< size
; i
++)
183 data
[i
] = ARMul_SafeReadByte (state
, addr
+ i
);
189 sim_stop (SIM_DESC sd ATTRIBUTE_UNUSED
)
191 state
->Emulate
= STOP
;
197 sim_resume (SIM_DESC sd ATTRIBUTE_UNUSED
,
199 int siggnal ATTRIBUTE_UNUSED
)
201 state
->EndCondition
= 0;
206 state
->Reg
[15] = ARMul_DoInstr (state
);
207 if (state
->EndCondition
== 0)
208 state
->EndCondition
= RDIError_BreakpointReached
;
212 state
->NextInstr
= RESUME
; /* treat as PC change */
213 state
->Reg
[15] = ARMul_DoProg (state
);
220 sim_create_inferior (SIM_DESC sd ATTRIBUTE_UNUSED
,
233 ARMul_SetPC (state
, bfd_get_start_address (abfd
));
234 mach
= bfd_get_mach (abfd
);
238 ARMul_SetPC (state
, 0); /* ??? */
243 if (abfd
!= NULL
&& (bfd_get_start_address (abfd
) & 1))
250 (*sim_callback
->printf_filtered
)
252 "Unknown machine type '%d'; please update sim_create_inferior.\n",
257 /* We wouldn't set the machine type with earlier toolchains, so we
258 explicitly select a processor capable of supporting all ARMs in
260 ARMul_SelectProcessor (state
, ARM_v5_Prop
| ARM_v5e_Prop
| ARM_v6_Prop
);
264 case bfd_mach_arm_6T2
:
266 case bfd_mach_arm_7EM
:
267 ARMul_SelectProcessor (state
, ARM_v5_Prop
| ARM_v5e_Prop
| ARM_v6_Prop
);
271 case bfd_mach_arm_XScale
:
272 ARMul_SelectProcessor (state
, ARM_v5_Prop
| ARM_v5e_Prop
| ARM_XScale_Prop
| ARM_v6_Prop
);
275 case bfd_mach_arm_iWMMXt2
:
276 case bfd_mach_arm_iWMMXt
:
278 extern int SWI_vector_installed
;
281 if (! SWI_vector_installed
)
283 /* Intialise the hardware vectors to zero. */
284 if (! SWI_vector_installed
)
285 for (i
= ARMul_ResetV
; i
<= ARMFIQV
; i
+= 4)
286 ARMul_WriteWord (state
, i
, 0);
288 /* ARM_WriteWord will have detected the write to the SWI vector,
289 but we want SWI_vector_installed to remain at 0 so that thumb
290 mode breakpoints will work. */
291 SWI_vector_installed
= 0;
294 ARMul_SelectProcessor (state
, ARM_v5_Prop
| ARM_v5e_Prop
| ARM_XScale_Prop
| ARM_iWMMXt_Prop
);
297 case bfd_mach_arm_ep9312
:
298 ARMul_SelectProcessor (state
, ARM_v4_Prop
| ARM_ep9312_Prop
);
302 if (bfd_family_coff (abfd
))
304 /* This is a special case in order to support COFF based ARM toolchains.
305 The COFF header does not have enough room to store all the different
306 kinds of ARM cpu, so the XScale, v5T and v5TE architectures all default
307 to v5. (See coff_set_flags() in bdf/coffcode.h). So if we see a v5
308 machine type here, we assume it could be any of the above architectures
309 and so select the most feature-full. */
310 ARMul_SelectProcessor (state
, ARM_v5_Prop
| ARM_v5e_Prop
| ARM_XScale_Prop
);
313 /* Otherwise drop through. */
315 case bfd_mach_arm_5T
:
316 ARMul_SelectProcessor (state
, ARM_v5_Prop
);
319 case bfd_mach_arm_5TE
:
320 ARMul_SelectProcessor (state
, ARM_v5_Prop
| ARM_v5e_Prop
);
324 case bfd_mach_arm_4T
:
325 ARMul_SelectProcessor (state
, ARM_v4_Prop
);
329 case bfd_mach_arm_3M
:
330 ARMul_SelectProcessor (state
, ARM_Lock_Prop
);
334 case bfd_mach_arm_2a
:
335 ARMul_SelectProcessor (state
, ARM_Fix26_Prop
);
339 memset (& info
, 0, sizeof (info
));
340 INIT_DISASSEMBLE_INFO (info
, stdout
, op_printf
, op_styled_printf
);
341 info
.read_memory_func
= sim_dis_read
;
342 info
.arch
= bfd_get_arch (abfd
);
343 info
.mach
= bfd_get_mach (abfd
);
344 info
.endian_code
= BFD_ENDIAN_LITTLE
;
346 info
.arch
= bfd_arch_arm
;
347 disassemble_init_for_target (& info
);
351 /* Set up the command line by laboriously stringing together
352 the environment carefully picked apart by our caller. */
354 /* Free any old stuff. */
355 if (state
->CommandLine
!= NULL
)
357 free (state
->CommandLine
);
358 state
->CommandLine
= NULL
;
361 /* See how much we need. */
362 for (arg
= argv
; *arg
!= NULL
; arg
++)
363 argvlen
+= strlen (*arg
) + 1;
366 state
->CommandLine
= malloc (argvlen
+ 1);
367 if (state
->CommandLine
!= NULL
)
370 state
->CommandLine
[0] = '\0';
372 for (arg
= argv
; *arg
!= NULL
; arg
++)
374 strcat (state
->CommandLine
, *arg
);
375 strcat (state
->CommandLine
, " ");
382 /* Now see if there's a MEMSIZE spec in the environment. */
385 if (strncmp (*env
, "MEMSIZE=", sizeof ("MEMSIZE=") - 1) == 0)
389 /* Set up memory limit. */
391 strtoul (*env
+ sizeof ("MEMSIZE=") - 1, &end_of_num
, 0);
401 frommem (struct ARMul_State
*state
, const unsigned char *memory
)
403 if (state
->bigendSig
== HIGH
)
404 return (memory
[0] << 24) | (memory
[1] << 16)
405 | (memory
[2] << 8) | (memory
[3] << 0);
407 return (memory
[3] << 24) | (memory
[2] << 16)
408 | (memory
[1] << 8) | (memory
[0] << 0);
412 tomem (struct ARMul_State
*state
,
413 unsigned char *memory
,
416 if (state
->bigendSig
== HIGH
)
418 memory
[0] = val
>> 24;
419 memory
[1] = val
>> 16;
420 memory
[2] = val
>> 8;
421 memory
[3] = val
>> 0;
425 memory
[3] = val
>> 24;
426 memory
[2] = val
>> 16;
427 memory
[1] = val
>> 8;
428 memory
[0] = val
>> 0;
433 arm_reg_store (SIM_CPU
*cpu
, int rn
, const void *buf
, int length
)
437 switch ((enum sim_arm_regs
) rn
)
439 case SIM_ARM_R0_REGNUM
:
440 case SIM_ARM_R1_REGNUM
:
441 case SIM_ARM_R2_REGNUM
:
442 case SIM_ARM_R3_REGNUM
:
443 case SIM_ARM_R4_REGNUM
:
444 case SIM_ARM_R5_REGNUM
:
445 case SIM_ARM_R6_REGNUM
:
446 case SIM_ARM_R7_REGNUM
:
447 case SIM_ARM_R8_REGNUM
:
448 case SIM_ARM_R9_REGNUM
:
449 case SIM_ARM_R10_REGNUM
:
450 case SIM_ARM_R11_REGNUM
:
451 case SIM_ARM_R12_REGNUM
:
452 case SIM_ARM_R13_REGNUM
:
453 case SIM_ARM_R14_REGNUM
:
454 case SIM_ARM_R15_REGNUM
: /* PC */
455 case SIM_ARM_FP0_REGNUM
:
456 case SIM_ARM_FP1_REGNUM
:
457 case SIM_ARM_FP2_REGNUM
:
458 case SIM_ARM_FP3_REGNUM
:
459 case SIM_ARM_FP4_REGNUM
:
460 case SIM_ARM_FP5_REGNUM
:
461 case SIM_ARM_FP6_REGNUM
:
462 case SIM_ARM_FP7_REGNUM
:
463 case SIM_ARM_FPS_REGNUM
:
464 ARMul_SetReg (state
, state
->Mode
, rn
, frommem (state
, buf
));
467 case SIM_ARM_PS_REGNUM
:
468 state
->Cpsr
= frommem (state
, buf
);
469 ARMul_CPSRAltered (state
);
472 case SIM_ARM_MAVERIC_COP0R0_REGNUM
:
473 case SIM_ARM_MAVERIC_COP0R1_REGNUM
:
474 case SIM_ARM_MAVERIC_COP0R2_REGNUM
:
475 case SIM_ARM_MAVERIC_COP0R3_REGNUM
:
476 case SIM_ARM_MAVERIC_COP0R4_REGNUM
:
477 case SIM_ARM_MAVERIC_COP0R5_REGNUM
:
478 case SIM_ARM_MAVERIC_COP0R6_REGNUM
:
479 case SIM_ARM_MAVERIC_COP0R7_REGNUM
:
480 case SIM_ARM_MAVERIC_COP0R8_REGNUM
:
481 case SIM_ARM_MAVERIC_COP0R9_REGNUM
:
482 case SIM_ARM_MAVERIC_COP0R10_REGNUM
:
483 case SIM_ARM_MAVERIC_COP0R11_REGNUM
:
484 case SIM_ARM_MAVERIC_COP0R12_REGNUM
:
485 case SIM_ARM_MAVERIC_COP0R13_REGNUM
:
486 case SIM_ARM_MAVERIC_COP0R14_REGNUM
:
487 case SIM_ARM_MAVERIC_COP0R15_REGNUM
:
488 memcpy (& DSPregs
[rn
- SIM_ARM_MAVERIC_COP0R0_REGNUM
],
489 buf
, sizeof (struct maverick_regs
));
490 return sizeof (struct maverick_regs
);
492 case SIM_ARM_MAVERIC_DSPSC_REGNUM
:
493 memcpy (&DSPsc
, buf
, sizeof DSPsc
);
496 case SIM_ARM_IWMMXT_COP0R0_REGNUM
:
497 case SIM_ARM_IWMMXT_COP0R1_REGNUM
:
498 case SIM_ARM_IWMMXT_COP0R2_REGNUM
:
499 case SIM_ARM_IWMMXT_COP0R3_REGNUM
:
500 case SIM_ARM_IWMMXT_COP0R4_REGNUM
:
501 case SIM_ARM_IWMMXT_COP0R5_REGNUM
:
502 case SIM_ARM_IWMMXT_COP0R6_REGNUM
:
503 case SIM_ARM_IWMMXT_COP0R7_REGNUM
:
504 case SIM_ARM_IWMMXT_COP0R8_REGNUM
:
505 case SIM_ARM_IWMMXT_COP0R9_REGNUM
:
506 case SIM_ARM_IWMMXT_COP0R10_REGNUM
:
507 case SIM_ARM_IWMMXT_COP0R11_REGNUM
:
508 case SIM_ARM_IWMMXT_COP0R12_REGNUM
:
509 case SIM_ARM_IWMMXT_COP0R13_REGNUM
:
510 case SIM_ARM_IWMMXT_COP0R14_REGNUM
:
511 case SIM_ARM_IWMMXT_COP0R15_REGNUM
:
512 case SIM_ARM_IWMMXT_COP1R0_REGNUM
:
513 case SIM_ARM_IWMMXT_COP1R1_REGNUM
:
514 case SIM_ARM_IWMMXT_COP1R2_REGNUM
:
515 case SIM_ARM_IWMMXT_COP1R3_REGNUM
:
516 case SIM_ARM_IWMMXT_COP1R4_REGNUM
:
517 case SIM_ARM_IWMMXT_COP1R5_REGNUM
:
518 case SIM_ARM_IWMMXT_COP1R6_REGNUM
:
519 case SIM_ARM_IWMMXT_COP1R7_REGNUM
:
520 case SIM_ARM_IWMMXT_COP1R8_REGNUM
:
521 case SIM_ARM_IWMMXT_COP1R9_REGNUM
:
522 case SIM_ARM_IWMMXT_COP1R10_REGNUM
:
523 case SIM_ARM_IWMMXT_COP1R11_REGNUM
:
524 case SIM_ARM_IWMMXT_COP1R12_REGNUM
:
525 case SIM_ARM_IWMMXT_COP1R13_REGNUM
:
526 case SIM_ARM_IWMMXT_COP1R14_REGNUM
:
527 case SIM_ARM_IWMMXT_COP1R15_REGNUM
:
528 return Store_Iwmmxt_Register (rn
- SIM_ARM_IWMMXT_COP0R0_REGNUM
, buf
);
538 arm_reg_fetch (SIM_CPU
*cpu
, int rn
, void *buf
, int length
)
540 unsigned char *memory
= buf
;
546 switch ((enum sim_arm_regs
) rn
)
548 case SIM_ARM_R0_REGNUM
:
549 case SIM_ARM_R1_REGNUM
:
550 case SIM_ARM_R2_REGNUM
:
551 case SIM_ARM_R3_REGNUM
:
552 case SIM_ARM_R4_REGNUM
:
553 case SIM_ARM_R5_REGNUM
:
554 case SIM_ARM_R6_REGNUM
:
555 case SIM_ARM_R7_REGNUM
:
556 case SIM_ARM_R8_REGNUM
:
557 case SIM_ARM_R9_REGNUM
:
558 case SIM_ARM_R10_REGNUM
:
559 case SIM_ARM_R11_REGNUM
:
560 case SIM_ARM_R12_REGNUM
:
561 case SIM_ARM_R13_REGNUM
:
562 case SIM_ARM_R14_REGNUM
:
563 case SIM_ARM_R15_REGNUM
: /* PC */
564 regval
= ARMul_GetReg (state
, state
->Mode
, rn
);
567 case SIM_ARM_FP0_REGNUM
:
568 case SIM_ARM_FP1_REGNUM
:
569 case SIM_ARM_FP2_REGNUM
:
570 case SIM_ARM_FP3_REGNUM
:
571 case SIM_ARM_FP4_REGNUM
:
572 case SIM_ARM_FP5_REGNUM
:
573 case SIM_ARM_FP6_REGNUM
:
574 case SIM_ARM_FP7_REGNUM
:
575 case SIM_ARM_FPS_REGNUM
:
576 memset (memory
, 0, length
);
579 case SIM_ARM_PS_REGNUM
:
580 regval
= ARMul_GetCPSR (state
);
583 case SIM_ARM_MAVERIC_COP0R0_REGNUM
:
584 case SIM_ARM_MAVERIC_COP0R1_REGNUM
:
585 case SIM_ARM_MAVERIC_COP0R2_REGNUM
:
586 case SIM_ARM_MAVERIC_COP0R3_REGNUM
:
587 case SIM_ARM_MAVERIC_COP0R4_REGNUM
:
588 case SIM_ARM_MAVERIC_COP0R5_REGNUM
:
589 case SIM_ARM_MAVERIC_COP0R6_REGNUM
:
590 case SIM_ARM_MAVERIC_COP0R7_REGNUM
:
591 case SIM_ARM_MAVERIC_COP0R8_REGNUM
:
592 case SIM_ARM_MAVERIC_COP0R9_REGNUM
:
593 case SIM_ARM_MAVERIC_COP0R10_REGNUM
:
594 case SIM_ARM_MAVERIC_COP0R11_REGNUM
:
595 case SIM_ARM_MAVERIC_COP0R12_REGNUM
:
596 case SIM_ARM_MAVERIC_COP0R13_REGNUM
:
597 case SIM_ARM_MAVERIC_COP0R14_REGNUM
:
598 case SIM_ARM_MAVERIC_COP0R15_REGNUM
:
599 memcpy (memory
, & DSPregs
[rn
- SIM_ARM_MAVERIC_COP0R0_REGNUM
],
600 sizeof (struct maverick_regs
));
601 return sizeof (struct maverick_regs
);
603 case SIM_ARM_MAVERIC_DSPSC_REGNUM
:
604 memcpy (memory
, & DSPsc
, sizeof DSPsc
);
607 case SIM_ARM_IWMMXT_COP0R0_REGNUM
:
608 case SIM_ARM_IWMMXT_COP0R1_REGNUM
:
609 case SIM_ARM_IWMMXT_COP0R2_REGNUM
:
610 case SIM_ARM_IWMMXT_COP0R3_REGNUM
:
611 case SIM_ARM_IWMMXT_COP0R4_REGNUM
:
612 case SIM_ARM_IWMMXT_COP0R5_REGNUM
:
613 case SIM_ARM_IWMMXT_COP0R6_REGNUM
:
614 case SIM_ARM_IWMMXT_COP0R7_REGNUM
:
615 case SIM_ARM_IWMMXT_COP0R8_REGNUM
:
616 case SIM_ARM_IWMMXT_COP0R9_REGNUM
:
617 case SIM_ARM_IWMMXT_COP0R10_REGNUM
:
618 case SIM_ARM_IWMMXT_COP0R11_REGNUM
:
619 case SIM_ARM_IWMMXT_COP0R12_REGNUM
:
620 case SIM_ARM_IWMMXT_COP0R13_REGNUM
:
621 case SIM_ARM_IWMMXT_COP0R14_REGNUM
:
622 case SIM_ARM_IWMMXT_COP0R15_REGNUM
:
623 case SIM_ARM_IWMMXT_COP1R0_REGNUM
:
624 case SIM_ARM_IWMMXT_COP1R1_REGNUM
:
625 case SIM_ARM_IWMMXT_COP1R2_REGNUM
:
626 case SIM_ARM_IWMMXT_COP1R3_REGNUM
:
627 case SIM_ARM_IWMMXT_COP1R4_REGNUM
:
628 case SIM_ARM_IWMMXT_COP1R5_REGNUM
:
629 case SIM_ARM_IWMMXT_COP1R6_REGNUM
:
630 case SIM_ARM_IWMMXT_COP1R7_REGNUM
:
631 case SIM_ARM_IWMMXT_COP1R8_REGNUM
:
632 case SIM_ARM_IWMMXT_COP1R9_REGNUM
:
633 case SIM_ARM_IWMMXT_COP1R10_REGNUM
:
634 case SIM_ARM_IWMMXT_COP1R11_REGNUM
:
635 case SIM_ARM_IWMMXT_COP1R12_REGNUM
:
636 case SIM_ARM_IWMMXT_COP1R13_REGNUM
:
637 case SIM_ARM_IWMMXT_COP1R14_REGNUM
:
638 case SIM_ARM_IWMMXT_COP1R15_REGNUM
:
639 return Fetch_Iwmmxt_Register (rn
- SIM_ARM_IWMMXT_COP0R0_REGNUM
, memory
);
647 tomem (state
, memory
, regval
);
660 unsigned int swi_mask
;
663 #define SWI_SWITCH "--swi-support"
665 static swi_options options
[] =
668 { "demon", SWI_MASK_DEMON
},
669 { "angel", SWI_MASK_ANGEL
},
670 { "redboot", SWI_MASK_REDBOOT
},
673 { "DEMON", SWI_MASK_DEMON
},
674 { "ANGEL", SWI_MASK_ANGEL
},
675 { "REDBOOT", SWI_MASK_REDBOOT
},
681 sim_target_parse_command_line (int argc
, char ** argv
)
685 for (i
= 1; i
< argc
; i
++)
687 char * ptr
= argv
[i
];
690 if ((ptr
== NULL
) || (* ptr
!= '-'))
693 if (strcmp (ptr
, "-t") == 0)
699 if (strcmp (ptr
, "-z") == 0)
701 /* Remove this option from the argv array. */
702 for (arg
= i
; arg
< argc
; arg
++)
705 argv
[arg
] = argv
[arg
+ 1];
713 if (strcmp (ptr
, "-d") == 0)
715 /* Remove this option from the argv array. */
716 for (arg
= i
; arg
< argc
; arg
++)
719 argv
[arg
] = argv
[arg
+ 1];
727 if (strncmp (ptr
, SWI_SWITCH
, sizeof SWI_SWITCH
- 1) != 0)
730 if (ptr
[sizeof SWI_SWITCH
- 1] == 0)
732 /* Remove this option from the argv array. */
733 for (arg
= i
; arg
< argc
; arg
++)
736 argv
[arg
] = argv
[arg
+ 1];
743 ptr
+= sizeof SWI_SWITCH
;
751 for (i
= ARRAY_SIZE (options
); i
--;)
752 if (strncmp (ptr
, options
[i
].swi_option
,
753 strlen (options
[i
].swi_option
)) == 0)
755 swi_mask
|= options
[i
].swi_mask
;
756 ptr
+= strlen (options
[i
].swi_option
);
769 fprintf (stderr
, "Ignoring swi options: %s\n", ptr
);
771 /* Remove this option from the argv array. */
772 for (arg
= i
; arg
< argc
; arg
++)
775 argv
[arg
] = argv
[arg
+ 1];
784 sim_target_parse_arg_array (char ** argv
)
786 sim_target_parse_command_line (countargv (argv
), argv
);
790 arm_pc_get (sim_cpu
*cpu
)
796 arm_pc_set (sim_cpu
*cpu
, sim_cia pc
)
798 ARMul_SetPC (state
, pc
);
802 free_state (SIM_DESC sd
)
804 if (STATE_MODULES (sd
) != NULL
)
805 sim_module_uninstall (sd
);
806 sim_cpu_free_all (sd
);
811 sim_open (SIM_OPEN_KIND kind
,
818 SIM_DESC sd
= sim_state_alloc (kind
, cb
);
819 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
821 /* Set default options before parsing user options. */
822 current_alignment
= STRICT_ALIGNMENT
;
824 /* The cpu data is kept in a separately allocated chunk of memory. */
825 if (sim_cpu_alloc_all (sd
, 0) != SIM_RC_OK
)
831 if (sim_pre_argv_init (sd
, argv
[0]) != SIM_RC_OK
)
837 /* The parser will print an error message for us, so we silently return. */
838 if (sim_parse_args (sd
, argv
) != SIM_RC_OK
)
844 /* Check for/establish the a reference program image. */
845 if (sim_analyze_program (sd
, STATE_PROG_FILE (sd
), abfd
) != SIM_RC_OK
)
851 /* Configure/verify the target byte order and other runtime
852 configuration options. */
853 if (sim_config (sd
) != SIM_RC_OK
)
855 sim_module_uninstall (sd
);
859 if (sim_post_argv_init (sd
) != SIM_RC_OK
)
861 /* Uninstall the modules to avoid memory leaks,
862 file descriptor leaks, etc. */
863 sim_module_uninstall (sd
);
867 /* CPU specific initialization. */
868 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
870 SIM_CPU
*cpu
= STATE_CPU (sd
, i
);
872 CPU_REG_FETCH (cpu
) = arm_reg_fetch
;
873 CPU_REG_STORE (cpu
) = arm_reg_store
;
874 CPU_PC_FETCH (cpu
) = arm_pc_get
;
875 CPU_PC_STORE (cpu
) = arm_pc_set
;
880 /* Copy over the argv contents so we can modify them. */
881 argv_copy
= dupargv (argv
);
883 sim_target_parse_arg_array (argv_copy
);
885 if (argv_copy
[1] != NULL
)
889 /* Scan for memory-size switches. */
890 for (i
= 0; (argv_copy
[i
] != NULL
) && (argv_copy
[i
][0] != 0); i
++)
891 if (argv_copy
[i
][0] == '-' && argv_copy
[i
][1] == 'm')
893 if (argv_copy
[i
][2] != '\0')
894 mem_size
= atoi (&argv_copy
[i
][2]);
895 else if (argv_copy
[i
+ 1] != NULL
)
897 mem_size
= atoi (argv_copy
[i
+ 1]);
902 sim_callback
->printf_filtered (sim_callback
,
903 "Missing argument to -m option\n");
909 freeargv (argv_copy
);
915 sim_stop_reason (SIM_DESC sd ATTRIBUTE_UNUSED
,
916 enum sim_stop
*reason
,
921 *reason
= sim_stopped
;
922 *sigrc
= GDB_SIGNAL_INT
;
924 else if (state
->EndCondition
== 0)
926 *reason
= sim_exited
;
927 *sigrc
= state
->Reg
[0] & 255;
931 *reason
= sim_stopped
;
932 if (state
->EndCondition
== RDIError_BreakpointReached
)
933 *sigrc
= GDB_SIGNAL_TRAP
;
934 else if ( state
->EndCondition
== RDIError_DataAbort
935 || state
->EndCondition
== RDIError_AddressException
)
936 *sigrc
= GDB_SIGNAL_BUS
;