This patch adds initial support for the -machine option, that allows command line specification of machine attributes. Besides its value per-se, it is the saner way we found to allow for enabling/disabling of kvm's in-kernel irqchip. machine-related options like kernel, initrd, etc, are now accepted under this switch. Note: This is against anthony's staging. --- hw/boards.h | 4 +++ hw/pc_piix.c | 3 ++ qemu-options.hx | 14 ++++++++++ vl.c | 72 +++++++++++++++++++++++++++++++++++-------------------- 4 files changed, 67 insertions(+), 26 deletions(-) diff --git a/hw/boards.h b/hw/boards.h index 18b6b8f..bac8583 100644 --- a/hw/boards.h +++ b/hw/boards.h @@ -35,6 +35,10 @@ extern QEMUMachine *current_machine; #define COMMON_MACHINE_OPTS() \ { \ + .name = "machine", \ + .type = QEMU_OPT_STRING, \ + }, \ + { \ .name = "ram_size", \ .type = QEMU_OPT_NUMBER, \ }, \ diff --git a/hw/pc_piix.c b/hw/pc_piix.c index f01194c..3ddb695 100644 --- a/hw/pc_piix.c +++ b/hw/pc_piix.c @@ -67,6 +67,9 @@ static void pc_init1(QemuOpts *opts, int pci_enabled) vmport_init(); + if (!kernel_cmdline) + kernel_cmdline = ""; + /* allocate ram and load rom/bios */ pc_memory_init(ram_size, kernel_filename, kernel_cmdline, initrd_filename, &below_4g_mem_size, &above_4g_mem_size); diff --git a/qemu-options.hx b/qemu-options.hx index a6928b7..76ca866 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -35,6 +35,20 @@ STEXI Select the emulated @var{machine} (@code{-M ?} for list) ETEXI +DEF("machine", HAS_ARG, QEMU_OPTION_machine, + "-machine [machine=m][,ram_size=ram][,boot_device=dev]\n" + " [,kernel=vmlinux][,cmdline=kernel_cmdline][,initrd=initrd]\n" + " [,cpu=cpu_type]\n" + " pc-specific options: [,acpi=on|off]\n" + " kvm-x86 specific options: [,apic_in_kernel=on|off]\n" + " select emulated machine (-machine ? for list)\n", + QEMU_ARCH_ALL) +STEXI +@item -machine @var{machine}[,@var{option}] +@findex -machine +Select the emulated @var{machine} (@code{-machine ?} for list) +ETEXI + DEF("cpu", HAS_ARG, QEMU_OPTION_cpu, "-cpu cpu select CPU (-cpu ? for list)\n", QEMU_ARCH_ALL) STEXI diff --git a/vl.c b/vl.c index 96b8d35..177ffe2 100644 --- a/vl.c +++ b/vl.c @@ -1605,6 +1605,16 @@ static QEMUMachine *find_machine(const char *name) if (m->alias && !strcmp(m->alias, name)) return m; } + + printf("Supported machines are:\n"); + for(m = first_machine; m != NULL; m = m->next) { + if (m->alias) + printf("%-10s %s (alias of %s)\n", + m->alias, m->desc, m->name); + printf("%-10s %s%s\n", + m->name, m->desc, + m->is_default ? " (default)" : ""); + } return NULL; } @@ -2567,7 +2577,7 @@ int main(int argc, char **argv, char **envp) DisplayState *ds; DisplayChangeListener *dcl; int cyls, heads, secs, translation; - QemuOpts *hda_opts = NULL, *opts; + QemuOpts *hda_opts = NULL, *machine_opts = NULL, *opts = NULL; int optind; const char *optarg; const char *loadvm = NULL; @@ -2697,21 +2707,29 @@ int main(int argc, char **argv, char **envp) exit(1); } switch(popt->index) { + case QEMU_OPTION_machine: { + const char *mach; + + machine_opts = qemu_opts_parse(&qemu_machine_opts, optarg, 0); + if (!machine_opts) { + fprintf(stderr, "parse error: %s\n", optarg); + exit(1); + } + mach = qemu_opt_get(machine_opts, "machine"); + + if (!mach) + break; + + machine = find_machine(mach); + + if (!machine) + exit(*mach != '?'); + break; + } case QEMU_OPTION_M: machine = find_machine(optarg); - if (!machine) { - QEMUMachine *m; - printf("Supported machines are:\n"); - for(m = first_machine; m != NULL; m = m->next) { - if (m->alias) - printf("%-10s %s (alias of %s)\n", - m->alias, m->desc, m->name); - printf("%-10s %s%s\n", - m->name, m->desc, - m->is_default ? " (default)" : ""); - } - exit(*optarg != '?'); - } + if (!machine) + exit(*optarg != '?'); break; case QEMU_OPTION_cpu: /* hw initialization will check this */ @@ -3723,47 +3741,49 @@ int main(int argc, char **argv, char **envp) } qemu_add_globals(); - opts = qemu_opts_create(&qemu_machine_opts, NULL, 0); + if (!machine_opts) + machine_opts = qemu_opts_create(&qemu_machine_opts, NULL, 0); + if (kernel_filename) { - qemu_opt_set(opts, "kernel", kernel_filename); + qemu_opt_set(machine_opts, "kernel", kernel_filename); if (kernel_cmdline) { - qemu_opt_set(opts, "cmdline", kernel_cmdline); + qemu_opt_set(machine_opts, "cmdline", kernel_cmdline); } if (initrd_filename) { - qemu_opt_set(opts, "initrd", initrd_filename); + qemu_opt_set(machine_opts, "initrd", initrd_filename); } } - qemu_opt_set(opts, "boot_device", boot_devices); + qemu_opt_set(machine_opts, "boot_device", boot_devices); if (cpu_model) { - qemu_opt_set(opts, "cpu", cpu_model); + qemu_opt_set(machine_opts, "cpu", cpu_model); } if (ram_size) { char buffer[64]; snprintf(buffer, sizeof(buffer), "%" PRId64, ram_size); - qemu_opt_set(opts, "ram_size", buffer); + qemu_opt_set(machine_opts, "ram_size", buffer); } if (acpi_enabled == 0) { - qemu_opt_set(opts, "acpi", "off"); + qemu_opt_set(machine_opts, "acpi", "off"); } if (machine->opts_desc) { - if (qemu_opts_validate(opts, machine->opts_desc) < 0) { + if (qemu_opts_validate(machine_opts, machine->opts_desc) < 0) { exit(1); } } else { - if (qemu_opts_validate(opts, common_machine_opts) < 0) { + if (qemu_opts_validate(machine_opts, common_machine_opts) < 0) { exit(1); } } - machine->init(machine, opts); + machine->init(machine, machine_opts); - qemu_opts_del(opts); + qemu_opts_del(machine_opts); cpu_synchronize_all_post_init(); -- 1.7.0.1 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html