56 lines
1.6 KiB
C
56 lines
1.6 KiB
C
#include "sc14450.h"
|
|
#include "exec/address-spaces.h"
|
|
#include "qapi/error.h"
|
|
#include "qemu/units.h"
|
|
|
|
typedef struct SC14450McuClass {
|
|
SysBusDeviceClass parent_class;
|
|
|
|
const char* cpu_type;
|
|
size_t flash_size;
|
|
} SC14450McuClass;
|
|
DECLARE_CLASS_CHECKERS(SC14450McuClass, SC14450_MCU, TYPE_SC14450_MCU)
|
|
|
|
static void sc14450_realize(DeviceState* dev, Error** errp)
|
|
{
|
|
SC14450McuState* s = SC14450_MCU(dev);
|
|
const SC14450McuClass* mc = SC14450_MCU_GET_CLASS(dev);
|
|
|
|
object_initialize_child(OBJECT(dev), "cpu", &s->cpu, mc->cpu_type);
|
|
object_property_set_bool(OBJECT(&s->cpu), "realized", true, &error_abort);
|
|
|
|
memory_region_init_ram(&s->flash, OBJECT(dev), "flash", mc->flash_size, &error_fatal);
|
|
memory_region_add_subregion(get_system_memory(), 0, &s->flash);
|
|
}
|
|
|
|
static void sc14450_class_init(ObjectClass* oc, void* data)
|
|
{
|
|
DeviceClass* dc = DEVICE_CLASS(oc);
|
|
dc->realize = sc14450_realize;
|
|
dc->user_creatable = false;
|
|
}
|
|
|
|
static void sc14450s_class_init(ObjectClass* oc, void* data)
|
|
{
|
|
SC14450McuClass* sc14450 = SC14450_MCU_CLASS(oc);
|
|
|
|
sc14450->cpu_type = CR16C_CPU_TYPE_NAME("SC14450C");
|
|
sc14450->flash_size = 16 * MiB;
|
|
}
|
|
|
|
static const TypeInfo sc14450_mcu_types[] = {
|
|
{
|
|
.name = TYPE_SC14450S_MCU,
|
|
.parent = TYPE_SC14450_MCU,
|
|
.class_init = sc14450s_class_init,
|
|
},
|
|
{
|
|
.name = TYPE_SC14450_MCU,
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
.instance_size = sizeof(SC14450McuState),
|
|
.class_size = sizeof(SC14450McuClass),
|
|
.class_init = sc14450_class_init,
|
|
.abstract = true,
|
|
}
|
|
};
|
|
DEFINE_TYPES(sc14450_mcu_types)
|