]>
Commit | Line | Data |
---|---|---|
b85e4829 AC |
1 | /* The common simulator framework for GDB, the GNU Debugger. |
2 | ||
3666a048 | 3 | Copyright 2002-2021 Free Software Foundation, Inc. |
b85e4829 AC |
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 | |
4744ac1b | 11 | the Free Software Foundation; either version 3 of the License, or |
b85e4829 AC |
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 | |
4744ac1b | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
21 | |
22 | ||
23 | #ifndef SIM_EVENTS_H | |
24 | #define SIM_EVENTS_H | |
25 | ||
26 | ||
27 | /* Notes: | |
28 | ||
29 | When scheduling an event, the a delta of zero/one refers to the | |
30 | timeline as follows: | |
31 | ||
32 | epoch 0|1 1|2 2|3 3| | |
33 | **queue**|--insn--|*queue*|--insn--|*queue*|--insn--|*queue*| | |
34 | | ^ ^ | ^ ^ | |
35 | `- +0 ------------ +1 --.. `----- +0 ------------- +1 --.. | |
36 | ||
37 | When the queue is initialized, the time is set to zero with a | |
38 | number of initialization events scheduled. Consequently, as also | |
39 | illustrated above, the event queue should be processed before the | |
40 | first instruction. That instruction being executed during tick 1. | |
41 | ||
42 | The simulator main loop may take a form similar to: | |
43 | ||
44 | if (halt-/restart-setjmp) | |
45 | { | |
46 | ||
47 | .... // Determine who should go next | |
48 | last-cpu-nr = get-last-cpu-nr (sd); | |
49 | next-cpu-nr = get-next-cpu-nr (sd); | |
50 | events-were-last? = (last-cpu-nr >= nr-cpus); | |
51 | events-were-next? = (next-cpu-nr >= nr-cpus); | |
52 | ||
53 | .... // process any outstanding events | |
54 | sim_events_preprocess (sd, events-were-last?, events-were-next?); | |
55 | if (events-were-next) | |
56 | next-cpu-nr = 0; | |
57 | ||
028f6515 | 58 | .... // prime main loop |
c906108c SS |
59 | |
60 | while (1) | |
61 | { | |
62 | .... // model one insn of next-cpu-nr .. nr-cpus | |
63 | if (sim_events_tick (sd)) | |
64 | sim_events_process (sd); | |
65 | next-cpu-nr = 0 | |
66 | } | |
67 | } | |
68 | ||
69 | NB. In the above pseudo code it is assumed that any cpu-nr >= | |
70 | nr-cpus is a marker for the event queue. */ | |
71 | ||
72 | ||
73 | typedef void sim_event_handler(SIM_DESC sd, void *data); | |
74 | ||
75 | typedef struct _sim_event sim_event; | |
76 | ||
77 | typedef struct _sim_events sim_events; | |
78 | struct _sim_events { | |
79 | int nr_ticks_to_process; | |
80 | sim_event *queue; | |
81 | sim_event *watchpoints; | |
82 | sim_event *watchedpoints; | |
83 | sim_event *free_list; | |
84 | /* flag additional work needed */ | |
85 | volatile int work_pending; | |
86 | /* the asynchronous event queue */ | |
87 | #ifndef MAX_NR_SIGNAL_SIM_EVENTS | |
88 | #define MAX_NR_SIGNAL_SIM_EVENTS 2 | |
89 | #endif | |
90 | sim_event *held; | |
91 | volatile int nr_held; | |
92 | /* timekeeping */ | |
93 | unsigned long elapsed_wallclock; | |
94 | SIM_ELAPSED_TIME resume_wallclock; | |
95 | signed64 time_of_event; | |
891e7fb1 | 96 | signed64 time_from_event; |
c906108c SS |
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, | |
2f632133 | 120 | ...) ATTRIBUTE_NULL_PRINTF (5, 6); |
c906108c SS |
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, | |
2f632133 | 128 | va_list ap) ATTRIBUTE_NULL_PRINTF (5, 0); |
c906108c SS |
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 | ||
4c0d76b9 MF |
152 | /* Schedule an event when a PC matches a range. */ |
153 | ||
154 | extern sim_event *sim_events_watch_pc | |
155 | (SIM_DESC sd, | |
156 | int is_within, | |
157 | unsigned64 lb, | |
158 | unsigned64 ub, | |
159 | sim_event_handler *handler, | |
160 | void *data); | |
161 | ||
162 | ||
c906108c SS |
163 | /* Schedule an event when the test (IS_WITHIN == (VAL >= LB && VAL <= |
164 | UB)) of the NR_BYTES value at HOST_ADDR with BYTE_ORDER endian is | |
165 | true. | |
166 | ||
167 | HOST_ADDR: pointer into the host address space. | |
1ac72f06 MF |
168 | BYTE_ORDER: BFD_ENDIAN_UNKNOWN - host endian; BFD_ENDIAN_BIG; |
169 | BFD_ENDIAN_LITTLE. */ | |
c906108c SS |
170 | |
171 | extern sim_event *sim_events_watch_sim | |
172 | (SIM_DESC sd, | |
173 | void *host_addr, | |
174 | int nr_bytes, | |
62fe7512 | 175 | enum bfd_endian byte_order, |
c906108c SS |
176 | int is_within, |
177 | unsigned64 lb, | |
178 | unsigned64 ub, | |
179 | sim_event_handler *handler, | |
180 | void *data); | |
181 | ||
182 | ||
183 | /* Schedule an event when the test (IS_WITHIN == (VAL >= LB && VAL <= | |
184 | UB)) of the NR_BYTES value at CORE_ADDR in BYTE_ORDER endian is | |
185 | true. | |
186 | ||
187 | CORE_ADDR/MAP: pointer into the target address space. | |
1ac72f06 MF |
188 | BYTE_ORDER: BFD_ENDIAN_UNKNOWN - host endian; BFD_ENDIAN_BIG; |
189 | BFD_ENDIAN_LITTLE. */ | |
c906108c SS |
190 | |
191 | extern sim_event *sim_events_watch_core | |
192 | (SIM_DESC sd, | |
193 | address_word core_addr, | |
194 | unsigned map, | |
195 | int nr_bytes, | |
62fe7512 | 196 | enum bfd_endian byte_order, |
c906108c SS |
197 | int is_within, |
198 | unsigned64 lb, | |
199 | unsigned64 ub, | |
200 | sim_event_handler *handler, | |
201 | void *data); | |
202 | ||
203 | /* Deschedule the specified event */ | |
204 | ||
205 | extern void sim_events_deschedule | |
206 | (SIM_DESC sd, | |
207 | sim_event *event_to_remove); | |
208 | ||
209 | ||
210 | /* Prepare for main simulator loop. Ensure that the next thing to do | |
211 | is not event processing. | |
212 | ||
213 | If the simulator halted part way through event processing then both | |
214 | EVENTS_WERE_LAST and EVENTS_WERE_NEXT shall be true. | |
215 | ||
216 | If the simulator halted after processing the last cpu, then only | |
217 | EVENTS_WERE_NEXT shall be true. */ | |
218 | ||
219 | INLINE_SIM_EVENTS\ | |
220 | (void) sim_events_preprocess | |
221 | (SIM_DESC sd, | |
222 | int events_were_last, | |
223 | int events_were_next); | |
224 | ||
225 | ||
226 | /* Progress time. | |
227 | ||
228 | Separated into two parts so that the main loop can save its context | |
229 | before the event queue is processed. When sim_events_tick*() | |
230 | returns true, any simulation context should be saved and | |
231 | sim_events_process() called. | |
232 | ||
233 | SIM_EVENTS_TICK advances the clock by 1 cycle. | |
234 | ||
235 | SIM_EVENTS_TICKN advances the clock by N cycles (1..MAXINT). */ | |
236 | ||
237 | INLINE_SIM_EVENTS\ | |
238 | (int) sim_events_tick | |
239 | (SIM_DESC sd); | |
240 | ||
241 | INLINE_SIM_EVENTS\ | |
242 | (int) sim_events_tickn | |
243 | (SIM_DESC sd, | |
244 | int n); | |
245 | ||
246 | INLINE_SIM_EVENTS\ | |
247 | (void) sim_events_process | |
248 | (SIM_DESC sd); | |
249 | ||
250 | ||
251 | /* Advance the clock by an additional SLIP cycles at the next call to | |
252 | sim_events_tick*(). For multiple calls, the effect is | |
253 | accumulative. */ | |
254 | ||
255 | INLINE_SIM_EVENTS\ | |
256 | (void) sim_events_slip | |
257 | (SIM_DESC sd, | |
258 | int slip); | |
259 | ||
260 | ||
6439295f | 261 | /* Progress time such that an event shall occur upon the next call to |
c906108c SS |
262 | sim_events tick */ |
263 | ||
264 | #if 0 | |
265 | INLINE_SIM_EVENTS\ | |
266 | (void) sim_events_timewarp | |
267 | (SIM_DESC sd); | |
268 | #endif | |
269 | ||
270 | ||
271 | /* local concept of elapsed target time */ | |
272 | ||
273 | INLINE_SIM_EVENTS\ | |
274 | (signed64) sim_events_time | |
275 | (SIM_DESC sd); | |
276 | ||
277 | ||
278 | /* local concept of elapsed host time (milliseconds) */ | |
279 | ||
280 | INLINE_SIM_EVENTS\ | |
281 | (unsigned long) sim_events_elapsed_time | |
282 | (SIM_DESC sd); | |
283 | ||
38e64f35 AC |
284 | /* Returns the time that remains before the event is raised. */ |
285 | INLINE_SIM_EVENTS\ | |
286 | (signed64) sim_events_remain_time | |
287 | (SIM_DESC sd, sim_event *event); | |
288 | ||
289 | ||
c906108c | 290 | #endif |