1 /* The common simulator framework for GDB, the GNU Debugger.
3 Copyright 2002-2023 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 3 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, see <http://www.gnu.org/licenses/>. */
22 /* This must come before any other includes. */
30 struct hw_handle_mapping
34 struct hw_instance
*ihandle
;
35 struct hw_handle_mapping
*next
;
42 struct hw_handle_mapping
*mappings
;
46 create_hw_handle_data (struct hw
*hw
)
48 if (hw_parent (hw
) == NULL
)
50 hw
->handles_of_hw
= HW_ZALLOC (hw
, struct hw_handle_data
);
54 hw
->handles_of_hw
= hw_root (hw
)->handles_of_hw
;
59 delete_hw_handle_data (struct hw
*hw
)
68 hw_handle_init (struct hw
*hw
)
70 struct hw_handle_mapping
*current_map
= db
->mappings
;
71 if (current_map
!= NULL
)
73 db
->nr_mappings
= db
->mappings
->external
;
74 /* verify that the mappings that were not removed are in
75 sequence down to nr 1 */
76 while (current_map
->next
!= NULL
)
78 if (current_map
->external
!= current_map
->next
->external
+ 1)
79 error ("hw_handle: hw_handle database possibly corrupt");
80 current_map
= current_map
->next
;
82 ASSERT (current_map
->next
== NULL
);
83 if (current_map
->external
!= 1)
84 error ("hw_handle: hw_handle database possibly corrupt");
95 hw_handle_ihandle2 (struct hw
*hw
,
98 struct hw_handle_data
*db
= hw
->handles_of_hw
;
99 struct hw_handle_mapping
*current_map
= db
->mappings
;
100 while (current_map
!= NULL
)
102 if (current_map
->external
== external
)
103 return current_map
->ihandle
;
104 current_map
= current_map
->next
;
111 hw_handle_phandle2 (struct hw
*hw
,
114 struct hw_handle_data
*db
= hw
->handles_of_hw
;
115 struct hw_handle_mapping
*current_map
= db
->mappings
;
116 while (current_map
!= NULL
)
118 if (current_map
->external
== external
)
119 return current_map
->phandle
;
120 current_map
= current_map
->next
;
127 hw_handle_2ihandle (struct hw
*hw
,
128 struct hw_instance
*internal
)
130 struct hw_handle_data
*db
= hw
->handles_of_hw
;
131 struct hw_handle_mapping
*current_map
= db
->mappings
;
132 while (current_map
!= NULL
)
134 if (current_map
->ihandle
== internal
)
135 return current_map
->external
;
136 current_map
= current_map
->next
;
143 hw_handle_2phandle (struct hw
*hw
,
146 struct hw_handle_data
*db
= hw
->handles_of_hw
;
147 struct hw_handle_mapping
*current_map
= db
->mappings
;
148 while (current_map
!= NULL
)
150 if (current_map
->phandle
== internal
)
151 return current_map
->external
;
152 current_map
= current_map
->next
;
159 hw_handle_add_ihandle (struct hw
*hw
,
160 struct hw_instance
*internal
)
162 struct hw_handle_data
*db
= hw
->handles_of_hw
;
163 if (hw_handle_2ihandle (hw
, internal
) != 0)
165 hw_abort (hw
, "attempting to add an ihandle already in the data base");
169 /* insert at the front making things in decending order */
170 struct hw_handle_mapping
*new_map
= ZALLOC (struct hw_handle_mapping
);
171 new_map
->next
= db
->mappings
;
172 new_map
->ihandle
= internal
;
173 db
->nr_mappings
+= 1;
174 new_map
->external
= db
->nr_mappings
;
175 db
->mappings
= new_map
;
181 hw_handle_add_phandle (struct hw
*hw
,
184 struct hw_handle_data
*db
= hw
->handles_of_hw
;
185 if (hw_handle_2phandle (hw
, internal
) != 0)
187 hw_abort (hw
, "attempting to add a phandle already in the data base");
191 /* insert at the front making things in decending order */
192 struct hw_handle_mapping
*new_map
= ZALLOC (struct hw_handle_mapping
);
193 new_map
->next
= db
->mappings
;
194 new_map
->phandle
= internal
;
195 db
->nr_mappings
+= 1;
196 new_map
->external
= db
->nr_mappings
;
197 db
->mappings
= new_map
;
203 hw_handle_remove_ihandle (struct hw
*hw
,
204 struct hw_instance
*internal
)
206 struct hw_handle_data
*db
= hw
->handles_of_hw
;
207 struct hw_handle_mapping
**current_map
= &db
->mappings
;
208 while (*current_map
!= NULL
)
210 if ((*current_map
)->ihandle
== internal
)
212 struct hw_handle_mapping
*delete = *current_map
;
213 *current_map
= delete->next
;
217 current_map
= &(*current_map
)->next
;
219 hw_abort (hw
, "attempt to remove nonexistant ihandle");
224 hw_handle_remove_phandle (struct hw
*hw
,
227 struct hw_handle_data
*db
= hw
->handles_of_hw
;
228 struct hw_handle_mapping
**current_map
= &db
->mappings
;
229 while (*current_map
!= NULL
)
231 if ((*current_map
)->phandle
== internal
)
233 struct hw_handle_mapping
*delete = *current_map
;
234 *current_map
= delete->next
;
238 current_map
= &(*current_map
)->next
;
240 hw_abort (hw
, "attempt to remove nonexistant phandle");