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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gdb-7.2/] [sim/] [common/] [hw-alloc.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
/* Hardware memory allocator.
/* Hardware memory allocator.
   Copyright (C) 1998, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
   Copyright (C) 1998, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
   Contributed by Cygnus Support.
   Contributed by Cygnus Support.
 
 
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
 
 
struct hw_alloc_data {
struct hw_alloc_data {
  void *alloc;
  void *alloc;
  int zalloc_p;
  int zalloc_p;
  struct hw_alloc_data *next;
  struct hw_alloc_data *next;
};
};
 
 
void
void
create_hw_alloc_data (struct hw *me)
create_hw_alloc_data (struct hw *me)
{
{
  /* NULL */
  /* NULL */
}
}
 
 
void
void
delete_hw_alloc_data (struct hw *me)
delete_hw_alloc_data (struct hw *me)
{
{
  while (me->alloc_of_hw != NULL)
  while (me->alloc_of_hw != NULL)
    {
    {
      hw_free (me, me->alloc_of_hw->alloc);
      hw_free (me, me->alloc_of_hw->alloc);
    }
    }
}
}
 
 
 
 
 
 
void *
void *
hw_zalloc (struct hw *me, unsigned long size)
hw_zalloc (struct hw *me, unsigned long size)
{
{
  struct hw_alloc_data *memory = ZALLOC (struct hw_alloc_data);
  struct hw_alloc_data *memory = ZALLOC (struct hw_alloc_data);
  memory->alloc = zalloc (size);
  memory->alloc = zalloc (size);
  memory->zalloc_p = 1;
  memory->zalloc_p = 1;
  memory->next = me->alloc_of_hw;
  memory->next = me->alloc_of_hw;
  me->alloc_of_hw = memory;
  me->alloc_of_hw = memory;
  return memory->alloc;
  return memory->alloc;
}
}
 
 
void *
void *
hw_malloc (struct hw *me, unsigned long size)
hw_malloc (struct hw *me, unsigned long size)
{
{
  struct hw_alloc_data *memory = ZALLOC (struct hw_alloc_data);
  struct hw_alloc_data *memory = ZALLOC (struct hw_alloc_data);
  memory->alloc = zalloc (size);
  memory->alloc = zalloc (size);
  memory->zalloc_p = 0;
  memory->zalloc_p = 0;
  memory->next = me->alloc_of_hw;
  memory->next = me->alloc_of_hw;
  me->alloc_of_hw = memory;
  me->alloc_of_hw = memory;
  return memory->alloc;
  return memory->alloc;
}
}
 
 
void
void
hw_free (struct hw *me,
hw_free (struct hw *me,
         void *alloc)
         void *alloc)
{
{
  struct hw_alloc_data **memory;
  struct hw_alloc_data **memory;
  for (memory = &me->alloc_of_hw;
  for (memory = &me->alloc_of_hw;
       *memory != NULL;
       *memory != NULL;
       memory = &(*memory)->next)
       memory = &(*memory)->next)
    {
    {
      if ((*memory)->alloc == alloc)
      if ((*memory)->alloc == alloc)
        {
        {
          struct hw_alloc_data *die = (*memory);
          struct hw_alloc_data *die = (*memory);
          (*memory) = die->next;
          (*memory) = die->next;
          if (die->zalloc_p)
          if (die->zalloc_p)
            zfree (die->alloc);
            zfree (die->alloc);
          else
          else
            free (die->alloc);
            free (die->alloc);
          zfree (die);
          zfree (die);
          return;
          return;
        }
        }
    }
    }
  hw_abort (me, "free of memory not belonging to a device");
  hw_abort (me, "free of memory not belonging to a device");
}
}
 
 

powered by: WebSVN 2.1.0

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