]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add files hw-alloc.[hc] (mising from last CI)
authorAndrew Cagney <cagney@redhat.com>
Mon, 25 May 1998 08:50:22 +0000 (08:50 +0000)
committerAndrew Cagney <cagney@redhat.com>
Mon, 25 May 1998 08:50:22 +0000 (08:50 +0000)
Move set_* macro's from hw-base to hw-device.

sim/common/.Sanitize
sim/common/ChangeLog
sim/common/hw-alloc.c [new file with mode: 0644]
sim/common/hw-alloc.h [new file with mode: 0644]
sim/common/hw-base.h
sim/common/hw-device.c
sim/common/hw-device.h

index c969031fd640676ab13b8b6000ba7675126933b1..5a612e2b5368f2e0da810256d3e4a495198d9e70 100644 (file)
@@ -57,6 +57,8 @@ genmloop.sh
 gennltvals.sh
 gentmap.c
 gentvals.sh
+hw-alloc.c
+hw-alloc.h
 hw-base.c
 hw-base.h
 hw-device.c
index 96431f080c7410bba041b91d676f898b488f3df6..69aebccfca42e6f6915e3dde1fae636d07cd88f6 100644 (file)
@@ -1,7 +1,13 @@
+Mon May 25 18:41:18 1998  Andrew Cagney  <cagney@b1.cygnus.com>
+
+       * hw-base.h (set_*): Move set method macros from here.
+       * hw-device.h: To here.
+
 Mon May 25 18:21:38 1998  Andrew Cagney  <cagney@b1.cygnus.com>
 
        * hw-base.h (create_hw_property_data, delete_hw_property_data):
        Declare.
+
        * hw-base.c (hw_create, hw_delete): Call
        * hw-properties.c (create_hw_property_data,
        delete_hw_property_data): Define.
diff --git a/sim/common/hw-alloc.c b/sim/common/hw-alloc.c
new file mode 100644 (file)
index 0000000..1172c4d
--- /dev/null
@@ -0,0 +1,99 @@
+/* Hardware memory allocator.
+   Copyright (C) 1998 Free Software Foundation, Inc.
+   Contributed by Cygnus Support.
+
+This file is part of GDB, the GNU debugger.
+
+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
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+
+#include "sim-main.h"
+#include "hw-base.h"
+
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+struct hw_alloc_data {
+  void *alloc;
+  int zalloc_p;
+  struct hw_alloc_data *next;
+};
+
+void
+create_hw_alloc_data (struct hw *me)
+{
+  /* NULL */
+}
+
+void
+delete_hw_alloc_data (struct hw *me)
+{
+  if (me->alloc_of_hw != NULL)
+    hw_abort (me, "hw-alloc botch");
+  while (me->alloc_of_hw != NULL)
+    {
+      hw_free (me, me->alloc_of_hw->alloc);
+    }
+}
+
+
+
+void *
+hw_zalloc (struct hw *me, unsigned long size)
+{
+  struct hw_alloc_data *memory = ZALLOC (struct hw_alloc_data);
+  memory->alloc = zalloc (size);
+  memory->zalloc_p = 1;
+  memory->next = me->alloc_of_hw;
+  me->alloc_of_hw = memory;
+  return memory->alloc;
+}
+
+void *
+hw_malloc (struct hw *me, unsigned long size)
+{
+  struct hw_alloc_data *memory = ZALLOC (struct hw_alloc_data);
+  memory->alloc = zalloc (size);
+  memory->zalloc_p = 0;
+  memory->next = me->alloc_of_hw;
+  me->alloc_of_hw = memory;
+  return memory->alloc;
+}
+
+void
+hw_free (struct hw *me,
+        void *alloc)
+{
+  struct hw_alloc_data **memory;
+  for (memory = &me->alloc_of_hw;
+       *memory != NULL;
+       memory = &(*memory)->next)
+    {
+      if ((*memory)->alloc == alloc)
+       {
+         struct hw_alloc_data *die = (*memory);
+         (*memory) = die->next;
+         if (die->zalloc_p)
+           zfree (die->alloc);
+         else
+           free (die->alloc);
+         zfree (die);
+         return;
+       }
+    }
+  hw_abort (me, "free of memory not belonging to a device");
+}
diff --git a/sim/common/hw-alloc.h b/sim/common/hw-alloc.h
new file mode 100644 (file)
index 0000000..cda038f
--- /dev/null
@@ -0,0 +1,48 @@
+/* Hardware memory allocator.
+   Copyright (C) 1998 Free Software Foundation, Inc.
+   Contributed by Cygnus Support.
+
+This file is part of GDB, the GNU debugger.
+
+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
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+
+#ifndef HW_ALLOC_H
+#define HW_ALLOC_H
+
+/* Mechanism for associating memory allocated by a device to that
+   device.
+
+   When a device is deleted any remaining memory regions associated to
+   it are reclaimed.
+
+   FIXME: Perhaphs this can be generalized. Perhaphs it should not
+   be. */
+
+
+#define HW_ZALLOC(me,type) (type*) hw_zalloc (me, sizeof (type))
+#define HW_MALLOC(me,type) (type*) hw_malloc (me, sizeof (type))
+
+extern void *hw_zalloc (struct hw *me, unsigned long size);
+extern void *hw_malloc (struct hw *me, unsigned long size);
+
+extern void hw_free (struct hw *me, void *);
+
+
+/* Duplicate a string allocating memory using the per-device heap */
+
+extern char *hw_strdup (struct hw *me, const char *str);
+
+#endif
index f63807c2750215a9f69d92cda6ad8f6119b70ea6..da379866fa5661df9cae495b8c28d15abda072ff 100644 (file)
@@ -70,37 +70,6 @@ void hw_delete
 
 /* Override device methods */
 
