diff mbox

sim: sim-close: unify sim_close logic

Message ID 1447572722-29090-1-git-send-email-vapier@gentoo.org
State Committed
Delegated to: Mike Frysinger
Headers show

Commit Message

Mike Frysinger Nov. 15, 2015, 7:32 a.m. UTC
Other than the nice advantage of all sims having to declare one fewer
common function, this also fixes leakage in pretty much every sim.
Many were not freeing any resources, and a few were inconsistent as
to the ones they did.  Now we have a single module that takes care of
all the logic for us.

Most of the non-cgen based ones could be deleted outright.  The cgen
ones required adding a callback to the arch-specific cleanup func.
The few that still have close callbacks are to manage their internal
state.

We do not convert erc32, m32c, ppc, rl78, or rx as they do not use
the common sim core.

Committed.
---
 sim/arm/ChangeLog         |  4 ++++
 sim/arm/wrapper.c         |  7 ------
 sim/avr/ChangeLog         |  4 ++++
 sim/avr/interp.c          |  6 -----
 sim/bfin/ChangeLog        |  4 ++++
 sim/bfin/interp.c         |  6 -----
 sim/common/ChangeLog      |  5 +++++
 sim/common/Make-common.in |  1 +
 sim/common/sim-close.c    | 57 +++++++++++++++++++++++++++++++++++++++++++++++
 sim/cr16/ChangeLog        |  4 ++++
 sim/cr16/interp.c         |  7 ------
 sim/cris/ChangeLog        |  4 ++++
 sim/cris/sim-if.c         |  7 ------
 sim/d10v/ChangeLog        |  4 ++++
 sim/d10v/interp.c         |  7 ------
 sim/frv/ChangeLog         |  8 +++++++
 sim/frv/sim-if.c          |  5 +----
 sim/frv/sim-main.h        |  3 +++
 sim/ft32/ChangeLog        |  4 ++++
 sim/ft32/interp.c         |  6 -----
 sim/h8300/ChangeLog       |  4 ++++
 sim/h8300/compile.c       |  6 -----
 sim/iq2000/ChangeLog      |  4 ++++
 sim/iq2000/sim-if.c       |  9 --------
 sim/lm32/ChangeLog        |  4 ++++
 sim/lm32/sim-if.c         |  9 --------
 sim/m32r/ChangeLog        |  4 ++++
 sim/m32r/sim-if.c         |  9 --------
 sim/m68hc11/ChangeLog     |  4 ++++
 sim/m68hc11/interp.c      | 16 -------------
 sim/mcore/ChangeLog       |  4 ++++
 sim/mcore/interp.c        |  6 -----
 sim/microblaze/ChangeLog  |  4 ++++
 sim/microblaze/interp.c   |  6 -----
 sim/mips/ChangeLog        |  8 +++++++
 sim/mips/interp.c         | 21 +----------------
 sim/mips/sim-main.h       |  2 ++
 sim/mn10300/ChangeLog     |  4 ++++
 sim/mn10300/interp.c      |  8 -------
 sim/moxie/ChangeLog       |  4 ++++
 sim/moxie/interp.c        |  7 ------
 sim/msp430/ChangeLog      |  7 ++++++
 sim/msp430/msp430-sim.c   |  4 +---
 sim/msp430/sim-main.h     |  3 +++
 sim/sh/ChangeLog          |  4 ++++
 sim/sh/interp.c           |  6 -----
 sim/sh64/ChangeLog        |  4 ++++
 sim/sh64/sim-if.c         |  9 --------
 sim/v850/ChangeLog        |  4 ++++
 sim/v850/interp.c         |  7 ------
 50 files changed, 173 insertions(+), 171 deletions(-)
 create mode 100644 sim/common/sim-close.c
diff mbox

Patch

diff --git a/sim/arm/ChangeLog b/sim/arm/ChangeLog
index 577579c..f87e18b 100644
--- a/sim/arm/ChangeLog
+++ b/sim/arm/ChangeLog
@@ -1,3 +1,7 @@ 
+2015-11-14  Mike Frysinger  <vapier@gentoo.org>
+
+	* wrapper.c (sim_close): Delete.
+
 2015-07-14  Nick Clifton  <nickc@redhat.com>
 
 	* armcopro.c: Remove extraneous whitespace.
