aboutsummaryrefslogtreecommitdiff
path: root/sim/common
diff options
context:
space:
mode:
Diffstat (limited to 'sim/common')
-rw-r--r--sim/common/.Sanitize2
-rw-r--r--sim/common/ChangeLog6
-rw-r--r--sim/common/hw-alloc.c99
-rw-r--r--sim/common/hw-alloc.h48
-rw-r--r--sim/common/hw-base.h31
-rw-r--r--sim/common/hw-device.c2
-rw-r--r--sim/common/hw-device.h30
7 files changed, 185 insertions, 33 deletions
diff --git a/sim/common/.Sanitize b/sim/common/.Sanitize
index c969031..5a612e2 100644
--- a/sim/common/.Sanitize
+++ b/sim/common/.Sanitize
@@ -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
diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog
index 96431f0..69aebcc 100644
--- a/sim/common/ChangeLog
+++ b/sim/common/ChangeLog
@@ -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
index 0000000..1172c4d
--- /dev/null
+++ b/sim/common/hw-alloc.c
@@ -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
index 0000000..cda038f
--- /dev/null
+++ b/sim/common/hw-alloc.h
@@ -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
diff --git a/sim/common/hw-base.h b/sim/common/hw-base.h
index f63807c..da37986 100644
--- a/sim/common/hw-base.h
+++ b/sim/common/hw-base.h
@@ -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);
diff --git a/sim/common/hw-device.c b/sim/common/hw-device.c
index b435ebd..41abab8 100644
--- a/sim/common/hw-device.c
+++ b/sim/common/hw-device.c
@@ -26,7 +26,6 @@
#include <stdlib.h>
#endif
-
/* Address methods */
const hw_unit *
@@ -36,7 +35,6 @@ hw_unit_address (struct hw *me)
}
-
/* IOCTL: */
int
diff --git a/sim/common/hw-device.h b/sim/common/hw-device.h
index a787089..44c0709 100644
--- a/sim/common/hw-device.h
+++ b/sim/common/hw-device.h
@@ -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))
+
/* 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)
+
/* 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))
/* 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))
extern char *hw_strdup (struct hw *me, const char *str);