1 /* The common simulator framework for GDB, the GNU Debugger.
3 Copyright 2002-2023 Free Software Foundation, Inc.
5 Contributed by Andrew Cagney and Red Hat.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
32 When scheduling an event, the a delta of zero/one refers to the
36 **queue**|--insn--|*queue*|--insn--|*queue*|--insn--|*queue*|
38 `- +0 ------------ +1 --.. `----- +0 ------------- +1 --..
40 When the queue is initialized, the time is set to zero with a
41 number of initialization events scheduled. Consequently, as also
42 illustrated above, the event queue should be processed before the
43 first instruction. That instruction being executed during tick 1.
45 The simulator main loop may take a form similar to:
47 if (halt-/restart-setjmp)
50 .... // Determine who should go next
51 last-cpu-nr = get-last-cpu-nr (sd);
52 next-cpu-nr = get-next-cpu-nr (sd);
53 events-were-last? = (last-cpu-nr >= nr-cpus);
54 events-were-next? = (next-cpu-nr >= nr-cpus);
56 .... // process any outstanding events
57 sim_events_preprocess (sd, events-were-last?, events-were-next?);
61 .... // prime main loop
65 .... // model one insn of next-cpu-nr .. nr-cpus
66 if (sim_events_tick (sd))
67 sim_events_process (sd);
72 NB. In the above pseudo code it is assumed that any cpu-nr >=
73 nr-cpus is a marker for the event queue. */
76 typedef void sim_event_handler(SIM_DESC sd
, void *data
);
78 typedef struct _sim_event sim_event
;
80 typedef struct _sim_events sim_events
;
82 int nr_ticks_to_process
;
84 sim_event
*watchpoints
;
85 sim_event
*watchedpoints
;
87 /* flag additional work needed */
88 volatile int work_pending
;
89 /* the asynchronous event queue */
90 #ifndef MAX_NR_SIGNAL_SIM_EVENTS
91 #define MAX_NR_SIGNAL_SIM_EVENTS 2
96 unsigned long elapsed_wallclock
;
97 SIM_ELAPSED_TIME resume_wallclock
;
98 int64_t time_of_event
;
99 int64_t time_from_event
;
104 /* Install the "events" module. */
106 extern SIM_RC
sim_events_install (SIM_DESC sd
);
109 /* Schedule an event DELTA_TIME ticks into the future */
111 extern sim_event
*sim_events_schedule
114 sim_event_handler
*handler
,
117 extern sim_event
*sim_events_schedule_tracef
120 sim_event_handler
*handler
,
123 ...) ATTRIBUTE_NULL_PRINTF (5, 6);
125 extern sim_event
*sim_events_schedule_vtracef
128 sim_event_handler
*handler
,
131 va_list ap
) ATTRIBUTE_NULL_PRINTF (5, 0);
134 extern void sim_events_schedule_after_signal
137 sim_event_handler
*handler
,
140 /* NB: signal level events can't have trace strings as malloc isn't
145 /* Schedule an event milli-seconds from NOW. The exact interpretation
146 of wallclock is host dependant. */
148 extern sim_event
*sim_events_watch_clock
150 unsigned delta_ms_time
,
151 sim_event_handler
*handler
,
155 /* Schedule an event when a PC matches a range. */
157 extern sim_event
*sim_events_watch_pc
162 sim_event_handler
*handler
,
166 /* Schedule an event when the test (IS_WITHIN == (VAL >= LB && VAL <=
167 UB)) of the NR_BYTES value at HOST_ADDR with BYTE_ORDER endian is
170 HOST_ADDR: pointer into the host address space.
171 BYTE_ORDER: BFD_ENDIAN_UNKNOWN - host endian; BFD_ENDIAN_BIG;
172 BFD_ENDIAN_LITTLE. */
174 extern sim_event
*sim_events_watch_sim
178 enum bfd_endian byte_order
,
182 sim_event_handler
*handler
,
186 /* Schedule an event when the test (IS_WITHIN == (VAL >= LB && VAL <=
187 UB)) of the NR_BYTES value at CORE_ADDR in BYTE_ORDER endian is
190 CORE_ADDR/MAP: pointer into the target address space.
191 BYTE_ORDER: BFD_ENDIAN_UNKNOWN - host endian; BFD_ENDIAN_BIG;
192 BFD_ENDIAN_LITTLE. */
194 extern sim_event
*sim_events_watch_core
196 address_word core_addr
,
199 enum bfd_endian byte_order
,
203 sim_event_handler
*handler
,
206 /* Deschedule the specified event */
208 extern void sim_events_deschedule
210 sim_event
*event_to_remove
);
213 /* Prepare for main simulator loop. Ensure that the next thing to do
214 is not event processing.
216 If the simulator halted part way through event processing then both
217 EVENTS_WERE_LAST and EVENTS_WERE_NEXT shall be true.
219 If the simulator halted after processing the last cpu, then only
220 EVENTS_WERE_NEXT shall be true. */
223 (void) sim_events_preprocess
225 int events_were_last
,
226 int events_were_next
);
231 Separated into two parts so that the main loop can save its context
232 before the event queue is processed. When sim_events_tick*()
233 returns true, any simulation context should be saved and
234 sim_events_process() called.
236 SIM_EVENTS_TICK advances the clock by 1 cycle.
238 SIM_EVENTS_TICKN advances the clock by N cycles (1..MAXINT). */
241 (int) sim_events_tick
245 (int) sim_events_tickn
250 (void) sim_events_process
254 /* Advance the clock by an additional SLIP cycles at the next call to
255 sim_events_tick*(). For multiple calls, the effect is
259 (void) sim_events_slip
264 /* Progress time such that an event shall occur upon the next call to
269 (void) sim_events_timewarp
274 /* local concept of elapsed target time */
277 (int64_t) sim_events_time
281 /* local concept of elapsed host time (milliseconds) */
284 (unsigned long) sim_events_elapsed_time
287 /* Returns the time that remains before the event is raised. */
289 (int64_t) sim_events_remain_time
290 (SIM_DESC sd
, sim_event
*event
);