diff --git a/sim/arm/wrapper.c b/sim/arm/wrapper.c
index b9b4a0b..79f0b1d 100644
--- a/sim/arm/wrapper.c
+++ b/sim/arm/wrapper.c
@@ -914,13 +914,6 @@  sim_open (SIM_OPEN_KIND kind,
 }
 
 void
-sim_close (SIM_DESC sd ATTRIBUTE_UNUSED,
-	   int quitting ATTRIBUTE_UNUSED)
-{
-  /* Nothing to do.  */
-}
-
-void
 sim_stop_reason (SIM_DESC sd ATTRIBUTE_UNUSED,
 		 enum sim_stop *reason,
 		 int *sigrc)
diff --git a/sim/avr/ChangeLog b/sim/avr/ChangeLog
index 0c2963c..fa21734 100644
--- a/sim/avr/ChangeLog
+++ b/sim/avr/ChangeLog
@@ -1,3 +1,7 @@ 
+2015-11-14  Mike Frysinger  <vapier@gentoo.org>
+
+	* interp.c (sim_close): Delete.
+
 2015-06-23  Mike Frysinger  <vapier@gentoo.org>
 
 	* configure: Regenerate.
diff --git a/sim/avr/interp.c b/sim/avr/interp.c
index a6588d3..0b84c3b 100644
--- a/sim/avr/interp.c
+++ b/sim/avr/interp.c
@@ -1758,12 +1758,6 @@  sim_open (SIM_OPEN_KIND kind, host_callback *cb, struct bfd *abfd, char **argv)
   return sd;
 }
 
