-/* This file is part of the program psim.
+/* The common simulator framework for GDB, the GNU Debugger.
- Copyright (C) 1994-1998, Andrew Cagney <cagney@highland.com.au>
+ Copyright 2002-2019 Free Software Foundation, Inc.
- 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 of the License, or
- (at your option) any later version.
+ Contributed by Andrew Cagney and Red Hat.
- 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.
-
- */
+ This file is part of GDB.
+
+ 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 3 of the License, 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, see <http://www.gnu.org/licenses/>. */
#ifndef HW_DEVICE_H
#define HW_DEVICE_H
-/* declared in sim-basics.h, this object is used everywhere */
-/* typedef struct _device device; */
-
/* Introduction:
/* Short cut back to the simulator object */
-#define hw_system(hw) ((hw)->system_of_hw + 0)
+#define hw_system(hw) ((hw)->system_of_hw)
+
+/* For requests initiated by a CPU the cpu that initiated the request */
+
+struct _sim_cpu *hw_system_cpu (struct hw *hw);
+
/* Device private data */
#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 */
-typedef unsigned (hw_reset_callback)
+typedef unsigned (hw_reset_method)
(struct hw *me);
#define hw_reset(hw) ((hw)->to_reset (hw))
+#define set_hw_reset(hw, method) \
+((hw)->to_reset = method)
+
\f
/* Hardware operations:
node is described as the bus owner and is responisble for
co-ordinating bus operations. On the bus, a SPACE:ADDR pair is used
to specify an address. A device that is both a bus owner (parent)
- and bus client (child) are refered to as a bridging device.
+ and bus client (child) are referred to as a bridging device.
A child performing a data (DMA) transfer will pass its request to
the bus owner (the devices parent). The bus owner will then either
The SPACE:ADDR pair specify an address on the common bus that
connects the parent and child devices. */
-typedef void (hw_attach_address_callback)
+typedef void (hw_attach_address_method)
(struct hw *me,
int level,
int space,
#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)
+typedef void (hw_detach_address_method)
(struct hw *me,
int level,
int space,
#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.
The SPACE:ADDR pair specify an address on the bus shared between
the parent and child devices. */
-typedef unsigned (hw_io_read_buffer_callback)
+typedef unsigned (hw_io_read_buffer_method)
(struct hw *me,
void *dest,
int space,
unsigned_word addr,
- unsigned nr_bytes,
- sim_cpu *processor,
- sim_cia cia);
+ unsigned nr_bytes);
-#define hw_io_read_buffer(hw, dest, space, addr, nr_bytes, processor, cia) \
-((hw)->to_io_read_buffer (hw, dest, space, addr, nr_bytes, processor, cia))
+#define hw_io_read_buffer(hw, dest, space, addr, nr_bytes) \
+((hw)->to_io_read_buffer (hw, dest, space, addr, nr_bytes))
-typedef unsigned (hw_io_write_buffer_callback)
+#define set_hw_io_read_buffer(hw, method) \
+((hw)->to_io_read_buffer = (method))
+
+typedef unsigned (hw_io_write_buffer_method)
(struct hw *me,
const void *source,
int space,
unsigned_word addr,
- unsigned nr_bytes,
- sim_cpu *processor,
- sim_cia cia);
+ unsigned nr_bytes);
-#define hw_io_write_buffer(hw, src, space, addr, nr_bytes, processor, cia) \
-((hw)->to_io_write_buffer (hw, src, space, addr, nr_bytes, processor, cia))
+#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
The SPACE:ADDR pair specify an address on the common bus connecting
the parent and child devices. */
-typedef unsigned (hw_dma_read_buffer_callback)
+typedef unsigned (hw_dma_read_buffer_method)
(struct hw *bus,
void *dest,
int space,
#define hw_dma_read_buffer(bus, dest, space, addr, nr_bytes) \
((bus)->to_dma_read_buffer (bus, dest, space, addr, nr_bytes))
-typedef unsigned (hw_dma_write_buffer_callback)
+#define set_hw_dma_read_buffer(me, method) \
+((me)->to_dma_read_buffer = (method))
+
+typedef unsigned (hw_dma_write_buffer_method)
(struct hw *bus,
const void *source,
int space,
#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
The number of words determined by the number of {address,size}
cells attributes of the device. */
-typedef struct _hw_unit {
+typedef struct _hw_unit
+{
int nr_cells;
unsigned_cell cells[4]; /* unused cells are zero */
} hw_unit;
textual representation. This is because the textual address of a
device is specified using the parent busses notation. */
-typedef int (hw_unit_decode_callback)
+typedef int (hw_unit_decode_method)
(struct hw *bus,
const char *encoded,
hw_unit *unit);
#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)
+typedef int (hw_unit_encode_method)
(struct hw *bus,
const hw_unit *unit,
char *encoded,
int sizeof_buf);
-
+
#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
Return a zero result if the address should be ignored when looking
for attach addresses. */
-typedef int (hw_unit_address_to_attach_address_callback)
+typedef int (hw_unit_address_to_attach_address_method)
(struct hw *bus,
const hw_unit *unit_addr,
int *attach_space,
#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)
+typedef int (hw_unit_size_to_attach_size_method)
(struct hw *bus,
const hw_unit *unit_size,
unsigned *attach_size,
#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
-/* 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);
\f
/* Utilities:
*/
-typedef enum {
+typedef enum
+{
hw_ioctl_break, /* unsigned_word requested_break */
hw_ioctl_set_trace, /* void */
hw_ioctl_create_stack, /* unsigned_word *sp, char **argv, char **envp */
nr_hw_ioctl_requests,
} hw_ioctl_request;
-typedef int (hw_ioctl_callback)
+typedef int (hw_ioctl_method)
(struct hw *me,
- sim_cpu *processor,
- sim_cia cia,
hw_ioctl_request request,
va_list ap);
int hw_ioctl
(struct hw *me,
- sim_cpu *processor,
- sim_cia cia,
hw_ioctl_request request,
...);
-/* Event queue:
-
- Device specific versions of certain event handlers */
-
-typedef struct _hw_event hw_event;
-typedef void (hw_event_handler) (struct hw *me, void *data);
-
-hw_event *hw_event_queue_schedule
-(struct hw *me,
- signed64 delta_time,
- hw_event_handler *handler,
- void *data);
-
-void hw_event_queue_deschedule
-(struct hw *me,
- hw_event *event_to_remove);
-
-signed64 hw_event_queue_time
-(struct hw *me);
-
-
-
/* Error reporting::
So that errors originating from devices appear in a consistent
*/
-void volatile NORETURN hw_abort
+void hw_abort
(struct hw *me,
const char *fmt,
- ...) __attribute__ ((format (printf, 2, 3)));
+ ...) __attribute__ ((format (printf, 2, 3), noreturn));
+
+void hw_vabort
+(struct hw *me,
+ const char *fmt,
+ va_list ap) __attribute__ ((noreturn));
+
+void hw_halt
+(struct hw *me,
+ int reason,
+ int status) __attribute__ ((noreturn));
+
#define hw_trace_p(hw) ((hw)->trace_of_hw_p + 0)
+void hw_trace
+(struct hw *me,
+ const char *fmt,
+ ...) __attribute__ ((format (printf, 2, 3)));
+
+#define HW_TRACE(ARGS) \
+do { \
+ if (hw_trace_p (me)) \
+ { \
+ hw_trace ARGS; \
+ } \
+} while (0)
/* Some of the related functions require specific types */
struct hw_port_data;
struct hw_base_data;
struct hw_alloc_data;
+struct hw_event_data;
+struct hw_handle_data;
+struct hw_instance_data;
/* Finally the hardware device - keep your grubby little mits off of
these internals! :-) */
-struct hw {
+struct hw
+{
/* our relatives */
struct hw *parent_of_hw;
/* hot links */
struct hw *root_of_hw;
- SIM_DESC system_of_hw;
+ struct sim_state *system_of_hw;
/* identifying data */
hw_unit unit_address_of_hw;
int nr_size_cells_of_hw_unit;
/* Soft reset */
- hw_reset_callback *to_reset;
+ hw_reset_method *to_reset;
/* Basic callbacks */
- hw_io_read_buffer_callback *to_io_read_buffer;
- hw_io_write_buffer_callback *to_io_write_buffer;
- hw_dma_read_buffer_callback *to_dma_read_buffer;
- hw_dma_write_buffer_callback *to_dma_write_buffer;
- hw_attach_address_callback *to_attach_address;
- hw_detach_address_callback *to_detach_address;
+ hw_io_read_buffer_method *to_io_read_buffer;
+ hw_io_write_buffer_method *to_io_write_buffer;
+ hw_dma_read_buffer_method *to_dma_read_buffer;
+ hw_dma_write_buffer_method *to_dma_write_buffer;
+ hw_attach_address_method *to_attach_address;
+ hw_detach_address_method *to_detach_address;
/* More complicated callbacks */
- hw_ioctl_callback *to_ioctl;
+ hw_ioctl_method *to_ioctl;
int trace_of_hw_p;
/* address callbacks */
- hw_unit_decode_callback *to_unit_decode;
- hw_unit_encode_callback *to_unit_encode;
- hw_unit_address_to_attach_address_callback *to_unit_address_to_attach_address;
- hw_unit_size_to_attach_size_callback *to_unit_size_to_attach_size;
+ hw_unit_decode_method *to_unit_decode;
+ hw_unit_encode_method *to_unit_encode;
+ hw_unit_address_to_attach_address_method *to_unit_address_to_attach_address;
+ hw_unit_size_to_attach_size_method *to_unit_size_to_attach_size;
/* related data */
struct hw_property_data *properties_of_hw;
struct hw_port_data *ports_of_hw;
struct hw_base_data *base_of_hw;
struct hw_alloc_data *alloc_of_hw;
+ struct hw_event_data *events_of_hw;
+ struct hw_handle_data *handles_of_hw;
+ struct hw_instance_data *instances_of_hw;
};