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