From 2ad10cb22246b16fdebece06646db288dbea1fdb Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 21 Jan 2016 22:46:34 -0500 Subject: [PATCH] sim: h8300: invert sim_state storage --- sim/h8300/ChangeLog | 16 ++++++++++++++++ sim/h8300/compile.c | 19 ++++++++++++------- sim/h8300/sim-main.h | 8 ++++---- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/sim/h8300/ChangeLog b/sim/h8300/ChangeLog index dfbaecb5daa..8ddbb548a41 100644 --- a/sim/h8300/ChangeLog +++ b/sim/h8300/ChangeLog @@ -1,3 +1,19 @@ +2021-05-17 Mike Frysinger + + * compile.c (h8_get_state): Change sd to H8300_SIM_STATE. + (h8_set_state): Likewise. + (h8_get_stats): Likewise. + (h8_increment_stats): Likewise. + (init_pointers): Likewise. + (step_once): Likewise. + (sim_info): Likewise. + (sim_open): Likewise. + (sim_load): Likewise. + * sim-main.h (SIM_HAVE_COMMON_SIM_STATE): Define. + (struct sim_state): Delete. + (struct h8300_sim_state): New struct. + (H8300_SIM_STATE): Define. + 2021-05-16 Mike Frysinger * compile.c: Replace config.h include with defs.h. diff --git a/sim/h8300/compile.c b/sim/h8300/compile.c index 2ac6dd0bf74..a45a676ad0e 100644 --- a/sim/h8300/compile.c +++ b/sim/h8300/compile.c @@ -139,13 +139,13 @@ h8_set_exception (SIM_DESC sd, int val) static enum h8300_sim_state h8_get_state (SIM_DESC sd) { - return sd -> state; + return H8300_SIM_STATE (sd)->state; } static void h8_set_state (SIM_DESC sd, enum h8300_sim_state val) { - sd -> state = val; + H8300_SIM_STATE (sd)->state = val; } #endif static unsigned int @@ -230,13 +230,13 @@ h8_set_reg (SIM_DESC sd, int regnum, int val) static int h8_get_stats (SIM_DESC sd, int idx) { - return sd -> stats[idx]; + return H8300_SIM_STATE (sd)->stats[idx]; } static void h8_increment_stats (SIM_DESC sd, int idx) { - sd -> stats[idx] ++; + H8300_SIM_STATE (sd)->stats[idx] ++; } #endif /* ADEBUG */ @@ -1612,6 +1612,8 @@ static int init_pointers_needed = 1; static void init_pointers (SIM_DESC sd) { + struct h8300_sim_state *state = H8300_SIM_STATE (sd); + if (init_pointers_needed) { int i; @@ -1637,7 +1639,7 @@ init_pointers (SIM_DESC sd) h8_set_memory_buf (sd, (unsigned char *) calloc (sizeof (char), memory_size)); - sd->memory_size = memory_size; + state->memory_size = memory_size; h8_set_mask (sd, memory_size - 1); @@ -1723,6 +1725,7 @@ step_once (SIM_DESC sd, SIM_CPU *cpu) int trace = 0; int intMask = 0; int oldmask; + const struct h8300_sim_state *state = H8300_SIM_STATE (sd); host_callback *sim_callback = STATE_CALLBACK (sd); init_pointers (sd); @@ -4529,6 +4532,7 @@ h8300_reg_fetch (SIM_CPU *cpu, int rn, unsigned char *buf, int length) void sim_info (SIM_DESC sd, int verbose) { + const struct h8300_sim_state *state = H8300_SIM_STATE (sd); double timetaken = (double) h8_get_ticks (sd) / (double) now_persec (); double virttime = h8_get_cycles (sd) / 10.0e6; @@ -4661,7 +4665,7 @@ sim_open (SIM_OPEN_KIND kind, SIM_DESC sd; sim_cpu *cpu; - sd = sim_state_alloc (kind, callback); + sd = sim_state_alloc_extra (kind, callback, sizeof (struct h8300_sim_state)); /* The cpu data is kept in a separately allocated chunk of memory. */ if (sim_cpu_alloc_all (sd, 1) != SIM_RC_OK) @@ -4745,6 +4749,7 @@ sim_open (SIM_OPEN_KIND kind, SIM_RC sim_load (SIM_DESC sd, const char *prog, bfd *abfd, int from_tty) { + struct h8300_sim_state *state = H8300_SIM_STATE (sd); bfd *prog_bfd; /* FIXME: The code below that sets a specific variant of the H8/300 @@ -4794,7 +4799,7 @@ sim_load (SIM_DESC sd, const char *prog, bfd *abfd, int from_tty) h8_set_memory_buf (sd, (unsigned char *) calloc (sizeof (char), memory_size)); - sd->memory_size = memory_size; + state->memory_size = memory_size; /* `msize' must be a power of two. */ if ((memory_size & (memory_size - 1)) != 0) diff --git a/sim/h8300/sim-main.h b/sim/h8300/sim-main.h index 68e44ae9333..57ff3071460 100644 --- a/sim/h8300/sim-main.h +++ b/sim/h8300/sim-main.h @@ -5,6 +5,8 @@ #ifndef SIM_MAIN_H #define SIM_MAIN_H +#define SIM_HAVE_COMMON_SIM_STATE + #define DEBUG /* These define the size of main memory for the simulator. @@ -130,15 +132,13 @@ struct _sim_cpu { sim_cpu_base base; }; -/* The sim_state struct. */ -struct sim_state { - sim_cpu *cpu[MAX_NR_PROCESSORS]; +struct h8300_sim_state { unsigned long memory_size; #ifdef ADEBUG int stats[O_LAST]; #endif - sim_state_base base; }; +#define H8300_SIM_STATE(sd) ((struct h8300_sim_state *) STATE_ARCH_DATA (sd)) /* The current state of the processor; registers, memory, etc. */ -- 2.30.2