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