int
hw_ioctl (struct hw *me,
- sim_cpu *processor,
- sim_cia cia,
hw_ioctl_request request,
...)
{
int status;
va_list ap;
va_start(ap, request);
- status = me->to_ioctl (me, processor, cia, request, ap);
+ status = me->to_ioctl (me, request, ap);
va_end(ap);
return status;
}
-/* I/O */
-
-void volatile
-hw_abort (struct hw *me,
- const char *fmt,
- ...)
-{
- SIM_DESC sd;
- const char *name;
- va_list ap;
- va_start(ap, fmt);
- /* find a system to abort through */
- if (me == NULL || hw_system (me) == NULL)
- sd = NULL;
- else
- sd = hw_system (me);
- /* find an identity */
- if (me != NULL && hw_path (me) != NULL && hw_path (me) [0] != '\0')
- name = hw_path (me);
- else if (me != NULL && hw_name (me) != NULL && hw_name (me)[0] != '\0')
- name = hw_name (me);
- else if (me != NULL && hw_family (me) != NULL && hw_family (me)[0] != '\0')
- name = hw_family (me);
- else
- name = "device";
- /* report the problem */
- sim_io_eprintf (sd, "%s: ", name);
- sim_io_evprintf (sd, fmt, ap);
- sim_io_error (sd, "%s", "");
-}
-
-void
-hw_trace (struct hw *me,
- const char *fmt,
- ...)
-{
- if (hw_trace_p (me)) /* to be sure, to be sure */
- {
- va_list ap;
- va_start (ap, fmt);
- sim_io_eprintf (hw_system (me), "%s: ", hw_path (me));
- sim_io_evprintf (hw_system (me), fmt, ap);
- sim_io_eprintf (hw_system (me), "\n");
- va_end (ap);
- }
-}
-
-\f
-/* The event queue abstraction (for devices) */
-
-
-struct _hw_event {
- void *data;
- struct hw *me;
- hw_event_handler *handler;
- sim_event *real;
-};
-
-/* Pass the H/W event onto the real handler */
-
-static void
-bounce_hw_event (SIM_DESC sd,
- void *data)
-{
- hw_event event = * (hw_event*) data;
- zfree (data);
- event.handler (event.me, event.data);
-}
-
-
-/* Map onto the event functions */
-
-hw_event *
-hw_event_queue_schedule (struct hw *me,
- signed64 delta_time,
- hw_event_handler *handler,
- void *data)
-{
- hw_event *event = ZALLOC (hw_event);
- event->data = data;
- event->handler = handler;
- event->me = me;
- event->real = sim_events_schedule (hw_system (me),
- delta_time,
- bounce_hw_event,
- event);
- return event;
-}
-
-void
-hw_event_queue_deschedule (struct hw *me,
- hw_event *event_to_remove)
-{
- sim_events_deschedule (hw_system (me),
- event_to_remove->real);
- zfree (event_to_remove);
-}
-
-signed64
-hw_event_queue_time (struct hw *me)
-{
- return sim_events_time (hw_system (me));
-}
-
-\f
/* Mechanism for associating allocated memory regions to a device.
When a device is deleted any remaining memory regions are also
reclaimed.
struct hw_alloc_data *next;
};
-extern void *
+void *
hw_zalloc (struct hw *me, unsigned long size)
{
struct hw_alloc_data *memory = ZALLOC (struct hw_alloc_data);
return memory->alloc;
}
-extern void *
+void *
hw_malloc (struct hw *me, unsigned long size)
{
struct hw_alloc_data *memory = ZALLOC (struct hw_alloc_data);
return memory->alloc;
}
-extern void
+void
hw_free (struct hw *me,
void *alloc)
{
hw_abort (me, "free of memory not belonging to a device");
}
-extern void
+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)
+{
+ if (str != NULL)
+ {
+ char *dup = hw_zalloc (me, strlen (str) + 1);
+ strcpy (dup, str);
+ return dup;
+ }
+ else
+ {
+ return NULL;
+ }
+}
/* 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 */
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)
(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))
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 int (hw_ioctl_callback)
(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,
...);
*/
-void volatile NORETURN hw_abort
+void hw_abort
(struct hw *me,
const char *fmt,
...) __attribute__ ((format (printf, 2, 3)));
+void hw_vabort
+(struct hw *me,
+ const char *fmt,
+ va_list ap);
+
+void hw_halt
+(struct hw *me,
+ int reason,
+ int status);
+
+
#define hw_trace_p(hw) ((hw)->trace_of_hw_p + 0)
void hw_trace
/* 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;