sim: avr: invert sim_state storage

This commit is contained in:
Mike Frysinger
2016-01-21 22:34:05 -05:00
parent e106fc358c
commit 937af0fde5
3 changed files with 23 additions and 11 deletions

View File

@@ -1,3 +1,14 @@
2021-05-17 Mike Frysinger <vapier@gentoo.org>
* interp.c (do_call): Change sd to avr_sim_state.
(step_once): Likewise.
(sim_open): Likewise.
(sim_create_inferior): Likewise.
* sim-main.h (SIM_HAVE_COMMON_SIM_STATE): Define.
(struct sim_state): Delete.
(struct avr_sim_state): New struct.
(AVR_SIM_STATE): Define.
2021-05-16 Mike Frysinger <vapier@gentoo.org>
* interp.c: Replace config.h include with defs.h.

View File

@@ -727,13 +727,13 @@ decode (unsigned int pc)
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++;
@@ -893,9 +893,9 @@ step_once (SIM_CPU *cpu)
/* 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++;
@@ -1681,7 +1681,7 @@ 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);
/* The cpu data is kept in a separately allocated chunk of memory. */
@@ -1752,6 +1752,7 @@ SIM_RC
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;
@@ -1763,7 +1764,7 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
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;
}

View File

@@ -19,6 +19,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifndef SIM_MAIN_H
#define SIM_MAIN_H
#define SIM_HAVE_COMMON_SIM_STATE
#include "sim-basics.h"
#include "sim-base.h"
@@ -33,13 +35,11 @@ struct _sim_cpu {
sim_cpu_base base;
};
struct sim_state {
sim_cpu *cpu[MAX_NR_PROCESSORS];
struct avr_sim_state {
/* If true, the pc needs more than 2 bytes. */
int avr_pc22;
sim_state_base base;
};
#define AVR_SIM_STATE(sd) ((struct avr_sim_state *) STATE_ARCH_DATA (sd))
#endif