-void
-sim_close (SIM_DESC sd, int quitting)
-{
-  sim_module_uninstall (sd);
-}
-
 SIM_RC
 sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char **argv, char **env)
 {
diff --git a/sim/bfin/ChangeLog b/sim/bfin/ChangeLog
index 2e62a74..b0205e3 100644
--- a/sim/bfin/ChangeLog
+++ b/sim/bfin/ChangeLog
@@ -1,3 +1,7 @@ 
+2015-11-14  Mike Frysinger  <vapier@gentoo.org>
+
+	* interp.c (sim_close): Delete.
+
 2015-10-11  Mike Frysinger  <vapier@gentoo.org>
 
 	PR sim/18407
diff --git a/sim/bfin/interp.c b/sim/bfin/interp.c
index 3013ca0..5ba204b 100644
--- a/sim/bfin/interp.c
+++ b/sim/bfin/interp.c
@@ -820,12 +820,6 @@  sim_open (SIM_OPEN_KIND kind, host_callback *callback,
   return sd;
 }
 
-void
-sim_close (SIM_DESC sd, int quitting)
-{
-  sim_module_uninstall (sd);
-}
-
 /* Some utils don't like having a NULL environ.  */
 static const char * const simple_env[] = { "HOME=/", "PATH=/bin", NULL };
 
diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog
index 2aa178c..151fc1b 100644
--- a/sim/common/ChangeLog
+++ b/sim/common/ChangeLog
@@ -1,3 +1,8 @@ 
+2015-11-14  Mike Frysinger  <vapier@gentoo.org>
+
+	* Make-common.in (SIM_NEW_COMMON_OBJS): Add sim-close.o
+	* sim-close.c: New file.
+
 2015-09-25  Andrew Bennett  <andrew.bennett@imgtec.com>
 	    Ali Lown  <ali.lown@imgtec.com>
 
diff --git a/sim/common/Make-common.in b/sim/common/Make-common.in
index 2f5ad89..aba97f7 100644
--- a/sim/common/Make-common.in
+++ b/sim/common/Make-common.in
@@ -173,6 +173,7 @@  SIM_COMMON_HW_OBJS = \
 SIM_NEW_COMMON_OBJS = \
 	sim-arange.o \
 	sim-bits.o \
+	sim-close.o \
 	sim-command.o \
 	sim-config.o \
 	sim-core.o \
diff --git a/sim/common/sim-close.c b/sim/common/sim-close.c
new file mode 100644
index 0000000..a1458d4
--- /dev/null
+++ b/sim/common/sim-close.c
@@ -0,0 +1,57 @@ 
+/* Miscellaneous simulator utilities.
+
+   Copyright (C) 2005-2015 Free Software Foundation, Inc.
+   Contributed by Analog Devices, Inc. and Stephane Carrez.
+
+   This file is part of simulators.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   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 "sim-main.h"
+#include "sim-module.h"
+#include "gdb/remote-sim.h"
+
+/* Generic implementation of sim_close that works with simulators that use
+   sim-module for all custom runtime options.  */
+
+#ifndef SIM_CLOSE_HOOK
+# define SIM_CLOSE_HOOK(sd, quitting)
+#endif
+
+void
+sim_close (SIM_DESC sd, int quitting)
+{
+  SIM_CLOSE_HOOK (sd, quitting);
+
+  /* If cgen is active, close it down.  */
+#ifdef CGEN_ARCH
+# define __cgen_cpu_close(arch) arch##_cgen_cpu_close
+# define _cgen_cpu_close(arch) __cgen_cpu_close (arch)
+# define cgen_cpu_close _cgen_cpu_close (CGEN_ARCH)
+  cgen_cpu_close (CPU_CPU_DESC (STATE_CPU (sd, 0)));
+#endif
+
+  /* Shut down all registered/active modules.  */
+  sim_module_uninstall (sd);
+
+  /* Ensure that any resources allocated through the callback
+     mechanism are released.  */
+  sim_io_shutdown (sd);
+
+  /* Break down all of the cpus.  */
+  sim_cpu_free_all (sd);
+
+  /* Finally break down the sim state itself.  */
+  sim_state_free (sd);
+}
diff --git a/sim/cr16/ChangeLog b/sim/cr16/ChangeLog
index ccc4abb..5cbb413 100644
--- a/sim/cr16/ChangeLog
+++ b/sim/cr16/ChangeLog
@@ -1,3 +1,7 @@ 
+2015-11-14  Mike Frysinger  <vapier@gentoo.org>
+
+	* interp.c (sim_close): Delete.
+
 2015-11-10  Mike Frysinger  <vapier@gentoo.org>
 
 	* interp.c (sim_cr16_translate_dmap_addr): Mark static.
diff --git a/sim/cr16/interp.c b/sim/cr16/interp.c
index 5b3f5bb..8af7aef 100644
--- a/sim/cr16/interp.c
+++ b/sim/cr16/interp.c
@@ -945,13 +945,6 @@  sim_open (SIM_OPEN_KIND kind, struct host_callback_struct *cb, struct bfd *abfd,
   return sd;
 }
 
-
-void
-sim_close (SIM_DESC sd, int quitting)
-{
-  /* Nothing to do.  */
-}
-
 uint8 *
 dmem_addr (uint32 offset)
 {
diff --git a/sim/cris/ChangeLog b/sim/cris/ChangeLog
index ad3f186..42ff285 100644
--- a/sim/cris/ChangeLog
+++ b/sim/cris/ChangeLog
@@ -1,3 +1,7 @@ 
+2015-11-14  Mike Frysinger  <vapier@gentoo.org>
+
+	* sim-if.c (sim_close): Delete.
+
 2015-06-23  Mike Frysinger  <vapier@gentoo.org>
 
 	* configure: Regenerate.
diff --git a/sim/cris/sim-if.c b/sim/cris/sim-if.c
index 36db517..9fb1e13 100644
--- a/sim/cris/sim-if.c
+++ b/sim/cris/sim-if.c
@@ -1060,13 +1060,6 @@  sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
 
   return sd;
 }
-
-void
-sim_close (SIM_DESC sd, int quitting ATTRIBUTE_UNUSED)
-{
-  cris_cgen_cpu_close (CPU_CPU_DESC (STATE_CPU (sd, 0)));
-  sim_module_uninstall (sd);
-}
 
 SIM_RC
 sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
diff --git a/sim/d10v/ChangeLog b/sim/d10v/ChangeLog
index 765d7a5..4f22db7 100644
--- a/sim/d10v/ChangeLog
+++ b/sim/d10v/ChangeLog
@@ -1,3 +1,7 @@ 
+2015-11-14  Mike Frysinger  <vapier@gentoo.org>
+
+	* interp.c (sim_close): Delete.
+
 2015-11-10  Mike Frysinger  <vapier@gentoo.org>
 
 	* interp.c (sim_d10v_translate_dmap_addr): Mark static.
diff --git a/sim/d10v/interp.c b/sim/d10v/interp.c
index 9c059f7..1cb1d7c 100644
--- a/sim/d10v/interp.c
+++ b/sim/d10v/interp.c
@@ -866,13 +866,6 @@  sim_open (SIM_OPEN_KIND kind, host_callback *cb, struct bfd *abfd, char **argv)
   return sd;
 }
 
