2 Copyright (C) 1998 Free Software Foundation, Inc.
3 Contributed by Andrew Cagney and Cygnus Solutions.
5 This file is part of GDB, the GNU debugger.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
46 struct hw_port_edge
*next
;
47 object_disposition disposition
;
51 hw_port_event_method
*to_port_event
;
52 const struct hw_port_descriptor
*ports
;
53 struct hw_port_edge
*edges
;
56 const struct hw_port_descriptor empty_hw_ports
[] = {
61 panic_hw_port_event (struct hw
*me
,
67 hw_abort (me
, "no port method");
71 create_hw_port_data (struct hw
*me
)
73 me
->ports_of_hw
= HW_ZALLOC (me
, struct hw_port_data
);
74 set_hw_port_event (me
, panic_hw_port_event
);
75 set_hw_ports (me
, empty_hw_ports
);
79 delete_hw_port_data (struct hw
*me
)
81 hw_free (me
, me
->ports_of_hw
);
82 me
->ports_of_hw
= NULL
;
86 set_hw_ports (struct hw
*me
,
87 const struct hw_port_descriptor ports
[])
89 me
->ports_of_hw
->ports
= ports
;
93 set_hw_port_event (struct hw
*me
,
94 hw_port_event_method
*port_event
)
96 me
->ports_of_hw
->to_port_event
= port_event
;
101 attach_hw_port_edge (struct hw
*me
,
102 struct hw_port_edge
**list
,
106 object_disposition disposition
)
108 struct hw_port_edge
*new_edge
= HW_ZALLOC (me
, struct hw_port_edge
);
109 new_edge
->my_port
= my_port
;
110 new_edge
->dest
= dest
;
111 new_edge
->dest_port
= dest_port
;
112 new_edge
->next
= *list
;
113 new_edge
->disposition
= disposition
;
119 detach_hw_port_edge (struct hw
*me
,
120 struct hw_port_edge
**list
,
125 while (*list
!= NULL
)
127 struct hw_port_edge
*old_edge
= *list
;
128 if (old_edge
->dest
== dest
129 && old_edge
->dest_port
== dest_port
130 && old_edge
->my_port
== my_port
)
132 if (old_edge
->disposition
== permenant_object
)
133 hw_abort (me
, "attempt to delete permenant port edge");
134 *list
= old_edge
->next
;
135 hw_free (me
, old_edge
);
139 hw_abort (me
, "attempt to delete unattached port");
145 clean_hw_port_edges (struct hw_port_edge
**list
)
147 while (*list
!= NULL
)
149 struct hw_port_edge
*old_edge
= *list
;
150 switch (old_edge
->disposition
)
152 case permenant_object
:
153 list
= &old_edge
->next
;
155 case temporary_object
:
156 *list
= old_edge
->next
;
157 hw_free (me
, old_edge
);
168 hw_port_event (struct hw
*me
,
172 int found_an_edge
= 0;
173 struct hw_port_edge
*edge
;
174 /* device's lines directly connected */
175 for (edge
= me
->ports_of_hw
->edges
;
179 if (edge
->my_port
== my_port
)
181 edge
->dest
->ports_of_hw
->to_port_event (edge
->dest
,
190 hw_abort (me
, "No edge for port %d", my_port
);
195 hw_port_attach (struct hw
*me
,
199 object_disposition disposition
)
201 attach_hw_port_edge (me
,
202 &me
->ports_of_hw
->edges
,
211 hw_port_detach (struct hw
*me
,
216 detach_hw_port_edge (me
,
217 &me
->ports_of_hw
->edges
,
225 hw_port_traverse (struct hw
*me
,
226 hw_port_traverse_function
*handler
,
229 struct hw_port_edge
*port_edge
;
230 for (port_edge
= me
->ports_of_hw
->edges
;
232 port_edge
= port_edge
->next
)
234 handler (me
, port_edge
->my_port
,
235 port_edge
->dest
, port_edge
->dest_port
,
242 hw_port_decode (struct hw
*me
,
243 const char *port_name
,
244 port_direction direction
)
246 if (port_name
== NULL
|| port_name
[0] == '\0')
248 if (isdigit(port_name
[0]))
250 return strtoul (port_name
, NULL
, 0);
254 const struct hw_port_descriptor
*ports
=
255 me
->ports_of_hw
->ports
;
258 while (ports
->name
!= NULL
)
260 if (ports
->direction
== bidirect_port
261 || ports
->direction
== direction
)
263 if (ports
->nr_ports
> 0)
265 int len
= strlen (ports
->name
);
266 if (strncmp (port_name
, ports
->name
, len
) == 0)
268 if (port_name
[len
] == '\0')
269 return ports
->number
;
270 else if(isdigit (port_name
[len
]))
272 int port
= (ports
->number
273 + strtoul (&port_name
[len
], NULL
, 0));
274 if (port
>= ports
->number
+ ports
->nr_ports
)
276 "Port %s out of range",
282 else if (strcmp (port_name
, ports
->name
) == 0)
283 return ports
->number
;
289 hw_abort (me
, "Unreconized port %s", port_name
);
295 hw_port_encode (struct hw
*me
,
299 port_direction direction
)
301 const struct hw_port_descriptor
*ports
= NULL
;
302 ports
= me
->ports_of_hw
->ports
;
304 while (ports
->name
!= NULL
)
306 if (ports
->direction
== bidirect_port
307 || ports
->direction
== direction
)
309 if (ports
->nr_ports
> 0)
311 if (port_number
>= ports
->number
312 && port_number
< ports
->number
+ ports
->nr_ports
)
314 strcpy (buf
, ports
->name
);
315 sprintf (buf
+ strlen(buf
), "%d", port_number
- ports
->number
);
316 if (strlen (buf
) >= sizeof_buf
)
317 hw_abort (me
, "hw_port_encode: buffer overflow");
323 if (ports
->number
== port_number
)
325 if (strlen(ports
->name
) >= sizeof_buf
)
326 hw_abort (me
, "hw_port_encode: buffer overflow");
327 strcpy(buf
, ports
->name
);
335 sprintf (buf
, "%d", port_number
);
336 if (strlen(buf
) >= sizeof_buf
)
337 hw_abort (me
, "hw_port_encode: buffer overflow");