OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-6.8/] [sim/] [cris/] [dv-cris.c] - Diff between revs 24 and 157

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

Rev 24 Rev 157
/* The CRIS interrupt framework for GDB, the GNU Debugger.
/* The CRIS interrupt framework for GDB, the GNU Debugger.
 
 
   Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
   Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
 
 
   This file is part of GDB.
   This file is part of GDB.
 
 
   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 "sim-main.h"
#include "sim-main.h"
#include "hw-main.h"
#include "hw-main.h"
 
 
/* DEVICE
/* DEVICE
 
 
   CRIS cpu virtual device (very rudimental; generic enough for all
   CRIS cpu virtual device (very rudimental; generic enough for all
   currently used CRIS versions).
   currently used CRIS versions).
 
 
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Implements the external CRIS functionality.  This includes the
   Implements the external CRIS functionality.  This includes the
   delivery of interrupts generated from other devices.
   delivery of interrupts generated from other devices.
 
 
 
 
   PROPERTIES
   PROPERTIES
 
 
   vec-for-int = <int-a> <vec-a> <int-b> <vec-b> ...
   vec-for-int = <int-a> <vec-a> <int-b> <vec-b> ...
   These are the translations to interrupt vector for values appearing
   These are the translations to interrupt vector for values appearing
   on the "int" port, as pairs of the value and the corresponding
   on the "int" port, as pairs of the value and the corresponding
   vector.  Defaults to no translation.  All values that may appear on
   vector.  Defaults to no translation.  All values that may appear on
   the "int" port must be defined, or the device aborts.
   the "int" port must be defined, or the device aborts.
 
 
   multiple-int = ("abort" | "ignore_previous" | <vector>)
   multiple-int = ("abort" | "ignore_previous" | <vector>)
   If multiple interrupt values are dispatched, this property decides
   If multiple interrupt values are dispatched, this property decides
   what to do.  The value is either a number corresponding to the
   what to do.  The value is either a number corresponding to the
   vector to use, or the string "abort" to cause a hard abort, or the
   vector to use, or the string "abort" to cause a hard abort, or the
   string "ignore_previous", to silently use the new vector instead.
   string "ignore_previous", to silently use the new vector instead.
   The default is "abort".
   The default is "abort".
 
 
 
 
   PORTS
   PORTS
 
 
   int (input)
   int (input)
   Interrupt port.  An event with a non-zero value on this port causes
   Interrupt port.  An event with a non-zero value on this port causes
   an interrupt.  If, after an event but before the interrupt has been
   an interrupt.  If, after an event but before the interrupt has been
   properly dispatched, a non-zero value appears that is different
   properly dispatched, a non-zero value appears that is different
   after mapping than the previous, then the property multiple_int
   after mapping than the previous, then the property multiple_int
   decides what to do.
   decides what to do.
 
 
   FIXME: reg port so internal registers can be read.  Requires
   FIXME: reg port so internal registers can be read.  Requires
   chip-specific versions, though.  Ports "nmi" and "reset".
   chip-specific versions, though.  Ports "nmi" and "reset".
 
 
 
 
   BUGS
   BUGS
   When delivering an interrupt, this code assumes that there is only
   When delivering an interrupt, this code assumes that there is only
   one processor (number 0).
   one processor (number 0).
 
 
   This code does not attempt to be efficient at handling pending
   This code does not attempt to be efficient at handling pending
   interrupts.  It simply schedules the interrupt delivery handler
   interrupts.  It simply schedules the interrupt delivery handler
   every instruction cycle until all pending interrupts go away.
   every instruction cycle until all pending interrupts go away.
   It also works around a bug in sim_events_process when doing so.
   It also works around a bug in sim_events_process when doing so.
   */
   */
 
 
/* Keep this an enum for simple addition of "reset" and "nmi".  */
/* Keep this an enum for simple addition of "reset" and "nmi".  */
enum
enum
 {
 {
   INT_PORT,
   INT_PORT,
 };
 };
 
 
static const struct hw_port_descriptor cris_ports[] =
static const struct hw_port_descriptor cris_ports[] =
 {
 {
   { "int", INT_PORT, 0, input_port },
   { "int", INT_PORT, 0, input_port },
   { NULL, 0, 0, 0 }
   { NULL, 0, 0, 0 }
 };
 };
 
 
struct cris_vec_tr
struct cris_vec_tr
 {
 {
   unsigned32 portval, vec;
   unsigned32 portval, vec;
 };
 };
 
 
