aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cagney <cagney@redhat.com>1998-05-25 08:18:03 +0000
committerAndrew Cagney <cagney@redhat.com>1998-05-25 08:18:03 +0000
commit69be0d4cb816ba39cbe29091d8579b661f57d3fc (patch)
tree4ab56c60c4aae652609f72a2031d57fd9ad54355
parent39e953a72287cfa9335871478f27258989a22a66 (diff)
downloadgdb-69be0d4cb816ba39cbe29091d8579b661f57d3fc.zip
gdb-69be0d4cb816ba39cbe29091d8579b661f57d3fc.tar.gz
gdb-69be0d4cb816ba39cbe29091d8579b661f57d3fc.tar.bz2
Split out hw-alloc code. Add constructor and destructor for hw-alloc.
-rw-r--r--sim/common/ChangeLog22
-rw-r--r--sim/common/Make-common.in7
-rw-r--r--sim/common/hw-base.c3
-rw-r--r--sim/common/hw-base.h9
-rw-r--r--sim/common/hw-device.c72
-rw-r--r--sim/common/hw-device.h17
-rw-r--r--sim/common/hw-properties.c79
7 files changed, 83 insertions, 126 deletions
diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog
index 1e32237..ae5e2a3 100644
--- a/sim/common/ChangeLog
+++ b/sim/common/ChangeLog
@@ -1,10 +1,25 @@
-Mon May 25 17:14:27 1998 Andrew Cagney <cagney@b1.cygnus.com>
+Mon May 25 17:40:46 1998 Andrew Cagney <cagney@b1.cygnus.com>
- * dv-pal.c: Update.
+ * hw-device.c, hw-properties.c: Include hw-base.h
+
+ * hw-alloc.h, hw-alloc.c: New files. Move alloc code to here.
+ * hw-device.c: From here.
+ * hw-base.h: Include "hw-events.h".
+
+ * hw-base.h (create_hw_alloc_data, delete_hw_alloc_data): Declare.
+ * hw-base.c (hw_create, hw_delete): Call.
+ * hw-alloc.c (create_hw_alloc_data, delete_hw_alloc_data): Define.
+
+ * Make-common.in (SIM_NEW_COMMON_OBJS): Add hw-alloc.o.
+ (hw-alloc.o): New target.
+
+Mon May 25 17:14:27 1998 Andrew Cagney <cagney@b1.cygnus.com>
* hw-events.h, hw-events.c: New files. Move event code to here.
* sim-hw.c: From here.
* hw-base.h: Include "hw-events.h".
+ * Make-common.in (SIM_NEW_COMMON_OBJS): Add hw-events.o.
+ (hw-events.o): New target.
* hw-device.h (struct hw): Add struct hw_event_data events_of_hw.
* hw-events.h (struct hw_event): Replace typedef hw_event.
@@ -13,8 +28,7 @@ Mon May 25 17:14:27 1998 Andrew Cagney <cagney@b1.cygnus.com>
* hw-base.c (hw_create, hw_delete): Call.
* hw-events.c (create_hw_event_data, delete_hw_event_data): Define.
- * Make-common.in (SIM_NEW_COMMON_OBJS): Add hw-events.o.
- (hw-events.o): New target.
+ * dv-pal.c: Update.
Mon May 25 16:55:16 1998 Andrew Cagney <cagney@b1.cygnus.com>
diff --git a/sim/common/Make-common.in b/sim/common/Make-common.in
index 23763e1..dcc8c7a 100644
--- a/sim/common/Make-common.in
+++ b/sim/common/Make-common.in
@@ -142,6 +142,7 @@ SIM_EXTRA_CLEAN =
# Those files are specified in LIB_OBJS below.
SIM_COMMON_HW_OBJS = \
+ hw-alloc.o \
hw-device.o \
hw-events.o \
hw-ports.o \
@@ -314,6 +315,7 @@ sim-options_h = $(srccom)/sim-options.h
sim-break_h = $(srccom)/sim-break.h
sim-signal_h = $(srccom)/sim-signal.h
+hw-alloc_h = $(srccom)/hw-alloc.h
hw-base_h = $(srccom)/hw-base.h
hw-device_h = $(srccom)/hw-device.h
hw-events_h = $(srccom)/hw-events.h
@@ -324,6 +326,7 @@ hw-properties_h = $(srccom)/hw-properties.h
hw-tree_h = $(srccom)/hw-tree.h
hw_base_headers = \
+ $(hw-alloc_h) \
$(hw-base_h) \
$(hw-device_h) \
$(hw-events_h) \
@@ -472,6 +475,10 @@ hw-config.h: Makefile.in $(srccom)/Make-common.in config.status Makefile
echo "};" >> tmp-hw.h
mv tmp-hw.h hw-config.h
+hw-alloc.o: $(srccom)/hw-alloc.c $(sim_main_headers) \
+ $(hw-alloc_h)
+ $(CC) -c $(srccom)/hw-alloc.c $(ALL_CFLAGS)
+
hw-base.o: $(srccom)/hw-base.c $(sim_main_headers) \
$(hw_base_headers) hw-config.h
$(CC) -c $(srccom)/hw-base.c $(ALL_CFLAGS)
diff --git a/sim/common/hw-base.c b/sim/common/hw-base.c
index 25b5c23..03aad9b 100644
--- a/sim/common/hw-base.c
+++ b/sim/common/hw-base.c
@@ -417,6 +417,7 @@ hw_create (struct sim_state *sd,
}
/* Attach dummy ports */
+ create_hw_alloc_data (hw);
create_hw_port_data (hw);
create_hw_event_data (hw);
@@ -500,7 +501,7 @@ hw_delete (struct hw *me)
}
/* blow away all memory belonging to the device */
- hw_free_all (me);
+ delete_hw_alloc_data (me);
/* finally */
zfree (me->base_of_hw);
diff --git a/sim/common/hw-base.h b/sim/common/hw-base.h
index 99d68ac..1866d64 100644
--- a/sim/common/hw-base.h
+++ b/sim/common/hw-base.h
@@ -28,6 +28,7 @@
#include "hw-properties.h"
#include "hw-events.h"
+#include "hw-alloc.h"
/* #include "hw-instances.h" */
/* #include "hw-handles.h" */
#include "hw-ports.h"
@@ -133,6 +134,14 @@ int do_hw_poll_read
unsigned size_of_buf);
+/* ALLOC */
+
+extern void create_hw_alloc_data
+(struct hw *hw);
+extern void delete_hw_alloc_data
+(struct hw *hw);
+
+
/* PORTS */
extern void create_hw_port_data
diff --git a/sim/common/hw-device.c b/sim/common/hw-device.c
index f47ae86..b435ebd 100644
--- a/sim/common/hw-device.c
+++ b/sim/common/hw-device.c
@@ -20,9 +20,7 @@
#include "sim-main.h"
-
-#include "hw-device.h"
-#include "hw-properties.h"
+#include "hw-base.h"
#if HAVE_STDLIB_H
#include <stdlib.h>
@@ -54,74 +52,6 @@ hw_ioctl (struct hw *me,
return status;
}
-/* Mechanism for associating allocated memory regions to a device.
- When a device is deleted any remaining memory regions are also
- reclaimed.
-
- FIXME: Perhaphs this can be generalized, perhaphs it should not
- be. */
-
-struct hw_alloc_data {
- void *alloc;
- int zalloc_p;
- struct hw_alloc_data *next;
-};
-
-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");
-}
-
-void
-hw_free_all (struct hw *me)
-{
- while (me->alloc_of_hw != NULL)
- {
- hw_free (me, me->alloc_of_hw->alloc);
- }
-}
-
char *
hw_strdup (struct hw *me, const char *str)
{
diff --git a/sim/common/hw-device.h b/sim/common/hw-device.h
index 558c41d..a787089 100644
--- a/sim/common/hw-device.h
+++ b/sim/common/hw-device.h
@@ -351,23 +351,6 @@ typedef int (hw_unit_size_to_attach_size_callback)
-/* Memory allocator / de-allocator.
-
- All memory allocated using the below will be automatically
- reclaimed when the device is deleted.
-
- A device implementation can either use these functions when
- allocating memory or use malloc/zalloc/free an co-ordinate its own
- garbage collection. */
-
-#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 *);
-extern void hw_free_all (struct hw *me);
-
extern char *hw_strdup (struct hw *me, const char *str);
diff --git a/sim/common/hw-properties.c b/sim/common/hw-properties.c
index a42c0c9..b46f295 100644
--- a/sim/common/hw-properties.c
+++ b/sim/common/hw-properties.c
@@ -19,9 +19,7 @@
*/
#include "sim-main.h"
-
-#include "hw-device.h"
-#include "hw-properties.h"
+#include "hw-base.h"
#include "sim-assert.h"
@@ -347,9 +345,10 @@ hw_find_array_property (struct hw *me,
{
const struct hw_property *node;
node = hw_find_property (me, property);
- if (node == NULL
- || node->type != array_property)
- hw_abort(me, "property %s not found or of wrong type", property);
+ if (node == NULL)
+ hw_abort (me, "property \"%s\" not found", property);
+ if (node->type != array_property)
+ hw_abort (me, "property \"%s\" of wrong type (array)", property);
return node;
}
@@ -374,8 +373,10 @@ hw_find_boolean_property (struct hw *me,
const struct hw_property *node;
unsigned_cell boolean;
node = hw_find_property (me, property);
- if (node == NULL || node->type != boolean_property)
- hw_abort (me, "property %s not found or of wrong type", property);
+ if (node == NULL)
+ hw_abort (me, "property \"%s\" not found", property);
+ if (node->type != boolean_property)
+ hw_abort (me, "property \"%s\" of wrong type (boolean)", property);
ASSERT (sizeof (boolean) == node->sizeof_array);
memcpy (&boolean, node->array, sizeof (boolean));
return boolean;
@@ -407,10 +408,11 @@ hw_find_ihandle_runtime_property (struct hw *me,
TRACE (trace_devices,
("hw_find_ihandle_runtime_property(me=0x%lx, property=%s)\n",
(long)me, property));
- if (entry == NULL
- || entry->property->type != ihandle_property
+ if (entry == NULL)
+ hw_abort (me, "property \"%s\" not found", property);
+ if (entry->property->type != ihandle_property
|| entry->property->disposition != permenant_object)
- hw_abort (me, "property %s not found or of wrong type", property);
+ hw_abort (me, "property \"%s\" of wrong type", property);
ASSERT (entry->init_array != NULL);
/* the full path */
ihandle->full_path = entry->init_array;
@@ -443,10 +445,12 @@ hw_find_ihandle_property (struct hw *me,
hw_instance *instance;
node = hw_find_property (me, property);
- if (node == NULL || node->type != ihandle_property)
- hw_abort(me, "property %s not found or of wrong type", property);
+ if (node == NULL)
+ hw_abort (me, "property \"%s\" not found", property);
+ if (node->type != ihandle_property)
+ hw_abort(me, "property \"%s\" of wrong type (ihandle)", property);
if (node->array == NULL)
- hw_abort(me, "runtime property %s not yet initialized", property);
+ hw_abort(me, "runtime property \"%s\" not yet initialized", property);
ASSERT (sizeof(ihandle) == node->sizeof_array);
memcpy (&ihandle, node->array, sizeof(ihandle));
@@ -479,8 +483,10 @@ hw_find_integer_property (struct hw *me,
("hw_find_integer(me=0x%lx, property=%s)\n",
(long)me, property));
node = hw_find_property (me, property);
- if (node == NULL || node->type != integer_property)
- hw_abort (me, "property %s not found or of wrong type", property);
+ if (node == NULL)
+ hw_abort (me, "property \"%s\" not found", property);
+ if (node->type != integer_property)
+ hw_abort (me, "property \"%s\" of wrong type (integer)", property);
ASSERT (sizeof(integer) == node->sizeof_array);
memcpy (&integer, node->array, sizeof (integer));
return BE2H_cell (integer);
@@ -501,12 +507,13 @@ hw_find_integer_array_property (struct hw *me,
/* check things sane */
node = hw_find_property (me, property);
- if (node == NULL
- || (node->type != integer_property
- && node->type != array_property))
- hw_abort (me, "property %s not found or of wrong type", property);
+ if (node == NULL)
+ hw_abort (me, "property \"%s\" not found", property);
+ if (node->type != integer_property
+ && node->type != array_property)
+ hw_abort (me, "property \"%s\" of wrong type (integer or array)", property);
if ((node->sizeof_array % sizeof_integer) != 0)
- hw_abort (me, "property %s contains an incomplete number of cells", property);
+ hw_abort (me, "property \"%s\" contains an incomplete number of cells", property);
if (node->sizeof_array <= sizeof_integer * index)
return 0;
@@ -612,12 +619,14 @@ hw_find_range_array_property (struct hw *me,
/* locate the property */
node = hw_find_property (me, property);
- if (node == NULL || node->type != range_array_property)
- hw_abort (me, "property %s not found or of wrong type", property);
+ if (node == NULL)
+ hw_abort (me, "property \"%s\" not found", property);
+ if (node->type != range_array_property)
+ hw_abort (me, "property \"%s\" of wrong type (range array)", property);
/* aligned ? */
if ((node->sizeof_array % sizeof_entry) != 0)
- hw_abort (me, "property %s contains an incomplete number of entries",
+ hw_abort (me, "property \"%s\" contains an incomplete number of entries",
property);
/* within bounds? */
@@ -700,12 +709,14 @@ hw_find_reg_array_property (struct hw *me,
/* locate the property */
node = hw_find_property (me, property);
- if (node == NULL || node->type != reg_array_property)
- hw_abort (me, "property %s not found or of wrong type", property);
+ if (node == NULL)
+ hw_abort (me, "property \"%s\" not found", property);
+ if (node->type != reg_array_property)
+ hw_abort (me, "property \"%s\" of wrong type (reg array)", property);
/* aligned ? */
if ((node->sizeof_array % sizeof_entry) != 0)
- hw_abort (me, "property %s contains an incomplete number of entries",
+ hw_abort (me, "property \"%s\" contains an incomplete number of entries",
property);
/* within bounds? */
@@ -745,8 +756,10 @@ hw_find_string_property (struct hw *me,
const struct hw_property *node;
const char *string;
node = hw_find_property (me, property);
- if (node == NULL || node->type != string_property)
- hw_abort (me, "property %s not found or of wrong type", property);
+ if (node == NULL)
+ hw_abort (me, "property \"%s\" not found", property);
+ if (node->type != string_property)
+ hw_abort (me, "property \"%s\" of wrong type (string)", property);
string = node->array;
ASSERT (strlen(string) + 1 == node->sizeof_array);
return string;
@@ -763,7 +776,7 @@ hw_add_string_array_property (struct hw *me,
char *array;
char *chp;
if (nr_strings == 0)
- hw_abort (me, "property %s must be non-null", property);
+ hw_abort (me, "property \"%s\" must be non-null", property);
/* total up the size of the needed array */
for (sizeof_array = 0, string_nr = 0;
string_nr < nr_strings;
@@ -798,11 +811,11 @@ hw_find_string_array_property (struct hw *me,
const struct hw_property *node;
node = hw_find_property (me, property);
if (node == NULL)
- hw_abort (me, "property %s not found", property);
+ hw_abort (me, "property \"%s\" not found", property);
switch (node->type)
{
default:
- hw_abort (me, "property %s of wrong type", property);
+ hw_abort (me, "property \"%s\" of wrong type", property);
break;
case string_property:
if (index == 0)
@@ -815,7 +828,7 @@ hw_find_string_array_property (struct hw *me,
case array_property:
if (node->sizeof_array == 0
|| ((char*)node->array)[node->sizeof_array - 1] != '\0')
- hw_abort (me, "property %s invalid for string array", property);
+ hw_abort (me, "property \"%s\" invalid for string array", property);
/* FALL THROUGH */
case string_array_property:
ASSERT (node->sizeof_array > 0);