From 4376f23233339bbf1d108cf73a7043a788b690c2 Mon Sep 17 00:00:00 2001 From: Glauber Costa Date: Tue, 26 Feb 2008 16:56:38 -0300 Subject: [PATCH] Isolate cpu initialization function in hw/pc.c This patch wraps up the piece of code in hw/pc.c that actually allocates and initializates a cpu. After that, plan is to be able to start it later on. Signed-off-by: Glauber Costa Signed-off-by: Avi Kivity --- hw/pc.c | 40 +++++++++++++++++++++++----------------- hw/pc.h | 1 + 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/hw/pc.c b/hw/pc.c index ef180ec84a..fad5d4ec2d 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -737,6 +737,28 @@ static int load_option_rom(const char *filename, int offset) return size; } +CPUState *pc_new_cpu(int cpu, const char *cpu_model, int pci_enabled) +{ + CPUState *env = cpu_init(cpu_model); + if (!env) { + fprintf(stderr, "Unable to find x86 CPU definition\n"); + exit(1); + } + if (cpu != 0) + env->hflags |= HF_HALTED_MASK; + if (smp_cpus > 1) { + /* XXX: enable it in all cases */ + env->cpuid_features |= CPUID_APIC; + } + register_savevm("cpu", cpu, 4, cpu_save, cpu_load, env); + qemu_register_reset(main_cpu_reset, env); + if (pci_enabled) { + apic_init(env); + } + vmport_init(env); + return env; +} + /* PC hardware initialisation */ static void pc_init1(ram_addr_t ram_size, int vga_ram_size, const char *boot_device, DisplayState *ds, @@ -776,23 +798,7 @@ static void pc_init1(ram_addr_t ram_size, int vga_ram_size, } for(i = 0; i < smp_cpus; i++) { - env = cpu_init(cpu_model); - if (!env) { - fprintf(stderr, "Unable to find x86 CPU definition\n"); - exit(1); - } - if (i != 0) - env->hflags |= HF_HALTED_MASK; - if (smp_cpus > 1) { - /* XXX: enable it in all cases */ - env->cpuid_features |= CPUID_APIC; - } - register_savevm("cpu", i, 4, cpu_save, cpu_load, env); - qemu_register_reset(main_cpu_reset, env); - if (pci_enabled) { - apic_init(env); - } - vmport_init(env); + env = pc_new_cpu(i, cpu_model, pci_enabled); } /* allocate RAM */ diff --git a/hw/pc.h b/hw/pc.h index d10956928e..f879f30e6a 100644 --- a/hw/pc.h +++ b/hw/pc.h @@ -85,6 +85,7 @@ extern int fd_bootchk; void ioport_set_a20(int enable); int ioport_get_a20(void); +CPUState *pc_new_cpu(int cpu, const char *cpu_model, int pci_enabled); /* acpi.c */ extern int acpi_enabled; -- 2.11.4.GIT