]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/common/sim-engine.h
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / sim / common / sim-engine.h
1 /* Generic simulator halt/resume.
2 Copyright (C) 1997-2023 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
4
5 This file is part of GDB, the GNU debugger.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #ifndef SIM_ENGINE_H
21 #define SIM_ENGINE_H
22
23 #include <stdarg.h>
24
25 #include "ansidecl.h"
26
27 typedef struct _sim_engine sim_engine;
28 struct _sim_engine
29 {
30 void *jmpbuf;
31 sim_cpu *last_cpu;
32 sim_cpu *next_cpu;
33 int nr_cpus;
34 enum sim_stop reason;
35 sim_event *stepper;
36 int sigrc;
37 };
38
39
40
41 /* jmpval: 0 (initial use) start simulator
42 1 halt simulator
43 2 restart simulator
44 This is required by the ISO C standard (the only time 0 is returned
45 is at the initial call to setjmp). */
46
47 enum {
48 sim_engine_start_jmpval,
49 sim_engine_halt_jmpval,
50 sim_engine_restart_jmpval,
51 };
52
53
54 /* Get/set the run state of CPU to REASON/SIGRC.
55 REASON/SIGRC are the values returned by sim_stop_reason. */
56 void sim_engine_get_run_state (SIM_DESC sd, enum sim_stop *reason, int *sigrc);
57 void sim_engine_set_run_state (SIM_DESC sd, enum sim_stop reason, int sigrc);
58
59
60 /* Halt the simulator *now* */
61
62 extern void sim_engine_halt
63 (SIM_DESC sd,
64 sim_cpu *last_cpu, /* NULL -> in event-mgr */
65 sim_cpu *next_cpu, /* NULL -> succ (last_cpu) or event-mgr */
66 sim_cia cia,
67 enum sim_stop reason,
68 int sigrc) ATTRIBUTE_NORETURN;
69
70 /* Halt hook - allow target specific operation when halting a
71 simulator */
72
73 #if !defined (SIM_ENGINE_HALT_HOOK)
74 #define SIM_ENGINE_HALT_HOOK(SD, LAST_CPU, CIA) \
75 if ((LAST_CPU) != NULL) CPU_PC_SET (LAST_CPU, CIA)
76 #endif
77
78 /* NB: If a port uses the SIM_CPU_EXCEPTION_* hooks, the default
79 SIM_ENGINE_HALT_HOOK and SIM_ENGINE_RESUME_HOOK must not be used.
80 They conflict in that the PC set by the HALT_HOOK may overwrite the
81 proper one, as intended to be saved by the EXCEPTION_TRIGGER
82 hook. */
83
84
85 /* restart the simulator *now* */
86
87 extern void sim_engine_restart
88 (SIM_DESC sd,
89 sim_cpu *last_cpu, /* NULL -> in event-mgr */
90 sim_cpu *next_cpu, /* NULL -> succ (last_cpu) or event-mgr */
91 sim_cia cia);
92
93 /* Restart hook - allow target specific operation when restarting a
94 simulator */
95
96 #if !defined (SIM_ENGINE_RESTART_HOOK)
97 #define SIM_ENGINE_RESTART_HOOK(SD, LAST_CPU, CIA) SIM_ENGINE_HALT_HOOK(SD, LAST_CPU, CIA)
98 #endif
99
100
101
102
103 /* Abort the simulator *now*.
104
105 This function is NULL safe. It can be called when either of SD or
106 CIA are NULL.
107
108 This function is setjmp/longjmp safe. It can be called when of
109 the sim_engine setjmp/longjmp buffer has not been established.
110
111 Simulators that are using components such as sim-core but are not
112 yet using this sim-engine module should link in file sim-abort.o
113 which implements a non setjmp/longjmp version of
114 sim_engine_abort. */
115
116 extern void sim_engine_abort
117 (SIM_DESC sd,
118 sim_cpu *cpu,
119 sim_cia cia,
120 const char *fmt,
121 ...) ATTRIBUTE_PRINTF (4, 5) ATTRIBUTE_NORETURN;
122
123 extern void sim_engine_vabort
124 (SIM_DESC sd,
125 sim_cpu *cpu,
126 sim_cia cia,
127 const char *fmt,
128 va_list ap) ATTRIBUTE_PRINTF (4, 0) ATTRIBUTE_NORETURN;
129
130 /* No abort hook - when possible this function exits using the
131 engine_halt function (and SIM_ENGINE_HALT_HOOK). */
132
133
134
135
136 /* Called by the generic sim_resume to run the simulation within the
137 above safty net.
138
139 An example implementation of sim_engine_run can be found in the
140 file sim-run.c */
141
142 extern void sim_engine_run
143 (SIM_DESC sd,
144 int next_cpu_nr,
145 int nr_cpus,
146 int siggnal); /* most simulators ignore siggnal */
147
148
149
150 /* Determine the state of next/last cpu when the simulator was last
151 halted - a value >= MAX_NR_PROCESSORS indicates that the
152 event-queue was next/last. */
153
154 extern int sim_engine_next_cpu_nr (SIM_DESC sd);
155 extern int sim_engine_last_cpu_nr (SIM_DESC sd);
156 extern int sim_engine_nr_cpus (SIM_DESC sd);
157
158
159 #endif