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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gdb-7.2/] [sim/] [ppc/] [hw_glue.c] - Diff between revs 835 and 841

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

Rev 835 Rev 841
/*  This file is part of the program psim.
/*  This file is part of the program psim.
 
 
    Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
    Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
 
 
    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 2 of the License, or
    the Free Software Foundation; either version 2 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, write to the Free Software
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 
    */
    */
 
 
 
 
#ifndef _HW_GLUE_C_
#ifndef _HW_GLUE_C_
#define _HW_GLUE_C_
#define _HW_GLUE_C_
 
 
#include "device_table.h"
#include "device_table.h"
 
 
 
 
/* DEVICE
/* DEVICE
 
 
 
 
   glue - glue to interconnect and test interrupts
   glue - glue to interconnect and test interrupts
 
 
 
 
   DESCRIPTION
   DESCRIPTION
 
 
 
 
   The glue device provides two functions.  Firstly, it provides a
   The glue device provides two functions.  Firstly, it provides a
   mechanism for inspecting and driving the interrupt net.  Secondly,
   mechanism for inspecting and driving the interrupt net.  Secondly,
   it provides a set of boolean primitives that can be used add
   it provides a set of boolean primitives that can be used add
   combinatorial operations to the interrupt network.
   combinatorial operations to the interrupt network.
 
 
   Glue devices have a variable number of big endian <<output>>
   Glue devices have a variable number of big endian <<output>>
   registers.  Each host-word size.  The registers can be both read
   registers.  Each host-word size.  The registers can be both read
   and written.
   and written.
 
 
   Writing a value to an output register causes an interrupt (of the
   Writing a value to an output register causes an interrupt (of the
   specified level) to be driven on the devices corresponding output
   specified level) to be driven on the devices corresponding output
   interrupt port.
   interrupt port.
 
 
   Reading an <<output>> register returns either the last value
   Reading an <<output>> register returns either the last value
   written or the most recently computed value (for that register) as
   written or the most recently computed value (for that register) as
   a result of an interrupt ariving (which ever was computed last).
   a result of an interrupt ariving (which ever was computed last).
 
 
   At present the following sub device types are available:
   At present the following sub device types are available:
 
 
   <<glue>>: In addition to driving its output interrupt port with any
   <<glue>>: In addition to driving its output interrupt port with any
   value written to an interrupt input port is stored in the
   value written to an interrupt input port is stored in the
   corresponding <<output>> register.  Such input interrupts, however,
   corresponding <<output>> register.  Such input interrupts, however,
   are not propogated to an output interrupt port.
   are not propogated to an output interrupt port.
 
 
   <<glue-and>>: The bit-wise AND of the interrupt inputs is computed
   <<glue-and>>: The bit-wise AND of the interrupt inputs is computed
   and then both stored in <<output>> register zero and propogated to
   and then both stored in <<output>> register zero and propogated to
   output interrupt output port zero.
   output interrupt output port zero.
 
 
 
 
   PROPERTIES
   PROPERTIES
 
 
 
 
   reg = <address> <size> (required)
   reg = <address> <size> (required)
 
 
   Specify the address (within the parent bus) that this device is to
   Specify the address (within the parent bus) that this device is to
   live.  The address must be 2048 * sizeof(word) (8k in a 32bit
   live.  The address must be 2048 * sizeof(word) (8k in a 32bit
   simulation) aligned.
   simulation) aligned.
 
 
 
 
   interrupt-ranges = <int-number> <range> (optional)
   interrupt-ranges = <int-number> <range> (optional)
 
 
   If present, this specifies the number of valid interrupt inputs (up
   If present, this specifies the number of valid interrupt inputs (up
   to the maximum of 2048).  By default, <<int-number>> is zero and
   to the maximum of 2048).  By default, <<int-number>> is zero and
   range is determined by the <<reg>> size.
   range is determined by the <<reg>> size.
 
 
 
 
   EXAMPLES
   EXAMPLES
 
 
 
 
   Enable tracing of the device:
   Enable tracing of the device:
 
 
   | -t glue-device \
   | -t glue-device \
 
 
 
 
   Create source, bitwize-and, and sink glue devices.  Since the
   Create source, bitwize-and, and sink glue devices.  Since the
   device at address <<0x10000>> is of size <<8>> it will have two
   device at address <<0x10000>> is of size <<8>> it will have two
   output interrupt ports.
   output interrupt ports.
 
 
   | -o '/iobus@0xf0000000/glue@0x10000/reg 0x10000 8' \
   | -o '/iobus@0xf0000000/glue@0x10000/reg 0x10000 8' \
   | -o '/iobus@0xf0000000/glue-and@0x20000/reg 0x20000 4' \
   | -o '/iobus@0xf0000000/glue-and@0x20000/reg 0x20000 4' \
   | -o '/iobus@0xf0000000/glue-and/interrupt-ranges 0 2' \
   | -o '/iobus@0xf0000000/glue-and/interrupt-ranges 0 2' \
   | -o '/iobus@0xf0000000/glue@0x30000/reg 0x30000 4' \
   | -o '/iobus@0xf0000000/glue@0x30000/reg 0x30000 4' \
 
 
 
 
   Wire the two source interrupts to the AND device:
   Wire the two source interrupts to the AND device:
 
 
   | -o '/iobus@0xf0000000/glue@0x10000 > 0 0 /iobus/glue-and' \
   | -o '/iobus@0xf0000000/glue@0x10000 > 0 0 /iobus/glue-and' \
   | -o '/iobus@0xf0000000/glue@0x10000 > 1 1 /iobus/glue-and' \
   | -o '/iobus@0xf0000000/glue@0x10000 > 1 1 /iobus/glue-and' \
 
 
 
 
   Wire the AND device up to the sink so that the and's output is not
   Wire the AND device up to the sink so that the and's output is not
   left open.
   left open.
 
 
   | -o '/iobus@0xf0000000/glue-and > 0 0 /iobus/glue@0x30000' \
   | -o '/iobus@0xf0000000/glue-and > 0 0 /iobus/glue@0x30000' \
 
 
 
 
   With the above configuration.  The client program is able to
   With the above configuration.  The client program is able to
   compute a two bit AND.  For instance the <<C>> stub below prints 1
   compute a two bit AND.  For instance the <<C>> stub below prints 1
   AND 0.
   AND 0.
 
 
   |  unsigned *input = (void*)0xf0010000;
   |  unsigned *input = (void*)0xf0010000;
   |  unsigned *output = (void*)0xf0030000;
   |  unsigned *output = (void*)0xf0030000;
   |  unsigned ans;
   |  unsigned ans;
   |  input[0] = htonl(1);
   |  input[0] = htonl(1);
   |  input[1] = htonl(0);
   |  input[1] = htonl(0);
   |  ans = ntohl(*output);
   |  ans = ntohl(*output);
   |  write_string("AND is ");
   |  write_string("AND is ");
   |  write_int(ans);
   |  write_int(ans);
   |  write_line();
   |  write_line();
 
 
 
 
   BUGS
   BUGS
 
 
 
 
   A future implementation of this device may support multiple
   A future implementation of this device may support multiple
   interrupt ranges.
   interrupt ranges.
 
 
   Some of the devices listed may not yet be fully implemented.
   Some of the devices listed may not yet be fully implemented.
 
 
   Additional devices such as a dff, an inverter or a latch may be
   Additional devices such as a dff, an inverter or a latch may be
   useful.
   useful.
 
 
   */
   */
 
 
 
 
