xref: /netbsd-src/external/gpl3/gdb/dist/sim/common/sim-resume.c (revision 88241920d21b339bf319c0e979ffda80c49a2936)
14e98e3e1Schristos /* Generic simulator resume.
2*88241920Schristos    Copyright (C) 1997-2024 Free Software Foundation, Inc.
34e98e3e1Schristos    Contributed by Cygnus Support.
44e98e3e1Schristos 
54e98e3e1Schristos This file is part of GDB, the GNU debugger.
64e98e3e1Schristos 
74e98e3e1Schristos This program is free software; you can redistribute it and/or modify
84e98e3e1Schristos it under the terms of the GNU General Public License as published by
94e98e3e1Schristos the Free Software Foundation; either version 3 of the License, or
104e98e3e1Schristos (at your option) any later version.
114e98e3e1Schristos 
124e98e3e1Schristos This program is distributed in the hope that it will be useful,
134e98e3e1Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of
144e98e3e1Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
154e98e3e1Schristos GNU General Public License for more details.
164e98e3e1Schristos 
174e98e3e1Schristos You should have received a copy of the GNU General Public License
184e98e3e1Schristos along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
194e98e3e1Schristos 
204b169a6bSchristos /* This must come before any other includes.  */
214b169a6bSchristos #include "defs.h"
224b169a6bSchristos 
234e98e3e1Schristos #include "sim-main.h"
244e98e3e1Schristos #include "sim-assert.h"
254b169a6bSchristos #include "sim-signal.h"
264e98e3e1Schristos 
274e98e3e1Schristos /* Halt the simulator after just one instruction */
284e98e3e1Schristos 
294e98e3e1Schristos static void
304e98e3e1Schristos has_stepped (SIM_DESC sd,
314e98e3e1Schristos 	     void *data)
324e98e3e1Schristos {
334e98e3e1Schristos   ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
344e98e3e1Schristos   sim_engine_halt (sd, NULL, NULL, NULL_CIA, sim_stopped, SIM_SIGTRAP);
354e98e3e1Schristos }
364e98e3e1Schristos 
374e98e3e1Schristos 
384e98e3e1Schristos /* Generic resume - assumes the existance of sim_engine_run */
394e98e3e1Schristos 
404e98e3e1Schristos void
414e98e3e1Schristos sim_resume (SIM_DESC sd,
424e98e3e1Schristos 	    int step,
434e98e3e1Schristos 	    int siggnal)
444e98e3e1Schristos {
454e98e3e1Schristos   sim_engine *engine = STATE_ENGINE (sd);
464e98e3e1Schristos   jmp_buf buf;
474e98e3e1Schristos   int jmpval;
484e98e3e1Schristos 
494e98e3e1Schristos   ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
504e98e3e1Schristos 
514e98e3e1Schristos   /* we only want to be single stepping the simulator once */
524e98e3e1Schristos   if (engine->stepper != NULL)
534e98e3e1Schristos     {
544e98e3e1Schristos       sim_events_deschedule (sd, engine->stepper);
554e98e3e1Schristos       engine->stepper = NULL;
564e98e3e1Schristos     }
574e98e3e1Schristos   if (step)
584e98e3e1Schristos     engine->stepper = sim_events_schedule (sd, 1, has_stepped, sd);
594e98e3e1Schristos 
604e98e3e1Schristos   sim_module_resume (sd);
614e98e3e1Schristos 
624e98e3e1Schristos   /* run/resume the simulator */
634e98e3e1Schristos   engine->jmpbuf = &buf;
644e98e3e1Schristos   jmpval = setjmp (buf);
654e98e3e1Schristos   if (jmpval == sim_engine_start_jmpval
664e98e3e1Schristos       || jmpval == sim_engine_restart_jmpval)
674e98e3e1Schristos     {
684e98e3e1Schristos       int last_cpu_nr = sim_engine_last_cpu_nr (sd);
694e98e3e1Schristos       int next_cpu_nr = sim_engine_next_cpu_nr (sd);
704e98e3e1Schristos       int nr_cpus = sim_engine_nr_cpus (sd);
714e98e3e1Schristos       int sig_to_deliver;
724e98e3e1Schristos 
734e98e3e1Schristos       sim_events_preprocess (sd, last_cpu_nr >= nr_cpus, next_cpu_nr >= nr_cpus);
744e98e3e1Schristos       if (next_cpu_nr >= nr_cpus)
754e98e3e1Schristos 	next_cpu_nr = 0;
764e98e3e1Schristos 
774e98e3e1Schristos       /* Only deliver the SIGGNAL [sic] the first time through - don't
784e98e3e1Schristos          re-deliver any SIGGNAL during a restart.  NOTE: A new local
794e98e3e1Schristos          variable is used to avoid problems with the automatic
804e98e3e1Schristos          variable ``siggnal'' being trashed by a long jump.  */
814e98e3e1Schristos       if (jmpval == sim_engine_start_jmpval)
824e98e3e1Schristos 	sig_to_deliver = siggnal;
834e98e3e1Schristos       else
844e98e3e1Schristos 	sig_to_deliver = 0;
854e98e3e1Schristos 
864e98e3e1Schristos #ifdef SIM_CPU_EXCEPTION_RESUME
874e98e3e1Schristos       {
884e98e3e1Schristos 	sim_cpu* cpu = STATE_CPU (sd, next_cpu_nr);
894e98e3e1Schristos 	SIM_CPU_EXCEPTION_RESUME (sd, cpu, sig_to_deliver);
904e98e3e1Schristos       }
914e98e3e1Schristos #endif
924e98e3e1Schristos 
934e98e3e1Schristos       sim_engine_run (sd, next_cpu_nr, nr_cpus, sig_to_deliver);
944e98e3e1Schristos     }
954e98e3e1Schristos   engine->jmpbuf = NULL;
964e98e3e1Schristos 
974e98e3e1Schristos   sim_module_suspend (sd);
984e98e3e1Schristos }
99