1 /* This file is part of the program psim.
3 Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #ifndef _SIM_EVENTS_H_
23 #define _SIM_EVENTS_H_
28 When scheduling an event, the a delta of zero/one refers to the
32 **queue**|--insn--|*queue*|--insn--|*queue*|--insn--|*queue*|
34 `- +0 ------------ +1 --.. `----- +0 ------------- +1 --..
36 When the queue is initialized, the time is set to zero with a
37 number of initialization events scheduled. Consequently, as also
38 illustrated above, the event queue should be processed before the
39 first instruction. That instruction being executed during tick 1.
41 The simulator main loop may take a form similar to:
43 if (halt-/restart-setjmp)
46 .... // Determine who should go next
47 last-cpu-nr = get-last-cpu-nr (sd);
48 next-cpu-nr = get-next-cpu-nr (sd);
49 events-were-last? = (last-cpu-nr >= nr-cpus);
50 events-were-next? = (next-cpu-nr >= nr-cpus);
52 .... // process any outstanding events
53 sim_events_preprocess (sd, events-were-last?, events-were-next?);
57 .... // prime main loop
61 .... // model one insn of next-cpu-nr .. nr-cpus
62 if (sim_events_tick (sd))
63 sim_events_process (sd);
68 NB. In the above pseudo code it is assumed that any cpu-nr >=
69 nr-cpus is a marker for the event queue. */
72 typedef void sim_event_handler(SIM_DESC sd
, void *data
);
74 typedef struct _sim_event sim_event
;
76 typedef struct _sim_events sim_events
;
78 int nr_ticks_to_process
;
80 sim_event
*watchpoints
;
81 sim_event
*watchedpoints
;
83 /* flag additional work needed */
84 volatile int work_pending
;
85 /* the asynchronous event queue */
86 #ifndef MAX_NR_SIGNAL_SIM_EVENTS
87 #define MAX_NR_SIGNAL_SIM_EVENTS 2
92 unsigned long elapsed_wallclock
;
93 SIM_ELAPSED_TIME resume_wallclock
;
94 signed64 time_of_event
;
101 /* Install the "events" module. */
104 (SIM_RC
) sim_events_install (SIM_DESC sd
);
107 /* Set Tracing Level */
110 (void) sim_events_set_trace
115 /* Schedule an event DELTA_TIME ticks into the future */
118 (sim_event
*) sim_events_schedule
121 sim_event_handler
*handler
,
125 (void) sim_events_schedule_after_signal
128 sim_event_handler
*handler
,
132 /* Schedule an event milli-seconds from NOW. The exact interpretation
133 of wallclock is host dependant. */
136 (sim_event
*) sim_events_watch_clock
138 unsigned delta_ms_time
,
139 sim_event_handler
*handler
,
143 /* Schedule an event when the test (IS_WITHIN == (VAL >= LB && VAL <=
144 UB)) of the NR_BYTES value at HOST_ADDR with BYTE_ORDER endian is
147 HOST_ADDR: pointer into the host address space.
148 BYTE_ORDER: 0 - host endian; BIG_ENDIAN; LITTLE_ENDIAN */
151 (sim_event
*) sim_events_watch_sim
159 sim_event_handler
*handler
,
163 /* Schedule an event when the test (IS_WITHIN == (VAL >= LB && VAL <=
164 UB)) of the NR_BYTES value at CORE_ADDR in BYTE_ORDER endian is
167 CORE_ADDR/MAP: pointer into the target address space.
168 BYTE_ORDER: 0 - current target endian; BIG_ENDIAN; LITTLE_ENDIAN */
171 (sim_event
*) sim_events_watch_core
173 address_word core_addr
,
174 sim_core_maps core_map
,
180 sim_event_handler
*handler
,
183 /* Deschedule the specified event */
186 (void) sim_events_deschedule
188 sim_event
*event_to_remove
);
191 /* Prepare for main simulator loop. Ensure that the next thing to do
192 is not event processing.
194 If the simulator halted part way through event processing then both
195 EVENTS_WERE_LAST and EVENTS_WERE_FIRST shall be true.
197 If the simulator halted after processing the last cpu, then only
198 EVENTS_WERE_NEXT shall be true. */
201 (void) sim_events_preprocess
203 int events_were_last
,
204 int events_were_next
);
207 /* Progress time - separated into two parts so that the main loop can
208 save its context before the event queue is processed.
210 sim_events_tickn advances the clock by N cycles (1..MAXINT) */
213 (int) sim_events_tick
217 (int) sim_events_tickn
222 (void) sim_events_process
226 /* Progress time such that an event shall occure upon the next call to
231 (void) sim_events_timewarp
236 /* local concept of time */
239 (signed64
) sim_events_time