diff --git a/qemu/hw/i386/pc_piix.c b/qemu/hw/i386/pc_piix.c index ef680c27..1f2cd1bd 100644 --- a/qemu/hw/i386/pc_piix.c +++ b/qemu/hw/i386/pc_piix.c @@ -49,6 +49,16 @@ static int pc_init_pci(struct uc_struct *uc, MachineState *machine) return pc_init1(uc, machine); } +static void pc_compat_2_2(struct uc_struct *uc, MachineState *machine) +{ +} + +static int pc_init_pci_2_2(struct uc_struct *uc, MachineState *machine) +{ + pc_compat_2_2(uc, machine); + return pc_init_pci(uc, machine); +} + static QEMUMachine pc_i440fx_machine_v2_2 = { "pc_piix", "pc-i440fx-2.2", @@ -59,23 +69,4 @@ static QEMUMachine pc_i440fx_machine_v2_2 = { UC_ARCH_X86, // X86 }; -static void pc_generic_machine_class_init(struct uc_struct *uc, ObjectClass *oc, void *data) -{ - MachineClass *mc = MACHINE_CLASS(uc, oc); - QEMUMachine *qm = data; - - mc->family = qm->family; - mc->name = qm->name; - mc->init = qm->init; - mc->reset = qm->reset; - mc->max_cpus = qm->max_cpus; - mc->is_default = qm->is_default; - mc->arch = qm->arch; -} - -void pc_machine_init(struct uc_struct *uc); -void pc_machine_init(struct uc_struct *uc) -{ - qemu_register_machine(uc, &pc_i440fx_machine_v2_2, - TYPE_PC_MACHINE, pc_generic_machine_class_init); -} +DEFINE_PC_MACHINE(v2_2, "pc-i440fx-2.2", pc_init_pci_2_2); diff --git a/qemu/include/hw/i386/pc.h b/qemu/include/hw/i386/pc.h index c67571d6..b4524eca 100644 --- a/qemu/include/hw/i386/pc.h +++ b/qemu/include/hw/i386/pc.h @@ -47,4 +47,26 @@ void x86_cpu_register_types(struct uc_struct *uc); #define PC_DEFAULT_MACHINE_OPTIONS \ .max_cpus = 255 +// Unicorn: Modified to work with Unicorn. +#define DEFINE_PC_MACHINE(suffix, namestr, initfn) \ + static void pc_machine_##suffix##_class_init(struct uc_struct *uc, ObjectClass *oc, void *data) \ + { \ + MachineClass *mc = MACHINE_CLASS(uc, oc); \ + mc->max_cpus = 255; \ + mc->is_default = 1; \ + mc->name = namestr; \ + mc->init = initfn; \ + mc->arch = UC_ARCH_X86; \ + } \ + static const TypeInfo pc_machine_type_##suffix = { \ + .name = namestr TYPE_MACHINE_SUFFIX, \ + .parent = TYPE_PC_MACHINE, \ + .class_init = pc_machine_##suffix##_class_init, \ + }; \ + void pc_machine_init_##suffix(struct uc_struct *uc); \ + void pc_machine_init_##suffix(struct uc_struct *uc) \ + { \ + type_register(uc, &pc_machine_type_##suffix); \ + } + #endif diff --git a/qemu/target/i386/unicorn.c b/qemu/target/i386/unicorn.c index 9e6be590..bb58c7b2 100644 --- a/qemu/target/i386/unicorn.c +++ b/qemu/target/i386/unicorn.c @@ -1336,8 +1336,6 @@ static bool x86_stop_interrupt(int intno) } } -void pc_machine_init(struct uc_struct *uc); - static bool x86_insn_hook_validate(uint32_t insn_enum) { //for x86 we can only hook IN, OUT, and SYSCALL @@ -1349,6 +1347,8 @@ static bool x86_insn_hook_validate(uint32_t insn_enum) return true; } +void pc_machine_init_v2_2(struct uc_struct *uc); + DEFAULT_VISIBILITY void x86_uc_init(struct uc_struct* uc) { @@ -1357,7 +1357,7 @@ void x86_uc_init(struct uc_struct* uc) register_accel_types(uc); pc_machine_register_types(uc); x86_cpu_register_types(uc); - pc_machine_init(uc); // pc_piix + pc_machine_init_v2_2(uc); // pc_piix uc->reg_read = x86_reg_read; uc->reg_write = x86_reg_write; uc->reg_reset = x86_reg_reset;