From 125bd964d9ea726fce4092bc987cd0b9c7e66174 Mon Sep 17 00:00:00 2001 From: Greg Bellows Date: Sun, 11 Mar 2018 13:50:11 -0400 Subject: [PATCH] target-arm: Add virt class and machine types Switch virt qemu machine support to use the newer object type, class, and instance model. Added virt TypeInfo with static registration along with virt specific class and machine structs. Also added virt class initialization method. Backports commit c29196904b2bad015edc553a5693c5c9e6f8177a from qemu --- qemu/hw/arm/virt.c | 54 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/qemu/hw/arm/virt.c b/qemu/hw/arm/virt.c index ab65080c..64fca456 100644 --- a/qemu/hw/arm/virt.c +++ b/qemu/hw/arm/virt.c @@ -39,6 +39,24 @@ #include "hw/boards.h" #include "exec/address-spaces.h" +// Unicorn: Daughterboard member removed, as it's not necessary +// for Unicorn's purposes. +typedef struct { + MachineClass parent; +} VirtMachineClass; + +typedef struct { + MachineState parent; +} VirtMachineState; + +#define TYPE_VIRT_MACHINE "virt" +#define VIRT_MACHINE(uc, obj) \ + OBJECT_CHECK((uc), VirtMachineState, (obj), TYPE_VIRT_MACHINE) +#define VIRT_MACHINE_GET_CLASS(uc, obj) \ + OBJECT_GET_CLASS(uc, VirtMachineClass, obj, TYPE_VIRT_MACHINE) +#define VIRT_MACHINE_CLASS(uc, klass) \ + OBJECT_CLASS_CHECK(uc, VirtMachineClass, klass, TYPE_VIRT_MACHINE) + static int machvirt_init(struct uc_struct *uc, MachineState *machine) { const char *cpu_model = machine->cpu_model; @@ -65,13 +83,35 @@ static int machvirt_init(struct uc_struct *uc, MachineState *machine) return 0; } +static void virt_class_init(struct uc_struct *uc, ObjectClass *oc, void *data) +{ + MachineClass *mc = MACHINE_CLASS(uc, oc); + + mc->name = TYPE_VIRT_MACHINE; + mc->init = machvirt_init; + mc->max_cpus = 8; + mc->is_default = 1; + mc->arch = UC_ARCH_ARM64; +} + +static const TypeInfo machvirt_info = { + TYPE_VIRT_MACHINE, + TYPE_MACHINE, + + sizeof(VirtMachineClass), + sizeof(VirtMachineState), + NULL, + + NULL, + NULL, + NULL, + + NULL, + + virt_class_init, +}; + void machvirt_machine_init(struct uc_struct *uc) { - static QEMUMachine machvirt_a15_machine = { 0 }; - machvirt_a15_machine.name = "virt", - machvirt_a15_machine.init = machvirt_init, - machvirt_a15_machine.is_default = 1, - machvirt_a15_machine.arch = UC_ARCH_ARM64, - - qemu_register_machine(uc, &machvirt_a15_machine, TYPE_MACHINE, NULL); + type_register_static(uc, &machvirt_info); }