enum {
enum {
  max_nr_interrupts = 2048,
  max_nr_interrupts = 2048,
};
};
 
 
typedef enum _hw_glue_type {
typedef enum _hw_glue_type {
  glue_undefined = 0,
  glue_undefined = 0,
  glue_io,
  glue_io,
  glue_and,
  glue_and,
  glue_nand,
  glue_nand,
  glue_or,
  glue_or,
  glue_xor,
  glue_xor,
  glue_nor,
  glue_nor,
  glue_not,
  glue_not,
} hw_glue_type;
} hw_glue_type;
 
 
typedef struct _hw_glue_device {
typedef struct _hw_glue_device {
  hw_glue_type type;
  hw_glue_type type;
  int int_number;
  int int_number;
  int *input;
  int *input;
  int nr_inputs;
  int nr_inputs;
  unsigned sizeof_input;
  unsigned sizeof_input;
  /* our output registers */
  /* our output registers */
  int space;
  int space;
  unsigned_word address;
  unsigned_word address;
  unsigned sizeof_output;
  unsigned sizeof_output;
  int *output;
  int *output;
  int nr_outputs;
  int nr_outputs;
} hw_glue_device;
} hw_glue_device;
 
 
 
 
static void
static void
hw_glue_init_address(device *me)
hw_glue_init_address(device *me)
{
{
  hw_glue_device *glue = (hw_glue_device*)device_data(me);
  hw_glue_device *glue = (hw_glue_device*)device_data(me);
 
 
  /* attach to my parent */
  /* attach to my parent */
  generic_device_init_address(me);
  generic_device_init_address(me);
 
 
  /* establish the output registers */
  /* establish the output registers */
  if (glue->output != NULL) {
  if (glue->output != NULL) {
    memset(glue->output, 0, glue->sizeof_output);
    memset(glue->output, 0, glue->sizeof_output);
  }
  }
  else {
  else {
    reg_property_spec unit;
    reg_property_spec unit;
    int reg_nr;
    int reg_nr;
    /* find a relevant reg entry */
    /* find a relevant reg entry */
    reg_nr = 0;
    reg_nr = 0;
    while (device_find_reg_array_property(me, "reg", reg_nr, &unit)
    while (device_find_reg_array_property(me, "reg", reg_nr, &unit)
           && !device_size_to_attach_size(device_parent(me), &unit.size,
           && !device_size_to_attach_size(device_parent(me), &unit.size,
                                          &glue->sizeof_output, me))
                                          &glue->sizeof_output, me))
      reg_nr++;
      reg_nr++;
    /* check out the size */
    /* check out the size */
    if (glue->sizeof_output == 0)
    if (glue->sizeof_output == 0)
      device_error(me, "at least one reg property size must be nonzero");
      device_error(me, "at least one reg property size must be nonzero");
    if (glue->sizeof_output % sizeof(unsigned_word) != 0)
    if (glue->sizeof_output % sizeof(unsigned_word) != 0)
      device_error(me, "reg property size must be %d aligned", sizeof(unsigned_word));
      device_error(me, "reg property size must be %d aligned", sizeof(unsigned_word));
    /* and the address */
    /* and the address */
    device_address_to_attach_address(device_parent(me),
    device_address_to_attach_address(device_parent(me),
                                     &unit.address, &glue->space, &glue->address,
                                     &unit.address, &glue->space, &glue->address,
                                     me);
                                     me);
    if (glue->address % (sizeof(unsigned_word) * max_nr_interrupts) != 0)
    if (glue->address % (sizeof(unsigned_word) * max_nr_interrupts) != 0)
      device_error(me, "reg property address must be %d aligned",
      device_error(me, "reg property address must be %d aligned",
                   sizeof(unsigned_word) * max_nr_interrupts);
                   sizeof(unsigned_word) * max_nr_interrupts);
    glue->nr_outputs = glue->sizeof_output / sizeof(unsigned_word);
    glue->nr_outputs = glue->sizeof_output / sizeof(unsigned_word);
    glue->output = zalloc(glue->sizeof_output);
    glue->output = zalloc(glue->sizeof_output);
  }
  }
 
 
  /* establish the input interrupt ports */
  /* establish the input interrupt ports */
  if (glue->input != NULL) {
  if (glue->input != NULL) {
    memset(glue->input, 0, glue->sizeof_input);
    memset(glue->input, 0, glue->sizeof_input);
  }
  }
  else {
  else {
    const device_property *ranges = device_find_property(me, "interrupt-ranges");
    const device_property *ranges = device_find_property(me, "interrupt-ranges");
    if (ranges == NULL) {
    if (ranges == NULL) {
      glue->int_number = 0;
      glue->int_number = 0;
      glue->nr_inputs = glue->nr_outputs;
      glue->nr_inputs = glue->nr_outputs;
    }
    }
    else if (ranges->sizeof_array != sizeof(unsigned_cell) * 2) {
    else if (ranges->sizeof_array != sizeof(unsigned_cell) * 2) {
      device_error(me, "invalid interrupt-ranges property (incorrect size)");
      device_error(me, "invalid interrupt-ranges property (incorrect size)");
    }
    }
    else {
    else {
      const unsigned_cell *int_range = ranges->array;
      const unsigned_cell *int_range = ranges->array;
      glue->int_number = BE2H_cell(int_range[0]);
      glue->int_number = BE2H_cell(int_range[0]);
      glue->nr_inputs = BE2H_cell(int_range[1]);
      glue->nr_inputs = BE2H_cell(int_range[1]);
    }
    }
    glue->sizeof_input = glue->nr_inputs * sizeof(unsigned);
    glue->sizeof_input = glue->nr_inputs * sizeof(unsigned);
    glue->input = zalloc(glue->sizeof_input);
    glue->input = zalloc(glue->sizeof_input);
  }
  }
 
 
  /* determine our type */
  /* determine our type */
  if (glue->type == glue_undefined) {
  if (glue->type == glue_undefined) {
    const char *name = device_name(me);
    const char *name = device_name(me);
    if (strcmp(name, "glue") == 0)
    if (strcmp(name, "glue") == 0)
      glue->type = glue_io;
      glue->type = glue_io;
    else if (strcmp(name, "glue-and") == 0)
    else if (strcmp(name, "glue-and") == 0)
      glue->type = glue_and;
      glue->type = glue_and;
    else
    else
      device_error(me, "unimplemented glue type");
      device_error(me, "unimplemented glue type");
  }
  }
 
 
  DTRACE(glue, ("int-number %d, nr_inputs %d, nr_outputs %d\n",
  DTRACE(glue, ("int-number %d, nr_inputs %d, nr_outputs %d\n",
                glue->int_number, glue->nr_inputs, glue->nr_outputs));
                glue->int_number, glue->nr_inputs, glue->nr_outputs));
}
}
 
 
static unsigned
static unsigned
hw_glue_io_read_buffer_callback(device *me,
hw_glue_io_read_buffer_callback(device *me,
                                void *dest,
                                void *dest,
                                int space,
                                int space,
                                unsigned_word addr,
                                unsigned_word addr,
                                unsigned nr_bytes,
                                unsigned nr_bytes,
                                cpu *processor,
                                cpu *processor,
                                unsigned_word cia)
                                unsigned_word cia)
{
{
  hw_glue_device *glue = (hw_glue_device*)device_data(me);
  hw_glue_device *glue = (hw_glue_device*)device_data(me);
  int reg = ((addr - glue->address) / sizeof(unsigned_word)) % glue->nr_outputs;
  int reg = ((addr - glue->address) / sizeof(unsigned_word)) % glue->nr_outputs;
  if (nr_bytes != sizeof(unsigned_word)
  if (nr_bytes != sizeof(unsigned_word)
      || (addr % sizeof(unsigned_word)) != 0)
      || (addr % sizeof(unsigned_word)) != 0)
     device_error(me, "missaligned read access (%d:0x%lx:%d) not supported",
     device_error(me, "missaligned read access (%d:0x%lx:%d) not supported",
                  space, (unsigned long)addr, nr_bytes);
                  space, (unsigned long)addr, nr_bytes);
  *(unsigned_word*)dest = H2BE_4(glue->output[reg]);
  *(unsigned_word*)dest = H2BE_4(glue->output[reg]);
  DTRACE(glue, ("read - interrupt %d (0x%lx), level %d\n",
  DTRACE(glue, ("read - interrupt %d (0x%lx), level %d\n",
                reg, (unsigned long) addr, glue->output[reg]));
                reg, (unsigned long) addr, glue->output[reg]));
  return nr_bytes;
  return nr_bytes;
}
}
 
 
 
 
static unsigned
static unsigned
hw_glue_io_write_buffer_callback(device *me,
hw_glue_io_write_buffer_callback(device *me,
                                 const void *source,
                                 const void *source,
                                 int space,
                                 int space,
                                 unsigned_word addr,
                                 unsigned_word addr,
                                 unsigned nr_bytes,
                                 unsigned nr_bytes,
                                 cpu *processor,
                                 cpu *processor,
                                 unsigned_word cia)
                                 unsigned_word cia)
{
{
  hw_glue_device *glue = (hw_glue_device*)device_data(me);
  hw_glue_device *glue = (hw_glue_device*)device_data(me);
  int reg = ((addr - glue->address) / sizeof(unsigned_word)) % max_nr_interrupts;
  int reg = ((addr - glue->address) / sizeof(unsigned_word)) % max_nr_interrupts;
  if (nr_bytes != sizeof(unsigned_word)
  if (nr_bytes != sizeof(unsigned_word)
      || (addr % sizeof(unsigned_word)) != 0)
      || (addr % sizeof(unsigned_word)) != 0)
    device_error(me, "missaligned write access (%d:0x%lx:%d) not supported",
    device_error(me, "missaligned write access (%d:0x%lx:%d) not supported",
                 space, (unsigned long)addr, nr_bytes);
                 space, (unsigned long)addr, nr_bytes);
  glue->output[reg] = H2BE_4(*(unsigned_word*)source);
  glue->output[reg] = H2BE_4(*(unsigned_word*)source);
  DTRACE(glue, ("write - interrupt %d (0x%lx), level %d\n",
  DTRACE(glue, ("write - interrupt %d (0x%lx), level %d\n",
                reg, (unsigned long) addr, glue->output[reg]));
                reg, (unsigned long) addr, glue->output[reg]));
  device_interrupt_event(me, reg, glue->output[reg], processor, cia);
  device_interrupt_event(me, reg, glue->output[reg], processor, cia);
  return nr_bytes;
  return nr_bytes;
}
}
 
 
static void
static void
hw_glue_interrupt_event(device *me,
hw_glue_interrupt_event(device *me,
                        int my_port,
                        int my_port,
                        device *source,
                        device *source,
                        int source_port,
                        int source_port,
                        int level,
                        int level,
                        cpu *processor,
                        cpu *processor,
                        unsigned_word cia)
                        unsigned_word cia)
{
{
  hw_glue_device *glue = (hw_glue_device*)device_data(me);
  hw_glue_device *glue = (hw_glue_device*)device_data(me);
  int i;
  int i;
  if (my_port < glue->int_number
  if (my_port < glue->int_number
      || my_port >= glue->int_number + glue->nr_inputs)
      || my_port >= glue->int_number + glue->nr_inputs)
    device_error(me, "interrupt %d outside of valid range", my_port);
    device_error(me, "interrupt %d outside of valid range", my_port);
  glue->input[my_port - glue->int_number] = level;
  glue->input[my_port - glue->int_number] = level;
  switch (glue->type) {
  switch (glue->type) {
  case glue_io:
  case glue_io:
    {
    {
      int port = my_port % glue->nr_outputs;
      int port = my_port % glue->nr_outputs;
      glue->output[port] = level;
      glue->output[port] = level;
      DTRACE(glue, ("input - interrupt %d (0x%lx), level %d\n",
      DTRACE(glue, ("input - interrupt %d (0x%lx), level %d\n",
                    my_port,
                    my_port,
                    (unsigned long)glue->address + port * sizeof(unsigned_word),
                    (unsigned long)glue->address + port * sizeof(unsigned_word),
                    level));
                    level));
      break;
      break;
    }
    }
  case glue_and:
  case glue_and:
    glue->output[0] = glue->input[0];
    glue->output[0] = glue->input[0];
    for (i = 1; i < glue->nr_inputs; i++)
    for (i = 1; i < glue->nr_inputs; i++)
      glue->output[0] &= glue->input[i];
      glue->output[0] &= glue->input[i];
    DTRACE(glue, ("and - interrupt %d, level %d arrived - output %d\n",
    DTRACE(glue, ("and - interrupt %d, level %d arrived - output %d\n",
                  my_port, level, glue->output[0]));
                  my_port, level, glue->output[0]));
    device_interrupt_event(me, 0, glue->output[0], processor, cia);
    device_interrupt_event(me, 0, glue->output[0], processor, cia);
    break;
    break;
  default:
  default:
    device_error(me, "operator not implemented");
    device_error(me, "operator not implemented");
    break;
    break;
  }
  }
}
}
 
 
 
 
static const device_interrupt_port_descriptor hw_glue_interrupt_ports[] = {
static const device_interrupt_port_descriptor hw_glue_interrupt_ports[] = {
  { "int", 0, max_nr_interrupts },
  { "int", 0, max_nr_interrupts },
  { NULL }
  { NULL }
};
};
 
 
 
 
static device_callbacks const hw_glue_callbacks = {
static device_callbacks const hw_glue_callbacks = {
  { hw_glue_init_address, NULL },
  { hw_glue_init_address, NULL },
  { NULL, }, /* address */
  { NULL, }, /* address */
  { hw_glue_io_read_buffer_callback,
  { hw_glue_io_read_buffer_callback,
      hw_glue_io_write_buffer_callback, },
      hw_glue_io_write_buffer_callback, },
  { NULL, }, /* DMA */
  { NULL, }, /* DMA */
  { hw_glue_interrupt_event, NULL, hw_glue_interrupt_ports }, /* interrupt */
  { hw_glue_interrupt_event, NULL, hw_glue_interrupt_ports }, /* interrupt */
  { NULL, }, /* unit */
  { NULL, }, /* unit */
  NULL, /* instance */
  NULL, /* instance */
};
};
 
 
 
 
static void *
static void *
hw_glue_create(const char *name,
hw_glue_create(const char *name,
              const device_unit *unit_address,
              const device_unit *unit_address,
              const char *args)
              const char *args)
{
{
  /* create the descriptor */
  /* create the descriptor */
  hw_glue_device *glue = ZALLOC(hw_glue_device);
  hw_glue_device *glue = ZALLOC(hw_glue_device);
  return glue;
  return glue;
}
}
 
 
 
 
const device_descriptor hw_glue_device_descriptor[] = {
const device_descriptor hw_glue_device_descriptor[] = {
  { "glue", hw_glue_create, &hw_glue_callbacks },
  { "glue", hw_glue_create, &hw_glue_callbacks },
  { "glue-and", hw_glue_create, &hw_glue_callbacks },
  { "glue-and", hw_glue_create, &hw_glue_callbacks },
  { "glue-nand", hw_glue_create, &hw_glue_callbacks },
  { "glue-nand", hw_glue_create, &hw_glue_callbacks },
  { "glue-or", hw_glue_create, &hw_glue_callbacks },
  { "glue-or", hw_glue_create, &hw_glue_callbacks },
  { "glue-xor", hw_glue_create, &hw_glue_callbacks },
  { "glue-xor", hw_glue_create, &hw_glue_callbacks },
  { "glue-nor", hw_glue_create, &hw_glue_callbacks },
  { "glue-nor", hw_glue_create, &hw_glue_callbacks },
  { "glue-not", hw_glue_create, &hw_glue_callbacks },
  { "glue-not", hw_glue_create, &hw_glue_callbacks },
  { NULL },
  { NULL },
};
};
 
 
#endif /* _HW_GLUE_C_ */
#endif /* _HW_GLUE_C_ */
 
 

powered by: WebSVN 2.1.0

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