-
-void
-sim_close (SIM_DESC sd, int quitting)
-{
-  /* Nothing to do.  */
-}
-
 uint8 *
 dmem_addr (uint16 offset)
 {
diff --git a/sim/frv/ChangeLog b/sim/frv/ChangeLog
index 44c920c..9ebf498 100644
--- a/sim/frv/ChangeLog
+++ b/sim/frv/ChangeLog
@@ -1,3 +1,11 @@ 
+2015-11-14  Mike Frysinger  <vapier@gentoo.org>
+
+	* interp.c (sim_close): Rename to ...
+	(frv_sim_close): ... this.  Delete calls to frv_cgen_cpu_close and
+	sim_module_uninstall.
+	* sim-main.h (frv_sim_close): Declare.
+	(SIM_CLOSE_HOOK): Define.
+
 2015-06-23  Mike Frysinger  <vapier@gentoo.org>
 
 	* configure.ac (AC_ARG_ENABLE(sim-trapdump)): Call AS_HELP_STRING.
diff --git a/sim/frv/sim-if.c b/sim/frv/sim-if.c
index 2668765..8c6ed6f 100644
--- a/sim/frv/sim-if.c
+++ b/sim/frv/sim-if.c
@@ -199,7 +199,7 @@  sim_open (kind, callback, abfd, argv)
 }
 
 void
-sim_close (sd, quitting)
+frv_sim_close (sd, quitting)
      SIM_DESC sd;
      int quitting;
 {
@@ -211,9 +211,6 @@  sim_close (sd, quitting)
       frv_cache_term (CPU_INSN_CACHE (cpu));
       frv_cache_term (CPU_DATA_CACHE (cpu));
     }
-
-  frv_cgen_cpu_close (CPU_CPU_DESC (STATE_CPU (sd, 0)));
-  sim_module_uninstall (sd);
 }
 
 SIM_RC
diff --git a/sim/frv/sim-main.h b/sim/frv/sim-main.h
index d5a67cb..ef14d64 100644
--- a/sim/frv/sim-main.h
+++ b/sim/frv/sim-main.h
@@ -43,6 +43,9 @@  along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "profile.h"
 
 void frv_sim_engine_halt_hook (SIM_DESC, SIM_CPU *, sim_cia);
+
+extern void frv_sim_close (SIM_DESC sd, int quitting);
+#define SIM_CLOSE_HOOK(...) frv_sim_close (__VA_ARGS__)
 
 /* The _sim_cpu struct.  */
 
diff --git a/sim/ft32/ChangeLog b/sim/ft32/ChangeLog
index f5b14ec..bb41fb8 100644
--- a/sim/ft32/ChangeLog
+++ b/sim/ft32/ChangeLog
@@ -1,3 +1,7 @@ 
+2015-11-14  Mike Frysinger  <vapier@gentoo.org>
+
+	* interp.c (sim_close): Delete.
+
 2015-09-29  James Bowman  <james.bowman@ftdichip.com>
 
 	* interp.c (step_once): Correct length for MEMSET and MEMCPY
diff --git a/sim/ft32/interp.c b/sim/ft32/interp.c
index f7daf1c..e2762b8 100644
--- a/sim/ft32/interp.c
+++ b/sim/ft32/interp.c
@@ -862,12 +862,6 @@  sim_open (SIM_OPEN_KIND kind,
   return sd;
 }
 
