#ifndef _HW_CORE_C_
#define _HW_CORE_C_
#include "device_table.h"
#include "corefile.h"
static void
hw_core_init_address_callback(device *me)
{
core *memory = (core*)device_data(me);
core_init(memory);
}
static void
hw_core_attach_address_callback(device *me,
attach_type attach,
int space,
unsigned_word addr,
unsigned nr_bytes,
access_type access,
device *client)
{
core *memory = (core*)device_data(me);
if (space != 0)
error("core_attach_address_callback() invalid address space\n");
core_attach(memory,
attach,
space,
access,
addr,
nr_bytes,
client);
}
static unsigned
hw_core_dma_read_buffer_callback(device *me,
void *dest,
int space,
unsigned_word addr,
unsigned nr_bytes)
{
core *memory = (core*)device_data(me);
return core_map_read_buffer(core_readable(memory),
dest,
addr,
nr_bytes);
}
static unsigned
hw_core_dma_write_buffer_callback(device *me,
const void *source,
int space,
unsigned_word addr,
unsigned nr_bytes,
int violate_read_only_section)
{
core *memory = (core*)device_data(me);
core_map *map = (violate_read_only_section
? core_readable(memory)
: core_writeable(memory));
return core_map_write_buffer(map,
source,
addr,
nr_bytes);
}
static device_callbacks const hw_core_callbacks = {
{ hw_core_init_address_callback, },
{ hw_core_attach_address_callback, },
{ NULL, },
{ hw_core_dma_read_buffer_callback,
hw_core_dma_write_buffer_callback, },
{ NULL, },
{ generic_device_unit_decode,
generic_device_unit_encode,
generic_device_address_to_attach_address,
generic_device_size_to_attach_size, },
};
static void *
hw_core_create(const char *name,
const device_unit *unit_address,
const char *args)
{
core *memory = core_create();
return memory;
}
const device_descriptor hw_core_device_descriptor[] = {
{ "core", hw_core_create, &hw_core_callbacks },
{ NULL },
};
#endif