o Implement generic halt/restart/abort module.
[deliverable/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 processing;
79 sim_event *queue;
80 sim_event *watchpoints;
81 sim_event *watchedpoints;
82 /* flag additional work needed */
83 volatile int work_pending;
84 /* the asynchronous event queue */
85 sim_event *volatile held;
86 sim_event *volatile *volatile held_end;
87 /* timekeeping */
88 SIM_ELAPSED_TIME initial_wallclock;
89 signed64 time_of_event;
90 int time_from_event;
91 int trace;
92 };
93
94
95
96 /* Install the "events" module. */
97
98 EXTERN_SIM_EVENTS\
99 (SIM_RC) sim_events_install (SIM_DESC sd);
100
101
102 /* Uninstall the "events" subsystem. */
103
104 EXTERN_SIM_EVENTS\
105 (void)
106 sim_events_uninstall (SIM_DESC sd);
107
108
109
110 /* Initialization */
111
112 EXTERN_SIM_EVENTS\
113 (SIM_RC) sim_events_init (SIM_DESC sd);
114
115
116 /* Set Tracing Level */
117
118 EXTERN_SIM_EVENTS\
119 (void) sim_events_set_trace
120 (SIM_DESC sd,
121 int level);
122
123
124 /* Schedule an event DELTA_TIME ticks into the future */
125
126 EXTERN_SIM_EVENTS\
127 (sim_event *) sim_events_schedule
128 (SIM_DESC sd,
129 signed64 delta_time,
130 sim_event_handler *handler,
131 void *data);
132
133 EXTERN_SIM_EVENTS\
134 (sim_event *) sim_events_schedule_after_signal
135 (SIM_DESC sd,
136 signed64 delta_time,
137 sim_event_handler *handler,
138 void *data);
139
140
141 /* Schedule an event WALLCLOCK milli-seconds from the start of the
142 simulation. The exact interpretation of wallclock is host
143 dependant. */
144
145 EXTERN_SIM_EVENTS\
146 (sim_event *) sim_events_watch_clock
147 (SIM_DESC sd,
148 unsigned wallclock_ms_time,
149 sim_event_handler *handler,
150 void *data);
151
152
153 /* Schedule an event when the NR_BYTES value at HOST_ADDR with
154 BYTE_ORDER lies within LB..UB (unsigned).
155
156 HOST_ADDR: pointer into the host address space.
157 BYTE_ORDER: 0 - host endian; BIG_ENDIAN; LITTLE_ENDIAN */
158
159 EXTERN_SIM_EVENTS\
160 (sim_event*) sim_events_watch_sim
161 (SIM_DESC sd,
162 void *host_addr,
163 int nr_bytes,
164 int byte_order,
165 unsigned64 lb,
166 unsigned64 ub,
167 sim_event_handler *handler,
168 void *data);
169
170
171 /* Schedule an event when the NR_BYTES value at CORE_ADDR with BYTE_ORDER
172 lies between LB..UB.
173
174 CORE_ADDR/MAP: pointer into the target address space.
175 BYTE_ORDER: 0 - current target endian; BIG_ENDIAN; LITTLE_ENDIAN */
176
177 EXTERN_SIM_EVENTS\
178 (sim_event*) sim_events_watch_core
179 (SIM_DESC sd,
180 address_word core_addr,
181 sim_core_maps core_map,
182 int nr_bytes,
183 int byte_order,
184 unsigned64 lb,
185 unsigned64 ub,
186 sim_event_handler *handler,
187 void *data);
188
189
190 /* Deschedule the specified event */
191
192 EXTERN_SIM_EVENTS\
193 (void) sim_events_deschedule
194 (SIM_DESC sd,
195 sim_event *event_to_remove);
196
197
198 /* Prepare for main simulator loop. Ensure that the next thing to do
199 is not event processing.
200
201 If the simulator halted part way through event processing then both
202 EVENTS_WERE_LAST and EVENTS_WERE_FIRST shall be true.
203
204 If the simulator halted after processing the last cpu, then only
205 EVENTS_WERE_NEXT shall be true. */
206
207 INLINE_SIM_EVENTS\
208 (void) sim_events_preprocess
209 (SIM_DESC sd,
210 int events_were_last,
211 int events_were_next);
212
213
214 /* Progress time - separated into two parts so that the main loop can
215 save its context before the event queue is processed */
216
217 INLINE_SIM_EVENTS\
218 (int) sim_events_tick
219 (SIM_DESC sd);
220
221 INLINE_SIM_EVENTS\
222 (void) sim_events_process
223 (SIM_DESC sd);
224
225
226
227 /* local concept of time */
228
229 INLINE_SIM_EVENTS\
230 (signed64) sim_events_time
231 (SIM_DESC sd);
232
233
234 #endif
This page took 0.035192 seconds and 4 git commands to generate.