#include "sc14480.h" #include "cpu-qom.h" #include "system/address-spaces.h" #include "hw/core/cpu.h" #include "hw/cr16c/boot.h" #include "qapi/error.h" #include "qemu/datadir.h" #include "qemu/units.h" static void sc14480_realize(DeviceState* dev, Error** errp) { SC14480McuState* s = SC14480_MCU(dev); object_initialize_child(OBJECT(dev), "cpu", &s->cpu, TYPE_CR16C_CPU); object_property_set_bool(OBJECT(&s->cpu), "realized", true, &error_abort); memory_region_init_ram(&s->non_shared_ram_or_icache, OBJECT(dev), "non_shared_ram_or_icache", 24*KiB, &error_fatal); memory_region_init_ram(&s->non_shared_ram_or_dcache, OBJECT(dev), "non_shared_ram_or_dcache", 8*KiB, &error_fatal); memory_region_init_ram(&s->shared_int_ram, OBJECT(dev), "shared_int_ram", 64*KiB, &error_fatal); memory_region_init_rom(&s->boot_rom, OBJECT(dev), "boot_rom", 2*KiB, &error_fatal); memory_region_add_subregion(get_system_memory(), 0x00000, &s->non_shared_ram_or_icache); memory_region_add_subregion(get_system_memory(), 0x08000, &s->non_shared_ram_or_dcache); memory_region_add_subregion(get_system_memory(), 0x10000, &s->shared_int_ram); memory_region_add_subregion(get_system_memory(), 0xFEF00, &s->boot_rom); char* bios_path = qemu_find_file(QEMU_FILE_TYPE_BIOS, "sc14480-bios.img"); if (!cr16c_load_firmware(&s->cpu, &s->boot_rom, bios_path)) { exit(1); } } static void sc14480_reset_hold(Object *obj, ResetType type) { SC14480McuClass* mcu_class = SC14480_MCU_GET_CLASS(obj); SC14480McuState* mcu_state = SC14480_MCU(obj); CR16CCPU* cpu = &mcu_state->cpu; CPUState* cpu_state = CPU(cpu); if (mcu_class->parent_phases.hold) { mcu_class->parent_phases.hold(obj, type); } cpu_reset(cpu_state); cpu_set_pc(cpu_state, 0xFEF00); } static void sc14480_class_init(ObjectClass* oc, const void* data) { DeviceClass* dc = DEVICE_CLASS(oc); SC14480McuClass* sc14480 = SC14480_MCU_CLASS(oc); ResettableClass *rc = RESETTABLE_CLASS(oc); resettable_class_set_parent_phases(rc, NULL, sc14480_reset_hold, NULL, &sc14480->parent_phases); dc->realize = sc14480_realize; } static const TypeInfo sc14480_mcu_types[] = { { .name = TYPE_SC14480_MCU, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(SC14480McuState), .class_size = sizeof(SC14480McuClass), .class_init = sc14480_class_init, }, }; DEFINE_TYPES(sc14480_mcu_types)