-#define set_hw_data(hw, value) \
-((hw)->data_of_hw = (value))
-
-#define set_hw_reset(hw, method) \
-((hw)->to_reset = method)
-
-#define set_hw_io_read_buffer(hw, method) \
-((hw)->to_io_read_buffer = (method))
-#define set_hw_io_write_buffer(hw, method) \
-((hw)->to_io_write_buffer = (method))
-
-#define set_hw_dma_read_buffer(me, method) \
-((me)->to_dma_read_buffer = (method))
-#define set_hw_dma_write_buffer(me, method) \
-((me)->to_dma_write_buffer = (method))
-
-#define set_hw_attach_address(hw, method) \
-((hw)->to_attach_address = (method))
-#define set_hw_detach_address(hw, method) \
-((hw)->to_detach_address = (method))
-
-#define set_hw_unit_decode(hw, method) \
-((hw)->to_unit_decode = (method))
-#define set_hw_unit_encode(hw, method) \
-((hw)->to_unit_encode = (method))
-
-#define set_hw_unit_address_to_attach_address(hw, method) \
-((hw)->to_unit_address_to_attach_address = (method))
-#define set_hw_unit_size_to_attach_size(hw, method) \
-((hw)->to_unit_size_to_attach_size = (method))
-
 typedef void (hw_delete_callback)
      (struct hw *me);
 
index b435ebd0f7031fc003ec60b5d6e216793fc5d70c..41abab877b785284b3353eb99015c3eb7fce04e3 100644 (file)
@@ -26,7 +26,6 @@
 #include <stdlib.h>
 #endif
 
-\f
 /* Address methods */
 
 const hw_unit *
@@ -36,7 +35,6 @@ hw_unit_address (struct hw *me)
 }
 
 
-\f
 /* IOCTL: */
 
 int
index a787089c87c7ff7985e93e1a4ad1bfb3df592373..44c0709fc8f1a43638f188036b19a5d2a2a28f44 100644 (file)
@@ -150,6 +150,9 @@ struct _sim_cpu *hw_system_cpu (struct hw *hw);
 
 #define hw_data(hw) ((hw)->data_of_hw)
 
+#define set_hw_data(hw, value) \
+((hw)->data_of_hw = (value))
+
 
 \f
 /* Perform a soft reset of the device */
@@ -159,6 +162,9 @@ typedef unsigned (hw_reset_callback)
 
 #define hw_reset(hw) ((hw)->to_reset (hw))
 
