1 /* Hardware event manager.
2 Copyright (C) 1998 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 This file is part of GDB, the GNU debugger.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 #include "sim-events.h"
28 /* The hw-events object is implemented using sim-events */
33 hw_event_callback
*callback
;
35 struct hw_event_data
*entry
;
38 struct hw_event_data
{
39 struct hw_event event
;
40 struct hw_event_data
*next
;
44 create_hw_event_data (struct hw
*me
)
46 if (me
->events_of_hw
!= NULL
)
47 hw_abort (me
, "stray events");
52 delete_hw_event_data (struct hw
*me
)
54 /* Remove the scheduled event. */
55 while (me
->events_of_hw
)
56 hw_event_queue_deschedule (me
, &me
->events_of_hw
->event
);
60 /* Pass the H/W event onto the real callback */
63 bounce_hw_event (SIM_DESC sd
,
67 struct hw_event_data
*entry
= (struct hw_event_data
*) data
;
68 struct hw
*me
= entry
->event
.me
;
69 void *event_data
= entry
->event
.data
;
70 hw_event_callback
*callback
= entry
->event
.callback
;
71 struct hw_event_data
**prev
= &me
->events_of_hw
;
72 while ((*prev
) != entry
)
73 prev
= &(*prev
)->next
;
74 (*prev
) = entry
->next
;
76 callback (me
, event_data
); /* may not return */
81 /* Map onto the event functions */
84 hw_event_queue_schedule (struct hw
*me
,
86 hw_event_callback
*callback
,
89 struct hw_event
*event
;
91 memset (&dummy
, 0, sizeof dummy
);
92 event
= hw_event_queue_schedule_vtracef (me
, delta_time
, callback
, data
,
98 hw_event_queue_schedule_tracef (struct hw
*me
,
100 hw_event_callback
*callback
,
105 struct hw_event
*event
;
108 event
= hw_event_queue_schedule_vtracef (me
, delta_time
, callback
, data
, fmt
, ap
);
114 hw_event_queue_schedule_vtracef (struct hw
*me
,
116 hw_event_callback
*callback
,
121 struct hw_event_data
*entry
= HW_ZALLOC (me
, struct hw_event_data
);
122 entry
->next
= me
->events_of_hw
;
123 me
->events_of_hw
= entry
;
125 entry
->event
.entry
= entry
;
126 entry
->event
.data
= data
;
127 entry
->event
.callback
= callback
;
128 entry
->event
.me
= me
;
129 entry
->event
.real
= sim_events_schedule_vtracef (hw_system (me
),
134 return &entry
->event
;
139 hw_event_queue_deschedule (struct hw
*me
,
140 struct hw_event
*event_to_remove
)
142 /* ZAP the event but only if it is still in the event queue. Note
143 that event_to_remove is only de-referenced after its validity has
145 struct hw_event_data
**prev
;
146 for (prev
= &me
->events_of_hw
;
148 prev
= &(*prev
)->next
)
150 struct hw_event_data
*entry
= (*prev
);
151 if (&entry
->event
== event_to_remove
)
153 sim_events_deschedule (hw_system (me
),
155 (*prev
) = entry
->next
;
164 hw_event_queue_time (struct hw
*me
)
166 return sim_events_time (hw_system (me
));
169 /* Returns the time that remains before the event is raised. */
171 hw_event_remain_time (struct hw
*me
, struct hw_event
*event
)
175 t
= sim_events_remain_time (hw_system (me
), event
->real
);
179 /* Only worry about this compling on ANSI systems.
180 Build with `make test-hw-events' in sim/<cpu> directory*/
183 #include "sim-main.h"
188 test_handler (struct hw
*me
,
192 if (*n
!= hw_event_queue_time (me
))
201 host_callback
*cb
= ZALLOC (host_callback
);
202 struct sim_state
*sd
= sim_state_alloc (0, cb
);
203 struct hw
*me
= ZALLOC (struct hw
);
204 sim_pre_argv_init (sd
, "test-hw-events");
205 sim_post_argv_init (sd
);
206 me
->system_of_hw
= sd
;
208 printf ("Create hw-event-data\n");
210 create_hw_alloc_data (me
);
211 create_hw_event_data (me
);
212 delete_hw_event_data (me
);
213 delete_hw_alloc_data (me
);
216 printf ("Create hw-events\n");
222 create_hw_alloc_data (me
);
223 create_hw_event_data (me
);
224 a
= hw_event_queue_schedule (me
, 0, NULL
, NULL
);
225 b
= hw_event_queue_schedule (me
, 1, NULL
, NULL
);
226 c
= hw_event_queue_schedule (me
, 2, NULL
, NULL
);
227 d
= hw_event_queue_schedule (me
, 1, NULL
, NULL
);
228 hw_event_queue_deschedule (me
, c
);
229 hw_event_queue_deschedule (me
, b
);
230 hw_event_queue_deschedule (me
, a
);
231 hw_event_queue_deschedule (me
, d
);
232 c
= HW_ZALLOC (me
, struct hw_event
);
233 hw_event_queue_deschedule (me
, b
); /* OOPS! */
235 delete_hw_event_data (me
);
236 delete_hw_alloc_data (me
);
239 printf ("Schedule hw-events\n");
245 e
= HW_NZALLOC (me
, struct hw_event
*, nr
);
246 n
= HW_NZALLOC (me
, int, nr
);
247 create_hw_alloc_data (me
);
248 create_hw_event_data (me
);
249 for (i
= 0; i
< nr
; i
++)
252 e
[i
] = hw_event_queue_schedule (me
, i
, test_handler
, &n
[i
]);
254 sim_events_preprocess (sd
, 1, 1);
255 for (i
= 0; i
< nr
; i
++)
257 if (sim_events_tick (sd
))
258 sim_events_process (sd
);
260 for (i
= 0; i
< nr
; i
++)
264 hw_event_queue_deschedule (me
, e
[i
]);
268 delete_hw_event_data (me
);
269 delete_hw_alloc_data (me
);
This page took 0.034918 seconds and 4 git commands to generate.