-void
-sim_close (SIM_DESC sd, int quitting)
-{
-  sim_module_uninstall (sd);
-}
-
 SIM_RC
 sim_create_inferior (SIM_DESC sd,
 		     struct bfd *abfd,
diff --git a/sim/h8300/ChangeLog b/sim/h8300/ChangeLog
index ce77765..b50c1a1 100644
--- a/sim/h8300/ChangeLog
+++ b/sim/h8300/ChangeLog
@@ -1,3 +1,7 @@ 
+2015-11-14  Mike Frysinger  <vapier@gentoo.org>
+
+	* compile.c (sim_close): Delete.
+
 2015-11-09  Mike Frysinger  <vapier@gentoo.org>
 
 	* compile.c (littleendian): Delete.
diff --git a/sim/h8300/compile.c b/sim/h8300/compile.c
index f3f794d..e5460fa 100644
--- a/sim/h8300/compile.c
+++ b/sim/h8300/compile.c
@@ -4966,12 +4966,6 @@  sim_open (SIM_OPEN_KIND kind,
   return sd;
 }
 
-void
-sim_close (SIM_DESC sd, int quitting)
-{
-  /* Nothing to do.  */
-}
-
 /* Called by gdb to load a program into memory.  */
 
 SIM_RC
diff --git a/sim/iq2000/ChangeLog b/sim/iq2000/ChangeLog
index 3eb722b..dcb6cc5 100644
--- a/sim/iq2000/ChangeLog
+++ b/sim/iq2000/ChangeLog
@@ -1,3 +1,7 @@ 
+2015-11-14  Mike Frysinger  <vapier@gentoo.org>
+
+	* sim-if.c (sim_close): Delete.
+
 2015-06-23  Mike Frysinger  <vapier@gentoo.org>
 
 	* configure: Regenerate.
diff --git a/sim/iq2000/sim-if.c b/sim/iq2000/sim-if.c
index 8e79f4a..a72f5c0 100644
--- a/sim/iq2000/sim-if.c
+++ b/sim/iq2000/sim-if.c
@@ -155,15 +155,6 @@  sim_open (kind, callback, abfd, argv)
 
   return sd;
 }
-
-void
-sim_close (sd, quitting)
-     SIM_DESC sd;
-     int quitting;
-{
-  iq2000_cgen_cpu_close (CPU_CPU_DESC (STATE_CPU (sd, 0)));
-  sim_module_uninstall (sd);
-}
 
 SIM_RC
 sim_create_inferior (sd, abfd, argv, envp)
diff --git a/sim/lm32/ChangeLog b/sim/lm32/ChangeLog
index 4b852db..59d3aa1 100644
--- a/sim/lm32/ChangeLog
+++ b/sim/lm32/ChangeLog
@@ -1,3 +1,7 @@ 
+2015-11-14  Mike Frysinger  <vapier@gentoo.org>
+
+	* sim-if.c (sim_close): Delete.
+
 2015-06-23  Mike Frysinger  <vapier@gentoo.org>
 
 	* configure: Regenerate.
diff --git a/sim/lm32/sim-if.c b/sim/lm32/sim-if.c
index a82b428..3b0575a 100644
--- a/sim/lm32/sim-if.c
+++ b/sim/lm32/sim-if.c
@@ -246,15 +246,6 @@  sim_open (kind, callback, abfd, argv)
 
   return sd;
 }
-
-void
-sim_close (sd, quitting)
-     SIM_DESC sd;
-     int quitting;
-{
-  lm32_cgen_cpu_close (CPU_CPU_DESC (STATE_CPU (sd, 0)));
-  sim_module_uninstall (sd);
-}
 
 SIM_RC
 sim_create_inferior (sd, abfd, argv, envp)
diff --git a/sim/m32r/ChangeLog b/sim/m32r/ChangeLog
index b38c0a5..8919efc 100644
--- a/sim/m32r/ChangeLog
+++ b/sim/m32r/ChangeLog
@@ -1,3 +1,7 @@ 
+2015-11-14  Mike Frysinger  <vapier@gentoo.org>
+
+	* sim-if.c (sim_close): Delete.
+
 2015-06-23  Mike Frysinger  <vapier@gentoo.org>
 
 	* configure: Regenerate.
diff --git a/sim/m32r/sim-if.c b/sim/m32r/sim-if.c
index d01bc0a..5fd8de0 100644
--- a/sim/m32r/sim-if.c
+++ b/sim/m32r/sim-if.c
@@ -179,15 +179,6 @@  sim_open (kind, callback, abfd, argv)
 
   return sd;
 }
-
-void
-sim_close (sd, quitting)
-     SIM_DESC sd;
-     int quitting;
-{
-  m32r_cgen_cpu_close (CPU_CPU_DESC (STATE_CPU (sd, 0)));
-  sim_module_uninstall (sd);
-}
 
 SIM_RC
 sim_create_inferior (sd, abfd, argv, envp)
diff --git a/sim/m68hc11/ChangeLog b/sim/m68hc11/ChangeLog
index 407e391..ba2db62 100644
--- a/sim/m68hc11/ChangeLog
+++ b/sim/m68hc11/ChangeLog
@@ -1,3 +1,7 @@ 
+2015-11-14  Mike Frysinger  <vapier@gentoo.org>
+
+	* interp.c (sim_close): Delete.
+
 2015-06-23  Mike Frysinger  <vapier@gentoo.org>
 
 	* configure: Regenerate.
