1 /* This file is part of the program psim.
3 Copyright (C) 1994-1995,1997-1998, Andrew Cagney <cagney@highland.com.au>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 struct hw_handle_mapping
{
29 struct hw_instance
*ihandle
;
30 struct hw_handle_mapping
*next
;
34 struct hw_handle_data
{
36 struct hw_handle_mapping
*mappings
;
40 create_hw_handle_data (struct hw
*hw
)
42 if (hw_parent (hw
) == NULL
)
44 hw
->handles_of_hw
= HW_ZALLOC (hw
, struct hw_handle_data
);
48 hw
->handles_of_hw
= hw_root (hw
)->handles_of_hw
;
53 delete_hw_handle_data (struct hw
*hw
)
62 hw_handle_init (struct hw
*hw
)
64 struct hw_handle_mapping
*current_map
= db
->mappings
;
65 if (current_map
!= NULL
)
67 db
->nr_mappings
= db
->mappings
->external
;
68 /* verify that the mappings that were not removed are in
69 sequence down to nr 1 */
70 while (current_map
->next
!= NULL
)
72 if (current_map
->external
!= current_map
->next
->external
+ 1)
73 error ("hw_handle: hw_handle database possibly corrupt");
74 current_map
= current_map
->next
;
76 ASSERT (current_map
->next
== NULL
);
77 if (current_map
->external
!= 1)
78 error ("hw_handle: hw_handle database possibly corrupt");
89 hw_handle_ihandle2 (struct hw
*hw
,
92 struct hw_handle_data
*db
= hw
->handles_of_hw
;
93 struct hw_handle_mapping
*current_map
= db
->mappings
;
94 while (current_map
!= NULL
)
96 if (current_map
->external
== external
)
97 return current_map
->ihandle
;
98 current_map
= current_map
->next
;
105 hw_handle_phandle2 (struct hw
*hw
,
108 struct hw_handle_data
*db
= hw
->handles_of_hw
;
109 struct hw_handle_mapping
*current_map
= db
->mappings
;
110 while (current_map
!= NULL
)
112 if (current_map
->external
== external
)
113 return current_map
->phandle
;
114 current_map
= current_map
->next
;
121 hw_handle_2ihandle (struct hw
*hw
,
122 struct hw_instance
*internal
)
124 struct hw_handle_data
*db
= hw
->handles_of_hw
;
125 struct hw_handle_mapping
*current_map
= db
->mappings
;
126 while (current_map
!= NULL
)
128 if (current_map
->ihandle
== internal
)
129 return current_map
->external
;
130 current_map
= current_map
->next
;
137 hw_handle_2phandle (struct hw
*hw
,
140 struct hw_handle_data
*db
= hw
->handles_of_hw
;
141 struct hw_handle_mapping
*current_map
= db
->mappings
;
142 while (current_map
!= NULL
)
144 if (current_map
->phandle
== internal
)
145 return current_map
->external
;
146 current_map
= current_map
->next
;
153 hw_handle_add_ihandle (struct hw
*hw
,
154 struct hw_instance
*internal
)
156 struct hw_handle_data
*db
= hw
->handles_of_hw
;
157 if (hw_handle_2ihandle (hw
, internal
) != NULL
)
159 hw_abort (hw
, "attempting to add an ihandle already in the data base");
163 /* insert at the front making things in decending order */
164 struct hw_handle_mapping
*new_map
= ZALLOC (struct hw_handle_mapping
);
165 new_map
->next
= db
->mappings
;
166 new_map
->ihandle
= internal
;
167 db
->nr_mappings
+= 1;
168 new_map
->external
= db
->nr_mappings
;
169 db
->mappings
= new_map
;
175 hw_handle_add_phandle (struct hw
*hw
,
178 struct hw_handle_data
*db
= hw
->handles_of_hw
;
179 if (hw_handle_2phandle (hw
, internal
) != NULL
)
181 hw_abort (hw
, "attempting to add a phandle already in the data base");
185 /* insert at the front making things in decending order */
186 struct hw_handle_mapping
*new_map
= ZALLOC (struct hw_handle_mapping
);
187 new_map
->next
= db
->mappings
;
188 new_map
->phandle
= internal
;
189 db
->nr_mappings
+= 1;
190 new_map
->external
= db
->nr_mappings
;
191 db
->mappings
= new_map
;
197 hw_handle_remove_ihandle (struct hw
*hw
,
198 struct hw_instance
*internal
)
200 struct hw_handle_data
*db
= hw
->handles_of_hw
;
201 struct hw_handle_mapping
**current_map
= &db
->mappings
;
202 while (*current_map
!= NULL
)
204 if ((*current_map
)->ihandle
== internal
)
206 struct hw_handle_mapping
*delete = *current_map
;
207 *current_map
= delete->next
;
211 current_map
= &(*current_map
)->next
;
213 hw_abort (hw
, "attempt to remove nonexistant ihandle");
218 hw_handle_remove_phandle (struct hw
*hw
,
221 struct hw_handle_data
*db
= hw
->handles_of_hw
;
222 struct hw_handle_mapping
**current_map
= &db
->mappings
;
223 while (*current_map
!= NULL
)
225 if ((*current_map
)->phandle
== internal
)
227 struct hw_handle_mapping
*delete = *current_map
;
228 *current_map
= delete->next
;
232 current_map
= &(*current_map
)->next
;
234 hw_abort (hw
, "attempt to remove nonexistant phandle");