3 Copyright (C) 2005-2021 Free Software Foundation, Inc.
4 Contributed by Mike Frysinger.
6 This file is part of simulators.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 /* This must come before any other includes. */
25 #include "sim-options.h"
28 sim_engine_run (SIM_DESC sd
,
29 int next_cpu_nr
, /* ignore */
30 int nr_cpus
, /* ignore */
31 int siggnal
) /* ignore */
35 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
37 cpu
= STATE_CPU (sd
, 0);
42 if (sim_events_tick (sd
))
43 sim_events_process (sd
);
48 free_state (SIM_DESC sd
)
50 if (STATE_MODULES (sd
) != NULL
)
51 sim_module_uninstall (sd
);
52 sim_cpu_free_all (sd
);
56 extern const SIM_MACH
* const riscv_sim_machs
[];
59 sim_open (SIM_OPEN_KIND kind
, host_callback
*callback
,
60 struct bfd
*abfd
, char * const *argv
)
64 SIM_DESC sd
= sim_state_alloc_extra (kind
, callback
,
65 sizeof (struct riscv_sim_state
));
67 /* Set default options before parsing user options. */
68 STATE_MACHS (sd
) = riscv_sim_machs
;
69 STATE_MODEL_NAME (sd
) = WITH_TARGET_WORD_BITSIZE
== 32 ? "RV32G" : "RV64G";
70 current_target_byte_order
= BFD_ENDIAN_LITTLE
;
72 /* The cpu data is kept in a separately allocated chunk of memory. */
73 if (sim_cpu_alloc_all (sd
, 1) != SIM_RC_OK
)
79 if (sim_pre_argv_init (sd
, argv
[0]) != SIM_RC_OK
)
85 /* XXX: Default to the Virtual environment. */
86 if (STATE_ENVIRONMENT (sd
) == ALL_ENVIRONMENT
)
87 STATE_ENVIRONMENT (sd
) = VIRTUAL_ENVIRONMENT
;
89 /* The parser will print an error message for us, so we silently return. */
90 if (sim_parse_args (sd
, argv
) != SIM_RC_OK
)
96 /* Check for/establish the a reference program image. */
97 if (sim_analyze_program (sd
,
98 (STATE_PROG_ARGV (sd
) != NULL
99 ? *STATE_PROG_ARGV (sd
)
100 : NULL
), abfd
) != SIM_RC_OK
)
106 /* Establish any remaining configuration options. */
107 if (sim_config (sd
) != SIM_RC_OK
)
113 if (sim_post_argv_init (sd
) != SIM_RC_OK
)
119 /* CPU specific initialization. */
120 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
122 SIM_CPU
*cpu
= STATE_CPU (sd
, i
);
124 initialize_cpu (sd
, cpu
, i
);
127 /* Allocate external memory if none specified by user.
128 Use address 4 here in case the user wanted address 0 unmapped. */
129 if (sim_core_read_buffer (sd
, NULL
, read_map
, &c
, 4, 1) == 0)
130 sim_do_commandf (sd
, "memory-size %#x", DEFAULT_MEM_SIZE
);
136 sim_create_inferior (SIM_DESC sd
, struct bfd
*abfd
,
137 char * const *argv
, char * const *env
)
139 SIM_CPU
*cpu
= STATE_CPU (sd
, 0);
144 addr
= bfd_get_start_address (abfd
);
147 sim_pc_set (cpu
, addr
);
149 /* Standalone mode (i.e. `run`) will take care of the argv for us in
150 sim_open() -> sim_parse_args(). But in debug mode (i.e. 'target sim'
151 with `gdb`), we need to handle it because the user can change the
152 argv on the fly via gdb's 'run'. */
153 if (STATE_PROG_ARGV (sd
) != argv
)
155 freeargv (STATE_PROG_ARGV (sd
));
156 STATE_PROG_ARGV (sd
) = dupargv (argv
);
159 initialize_env (sd
, (void *)argv
, (void *)env
);