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 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/>. */
27 struct hw_handle_mapping {
30 struct hw_instance *ihandle;
31 struct hw_handle_mapping *next;
35 struct hw_handle_data {
37 struct hw_handle_mapping *mappings;
41 create_hw_handle_data (struct hw *hw)
43 if (hw_parent (hw) == NULL)
45 hw->handles_of_hw = HW_ZALLOC (hw, struct hw_handle_data);
49 hw->handles_of_hw = hw_root (hw)->handles_of_hw;
54 delete_hw_handle_data (struct hw *hw)
63 hw_handle_init (struct hw *hw)
65 struct hw_handle_mapping *current_map = db->mappings;
66 if (current_map != NULL)
68 db->nr_mappings = db->mappings->external;
69 /* verify that the mappings that were not removed are in
70 sequence down to nr 1 */
71 while (current_map->next != NULL)
73 if (current_map->external != current_map->next->external + 1)
74 error ("hw_handle: hw_handle database possibly corrupt");
75 current_map = current_map->next;
77 ASSERT (current_map->next == NULL);
78 if (current_map->external != 1)
79 error ("hw_handle: hw_handle database possibly corrupt");
90 hw_handle_ihandle2 (struct hw *hw,
93 struct hw_handle_data *db = hw->handles_of_hw;
94 struct hw_handle_mapping *current_map = db->mappings;
95 while (current_map != NULL)
97 if (current_map->external == external)
98 return current_map->ihandle;
99 current_map = current_map->next;
106 hw_handle_phandle2 (struct hw *hw,
109 struct hw_handle_data *db = hw->handles_of_hw;
110 struct hw_handle_mapping *current_map = db->mappings;
111 while (current_map != NULL)
113 if (current_map->external == external)
114 return current_map->phandle;
115 current_map = current_map->next;
122 hw_handle_2ihandle (struct hw *hw,
123 struct hw_instance *internal)
125 struct hw_handle_data *db = hw->handles_of_hw;
126 struct hw_handle_mapping *current_map = db->mappings;
127 while (current_map != NULL)
129 if (current_map->ihandle == internal)
130 return current_map->external;
131 current_map = current_map->next;
138 hw_handle_2phandle (struct hw *hw,
141 struct hw_handle_data *db = hw->handles_of_hw;
142 struct hw_handle_mapping *current_map = db->mappings;
143 while (current_map != NULL)
145 if (current_map->phandle == internal)
146 return current_map->external;
147 current_map = current_map->next;
154 hw_handle_add_ihandle (struct hw *hw,
155 struct hw_instance *internal)
157 struct hw_handle_data *db = hw->handles_of_hw;
158 if (hw_handle_2ihandle (hw, internal) != 0)
160 hw_abort (hw, "attempting to add an ihandle already in the data base");
164 /* insert at the front making things in decending order */
165 struct hw_handle_mapping *new_map = ZALLOC (struct hw_handle_mapping);
166 new_map->next = db->mappings;
167 new_map->ihandle = internal;
168 db->nr_mappings += 1;
169 new_map->external = db->nr_mappings;
170 db->mappings = new_map;
176 hw_handle_add_phandle (struct hw *hw,
179 struct hw_handle_data *db = hw->handles_of_hw;
180 if (hw_handle_2phandle (hw, internal) != 0)
182 hw_abort (hw, "attempting to add a phandle already in the data base");
186 /* insert at the front making things in decending order */
187 struct hw_handle_mapping *new_map = ZALLOC (struct hw_handle_mapping);
188 new_map->next = db->mappings;
189 new_map->phandle = internal;
190 db->nr_mappings += 1;
191 new_map->external = db->nr_mappings;
192 db->mappings = new_map;
198 hw_handle_remove_ihandle (struct hw *hw,
199 struct hw_instance *internal)
201 struct hw_handle_data *db = hw->handles_of_hw;
202 struct hw_handle_mapping **current_map = &db->mappings;
203 while (*current_map != NULL)
205 if ((*current_map)->ihandle == internal)
207 struct hw_handle_mapping *delete = *current_map;
208 *current_map = delete->next;
212 current_map = &(*current_map)->next;
214 hw_abort (hw, "attempt to remove nonexistant ihandle");
219 hw_handle_remove_phandle (struct hw *hw,
222 struct hw_handle_data *db = hw->handles_of_hw;
223 struct hw_handle_mapping **current_map = &db->mappings;
224 while (*current_map != NULL)
226 if ((*current_map)->phandle == internal)
228 struct hw_handle_mapping *delete = *current_map;
229 *current_map = delete->next;
233 current_map = &(*current_map)->next;
235 hw_abort (hw, "attempt to remove nonexistant phandle");