Move set_* macro's from hw-base to hw-device.
gennltvals.sh
gentmap.c
gentvals.sh
+hw-alloc.c
+hw-alloc.h
hw-base.c
hw-base.h
hw-device.c
+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.
--- /dev/null
+/* 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");
+}
--- /dev/null
+/* 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
/* 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);
#include <stdlib.h>
#endif
-\f
/* Address methods */
const hw_unit *
}
-\f
/* IOCTL: */
int
#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 */
#define hw_reset(hw) ((hw)->to_reset (hw))
+#define set_hw_reset(hw, method) \
+((hw)->to_reset = method)
+
\f
/* Hardware operations:
#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,
#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.
#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,
#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
#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,
#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
#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,
#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
#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,
#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);