xref: /netbsd-src/external/gpl3/gdb/dist/sim/common/sim-close.c (revision 88241920d21b339bf319c0e979ffda80c49a2936)
1ba340e45Schristos /* Miscellaneous simulator utilities.
2ba340e45Schristos 
3*88241920Schristos    Copyright (C) 2005-2024 Free Software Foundation, Inc.
4ba340e45Schristos    Contributed by Analog Devices, Inc. and Stephane Carrez.
5ba340e45Schristos 
6ba340e45Schristos    This file is part of simulators.
7ba340e45Schristos 
8ba340e45Schristos    This program is free software; you can redistribute it and/or modify
9ba340e45Schristos    it under the terms of the GNU General Public License as published by
10ba340e45Schristos    the Free Software Foundation; either version 3 of the License, or
11ba340e45Schristos    (at your option) any later version.
12ba340e45Schristos 
13ba340e45Schristos    This program is distributed in the hope that it will be useful,
14ba340e45Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
15ba340e45Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16ba340e45Schristos    GNU General Public License for more details.
17ba340e45Schristos 
18ba340e45Schristos    You should have received a copy of the GNU General Public License
19ba340e45Schristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
20ba340e45Schristos 
214b169a6bSchristos /* This must come before any other includes.  */
224b169a6bSchristos #include "defs.h"
234b169a6bSchristos 
24*88241920Schristos #include "symcat.h"
25*88241920Schristos 
26ba340e45Schristos #include "sim-main.h"
27ba340e45Schristos #include "sim-module.h"
284b169a6bSchristos #include "sim/sim.h"
29ba340e45Schristos 
30ba340e45Schristos /* Generic implementation of sim_close that works with simulators that use
31ba340e45Schristos    sim-module for all custom runtime options.  */
32ba340e45Schristos 
33ba340e45Schristos #ifndef SIM_CLOSE_HOOK
34ba340e45Schristos # define SIM_CLOSE_HOOK(sd, quitting)
35ba340e45Schristos #endif
36ba340e45Schristos 
37ba340e45Schristos void
38ba340e45Schristos sim_close (SIM_DESC sd, int quitting)
39ba340e45Schristos {
40ba340e45Schristos   SIM_CLOSE_HOOK (sd, quitting);
41ba340e45Schristos 
42ba340e45Schristos   /* If cgen is active, close it down.  */
43ba340e45Schristos #ifdef CGEN_ARCH
44ba340e45Schristos # define cgen_cpu_close XCONCAT2 (CGEN_ARCH,_cgen_cpu_close)
45ba340e45Schristos   cgen_cpu_close (CPU_CPU_DESC (STATE_CPU (sd, 0)));
46ba340e45Schristos #endif
47ba340e45Schristos 
48ba340e45Schristos   /* Shut down all registered/active modules.  */
49ba340e45Schristos   sim_module_uninstall (sd);
50ba340e45Schristos 
51ba340e45Schristos   /* Ensure that any resources allocated through the callback
52ba340e45Schristos      mechanism are released.  */
53ba340e45Schristos   sim_io_shutdown (sd);
54ba340e45Schristos 
55ba340e45Schristos   /* Break down all of the cpus.  */
56ba340e45Schristos   sim_cpu_free_all (sd);
57ba340e45Schristos 
58ba340e45Schristos   /* Finally break down the sim state itself.  */
59ba340e45Schristos   sim_state_free (sd);
60ba340e45Schristos }
61