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 event
= hw_event_queue_schedule_vtracef (me
, delta_time
, callback
, data
,
97 hw_event_queue_schedule_tracef (struct hw
*me
,
99 hw_event_callback
*callback
,
104 struct hw_event
*event
;
107 event
= hw_event_queue_schedule_vtracef (me
, delta_time
, callback
, data
, fmt
, ap
);
113 hw_event_queue_schedule_vtracef (struct hw
*me
,
115 hw_event_callback
*callback
,
120 struct hw_event_data
*entry
= HW_ZALLOC (me
, struct hw_event_data
);
121 entry
->next
= me
->events_of_hw
;
122 me
->events_of_hw
= entry
;
124 entry
->event
.entry
= entry
;
125 entry
->event
.data
= data
;
126 entry
->event
.callback
= callback
;
127 entry
->event
.me
= me
;
128 entry
->event
.real
= sim_events_schedule_vtracef (hw_system (me
),
133 return &entry
->event
;
138 hw_event_queue_deschedule (struct hw
*me
,
139 struct hw_event
*event_to_remove
)
141 /* ZAP the event but only if it is still in the event queue. Note
142 that event_to_remove is only de-referenced after its validity has
144 struct hw_event_data
**prev
;
145 for (prev
= &me
->events_of_hw
;
147 prev
= &(*prev
)->next
)
149 struct hw_event_data
*entry
= (*prev
);
150 if (&entry
->event
== event_to_remove
)
152 sim_events_deschedule (hw_system (me
),
154 (*prev
) = entry
->next
;
163 hw_event_queue_time (struct hw
*me
)
165 return sim_events_time (hw_system (me
));
168 /* Returns the time that remains before the event is raised. */
170 hw_event_remain_time (struct hw
*me
, struct hw_event
*event
)
174 t
= sim_events_remain_time (hw_system (me
), event
->real
);
178 /* Only worry about this compling on ANSI systems.
179 Build with `make test-hw-events' in sim/<cpu> directory*/
182 #include "sim-main.h"
187 test_handler (struct hw
*me
,
191 if (*n
!= hw_event_queue_time (me
))
200 host_callback
*cb
= ZALLOC (host_callback
);
201 struct sim_state
*sd
= sim_state_alloc (0, cb
);
202 struct hw
*me
= ZALLOC (struct hw
);
203 sim_pre_argv_init (sd
, "test-hw-events");
204 sim_post_argv_init (sd
);
205 me
->system_of_hw
= sd
;
207 printf ("Create hw-event-data\n");
209 create_hw_alloc_data (me
);
210 create_hw_event_data (me
);
211 delete_hw_event_data (me
);
212 delete_hw_alloc_data (me
);
215 printf ("Create hw-events\n");
221 create_hw_alloc_data (me
);
222 create_hw_event_data (me
);
223 a
= hw_event_queue_schedule (me
, 0, NULL
, NULL
);
224 b
= hw_event_queue_schedule (me
, 1, NULL
, NULL
);
225 c
= hw_event_queue_schedule (me
, 2, NULL
, NULL
);
226 d
= hw_event_queue_schedule (me
, 1, NULL
, NULL
);
227 hw_event_queue_deschedule (me
, c
);
228 hw_event_queue_deschedule (me
, b
);
229 hw_event_queue_deschedule (me
, a
);
230 hw_event_queue_deschedule (me
, d
);
231 c
= HW_ZALLOC (me
, struct hw_event
);
232 hw_event_queue_deschedule (me
, b
); /* OOPS! */
234 delete_hw_event_data (me
);
235 delete_hw_alloc_data (me
);
238 printf ("Schedule hw-events\n");
244 e
= HW_NZALLOC (me
, struct hw_event
*, nr
);
245 n
= HW_NZALLOC (me
, int, nr
);
246 create_hw_alloc_data (me
);
247 create_hw_event_data (me
);
248 for (i
= 0; i
< nr
; i
++)
251 e
[i
] = hw_event_queue_schedule (me
, i
, test_handler
, &n
[i
]);
253 sim_events_preprocess (sd
, 1, 1);
254 for (i
= 0; i
< nr
; i
++)
256 if (sim_events_tick (sd
))
257 sim_events_process (sd
);
259 for (i
= 0; i
< nr
; i
++)
263 hw_event_queue_deschedule (me
, e
[i
]);
267 delete_hw_event_data (me
);
268 delete_hw_alloc_data (me
);
This page took 0.033963 seconds and 4 git commands to generate.