OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [gdb-6.8/] [pre-binutils-2.20.1-sync/] [sim/] [common/] [hw-ports.c] - Diff between revs 157 and 223

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 157 Rev 223
/* Hardware ports.
/* Hardware ports.
   Copyright (C) 1998, 2007, 2008 Free Software Foundation, Inc.
   Copyright (C) 1998, 2007, 2008 Free Software Foundation, Inc.
   Contributed by Andrew Cagney and Cygnus Solutions.
   Contributed by Andrew Cagney and Cygnus Solutions.
 
 
This file is part of GDB, the GNU debugger.
This file is part of GDB, the GNU debugger.
 
 
This program is free software; you can redistribute it and/or modify
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
(at your option) any later version.
 
 
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
GNU General Public License for more details.
 
 
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 
 
 
#include "hw-main.h"
#include "hw-main.h"
#include "hw-base.h"
#include "hw-base.h"
 
 
#ifdef HAVE_STDLIB_H
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#include <stdlib.h>
#endif
#endif
 
 
#ifdef HAVE_STRING_H
#ifdef HAVE_STRING_H
#include <string.h>
#include <string.h>
#else
#else
#ifdef HAVE_STRINGS_H
#ifdef HAVE_STRINGS_H
#include <strings.h>
#include <strings.h>
#endif
#endif
#endif
#endif
 
 
#include <ctype.h>
#include <ctype.h>
 
 
#define TRACE(x,y)
#define TRACE(x,y)
 
 
 
 
struct hw_port_edge {
struct hw_port_edge {
  int my_port;
  int my_port;
  struct hw *dest;
  struct hw *dest;
  int dest_port;
  int dest_port;
  struct hw_port_edge *next;
  struct hw_port_edge *next;
  object_disposition disposition;
  object_disposition disposition;
};
};
 
 
struct hw_port_data {
struct hw_port_data {
  hw_port_event_method *to_port_event;
  hw_port_event_method *to_port_event;
  const struct hw_port_descriptor *ports;
  const struct hw_port_descriptor *ports;
  struct hw_port_edge *edges;
  struct hw_port_edge *edges;
};
};
 
 
const struct hw_port_descriptor empty_hw_ports[] = {
const struct hw_port_descriptor empty_hw_ports[] = {
  { NULL, },
  { NULL, },
};
};
 
 
static void
static void
panic_hw_port_event (struct hw *me,
panic_hw_port_event (struct hw *me,
                     int my_port,
                     int my_port,
                     struct hw *source,
                     struct hw *source,
                     int source_port,
                     int source_port,
                     int level)
                     int level)
{
{
  hw_abort (me, "no port method");
  hw_abort (me, "no port method");
}
}
 
 
void
void
create_hw_port_data (struct hw *me)
create_hw_port_data (struct hw *me)
{
{
  me->ports_of_hw = HW_ZALLOC (me, struct hw_port_data);
  me->ports_of_hw = HW_ZALLOC (me, struct hw_port_data);
  set_hw_port_event (me, panic_hw_port_event);
  set_hw_port_event (me, panic_hw_port_event);
  set_hw_ports (me, empty_hw_ports);
  set_hw_ports (me, empty_hw_ports);
}
}
 
 
void
void
delete_hw_port_data (struct hw *me)
delete_hw_port_data (struct hw *me)
{
{
  hw_free (me, me->ports_of_hw);
  hw_free (me, me->ports_of_hw);
  me->ports_of_hw = NULL;
  me->ports_of_hw = NULL;
}
}
 
 
void
void
set_hw_ports (struct hw *me,
set_hw_ports (struct hw *me,
              const struct hw_port_descriptor ports[])
              const struct hw_port_descriptor ports[])
{
{
  me->ports_of_hw->ports = ports;
  me->ports_of_hw->ports = ports;
}
}
 
 
void
void
set_hw_port_event (struct hw *me,
set_hw_port_event (struct hw *me,
                   hw_port_event_method *port_event)
                   hw_port_event_method *port_event)
{
{
  me->ports_of_hw->to_port_event = port_event;
  me->ports_of_hw->to_port_event = port_event;
}
}
 
 
 
 
static void
static void
attach_hw_port_edge (struct hw *me,
attach_hw_port_edge (struct hw *me,
                     struct hw_port_edge **list,
                     struct hw_port_edge **list,
                     int my_port,
                     int my_port,
                     struct hw *dest,
                     struct hw *dest,
                     int dest_port,
                     int dest_port,
                     object_disposition disposition)
                     object_disposition disposition)
{
{
  struct hw_port_edge *new_edge = HW_ZALLOC (me, struct hw_port_edge);
  struct hw_port_edge *new_edge = HW_ZALLOC (me, struct hw_port_edge);
  new_edge->my_port = my_port;
  new_edge->my_port = my_port;
  new_edge->dest = dest;
  new_edge->dest = dest;
  new_edge->dest_port = dest_port;
  new_edge->dest_port = dest_port;
  new_edge->next = *list;
  new_edge->next = *list;
  new_edge->disposition = disposition;
  new_edge->disposition = disposition;
  *list = new_edge;
  *list = new_edge;
}
}
 
 
 
 
static void
static void
detach_hw_port_edge (struct hw *me,
detach_hw_port_edge (struct hw *me,
                     struct hw_port_edge **list,
                     struct hw_port_edge **list,
                     int my_port,
                     int my_port,
                     struct hw *dest,
                     struct hw *dest,
                     int dest_port)
                     int dest_port)
{
{
  while (*list != NULL)
  while (*list != NULL)
    {
    {
      struct hw_port_edge *old_edge = *list;
      struct hw_port_edge *old_edge = *list;
      if (old_edge->dest == dest
      if (old_edge->dest == dest
          && old_edge->dest_port == dest_port
          && old_edge->dest_port == dest_port
          && old_edge->my_port == my_port)
          && old_edge->my_port == my_port)
        {
        {
          if (old_edge->disposition == permenant_object)
          if (old_edge->disposition == permenant_object)
            hw_abort (me, "attempt to delete permenant port edge");
            hw_abort (me, "attempt to delete permenant port edge");
          *list = old_edge->next;
          *list = old_edge->next;
          hw_free (me, old_edge);
          hw_free (me, old_edge);
          return;
          return;
        }
        }
    }
    }
  hw_abort (me, "attempt to delete unattached port");
  hw_abort (me, "attempt to delete unattached port");
}
}
 
 
 
 
#if 0
#if 0
static void
static void
clean_hw_port_edges (struct hw_port_edge **list)
clean_hw_port_edges (struct hw_port_edge **list)
{
{
  while (*list != NULL)
  while (*list != NULL)
    {
    {
      struct hw_port_edge *old_edge = *list;
      struct hw_port_edge *old_edge = *list;
      switch (old_edge->disposition)
      switch (old_edge->disposition)
        {
        {
        case permenant_object:
        case permenant_object:
          list = &old_edge->next;
          list = &old_edge->next;
          break;
          break;
        case temporary_object:
        case temporary_object:
          *list = old_edge->next;
          *list = old_edge->next;
          hw_free (me, old_edge);
          hw_free (me, old_edge);
          break;
          break;
        }
        }
    }
    }
}
}
#endif
#endif
 
 
 
 
/* Ports: */
/* Ports: */
 
 
void
void
hw_port_event (struct hw *me,
hw_port_event (struct hw *me,
               int my_port,
               int my_port,
               int level)
               int level)
{
{
  int found_an_edge = 0;
  int found_an_edge = 0;
  struct hw_port_edge *edge;
  struct hw_port_edge *edge;
  /* device's lines directly connected */
  /* device's lines directly connected */
  for (edge = me->ports_of_hw->edges;
  for (edge = me->ports_of_hw->edges;
       edge != NULL;
       edge != NULL;
       edge = edge->next)
       edge = edge->next)
    {
    {
      if (edge->my_port == my_port)
      if (edge->my_port == my_port)
        {
        {
          edge->dest->ports_of_hw->to_port_event (edge->dest,
          edge->dest->ports_of_hw->to_port_event (edge->dest,
                                                  edge->dest_port,
                                                  edge->dest_port,
                                                  me,
                                                  me,
                                                  my_port,
                                                  my_port,
                                                  level);
                                                  level);
          found_an_edge = 1;
          found_an_edge = 1;
        }
        }
    }
    }
  if (!found_an_edge)
  if (!found_an_edge)
    hw_abort (me, "No edge for port %d", my_port);
    hw_abort (me, "No edge for port %d", my_port);
}
}
 
 
 
 
void
void
hw_port_attach (struct hw *me,
hw_port_attach (struct hw *me,
                int my_port,
                int my_port,
                struct hw *dest,
                struct hw *dest,
                int dest_port,
                int dest_port,
                object_disposition disposition)
                object_disposition disposition)
{
{
  attach_hw_port_edge (me,
  attach_hw_port_edge (me,
                       &me->ports_of_hw->edges,
                       &me->ports_of_hw->edges,
                       my_port,
                       my_port,
                       dest,
                       dest,
                       dest_port,
                       dest_port,
                       disposition);
                       disposition);
}
}
 
 
 
 
void
void
hw_port_detach (struct hw *me,
hw_port_detach (struct hw *me,
                int my_port,
                int my_port,
                struct hw *dest,
                struct hw *dest,
                int dest_port)
                int dest_port)
{
{
  detach_hw_port_edge (me,
  detach_hw_port_edge (me,
                       &me->ports_of_hw->edges,
                       &me->ports_of_hw->edges,
                       my_port,
                       my_port,
                       dest,
                       dest,
                       dest_port);
                       dest_port);
}
}
 
 
 
 
void
void
hw_port_traverse (struct hw *me,
hw_port_traverse (struct hw *me,
                  hw_port_traverse_function *handler,
                  hw_port_traverse_function *handler,
                  void *data)
                  void *data)
{
{
  struct hw_port_edge *port_edge;
  struct hw_port_edge *port_edge;
  for (port_edge = me->ports_of_hw->edges;
  for (port_edge = me->ports_of_hw->edges;
       port_edge != NULL;
       port_edge != NULL;
       port_edge = port_edge->next)
       port_edge = port_edge->next)
    {
    {
      handler (me, port_edge->my_port,
      handler (me, port_edge->my_port,
               port_edge->dest, port_edge->dest_port,
               port_edge->dest, port_edge->dest_port,
               data);
               data);
    }
    }
}
}
 
 
 
 
int
int
hw_port_decode (struct hw *me,
hw_port_decode (struct hw *me,
                const char *port_name,
                const char *port_name,
                port_direction direction)
                port_direction direction)
{
{
  if (port_name == NULL || port_name[0] == '\0')
  if (port_name == NULL || port_name[0] == '\0')
    return 0;
    return 0;
  if (isdigit(port_name[0]))
  if (isdigit(port_name[0]))
    {
    {
      return strtoul (port_name, NULL, 0);
      return strtoul (port_name, NULL, 0);
    }
    }
  else
  else
    {
    {
      const struct hw_port_descriptor *ports =
      const struct hw_port_descriptor *ports =
        me->ports_of_hw->ports;
        me->ports_of_hw->ports;
      if (ports != NULL)
      if (ports != NULL)
        {
        {
          while (ports->name != NULL)
          while (ports->name != NULL)
            {
            {
              if (ports->direction == bidirect_port
              if (ports->direction == bidirect_port
                  || ports->direction == direction)
                  || ports->direction == direction)
                {
                {
                  if (ports->nr_ports > 0)
                  if (ports->nr_ports > 0)
                    {
                    {
                      int len = strlen (ports->name);
                      int len = strlen (ports->name);
                      if (strncmp (port_name, ports->name, len) == 0)
                      if (strncmp (port_name, ports->name, len) == 0)
                        {
                        {
                          if (port_name[len] == '\0')
                          if (port_name[len] == '\0')
                            return ports->number;
                            return ports->number;
                          else if(isdigit (port_name[len]))
                          else if(isdigit (port_name[len]))
                            {
                            {
                              int port = (ports->number
                              int port = (ports->number
                                          + strtoul (&port_name[len], NULL, 0));
                                          + strtoul (&port_name[len], NULL, 0));
                              if (port >= ports->number + ports->nr_ports)
                              if (port >= ports->number + ports->nr_ports)
                                hw_abort (me,
                                hw_abort (me,
                                          "Port %s out of range",
                                          "Port %s out of range",
                                          port_name);
                                          port_name);
                              return port;
                              return port;
                            }
                            }
                        }
                        }
                    }
                    }
                  else if (strcmp (port_name, ports->name) == 0)
                  else if (strcmp (port_name, ports->name) == 0)
                    return ports->number;
                    return ports->number;
                }
                }
              ports++;
              ports++;
            }
            }
        }
        }
    }
    }
  hw_abort (me, "Unreconized port %s", port_name);
  hw_abort (me, "Unreconized port %s", port_name);
  return 0;
  return 0;
}
}
 
 
 
 
int
int
hw_port_encode (struct hw *me,
hw_port_encode (struct hw *me,
                int port_number,
                int port_number,
                char *buf,
                char *buf,
                int sizeof_buf,
                int sizeof_buf,
                port_direction direction)
                port_direction direction)
{
{
  const struct hw_port_descriptor *ports = NULL;
  const struct hw_port_descriptor *ports = NULL;
  ports = me->ports_of_hw->ports;
  ports = me->ports_of_hw->ports;
  if (ports != NULL) {
  if (ports != NULL) {
    while (ports->name != NULL)
    while (ports->name != NULL)
      {
      {
        if (ports->direction == bidirect_port
        if (ports->direction == bidirect_port
            || ports->direction == direction)
            || ports->direction == direction)
          {
          {
            if (ports->nr_ports > 0)
            if (ports->nr_ports > 0)
              {
              {
                if (port_number >= ports->number
                if (port_number >= ports->number
                    && port_number < ports->number + ports->nr_ports)
                    && port_number < ports->number + ports->nr_ports)
                  {
                  {
                    strcpy (buf, ports->name);
                    strcpy (buf, ports->name);
                    sprintf (buf + strlen(buf), "%d", port_number - ports->number);
                    sprintf (buf + strlen(buf), "%d", port_number - ports->number);
                    if (strlen (buf) >= sizeof_buf)
                    if (strlen (buf) >= sizeof_buf)
                      hw_abort (me, "hw_port_encode: buffer overflow");
                      hw_abort (me, "hw_port_encode: buffer overflow");
                    return strlen (buf);
                    return strlen (buf);
                  }
                  }
              }
              }
            else
            else
              {
              {
                if (ports->number == port_number)
                if (ports->number == port_number)
                  {
                  {
                    if (strlen(ports->name) >= sizeof_buf)
                    if (strlen(ports->name) >= sizeof_buf)
                      hw_abort (me, "hw_port_encode: buffer overflow");
                      hw_abort (me, "hw_port_encode: buffer overflow");
                    strcpy(buf, ports->name);
                    strcpy(buf, ports->name);
                    return strlen(buf);
                    return strlen(buf);
                  }
                  }
              }
              }
          }
          }
        ports++;
        ports++;
      }
      }
  }
  }
  sprintf (buf, "%d", port_number);
  sprintf (buf, "%d", port_number);
  if (strlen(buf) >= sizeof_buf)
  if (strlen(buf) >= sizeof_buf)
    hw_abort (me, "hw_port_encode: buffer overflow");
    hw_abort (me, "hw_port_encode: buffer overflow");
  return strlen(buf);
  return strlen(buf);
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.