Add note to check that all changes have been pushed before creating the source tarballs
[binutils-gdb.git] / sim / common / hw-handles.c
blob6d58b9ad42fbeaf19038a707877920e7b908b484
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. */
23 #include "defs.h"
25 #include <stdlib.h>
27 #include "hw-main.h"
28 #include "hw-base.h"
30 struct hw_handle_mapping
32 cell_word external;
33 struct hw *phandle;
34 struct hw_instance *ihandle;
35 struct hw_handle_mapping *next;
39 struct hw_handle_data
41 int nr_mappings;
42 struct hw_handle_mapping *mappings;
45 void
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);
52 else
54 hw->handles_of_hw = hw_root (hw)->handles_of_hw;
58 void
59 delete_hw_handle_data (struct hw *hw)
61 /* NULL */
66 #if 0
67 void
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");
86 else
88 db->nr_mappings = 0;
91 #endif
94 struct hw_instance *
95 hw_handle_ihandle2 (struct hw *hw,
96 cell_word external)
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;
106 return (void*)0;
110 struct hw *
111 hw_handle_phandle2 (struct hw *hw,
112 cell_word external)
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;
122 return (void*)0;
126 cell_word
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;
138 return 0;
142 cell_word
143 hw_handle_2phandle (struct hw *hw,
144 struct hw *internal)
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;
154 return 0;
158 void
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");
167 else
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;
180 void
181 hw_handle_add_phandle (struct hw *hw,
182 struct hw *internal)
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");
189 else
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;
202 void
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;
214 free (delete);
215 return;
217 current_map = &(*current_map)->next;
219 hw_abort (hw, "attempt to remove nonexistant ihandle");
223 void
224 hw_handle_remove_phandle (struct hw *hw,
225 struct hw *internal)
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;
235 free (delete);
236 return;
238 current_map = &(*current_map)->next;
240 hw_abort (hw, "attempt to remove nonexistant phandle");