]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/common/hw-events.c
* config/sh/tm-sh.h (BELIEVE_PCC_PROMOTION): Define, so that
[thirdparty/binutils-gdb.git] / sim / common / hw-events.c
CommitLineData
39e953a7
AC
1/* Hardware event manager.
2 Copyright (C) 1998 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
4
5This file is part of GDB, the GNU debugger.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License along
18with this program; if not, write to the Free Software Foundation, Inc.,
1959 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21
22#include "sim-main.h"
23#include "hw-base.h"
24
25#include "sim-events.h"
26
27
28/* The hw-events object is implemented using sim-events */
29
30struct hw_event {
31 void *data;
32 struct hw *me;
33 hw_event_callback *callback;
34 sim_event *real;
35 struct hw_event_data *entry;
36};
37
38struct hw_event_data {
39 struct hw_event event;
40 struct hw_event_data *next;
41 struct hw_event_data **prev;
42};
43
44void
45create_hw_event_data (struct hw *me)
46{
47 /* NOP */
48}
49
50void
51delete_hw_event_data (struct hw *me)
52{
53 if (me->events_of_hw != NULL)
54 hw_abort (me, "stray events");
55}
56
57
58static void
59delete_hw_event (struct hw *me,
60 struct hw_event **event)
61{
62 struct hw_event_data *entry = (*event)->entry;
63 *(entry->prev) = entry->next;
64 entry->next->prev = entry->prev;
65 (*event) = NULL;
66}
67
68
69static void
70create_hw_event (struct hw *me,
71 struct hw_event **event)
72{
73 struct hw_event_data *entry = HW_ZALLOC (me, struct hw_event_data);
74 entry->next = me->events_of_hw;
75 entry->prev = &me->events_of_hw;
76 me->events_of_hw->prev = &entry->next;
77 me->events_of_hw = entry;
78 (*event) = &entry->event;
79}
80
81
82
83/* Pass the H/W event onto the real callback */
84
85static void
86bounce_hw_event (SIM_DESC sd,
87 void *data)
88{
89 /* save the data */
90 struct hw_event *event = (struct hw_event*)data;
91 struct hw *me = event->me;
92 void *event_data = event->data;
93 hw_event_callback *callback = event->callback;
94 hw_free (me, data);
95 event = NULL;
96 callback (me, event_data);
97}
98
99
100
101/* Map onto the event functions */
102
103struct hw_event *
104hw_event_queue_schedule (struct hw *me,
105 signed64 delta_time,
106 hw_event_callback *callback,
107 void *data)
108{
109 struct hw_event *event;
110 create_hw_event (me, &event);
111 /* fill it in */
112 event->data = data;
113 event->callback = callback;
114 event->me = me;
115 event->real = sim_events_schedule (hw_system (me),
116 delta_time,
117 bounce_hw_event,
118 event);
119 return event;
120}
121
122
123void
124hw_event_queue_deschedule (struct hw *me,
125 struct hw_event *event_to_remove)
126{
127 /* remove it from the event queue */
128 sim_events_deschedule (hw_system (me),
129 event_to_remove->real);
130 delete_hw_event (me, &event_to_remove);
131}
132
133
134signed64
135hw_event_queue_time (struct hw *me)
136{
137 return sim_events_time (hw_system (me));
138}
139
140