diff --git a/sim/m68hc11/interp.c b/sim/m68hc11/interp.c
index a1d98a7..bb93e6c 100644
--- a/sim/m68hc11/interp.c
+++ b/sim/m68hc11/interp.c
@@ -499,22 +499,6 @@  sim_open (SIM_OPEN_KIND kind, host_callback *callback,
   return sd;
 }
 
-
-void
-sim_close (SIM_DESC sd, int quitting)
-{
-  /* shut down modules */
-  sim_module_uninstall (sd);
-
-  /* Ensure that any resources allocated through the callback
-     mechanism are released: */
-  sim_io_shutdown (sd);
-
-  /* FIXME - free SD */
-  sim_state_free (sd);
-  return;
-}
-
 /* Generic implementation of sim_engine_run that works within the
    sim_engine setjmp/longjmp framework. */
 
diff --git a/sim/mcore/ChangeLog b/sim/mcore/ChangeLog
index 99e72de..70d7ae9 100644
--- a/sim/mcore/ChangeLog
+++ b/sim/mcore/ChangeLog
@@ -1,3 +1,7 @@ 
+2015-11-14  Mike Frysinger  <vapier@gentoo.org>
+
+	* interp.c (sim_close): Delete.
+
 2015-06-23  Mike Frysinger  <vapier@gentoo.org>
 
 	* configure: Regenerate.
diff --git a/sim/mcore/interp.c b/sim/mcore/interp.c
index 64d148a..2a9f193 100644
--- a/sim/mcore/interp.c
+++ b/sim/mcore/interp.c
@@ -1452,12 +1452,6 @@  sim_open (SIM_OPEN_KIND kind, host_callback *cb, struct bfd *abfd, char **argv)
   return sd;
 }
 
-void
-sim_close (SIM_DESC sd, int quitting)
-{
-  /* nothing to do */
-}
-
 SIM_RC
 sim_create_inferior (SIM_DESC sd, struct bfd *prog_bfd, char **argv, char **env)
 {
diff --git a/sim/microblaze/ChangeLog b/sim/microblaze/ChangeLog
index 765480c..cb6f742 100644
--- a/sim/microblaze/ChangeLog
+++ b/sim/microblaze/ChangeLog
@@ -1,3 +1,7 @@ 
+2015-11-14  Mike Frysinger  <vapier@gentoo.org>
+
+	* interp.c (sim_close): Delete.
+
 2015-06-23  Mike Frysinger  <vapier@gentoo.org>
 
 	* configure: Regenerate.
diff --git a/sim/microblaze/interp.c b/sim/microblaze/interp.c
index 93e622d..3ca5e1f 100644
--- a/sim/microblaze/interp.c
+++ b/sim/microblaze/interp.c
@@ -459,12 +459,6 @@  sim_open (SIM_OPEN_KIND kind, host_callback *cb, struct bfd *abfd, char **argv)
   return sd;
 }
 
-void
-sim_close (SIM_DESC sd, int quitting)
-{
-  /* Do nothing.  */
-}
-
 SIM_RC
 sim_create_inferior (SIM_DESC sd, struct bfd *prog_bfd, char **argv, char **env)
 {
diff --git a/sim/mips/ChangeLog b/sim/mips/ChangeLog
index 2865266..149abb1 100644
--- a/sim/mips/ChangeLog
+++ b/sim/mips/ChangeLog
@@ -1,3 +1,11 @@ 
+2015-11-14  Mike Frysinger  <vapier@gentoo.org>
+
+	* interp.c (sim_close): Rename to ...
+	(mips_sim_close): ... this.  Delete calls to sim_module_uninstall and
+	sim_io_shutdown.
+	* sim-main.h (mips_sim_close): Declare.
+	(SIM_CLOSE_HOOK): Define.
+
 2015-09-25  Andrew Bennett  <andrew.bennett@imgtec.com>
 	    Ali Lown  <ali.lown@imgtec.com>
 
diff --git a/sim/mips/interp.c b/sim/mips/interp.c
index 9dc8964..8a584d3 100644
--- a/sim/mips/interp.c
+++ b/sim/mips/interp.c
@@ -834,34 +834,15 @@  get_insn_name (sim_cpu *cpu, int i)
 }
 
 void
