Don't write to inferior_ptid in linux_get_siginfo_data
[deliverable/binutils-gdb.git] / sim / common / hw-handles.c
... / ...
CommitLineData
1/* The common simulator framework for GDB, the GNU Debugger.
2
3 Copyright 2002-2020 Free Software Foundation, Inc.
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
11 the Free Software Foundation; either version 3 of the License, or
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
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21
22
23#include "hw-main.h"
24#include "hw-base.h"
25
26#if HAVE_STDLIB_H
27#include <stdlib.h>
28#endif
29
30struct hw_handle_mapping
31{
32 cell_word external;
33 struct hw *phandle;
34 struct hw_instance *ihandle;
35 struct hw_handle_mapping *next;
36};
37
38
39struct hw_handle_data
40{
41 int nr_mappings;
42 struct hw_handle_mapping *mappings;
43};
44
45void
46create_hw_handle_data (struct hw *hw)
47{
48 if (hw_parent (hw) == NULL)
49 {
50 hw->handles_of_hw = HW_ZALLOC (hw, struct hw_handle_data);
51 }
52 else
53 {
54 hw->handles_of_hw = hw_root (hw)->handles_of_hw;
55 }
56}
57
58void
59delete_hw_handle_data (struct hw *hw)
60{
61 /* NULL */
62}
63
64
65
66#if 0
67void
68hw_handle_init (struct hw *hw)
69{
70 struct hw_handle_mapping *current_map = db->mappings;
71 if (current_map != NULL)
72 {
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)
77 {
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;
81 }
82 ASSERT (current_map->next == NULL);
83 if (current_map->external != 1)
84 error ("hw_handle: hw_handle database possibly corrupt");
85 }
86 else
87 {
88 db->nr_mappings = 0;
89 }
90}
91#endif
92
93
94struct hw_instance *
95hw_handle_ihandle2 (struct hw *hw,
96 cell_word external)
97{
98 struct hw_handle_data *db = hw->handles_of_hw;
99 struct hw_handle_mapping *current_map = db->mappings;
100 while (current_map != NULL)
101 {
102 if (current_map->external == external)
103 return current_map->ihandle;
104 current_map = current_map->next;
105 }
106 return (void*)0;
107}
108
109
110struct hw *
111hw_handle_phandle2 (struct hw *hw,
112 cell_word external)
113{
114 struct hw_handle_data *db = hw->handles_of_hw;
115 struct hw_handle_mapping *current_map = db->mappings;
116 while (current_map != NULL)
117 {
118 if (current_map->external == external)
119 return current_map->phandle;
120 current_map = current_map->next;
121 }
122 return (void*)0;
123}
124
125
126cell_word
127hw_handle_2ihandle (struct hw *hw,
128 struct hw_instance *internal)
129{
130 struct hw_handle_data *db = hw->handles_of_hw;
131 struct hw_handle_mapping *current_map = db->mappings;
132 while (current_map != NULL)
133 {
134 if (current_map->ihandle == internal)
135 return current_map->external;
136 current_map = current_map->next;
137 }
138 return 0;
139}
140
141
142cell_word
143hw_handle_2phandle (struct hw *hw,
144 struct hw *internal)
145{
146 struct hw_handle_data *db = hw->handles_of_hw;
147 struct hw_handle_mapping *current_map = db->mappings;
148 while (current_map != NULL)
149 {
150 if (current_map->phandle == internal)
151 return current_map->external;
152 current_map = current_map->next;
153 }
154 return 0;
155}
156
157
158void
159hw_handle_add_ihandle (struct hw *hw,
160 struct hw_instance *internal)
161{
162 struct hw_handle_data *db = hw->handles_of_hw;
163 if (hw_handle_2ihandle (hw, internal) != 0)
164 {
165 hw_abort (hw, "attempting to add an ihandle already in the data base");
166 }
167 else
168 {
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;
176 }
177}
178
179
180void
181hw_handle_add_phandle (struct hw *hw,
182 struct hw *internal)
183{
184 struct hw_handle_data *db = hw->handles_of_hw;
185 if (hw_handle_2phandle (hw, internal) != 0)
186 {
187 hw_abort (hw, "attempting to add a phandle already in the data base");
188 }
189 else
190 {
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;
198 }
199}
200
201
202void
203hw_handle_remove_ihandle (struct hw *hw,
204 struct hw_instance *internal)
205{
206 struct hw_handle_data *db = hw->handles_of_hw;
207 struct hw_handle_mapping **current_map = &db->mappings;
208 while (*current_map != NULL)
209 {
210 if ((*current_map)->ihandle == internal)
211 {
212 struct hw_handle_mapping *delete = *current_map;
213 *current_map = delete->next;
214 free (delete);
215 return;
216 }
217 current_map = &(*current_map)->next;
218 }
219 hw_abort (hw, "attempt to remove nonexistant ihandle");
220}
221
222
223void
224hw_handle_remove_phandle (struct hw *hw,
225 struct hw *internal)
226{
227 struct hw_handle_data *db = hw->handles_of_hw;
228 struct hw_handle_mapping **current_map = &db->mappings;
229 while (*current_map != NULL)
230 {
231 if ((*current_map)->phandle == internal)
232 {
233 struct hw_handle_mapping *delete = *current_map;
234 *current_map = delete->next;
235 free (delete);
236 return;
237 }
238 current_map = &(*current_map)->next;
239 }
240 hw_abort (hw, "attempt to remove nonexistant phandle");
241}
This page took 0.027613 seconds and 4 git commands to generate.