enum cris_multiple_ints
enum cris_multiple_ints
  {
  {
    cris_multint_abort,
    cris_multint_abort,
    cris_multint_ignore_previous,
    cris_multint_ignore_previous,
    cris_multint_vector
    cris_multint_vector
  };
  };
 
 
struct cris_hw
struct cris_hw
 {
 {
   struct hw_event *pending_handler;
   struct hw_event *pending_handler;
   unsigned32 pending_vector;
   unsigned32 pending_vector;
   struct cris_vec_tr *int_to_vec;
   struct cris_vec_tr *int_to_vec;
   enum cris_multiple_ints multi_int_action;
   enum cris_multiple_ints multi_int_action;
   unsigned32 multiple_int_vector;
   unsigned32 multiple_int_vector;
 };
 };
 
 
/* An event function, calling the actual CPU-model-specific
/* An event function, calling the actual CPU-model-specific
   interrupt-delivery function.  */
   interrupt-delivery function.  */
 
 
static void
static void
deliver_cris_interrupt (struct hw *me, void *data)
deliver_cris_interrupt (struct hw *me, void *data)
{
{
  struct cris_hw *crishw = hw_data (me);
  struct cris_hw *crishw = hw_data (me);
  SIM_DESC simulator = hw_system (me);
  SIM_DESC simulator = hw_system (me);
  sim_cpu *cpu = STATE_CPU (simulator, 0);
  sim_cpu *cpu = STATE_CPU (simulator, 0);
  unsigned int intno = crishw->pending_vector;
  unsigned int intno = crishw->pending_vector;
 
 
 if (CPU_CRIS_DELIVER_INTERRUPT (cpu) (cpu, CRIS_INT_INT, intno))
 if (CPU_CRIS_DELIVER_INTERRUPT (cpu) (cpu, CRIS_INT_INT, intno))
    {
    {
      crishw->pending_vector = 0;
      crishw->pending_vector = 0;
      crishw->pending_handler = NULL;
      crishw->pending_handler = NULL;
      return;
      return;
    }
    }
 
 
 {
 {
   /* Bug workaround: at time T with a pending number of cycles N to
   /* Bug workaround: at time T with a pending number of cycles N to
      process, if re-scheduling an event at time T+M, M < N,
      process, if re-scheduling an event at time T+M, M < N,
      sim_events_process gets stuck at T (updating the "time" to
      sim_events_process gets stuck at T (updating the "time" to
      before the event rather than after the event, or somesuch).
      before the event rather than after the event, or somesuch).
 
 
      Hacking this locally is thankfully easy: if we see the same
      Hacking this locally is thankfully easy: if we see the same
      simulation time, increase the number of cycles.  Do this every
      simulation time, increase the number of cycles.  Do this every
      time we get here, until a new time is seen (supposedly unstuck
      time we get here, until a new time is seen (supposedly unstuck
      re-delivery).  (Fixing in SIM/GDB source will hopefully then
      re-delivery).  (Fixing in SIM/GDB source will hopefully then
      also be easier, having a tangible test-case.)  */
      also be easier, having a tangible test-case.)  */
   static signed64 last_events_time = 0;
   static signed64 last_events_time = 0;
   static signed64 delta = 1;
   static signed64 delta = 1;
   signed64 this_events_time = hw_event_queue_time (me);
   signed64 this_events_time = hw_event_queue_time (me);
 
 
   if (this_events_time == last_events_time)
   if (this_events_time == last_events_time)
     delta++;
     delta++;
   else
   else
     {
     {
       delta = 1;
       delta = 1;
       last_events_time = this_events_time;
       last_events_time = this_events_time;
     }
     }
 
 
   crishw->pending_handler
   crishw->pending_handler
     = hw_event_queue_schedule (me, delta, deliver_cris_interrupt, NULL);
     = hw_event_queue_schedule (me, delta, deliver_cris_interrupt, NULL);
 }
 }
}
}
 
 
 
 
/* A port-event function for events arriving to an interrupt port.  */
/* A port-event function for events arriving to an interrupt port.  */
 
 
static void
static void
cris_port_event (struct hw *me,
cris_port_event (struct hw *me,
                 int my_port,
                 int my_port,
                 struct hw *source,
                 struct hw *source,
                 int source_port,
                 int source_port,
                 int intparam)
                 int intparam)
{
{
  struct cris_hw *crishw = hw_data (me);
  struct cris_hw *crishw = hw_data (me);
  unsigned32 vec;
  unsigned32 vec;
 
 
  /* A few placeholders; only the INT port is implemented.  */
  /* A few placeholders; only the INT port is implemented.  */
  switch (my_port)
  switch (my_port)
    {
    {
    case INT_PORT:
    case INT_PORT:
      HW_TRACE ((me, "INT value=0x%x", intparam));
      HW_TRACE ((me, "INT value=0x%x", intparam));
      break;
      break;
 
 
    default:
    default:
      hw_abort (me, "bad switch");
      hw_abort (me, "bad switch");
      break;
      break;
    }
    }
 
 
  if (intparam == 0)
  if (intparam == 0)
    return;
    return;
 
 
  if (crishw->int_to_vec != NULL)
  if (crishw->int_to_vec != NULL)
    {
    {
      unsigned int i;
      unsigned int i;
      for (i = 0; crishw->int_to_vec[i].portval != 0; i++)
      for (i = 0; crishw->int_to_vec[i].portval != 0; i++)
        if (crishw->int_to_vec[i].portval == intparam)
        if (crishw->int_to_vec[i].portval == intparam)
          break;
          break;
 
 
      if (crishw->int_to_vec[i].portval == 0)
      if (crishw->int_to_vec[i].portval == 0)
        hw_abort (me, "unsupported value for int port: 0x%x", intparam);
        hw_abort (me, "unsupported value for int port: 0x%x", intparam);
 
 
      vec = crishw->int_to_vec[i].vec;
      vec = crishw->int_to_vec[i].vec;
    }
    }
  else
  else
    vec = (unsigned32) intparam;
    vec = (unsigned32) intparam;
 
 
  if (crishw->pending_vector != 0)
  if (crishw->pending_vector != 0)
    {
    {
      if (vec == crishw->pending_vector)
      if (vec == crishw->pending_vector)
        return;
        return;
 
 
      switch (crishw->multi_int_action)
      switch (crishw->multi_int_action)
        {
        {
        case cris_multint_abort:
        case cris_multint_abort:
          hw_abort (me, "int 0x%x (0x%x) while int 0x%x hasn't been delivered",
          hw_abort (me, "int 0x%x (0x%x) while int 0x%x hasn't been delivered",
                    vec, intparam, crishw->pending_vector);
                    vec, intparam, crishw->pending_vector);
          break;
          break;
 
 
        case cris_multint_ignore_previous:
        case cris_multint_ignore_previous:
          break;
          break;
 
 
        case cris_multint_vector:
        case cris_multint_vector:
          vec = crishw->multiple_int_vector;
          vec = crishw->multiple_int_vector;
          break;
          break;
 
 
        default:
        default:
          hw_abort (me, "bad switch");
          hw_abort (me, "bad switch");
        }
        }
    }
    }
 
 
  crishw->pending_vector = vec;
  crishw->pending_vector = vec;
 
 
  /* Schedule our event handler *now*.  */
  /* Schedule our event handler *now*.  */
  if (crishw->pending_handler == NULL)
  if (crishw->pending_handler == NULL)
    crishw->pending_handler
    crishw->pending_handler
      = hw_event_queue_schedule (me, 0, deliver_cris_interrupt, NULL);
      = hw_event_queue_schedule (me, 0, deliver_cris_interrupt, NULL);
}
}
 
 
/* Instance initializer function.  */
/* Instance initializer function.  */
 
 
static void
static void
cris_finish (struct hw *me)
cris_finish (struct hw *me)
{
{
  struct cris_hw *crishw;
  struct cris_hw *crishw;
  const struct hw_property *vec_for_int;
  const struct hw_property *vec_for_int;
  const struct hw_property *multiple_int;
  const struct hw_property *multiple_int;
 
 
  crishw = HW_ZALLOC (me, struct cris_hw);
  crishw = HW_ZALLOC (me, struct cris_hw);
  set_hw_data (me, crishw);
  set_hw_data (me, crishw);
  set_hw_ports (me, cris_ports);
  set_hw_ports (me, cris_ports);
  set_hw_port_event (me, cris_port_event);
  set_hw_port_event (me, cris_port_event);
 
 
  vec_for_int = hw_find_property (me, "vec-for-int");
  vec_for_int = hw_find_property (me, "vec-for-int");
  if (vec_for_int != NULL)
  if (vec_for_int != NULL)
    {
    {
      unsigned32 vecsize;
      unsigned32 vecsize;
      unsigned32 i;
      unsigned32 i;
 
 
      if (hw_property_type (vec_for_int) != array_property)
      if (hw_property_type (vec_for_int) != array_property)
        hw_abort (me, "property \"vec-for-int\" has the wrong type");
        hw_abort (me, "property \"vec-for-int\" has the wrong type");
 
 
      vecsize = hw_property_sizeof_array (vec_for_int) / sizeof (signed_cell);
      vecsize = hw_property_sizeof_array (vec_for_int) / sizeof (signed_cell);
 
 
      if ((vecsize % 2) != 0)
      if ((vecsize % 2) != 0)
        hw_abort (me, "translation vector does not consist of even pairs");
        hw_abort (me, "translation vector does not consist of even pairs");
 
 
      crishw->int_to_vec
      crishw->int_to_vec
        = hw_malloc (me, (vecsize/2 + 1) * sizeof (crishw->int_to_vec[0]));
        = hw_malloc (me, (vecsize/2 + 1) * sizeof (crishw->int_to_vec[0]));
 
 
      for (i = 0; i < vecsize/2; i++)
      for (i = 0; i < vecsize/2; i++)
        {
        {
          signed_cell portval_sc;
          signed_cell portval_sc;
          signed_cell vec_sc;
          signed_cell vec_sc;
 
 
          if (!hw_find_integer_array_property (me, "vec-for-int", i*2,
          if (!hw_find_integer_array_property (me, "vec-for-int", i*2,
                                               &portval_sc)
                                               &portval_sc)
              || !hw_find_integer_array_property (me, "vec-for-int", i*2 + 1,
              || !hw_find_integer_array_property (me, "vec-for-int", i*2 + 1,
                                                  &vec_sc)
                                                  &vec_sc)
              || portval_sc < 0
              || portval_sc < 0
              || vec_sc < 0)
              || vec_sc < 0)
            hw_abort (me, "no valid vector translation pair %u", i);
            hw_abort (me, "no valid vector translation pair %u", i);
 
 
          crishw->int_to_vec[i].portval = (unsigned32) portval_sc;
          crishw->int_to_vec[i].portval = (unsigned32) portval_sc;
          crishw->int_to_vec[i].vec = (unsigned32) vec_sc;
          crishw->int_to_vec[i].vec = (unsigned32) vec_sc;
        }
        }
 
 
      crishw->int_to_vec[i].portval = 0;
      crishw->int_to_vec[i].portval = 0;
      crishw->int_to_vec[i].vec = 0;
      crishw->int_to_vec[i].vec = 0;
    }
    }
 
 
  multiple_int = hw_find_property (me, "multiple-int");
  multiple_int = hw_find_property (me, "multiple-int");
  if (multiple_int != NULL)
  if (multiple_int != NULL)
    {
    {
      if (hw_property_type (multiple_int) == integer_property)
      if (hw_property_type (multiple_int) == integer_property)
        {
        {
          crishw->multiple_int_vector
          crishw->multiple_int_vector
            = hw_find_integer_property (me, "multiple-int");
            = hw_find_integer_property (me, "multiple-int");
          crishw->multi_int_action = cris_multint_vector;
          crishw->multi_int_action = cris_multint_vector;
        }
        }
      else
      else
        {
        {
          const char *action = hw_find_string_property (me, "multiple-int");
          const char *action = hw_find_string_property (me, "multiple-int");
 
 
          if (action == NULL)
          if (action == NULL)
            hw_abort (me, "property \"multiple-int\" has the wrong type");
            hw_abort (me, "property \"multiple-int\" has the wrong type");
 
 
          if (strcmp (action, "abort") == 0)
          if (strcmp (action, "abort") == 0)
            crishw->multi_int_action = cris_multint_abort;
            crishw->multi_int_action = cris_multint_abort;
          else if (strcmp (action, "ignore_previous") == 0)
          else if (strcmp (action, "ignore_previous") == 0)
            crishw->multi_int_action = cris_multint_ignore_previous;
            crishw->multi_int_action = cris_multint_ignore_previous;
          else
          else
            hw_abort (me, "property \"multiple-int\" must be one of <vector number>\n"
            hw_abort (me, "property \"multiple-int\" must be one of <vector number>\n"
                      "\"abort\" and \"ignore_previous\", not \"%s\"", action);
                      "\"abort\" and \"ignore_previous\", not \"%s\"", action);
        }
        }
    }
    }
  else
  else
    crishw->multi_int_action = cris_multint_abort;
    crishw->multi_int_action = cris_multint_abort;
}
}
 
 
const struct hw_descriptor dv_cris_descriptor[] = {
const struct hw_descriptor dv_cris_descriptor[] = {
  { "cris", cris_finish, },
  { "cris", cris_finish, },
  { NULL },
  { NULL },
};
};
 
 

powered by: WebSVN 2.1.0

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