-sim_close (SIM_DESC sd, int quitting)
+mips_sim_close (SIM_DESC sd, int quitting)
 {
-#ifdef DEBUG
-  printf("DBG: sim_close: entered (quitting = %d)\n",quitting);
-#endif
-
-
-  /* "quitting" is non-zero if we cannot hang on errors */
-
-  /* shut down modules */
-  sim_module_uninstall (sd);
-
-  /* Ensure that any resources allocated through the callback
-     mechanism are released: */
-  sim_io_shutdown (sd);
-
 #if WITH_TRACE_ANY_P
   if (tracefh != NULL && tracefh != stderr)
    fclose(tracefh);
   tracefh = NULL;
 #endif
-
-  /* FIXME - free SD */
-
-  return;
 }
 
-
 int
 sim_write (SIM_DESC sd, SIM_ADDR addr, const unsigned char *buffer, int size)
 {
diff --git a/sim/mips/sim-main.h b/sim/mips/sim-main.h
index 42d8db3..adf60c7 100644
--- a/sim/mips/sim-main.h
+++ b/sim/mips/sim-main.h
@@ -474,6 +474,8 @@  struct _sim_cpu {
   sim_cpu_base base;
 };
 
+extern void mips_sim_close (SIM_DESC sd, int quitting);
+#define SIM_CLOSE_HOOK(...) mips_sim_close (__VA_ARGS__)
 
 /* MIPS specific simulator watch config */
 
diff --git a/sim/mn10300/ChangeLog b/sim/mn10300/ChangeLog
index e1bd8f1..e00b48f 100644
--- a/sim/mn10300/ChangeLog
+++ b/sim/mn10300/ChangeLog
@@ -1,3 +1,7 @@ 
+2015-11-14  Mike Frysinger  <vapier@gentoo.org>
+
+	* interp.c (sim_close): Delete.
+
 2015-06-23  Mike Frysinger  <vapier@gentoo.org>
 
 	* configure: Regenerate.
diff --git a/sim/mn10300/interp.c b/sim/mn10300/interp.c
index 14344fc..f3941ae 100644
--- a/sim/mn10300/interp.c
+++ b/sim/mn10300/interp.c
@@ -317,14 +317,6 @@  sim_open (SIM_OPEN_KIND kind,
   return sd;
 }
 
-
-void
-sim_close (SIM_DESC sd, int quitting)
-{
-  sim_module_uninstall (sd);
-}
-
-
 SIM_RC
 sim_create_inferior (SIM_DESC sd,
 		     struct bfd *prog_bfd,
diff --git a/sim/moxie/ChangeLog b/sim/moxie/ChangeLog
index 04b74ce..9f6cfde 100644
--- a/sim/moxie/ChangeLog
+++ b/sim/moxie/ChangeLog
@@ -1,3 +1,7 @@ 
+2015-11-14  Mike Frysinger  <vapier@gentoo.org>
+
+	* interp.c (sim_close): Delete.
+
 2015-10-11  Mike Frysinger  <vapier@gentoo.org>
 
 	PR sim/18273
diff --git a/sim/moxie/interp.c b/sim/moxie/interp.c
index df92cee..b2e6352 100644
--- a/sim/moxie/interp.c
+++ b/sim/moxie/interp.c
@@ -1246,13 +1246,6 @@  sim_open (SIM_OPEN_KIND kind, host_callback *cb, struct bfd *abfd, char **argv)
   return sd;
 }
 
-void
-sim_close (SIM_DESC sd, int quitting)
-{
-  /* nothing to do */
-}
-
-
 /* Load the device tree blob.  */
 
 static void
diff --git a/sim/msp430/ChangeLog b/sim/msp430/ChangeLog
index 08da33d..de174bf 100644
--- a/sim/msp430/ChangeLog
+++ b/sim/msp430/ChangeLog
@@ -1,3 +1,10 @@ 
+2015-11-14  Mike Frysinger  <vapier@gentoo.org>
+
+	* interp.c (sim_close): Rename to ...
+	(msp430_sim_close): ... this.  Delete call to sim_state_free.
+	* sim-main.h (msp430_sim_close): Declare.
+	(SIM_CLOSE_HOOK): Define.
+
 2015-06-24  Mike Frysinger  <vapier@gentoo.org>
 
 	* msp430-sim.c (trace_reg_put): Change TRACE_VPU to TRACE_REGISTER.
diff --git a/sim/msp430/msp430-sim.c b/sim/msp430/msp430-sim.c
index f32cb69..7f329c4 100644
--- a/sim/msp430/msp430-sim.c
+++ b/sim/msp430/msp430-sim.c
@@ -239,11 +239,9 @@  sim_open (SIM_OPEN_KIND kind,
 }
 
 void
-sim_close (SIM_DESC sd,
-	   int quitting)
+msp430_sim_close (SIM_DESC sd, int quitting)
 {
   free (STATE_SYMBOL_TABLE (sd));
-  sim_state_free (sd);
 }
 
 SIM_RC
diff --git a/sim/msp430/sim-main.h b/sim/msp430/sim-main.h
index 19c8cca..aa51c15 100644
--- a/sim/msp430/sim-main.h
+++ b/sim/msp430/sim-main.h
@@ -54,4 +54,7 @@  struct sim_state
 #include "sim-engine.h"
 #include "sim-options.h"
 
+extern void msp430_sim_close (SIM_DESC sd, int quitting);
+#define SIM_CLOSE_HOOK(...) msp430_sim_close (__VA_ARGS__)
+
 #endif /* _MSP430_MAIN_SIM_H_ */
diff --git a/sim/sh/ChangeLog b/sim/sh/ChangeLog
index 458d0c3..d19a881 100644
--- a/sim/sh/ChangeLog
+++ b/sim/sh/ChangeLog
@@ -1,3 +1,7 @@ 
+2015-11-14  Mike Frysinger  <vapier@gentoo.org>
+
+	* interp.c (sim_close): Delete.
+
 2015-06-23  Mike Frysinger  <vapier@gentoo.org>
 
 	* configure: Regenerate.
diff --git a/sim/sh/interp.c b/sim/sh/interp.c
index 2f02e69..55a2d64 100644
--- a/sim/sh/interp.c
+++ b/sim/sh/interp.c
@@ -2501,12 +2501,6 @@  parse_and_set_memory_size (const char *str)
     callback->printf_filtered (callback, "Bad memory size %d; must be 1 to 24, inclusive\n", n);
 }
 
