xref: /netbsd-src/external/gpl3/gdb/dist/sim/common/sim-engine.h (revision 88241920d21b339bf319c0e979ffda80c49a2936)
14e98e3e1Schristos /* Generic simulator halt/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 
204e98e3e1Schristos #ifndef SIM_ENGINE_H
214e98e3e1Schristos #define SIM_ENGINE_H
224e98e3e1Schristos 
234b169a6bSchristos #include <stdarg.h>
244b169a6bSchristos 
254b169a6bSchristos #include "ansidecl.h"
264e98e3e1Schristos 
274e98e3e1Schristos typedef struct _sim_engine sim_engine;
284e98e3e1Schristos struct _sim_engine
294e98e3e1Schristos {
304e98e3e1Schristos   void *jmpbuf;
314e98e3e1Schristos   sim_cpu *last_cpu;
324e98e3e1Schristos   sim_cpu *next_cpu;
334e98e3e1Schristos   int nr_cpus;
344e98e3e1Schristos   enum sim_stop reason;
354e98e3e1Schristos   sim_event *stepper;
364e98e3e1Schristos   int sigrc;
374e98e3e1Schristos };
384e98e3e1Schristos 
394e98e3e1Schristos 
404e98e3e1Schristos 
414e98e3e1Schristos /* jmpval: 0 (initial use) start simulator
424e98e3e1Schristos            1               halt simulator
434e98e3e1Schristos            2               restart simulator
444e98e3e1Schristos    This is required by the ISO C standard (the only time 0 is returned
454e98e3e1Schristos    is at the initial call to setjmp). */
464e98e3e1Schristos 
474e98e3e1Schristos enum {
484e98e3e1Schristos   sim_engine_start_jmpval,
494e98e3e1Schristos   sim_engine_halt_jmpval,
504e98e3e1Schristos   sim_engine_restart_jmpval,
514e98e3e1Schristos };
524e98e3e1Schristos 
534e98e3e1Schristos 
544e98e3e1Schristos /* Get/set the run state of CPU to REASON/SIGRC.
554e98e3e1Schristos    REASON/SIGRC are the values returned by sim_stop_reason.  */
564e98e3e1Schristos void sim_engine_get_run_state (SIM_DESC sd, enum sim_stop *reason, int *sigrc);
574e98e3e1Schristos void sim_engine_set_run_state (SIM_DESC sd, enum sim_stop reason, int sigrc);
584e98e3e1Schristos 
594e98e3e1Schristos 
604e98e3e1Schristos /* Halt the simulator *now* */
614e98e3e1Schristos 
624e98e3e1Schristos extern void sim_engine_halt
634e98e3e1Schristos (SIM_DESC sd,
644e98e3e1Schristos  sim_cpu *last_cpu, /* NULL -> in event-mgr */
654e98e3e1Schristos  sim_cpu *next_cpu, /* NULL -> succ (last_cpu) or event-mgr */
664e98e3e1Schristos  sim_cia cia,
674e98e3e1Schristos  enum sim_stop reason,
684b169a6bSchristos  int sigrc) ATTRIBUTE_NORETURN;
694e98e3e1Schristos 
704e98e3e1Schristos /* Halt hook - allow target specific operation when halting a
714e98e3e1Schristos    simulator */
724e98e3e1Schristos 
734e98e3e1Schristos #if !defined (SIM_ENGINE_HALT_HOOK)
744e98e3e1Schristos #define SIM_ENGINE_HALT_HOOK(SD, LAST_CPU, CIA) \
75212397c6Schristos if ((LAST_CPU) != NULL) CPU_PC_SET (LAST_CPU, CIA)
764e98e3e1Schristos #endif
774e98e3e1Schristos 
784e98e3e1Schristos /* NB: If a port uses the SIM_CPU_EXCEPTION_* hooks, the default
794e98e3e1Schristos    SIM_ENGINE_HALT_HOOK and SIM_ENGINE_RESUME_HOOK must not be used.
804e98e3e1Schristos    They conflict in that the PC set by the HALT_HOOK may overwrite the
814e98e3e1Schristos    proper one, as intended to be saved by the EXCEPTION_TRIGGER
824e98e3e1Schristos    hook. */
834e98e3e1Schristos 
844e98e3e1Schristos 
854e98e3e1Schristos /* restart the simulator *now* */
864e98e3e1Schristos 
874e98e3e1Schristos extern void sim_engine_restart
884e98e3e1Schristos (SIM_DESC sd,
894e98e3e1Schristos  sim_cpu *last_cpu, /* NULL -> in event-mgr */
904e98e3e1Schristos  sim_cpu *next_cpu, /* NULL -> succ (last_cpu) or event-mgr */
91*88241920Schristos  sim_cia cia) ATTRIBUTE_NORETURN;
924e98e3e1Schristos 
934e98e3e1Schristos /* Restart hook - allow target specific operation when restarting a
944e98e3e1Schristos    simulator */
954e98e3e1Schristos 
964e98e3e1Schristos #if !defined (SIM_ENGINE_RESTART_HOOK)
974e98e3e1Schristos #define SIM_ENGINE_RESTART_HOOK(SD, LAST_CPU, CIA) SIM_ENGINE_HALT_HOOK(SD, LAST_CPU, CIA)
984e98e3e1Schristos #endif
994e98e3e1Schristos 
1004e98e3e1Schristos 
1014e98e3e1Schristos 
1024e98e3e1Schristos 
1034e98e3e1Schristos /* Abort the simulator *now*.
1044e98e3e1Schristos 
1054e98e3e1Schristos    This function is NULL safe.  It can be called when either of SD or
1064e98e3e1Schristos    CIA are NULL.
1074e98e3e1Schristos 
1084e98e3e1Schristos    This function is setjmp/longjmp safe.  It can be called when of
1094e98e3e1Schristos    the sim_engine setjmp/longjmp buffer has not been established.
1104e98e3e1Schristos 
1114e98e3e1Schristos    Simulators that are using components such as sim-core but are not
1124e98e3e1Schristos    yet using this sim-engine module should link in file sim-abort.o
1134e98e3e1Schristos    which implements a non setjmp/longjmp version of
1144e98e3e1Schristos    sim_engine_abort. */
1154e98e3e1Schristos 
1164e98e3e1Schristos extern void sim_engine_abort
1174e98e3e1Schristos (SIM_DESC sd,
1184e98e3e1Schristos  sim_cpu *cpu,
1194e98e3e1Schristos  sim_cia cia,
1204e98e3e1Schristos  const char *fmt,
1214b169a6bSchristos  ...) ATTRIBUTE_PRINTF (4, 5) ATTRIBUTE_NORETURN;
1224e98e3e1Schristos 
1234e98e3e1Schristos extern void sim_engine_vabort
1244e98e3e1Schristos (SIM_DESC sd,
1254e98e3e1Schristos  sim_cpu *cpu,
1264e98e3e1Schristos  sim_cia cia,
1274e98e3e1Schristos  const char *fmt,
1284b169a6bSchristos  va_list ap) ATTRIBUTE_PRINTF (4, 0) ATTRIBUTE_NORETURN;
1294e98e3e1Schristos 
1304e98e3e1Schristos /* No abort hook - when possible this function exits using the
1314e98e3e1Schristos    engine_halt function (and SIM_ENGINE_HALT_HOOK). */
1324e98e3e1Schristos 
1334e98e3e1Schristos 
1344e98e3e1Schristos 
1354e98e3e1Schristos 
1364e98e3e1Schristos /* Called by the generic sim_resume to run the simulation within the
1374e98e3e1Schristos    above safty net.
1384e98e3e1Schristos 
1394e98e3e1Schristos    An example implementation of sim_engine_run can be found in the
1404e98e3e1Schristos    file sim-run.c */
1414e98e3e1Schristos 
1424e98e3e1Schristos extern void sim_engine_run
1434e98e3e1Schristos (SIM_DESC sd,
1444e98e3e1Schristos  int next_cpu_nr,
1454e98e3e1Schristos  int nr_cpus,
1464e98e3e1Schristos  int siggnal); /* most simulators ignore siggnal */
1474e98e3e1Schristos 
1484e98e3e1Schristos 
1494e98e3e1Schristos 
1504e98e3e1Schristos /* Determine the state of next/last cpu when the simulator was last
1514e98e3e1Schristos    halted - a value >= MAX_NR_PROCESSORS indicates that the
1524e98e3e1Schristos    event-queue was next/last. */
1534e98e3e1Schristos 
1544e98e3e1Schristos extern int sim_engine_next_cpu_nr (SIM_DESC sd);
1554e98e3e1Schristos extern int sim_engine_last_cpu_nr (SIM_DESC sd);
1564e98e3e1Schristos extern int sim_engine_nr_cpus (SIM_DESC sd);
1574e98e3e1Schristos 
1584e98e3e1Schristos 
1594e98e3e1Schristos #endif
160