[binutils-gdb] sim: avr: invert sim_state storage

Michael Frysinger vapier@sourceware.org
Mon May 17 06:08:17 GMT 2021


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=937af0fde5cf532c7f3958662525c45d46edd047

commit 937af0fde5cf532c7f3958662525c45d46edd047
Author: Mike Frysinger <vapier@gentoo.org>
Date:   Thu Jan 21 22:34:05 2016 -0500

    sim: avr: invert sim_state storage

Diff:
---
 sim/avr/ChangeLog  | 11 +++++++++++
 sim/avr/interp.c   | 13 +++++++------
 sim/avr/sim-main.h | 10 +++++-----
 3 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/sim/avr/ChangeLog b/sim/avr/ChangeLog
index 2a979aa6d95..a93bd599db0 100644
--- a/sim/avr/ChangeLog
+++ b/sim/avr/ChangeLog
@@ -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.
diff --git a/sim/avr/interp.c b/sim/avr/interp.c
index 75a10efe90a..d456c39390a 100644
--- a/sim/avr/interp.c
+++ b/sim/avr/interp.c
@@ -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;
 }
diff --git a/sim/avr/sim-main.h b/sim/avr/sim-main.h
index 24f975fb615..4f18882ae46 100644
--- a/sim/avr/sim-main.h
+++ b/sim/avr/sim-main.h
@@ -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


More information about the Gdb-cvs mailing list