]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/common/hw-handles.c
1 /* The common simulator framework for GDB, the GNU Debugger.
3 Copyright 2002, 2007 Free Software Foundation, Inc.
5 Contributed by Andrew Cagney and Red Hat.
7 This file is part of GDB.
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
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
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.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
29 struct hw_handle_mapping
{
32 struct hw_instance
*ihandle
;
33 struct hw_handle_mapping
*next
;
37 struct hw_handle_data
{
39 struct hw_handle_mapping
*mappings
;
43 create_hw_handle_data (struct hw
*hw
)
45 if (hw_parent (hw
) == NULL
)
47 hw
->handles_of_hw
= HW_ZALLOC (hw
, struct hw_handle_data
);
51 hw
->handles_of_hw
= hw_root (hw
)->handles_of_hw
;
56 delete_hw_handle_data (struct hw
*hw
)
65 hw_handle_init (struct hw
*hw
)
67 struct hw_handle_mapping
*current_map
= db
->mappings
;
68 if (current_map
!= NULL
)
70 db
->nr_mappings
= db
->mappings
->external
;
71 /* verify that the mappings that were not removed are in
72 sequence down to nr 1 */
73 while (current_map
->next
!= NULL
)
75 if (current_map
->external
!= current_map
->next
->external
+ 1)
76 error ("hw_handle: hw_handle database possibly corrupt");
77 current_map
= current_map
->next
;
79 ASSERT (current_map
->next
== NULL
);
80 if (current_map
->external
!= 1)
81 error ("hw_handle: hw_handle database possibly corrupt");
92 hw_handle_ihandle2 (struct hw
*hw
,
95 struct hw_handle_data
*db
= hw
->handles_of_hw
;
96 struct hw_handle_mapping
*current_map
= db
->mappings
;
97 while (current_map
!= NULL
)
99 if (current_map
->external
== external
)
100 return current_map
->ihandle
;
101 current_map
= current_map
->next
;
108 hw_handle_phandle2 (struct hw
*hw
,
111 struct hw_handle_data
*db
= hw
->handles_of_hw
;
112 struct hw_handle_mapping
*current_map
= db
->mappings
;
113 while (current_map
!= NULL
)
115 if (current_map
->external
== external
)
116 return current_map
->phandle
;
117 current_map
= current_map
->next
;
124 hw_handle_2ihandle (struct hw
*hw
,
125 struct hw_instance
*internal
)
127 struct hw_handle_data
*db
= hw
->handles_of_hw
;
128 struct hw_handle_mapping
*current_map
= db
->mappings
;
129 while (current_map
!= NULL
)
131 if (current_map
->ihandle
== internal
)
132 return current_map
->external
;
133 current_map
= current_map
->next
;
140 hw_handle_2phandle (struct hw
*hw
,
143 struct hw_handle_data
*db
= hw
->handles_of_hw
;
144 struct hw_handle_mapping
*current_map
= db
->mappings
;
145 while (current_map
!= NULL
)
147 if (current_map
->phandle
== internal
)
148 return current_map
->external
;
149 current_map
= current_map
->next
;
156 hw_handle_add_ihandle (struct hw
*hw
,
157 struct hw_instance
*internal
)
159 struct hw_handle_data
*db
= hw
->handles_of_hw
;
160 if (hw_handle_2ihandle (hw
, internal
) != 0)
162 hw_abort (hw
, "attempting to add an ihandle already in the data base");
166 /* insert at the front making things in decending order */
167 struct hw_handle_mapping
*new_map
= ZALLOC (struct hw_handle_mapping
);
168 new_map
->next
= db
->mappings
;
169 new_map
->ihandle
= internal
;
170 db
->nr_mappings
+= 1;
171 new_map
->external
= db
->nr_mappings
;
172 db
->mappings
= new_map
;
178 hw_handle_add_phandle (struct hw
*hw
,
181 struct hw_handle_data
*db
= hw
->handles_of_hw
;
182 if (hw_handle_2phandle (hw
, internal
) != 0)
184 hw_abort (hw
, "attempting to add a phandle already in the data base");
188 /* insert at the front making things in decending order */
189 struct hw_handle_mapping
*new_map
= ZALLOC (struct hw_handle_mapping
);
190 new_map
->next
= db
->mappings
;
191 new_map
->phandle
= internal
;
192 db
->nr_mappings
+= 1;
193 new_map
->external
= db
->nr_mappings
;
194 db
->mappings
= new_map
;
200 hw_handle_remove_ihandle (struct hw
*hw
,
201 struct hw_instance
*internal
)
203 struct hw_handle_data
*db
= hw
->handles_of_hw
;
204 struct hw_handle_mapping
**current_map
= &db
->mappings
;
205 while (*current_map
!= NULL
)
207 if ((*current_map
)->ihandle
== internal
)
209 struct hw_handle_mapping
*delete = *current_map
;
210 *current_map
= delete->next
;
214 current_map
= &(*current_map
)->next
;
216 hw_abort (hw
, "attempt to remove nonexistant ihandle");
221 hw_handle_remove_phandle (struct hw
*hw
,
224 struct hw_handle_data
*db
= hw
->handles_of_hw
;
225 struct hw_handle_mapping
**current_map
= &db
->mappings
;
226 while (*current_map
!= NULL
)
228 if ((*current_map
)->phandle
== internal
)
230 struct hw_handle_mapping
*delete = *current_map
;
231 *current_map
= delete->next
;
235 current_map
= &(*current_map
)->next
;
237 hw_abort (hw
, "attempt to remove nonexistant phandle");