]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/common/sim-events.h
This commit was generated by cvs2svn to track changes on a CVS vendor
[thirdparty/binutils-gdb.git] / sim / common / sim-events.h
1 /* This file is part of the program psim.
2
3 Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
4
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.
9
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.
14
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.
18
19 */
20
21
22 #ifndef SIM_EVENTS_H
23 #define SIM_EVENTS_H
24
25
26 /* Notes:
27
28 When scheduling an event, the a delta of zero/one refers to the
29 timeline as follows:
30
31 epoch 0|1 1|2 2|3 3|
32 **queue**|--insn--|*queue*|--insn--|*queue*|--insn--|*queue*|
33 | ^ ^ | ^ ^
34 `- +0 ------------ +1 --.. `----- +0 ------------- +1 --..
35
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.
40
41 The simulator main loop may take a form similar to:
42
43 if (halt-/restart-setjmp)
44 {
45
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);
51
52 .... // process any outstanding events
53 sim_events_preprocess (sd, events-were-last?, events-were-next?);
54 if (events-were-next)
55 next-cpu-nr = 0;
56
57 .... // prime main loop
58
59 while (1)
60 {
61 .... // model one insn of next-cpu-nr .. nr-cpus
62 if (sim_events_tick (sd))
63 sim_events_process (sd);
64 next-cpu-nr = 0
65 }
66 }
67
68 NB. In the above pseudo code it is assumed that any cpu-nr >=
69 nr-cpus is a marker for the event queue. */
70
71
72 typedef void sim_event_handler(SIM_DESC sd, void *data);
73
74 typedef struct _sim_event sim_event;
75
76 typedef struct _sim_events sim_events;
77 struct _sim_events {
78 int nr_ticks_to_process;
79 sim_event *queue;
80 sim_event *watchpoints;
81 sim_event *watchedpoints;
82 sim_event *free_list;
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
88 #endif
89 sim_event *held;
90 volatile int nr_held;
91 /* timekeeping */
92 unsigned long elapsed_wallclock;
93 SIM_ELAPSED_TIME resume_wallclock;
94 signed64 time_of_event;
95 int time_from_event;
96 int trace;
97 };
98
99
100
101 /* Install the "events" module. */
102
103 extern SIM_RC sim_events_install (SIM_DESC sd);
104
105
106 /* Schedule an event DELTA_TIME ticks into the future */
107
108 extern sim_event *sim_events_schedule
109 (SIM_DESC sd,
110 signed64 delta_time,
111 sim_event_handler *handler,
112 void *data);
113
114 extern sim_event *sim_events_schedule_tracef
115 (SIM_DESC sd,
116 signed64 delta_time,
117 sim_event_handler *handler,
118 void *data,
119 const char *fmt,
120 ...) __attribute__ ((format (printf, 5, 6)));
121
122 extern sim_event *sim_events_schedule_vtracef
123 (SIM_DESC sd,
124 signed64 delta_time,
125 sim_event_handler *handler,
126 void *data,
127 const char *fmt,
128 va_list ap);
129
130
131 extern void sim_events_schedule_after_signal
132 (SIM_DESC sd,
133 signed64 delta_time,
134 sim_event_handler *handler,
135 void *data);
136
137 /* NB: signal level events can't have trace strings as malloc isn't
138 available */
139
140
141
142 /* Schedule an event milli-seconds from NOW. The exact interpretation
143 of wallclock is host dependant. */
144
145 extern sim_event *sim_events_watch_clock
146 (SIM_DESC sd,
147 unsigned delta_ms_time,
148 sim_event_handler *handler,
149 void *data);
150
151
152 /* Schedule an event when the test (IS_WITHIN == (VAL >= LB && VAL <=
153 UB)) of the NR_BYTES value at HOST_ADDR with BYTE_ORDER endian is
154 true.
155
156 HOST_ADDR: pointer into the host address space.
157 BYTE_ORDER: 0 - host endian; BIG_ENDIAN; LITTLE_ENDIAN */
158
159 extern sim_event *sim_events_watch_sim
160 (SIM_DESC sd,
161 void *host_addr,
162 int nr_bytes,
163 int byte_order,
164 int is_within,
165 unsigned64 lb,
166 unsigned64 ub,
167 sim_event_handler *handler,
168 void *data);
169
170
171 /* Schedule an event when the test (IS_WITHIN == (VAL >= LB && VAL <=
172 UB)) of the NR_BYTES value at CORE_ADDR in BYTE_ORDER endian is
173 true.
174
175 CORE_ADDR/MAP: pointer into the target address space.
176 BYTE_ORDER: 0 - current target endian; BIG_ENDIAN; LITTLE_ENDIAN */
177
178 extern sim_event *sim_events_watch_core
179 (SIM_DESC sd,
180 address_word core_addr,
181 unsigned map,
182 int nr_bytes,
183 int byte_order,
184 int is_within,
185 unsigned64 lb,
186 unsigned64 ub,
187 sim_event_handler *handler,
188 void *data);
189
190 /* Deschedule the specified event */
191
192 extern void sim_events_deschedule
193 (SIM_DESC sd,
194 sim_event *event_to_remove);
195
196
197 /* Prepare for main simulator loop. Ensure that the next thing to do
198 is not event processing.
199
200 If the simulator halted part way through event processing then both
201 EVENTS_WERE_LAST and EVENTS_WERE_NEXT shall be true.
202
203 If the simulator halted after processing the last cpu, then only
204 EVENTS_WERE_NEXT shall be true. */
205
206 INLINE_SIM_EVENTS\
207 (void) sim_events_preprocess
208 (SIM_DESC sd,
209 int events_were_last,
210 int events_were_next);
211
212
213 /* Progress time.
214
215 Separated into two parts so that the main loop can save its context
216 before the event queue is processed. When sim_events_tick*()
217 returns true, any simulation context should be saved and
218 sim_events_process() called.
219
220 SIM_EVENTS_TICK advances the clock by 1 cycle.
221
222 SIM_EVENTS_TICKN advances the clock by N cycles (1..MAXINT). */
223
224 INLINE_SIM_EVENTS\
225 (int) sim_events_tick
226 (SIM_DESC sd);
227
228 INLINE_SIM_EVENTS\
229 (int) sim_events_tickn
230 (SIM_DESC sd,
231 int n);
232
233 INLINE_SIM_EVENTS\
234 (void) sim_events_process
235 (SIM_DESC sd);
236
237
238 /* Advance the clock by an additional SLIP cycles at the next call to
239 sim_events_tick*(). For multiple calls, the effect is
240 accumulative. */
241
242 INLINE_SIM_EVENTS\
243 (void) sim_events_slip
244 (SIM_DESC sd,
245 int slip);
246
247
248 /* Progress time such that an event shall occure upon the next call to
249 sim_events tick */
250
251 #if 0
252 INLINE_SIM_EVENTS\
253 (void) sim_events_timewarp
254 (SIM_DESC sd);
255 #endif
256
257
258 /* local concept of elapsed target time */
259
260 INLINE_SIM_EVENTS\
261 (signed64) sim_events_time
262 (SIM_DESC sd);
263
264
265 /* local concept of elapsed host time (milliseconds) */
266
267 INLINE_SIM_EVENTS\
268 (unsigned long) sim_events_elapsed_time
269 (SIM_DESC sd);
270
271 #endif