sim: clean up C11 header includes
[deliverable/binutils-gdb.git] / sim / common / hw-handles.c
CommitLineData
b85e4829
AC
1/* The common simulator framework for GDB, the GNU Debugger.
2
3666a048 3 Copyright 2002-2021 Free Software Foundation, Inc.
b85e4829
AC
4
5 Contributed by Andrew Cagney and Red Hat.
6
7 This file is part of GDB.
8
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
4744ac1b 11 the Free Software Foundation; either version 3 of the License, or
b85e4829
AC
12 (at your option) any later version.
13
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.
18
19 You should have received a copy of the GNU General Public License
4744ac1b 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
21
22
23#include "hw-main.h"
24#include "hw-base.h"
25
b6061d4d 26#include <stdlib.h>
c906108c 27
12c4cbd5
MF
28struct hw_handle_mapping
29{
c906108c
SS
30 cell_word external;
31 struct hw *phandle;
32 struct hw_instance *ihandle;
33 struct hw_handle_mapping *next;
34};
35
36
12c4cbd5
MF
37struct hw_handle_data
38{
c906108c
SS
39 int nr_mappings;
40 struct hw_handle_mapping *mappings;
41};
42
43void
44create_hw_handle_data (struct hw *hw)
45{
46 if (hw_parent (hw) == NULL)
47 {
48 hw->handles_of_hw = HW_ZALLOC (hw, struct hw_handle_data);
49 }
50 else
51 {
52 hw->handles_of_hw = hw_root (hw)->handles_of_hw;
53 }
54}
55
56void
57delete_hw_handle_data (struct hw *hw)
58{
59 /* NULL */
60}
61
62
63
64#if 0
65void
66hw_handle_init (struct hw *hw)
67{
68 struct hw_handle_mapping *current_map = db->mappings;
69 if (current_map != NULL)
70 {
71 db->nr_mappings = db->mappings->external;
72 /* verify that the mappings that were not removed are in
73 sequence down to nr 1 */
74 while (current_map->next != NULL)
75 {
76 if (current_map->external != current_map->next->external + 1)
77 error ("hw_handle: hw_handle database possibly corrupt");
78 current_map = current_map->next;
79 }
80 ASSERT (current_map->next == NULL);
81 if (current_map->external != 1)
82 error ("hw_handle: hw_handle database possibly corrupt");
83 }
84 else
85 {
86 db->nr_mappings = 0;
87 }
88}
89#endif
90
91
92struct hw_instance *
93hw_handle_ihandle2 (struct hw *hw,
94 cell_word external)
95{
96 struct hw_handle_data *db = hw->handles_of_hw;
97 struct hw_handle_mapping *current_map = db->mappings;
98 while (current_map != NULL)
99 {
100 if (current_map->external == external)
101 return current_map->ihandle;
102 current_map = current_map->next;
103 }
104 return (void*)0;
105}
106
107
108struct hw *
109hw_handle_phandle2 (struct hw *hw,
110 cell_word external)
111{
112 struct hw_handle_data *db = hw->handles_of_hw;
113 struct hw_handle_mapping *current_map = db->mappings;
114 while (current_map != NULL)
115 {
116 if (current_map->external == external)
117 return current_map->phandle;
118 current_map = current_map->next;
119 }
120 return (void*)0;
121}
122
123
124cell_word
125hw_handle_2ihandle (struct hw *hw,
126 struct hw_instance *internal)
127{
128 struct hw_handle_data *db = hw->handles_of_hw;
129 struct hw_handle_mapping *current_map = db->mappings;
130 while (current_map != NULL)
131 {
132 if (current_map->ihandle == internal)
133 return current_map->external;
134 current_map = current_map->next;
135 }
136 return 0;
137}
138
139
140cell_word
141hw_handle_2phandle (struct hw *hw,
142 struct hw *internal)
143{
144 struct hw_handle_data *db = hw->handles_of_hw;
145 struct hw_handle_mapping *current_map = db->mappings;
146 while (current_map != NULL)
147 {
148 if (current_map->phandle == internal)
149 return current_map->external;
150 current_map = current_map->next;
151 }
152 return 0;
153}
154
155
156void
157hw_handle_add_ihandle (struct hw *hw,
158 struct hw_instance *internal)
159{
160 struct hw_handle_data *db = hw->handles_of_hw;
028f6515 161 if (hw_handle_2ihandle (hw, internal) != 0)
c906108c
SS
162 {
163 hw_abort (hw, "attempting to add an ihandle already in the data base");
164 }
165 else
166 {
167 /* insert at the front making things in decending order */
168 struct hw_handle_mapping *new_map = ZALLOC (struct hw_handle_mapping);
169 new_map->next = db->mappings;
170 new_map->ihandle = internal;
171 db->nr_mappings += 1;
172 new_map->external = db->nr_mappings;
173 db->mappings = new_map;
174 }
175}
176
177
178void
179hw_handle_add_phandle (struct hw *hw,
180 struct hw *internal)
181{
182 struct hw_handle_data *db = hw->handles_of_hw;
028f6515 183 if (hw_handle_2phandle (hw, internal) != 0)
c906108c
SS
184 {
185 hw_abort (hw, "attempting to add a phandle already in the data base");
186 }
187 else
188 {
189 /* insert at the front making things in decending order */
190 struct hw_handle_mapping *new_map = ZALLOC (struct hw_handle_mapping);
191 new_map->next = db->mappings;
192 new_map->phandle = internal;
193 db->nr_mappings += 1;
194 new_map->external = db->nr_mappings;
195 db->mappings = new_map;
196 }
197}
198
199
200void
201hw_handle_remove_ihandle (struct hw *hw,
202 struct hw_instance *internal)
203{
204 struct hw_handle_data *db = hw->handles_of_hw;
205 struct hw_handle_mapping **current_map = &db->mappings;
206 while (*current_map != NULL)
207 {
208 if ((*current_map)->ihandle == internal)
209 {
210 struct hw_handle_mapping *delete = *current_map;
211 *current_map = delete->next;
d79fe0d6 212 free (delete);
c906108c
SS
213 return;
214 }
215 current_map = &(*current_map)->next;
216 }
217 hw_abort (hw, "attempt to remove nonexistant ihandle");
218}
219
220
221void
222hw_handle_remove_phandle (struct hw *hw,
223 struct hw *internal)
224{
225 struct hw_handle_data *db = hw->handles_of_hw;
226 struct hw_handle_mapping **current_map = &db->mappings;
227 while (*current_map != NULL)
228 {
229 if ((*current_map)->phandle == internal)
230 {
231 struct hw_handle_mapping *delete = *current_map;
232 *current_map = delete->next;
d79fe0d6 233 free (delete);
c906108c
SS
234 return;
235 }
236 current_map = &(*current_map)->next;
237 }
238 hw_abort (hw, "attempt to remove nonexistant phandle");
239}
This page took 0.978361 seconds and 4 git commands to generate.