+#define set_hw_reset(hw, method) \
+((hw)->to_reset = method)
+
 \f
 /* Hardware operations:
 
@@ -195,6 +201,8 @@ typedef void (hw_attach_address_callback)
 #define hw_attach_address(me, level, space, addr, nr_bytes, client) \
 ((me)->to_attach_address (me, level, space, addr, nr_bytes, client))
 
+#define set_hw_attach_address(hw, method) \
+((hw)->to_attach_address = (method))
 
 typedef void (hw_detach_address_callback)
      (struct hw *me,
@@ -207,6 +215,9 @@ typedef void (hw_detach_address_callback)
 #define hw_detach_address(me, level, space, addr, nr_bytes, client) \
 ((me)->to_detach_address (me, level, space, addr, nr_bytes, client))
 
+#define set_hw_detach_address(hw, method) \
+((hw)->to_detach_address = (method))
+
 
 /* An IO operation from a parent to a child via the conecting bus.
 
@@ -223,6 +234,9 @@ typedef unsigned (hw_io_read_buffer_callback)
 #define hw_io_read_buffer(hw, dest, space, addr, nr_bytes) \
 ((hw)->to_io_read_buffer (hw, dest, space, addr, nr_bytes))
 
+#define set_hw_io_read_buffer(hw, method) \
+((hw)->to_io_read_buffer = (method))
+
 typedef unsigned (hw_io_write_buffer_callback)
      (struct hw *me,
       const void *source,
@@ -233,6 +247,8 @@ typedef unsigned (hw_io_write_buffer_callback)
 #define hw_io_write_buffer(hw, src, space, addr, nr_bytes) \
 ((hw)->to_io_write_buffer (hw, src, space, addr, nr_bytes))
 
+#define set_hw_io_write_buffer(hw, method) \
+((hw)->to_io_write_buffer = (method))
 
 
 /* Conversly, the device pci1000,1@1 may need to perform a dma transfer
@@ -254,6 +270,9 @@ typedef unsigned (hw_dma_read_buffer_callback)
 #define hw_dma_read_buffer(bus, dest, space, addr, nr_bytes) \
 ((bus)->to_dma_read_buffer (bus, dest, space, addr, nr_bytes))
 
+#define set_hw_dma_read_buffer(me, method) \
+((me)->to_dma_read_buffer = (method))
+
 typedef unsigned (hw_dma_write_buffer_callback)
      (struct hw *bus,
       const void *source,
@@ -264,6 +283,9 @@ typedef unsigned (hw_dma_write_buffer_callback)
 
 #define hw_dma_write_buffer(bus, src, space, addr, nr_bytes, violate_ro) \
 ((bus)->to_dma_write_buffer (bus, src, space, addr, nr_bytes, violate_ro))
+
+#define set_hw_dma_write_buffer(me, method) \
+((me)->to_dma_write_buffer = (method))
 \f
 /* Address/size specs for devices are encoded following a convention
    similar to that used by OpenFirmware.  In particular, an
@@ -310,6 +332,8 @@ typedef int (hw_unit_decode_callback)
 #define hw_unit_decode(bus, encoded, unit) \
 ((bus)->to_unit_decode (bus, encoded, unit))
 
+#define set_hw_unit_decode(hw, method) \
+((hw)->to_unit_decode = (method))
 
 typedef int (hw_unit_encode_callback)
      (struct hw *bus,
@@ -320,6 +344,8 @@ typedef int (hw_unit_encode_callback)
 #define hw_unit_encode(bus, unit, encoded, sizeof_encoded) \
 ((bus)->to_unit_encode (bus, unit, encoded, sizeof_encoded))
 
+#define set_hw_unit_encode(hw, method) \
+((hw)->to_unit_encode = (method))
 
 
 /* As the bus that the device is attached too, to translate a devices
@@ -339,6 +365,8 @@ typedef int (hw_unit_address_to_attach_address_callback)
 #define hw_unit_address_to_attach_address(bus, unit_addr, attach_space, attach_addr, client) \
 ((bus)->to_unit_address_to_attach_address (bus, unit_addr, attach_space, attach_addr, client))
 
+#define set_hw_unit_address_to_attach_address(hw, method) \
+((hw)->to_unit_address_to_attach_address = (method))
 
 typedef int (hw_unit_size_to_attach_size_callback)
      (struct hw *bus,
@@ -349,6 +377,8 @@ typedef int (hw_unit_size_to_attach_size_callback)
 #define hw_unit_size_to_attach_size(bus, unit_size, attach_size, client) \
 ((bus)->to_unit_size_to_attach_size (bus, unit_size, attach_size, client))
 
+#define set_hw_unit_size_to_attach_size(hw, method) \
+((hw)->to_unit_size_to_attach_size = (method))
 
 \f
 extern char *hw_strdup (struct hw *me, const char *str);