/* Simulator for Atmel's AVR core.
- Copyright (C) 2009-2015 Free Software Foundation, Inc.
+ Copyright (C) 2009-2021 Free Software Foundation, Inc.
Written by Tristan Gingold, AdaCore.
This file is part of GDB, the GNU debugger.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
-#include "config.h"
+/* This must come before any other includes. */
+#include "defs.h"
-#ifdef HAVE_STRING_H
#include <string.h>
-#endif
+
#include "bfd.h"
#include "libiberty.h"
-#include "gdb/remote-sim.h"
+#include "sim/sim.h"
#include "sim-main.h"
#include "sim-base.h"
static void
do_call (SIM_CPU *cpu, unsigned int npc)
{
- SIM_DESC sd = CPU_STATE (cpu);
+ const struct avr_sim_state *state = AVR_SIM_STATE (CPU_STATE (cpu));
unsigned int sp = read_word (REG_SP);
/* Big endian! */
sram[sp--] = cpu->pc;
sram[sp--] = cpu->pc >> 8;
- if (sd->avr_pc22)
+ if (state->avr_pc22)
{
sram[sp--] = cpu->pc >> 16;
cpu->cycles++;
/* Fall through */
case OP_ret:
{
- SIM_DESC sd = CPU_STATE (cpu);
+ const struct avr_sim_state *state = AVR_SIM_STATE (CPU_STATE (cpu));
unsigned int sp = read_word (REG_SP);
- if (sd->avr_pc22)
+ if (state->avr_pc22)
{
cpu->pc = sram[++sp] << 16;
cpu->cycles++;
case OP_break:
/* Stop on this address. */
- sim_engine_halt (CPU_STATE (cpu), cpu, NULL, cpu->pc, sim_stopped, SIM_SIGTRAP);
- cpu->pc = ipc;
+ sim_engine_halt (CPU_STATE (cpu), cpu, NULL, ipc, sim_stopped, SIM_SIGTRAP);
break;
case OP_bld:
}
SIM_DESC
-sim_open (SIM_OPEN_KIND kind, host_callback *cb, struct bfd *abfd, char **argv)
+sim_open (SIM_OPEN_KIND kind, host_callback *cb,
+ struct bfd *abfd, char * const *argv)
{
int i;
- SIM_DESC sd = sim_state_alloc (kind, cb);
+ SIM_DESC sd = sim_state_alloc_extra (kind, cb, sizeof (struct avr_sim_state));
SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
+ /* Set default options before parsing user options. */
+ current_alignment = STRICT_ALIGNMENT;
+
/* The cpu data is kept in a separately allocated chunk of memory. */
- if (sim_cpu_alloc_all (sd, 1, /*cgen_cpu_max_extra_bytes ()*/0) != SIM_RC_OK)
+ if (sim_cpu_alloc_all (sd, 1) != SIM_RC_OK)
{
free_state (sd);
return 0;
}
- {
- /* XXX: Only first core gets profiled ? */
- SIM_CPU *cpu = STATE_CPU (sd, 0);
- STATE_WATCHPOINTS (sd)->pc = &cpu->pc;
- STATE_WATCHPOINTS (sd)->sizeof_pc = sizeof (cpu->pc);
- }
-
if (sim_pre_argv_init (sd, argv[0]) != SIM_RC_OK)
{
free_state (sd);
return 0;
}
- /* getopt will print the error message so we just have to exit if this fails.
- FIXME: Hmmm... in the case of gdb we need getopt to call
- print_filtered. */
+ /* The parser will print an error message for us, so we silently return. */
if (sim_parse_args (sd, argv) != SIM_RC_OK)
{
free_state (sd);
}
SIM_RC
-sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char **argv, char **env)
+sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
+ char * const *argv, char * const *env)
{
+ struct avr_sim_state *state = AVR_SIM_STATE (sd);
SIM_CPU *cpu = STATE_CPU (sd, 0);
SIM_ADDR addr;
sim_pc_set (cpu, addr);
if (abfd != NULL)
- sd->avr_pc22 = (bfd_get_mach (abfd) >= bfd_mach_avr6);
+ state->avr_pc22 = (bfd_get_mach (abfd) >= bfd_mach_avr6);
return SIM_RC_OK;
}