-void
-sim_close (SIM_DESC sd, int quitting)
-{
-  /* nothing to do */
-}
-
 SIM_RC
 sim_create_inferior (SIM_DESC sd, struct bfd *prog_bfd, char **argv, char **env)
 {
diff --git a/sim/sh64/ChangeLog b/sim/sh64/ChangeLog
index cff434d..2643913 100644
--- a/sim/sh64/ChangeLog
+++ b/sim/sh64/ChangeLog
@@ -1,3 +1,7 @@ 
+2015-11-14  Mike Frysinger  <vapier@gentoo.org>
+
+	* sim-if.c (sim_close): Delete.
+
 2015-06-23  Mike Frysinger  <vapier@gentoo.org>
 
 	* configure: Regenerate.
diff --git a/sim/sh64/sim-if.c b/sim/sh64/sim-if.c
index 200552d..29e0936 100644
--- a/sim/sh64/sim-if.c
+++ b/sim/sh64/sim-if.c
@@ -161,15 +161,6 @@  sim_open (kind, callback, abfd, argv)
 
   return sd;
 }
-
-void
-sim_close (sd, quitting)
-     SIM_DESC sd;
-     int quitting;
-{
-  sh_cgen_cpu_close (CPU_CPU_DESC (STATE_CPU (sd, 0)));
-  sim_module_uninstall (sd);
-}
 
 SIM_RC
 sim_create_inferior (sd, abfd, argv, envp)
diff --git a/sim/v850/ChangeLog b/sim/v850/ChangeLog
index e0b0f18..e0b92d9 100644
--- a/sim/v850/ChangeLog
+++ b/sim/v850/ChangeLog
@@ -1,3 +1,7 @@ 
+2015-11-14  Mike Frysinger  <vapier@gentoo.org>
+
+	* interp.c (sim_close): Delete.
+
 2015-06-23  Mike Frysinger  <vapier@gentoo.org>
 
 	* configure: Regenerate.
diff --git a/sim/v850/interp.c b/sim/v850/interp.c
index 5b46feb..f055149 100644
--- a/sim/v850/interp.c
+++ b/sim/v850/interp.c
@@ -303,13 +303,6 @@  sim_open (SIM_OPEN_KIND    kind,
   return sd;
 }
 
-
-void
-sim_close (SIM_DESC sd, int quitting)
-{
-  sim_module_uninstall (sd);
-}
-
 SIM_RC
 sim_create_inferior (SIM_DESC      sd,
 		     struct bfd *  prog_bfd,