From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JxMYm-0004sx-Hm for qemu-devel@nongnu.org; Sat, 17 May 2008 09:34:52 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JxMYl-0004sP-1Y for qemu-devel@nongnu.org; Sat, 17 May 2008 09:34:52 -0400 Received: from [199.232.76.173] (port=41443 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JxMYk-0004sD-JM for qemu-devel@nongnu.org; Sat, 17 May 2008 09:34:50 -0400 Received: from fmmailgate02.web.de ([217.72.192.227]:43476) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JxMYk-0004Xm-5t for qemu-devel@nongnu.org; Sat, 17 May 2008 09:34:50 -0400 Received: from smtp07.web.de (fmsmtp07.dlan.cinetic.de [172.20.5.215]) by fmmailgate02.web.de (Postfix) with ESMTP id 6B74FDCE77DE for ; Sat, 17 May 2008 15:34:49 +0200 (CEST) Received: from [88.64.29.150] (helo=[192.168.1.198]) by smtp07.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.109 #226) id 1JxMYj-0000JS-00 for qemu-devel@nongnu.org; Sat, 17 May 2008 15:34:49 +0200 Message-ID: <482EDEF8.7030309@web.de> Date: Sat, 17 May 2008 15:34:48 +0200 From: Jan Kiszka MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Sender: jan.kiszka@web.de Subject: [Qemu-devel] [RFC][PATCH 1/2] machine-specific command line switches Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org For a different project, I once wrote a patch to organize purely machine-specific command line switches under the hood of the respective machine implementations. Now the MusicPal has precisely that need as well. So I reanimated the patch, and here we go: The idea is to add two fields to QEMUMachine and process them: o options_help - a string that is inserted under a separate section of the "qemu -h" output. o parse_option - a callback invoked if a given option was not handled by the generic code. It returns -1 if the option is unkown, 0 if it is know but comes without an argument, and 1 when the argument was consumed. Signed-off-by: Jan Kiszka --- hw/boards.h | 4 ++++ vl.c | 41 +++++++++++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 10 deletions(-) Index: b/hw/boards.h =================================================================== --- a/hw/boards.h +++ b/hw/boards.h @@ -10,12 +10,16 @@ typedef void QEMUMachineInitFunc(ram_add const char *initrd_filename, const char *cpu_model); +typedef int QEMUMachineParseOption(const char *optname, const char *optarg); + typedef struct QEMUMachine { const char *name; const char *desc; QEMUMachineInitFunc *init; #define RAMSIZE_FIXED (1 << 0) ram_addr_t ram_require; + const char *options_help; + QEMUMachineParseOption *parse_option; struct QEMUMachine *next; } QEMUMachine; Index: b/vl.c =================================================================== --- a/vl.c +++ b/vl.c @@ -7141,6 +7141,8 @@ static int main_loop(void) static void help(int exitcode) { + QEMUMachine *m; + printf("QEMU PC emulator version " QEMU_VERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n" "usage: %s [options] [disk_image]\n" "\n" @@ -7275,14 +7277,7 @@ static void help(int exitcode) "-clock force the use of the given methods for timer alarm.\n" " To see what timers are available use -clock ?\n" "-startdate select initial date of the clock\n" - "\n" - "During emulation, the following keys are useful:\n" - "ctrl-alt-f toggle full screen\n" - "ctrl-alt-n switch to virtual console 'n'\n" - "ctrl-alt toggle mouse and keyboard grab\n" - "\n" - "When using -nographic, press 'ctrl-a h' to get some help.\n" - , + "\n", "qemu", DEFAULT_RAM_SIZE, #ifndef _WIN32 @@ -7291,6 +7286,17 @@ static void help(int exitcode) #endif DEFAULT_GDBSTUB_PORT, "/tmp/qemu.log"); + for (m = first_machine; m != NULL; m = m->next) { + if (m->options_help) + printf("Options specific to %s machine:\n%s\n", + m->name, m->options_help); + } + printf("During emulation, the following keys are useful:\n" + "ctrl-alt-f toggle full screen\n" + "ctrl-alt-n switch to virtual console 'n'\n" + "ctrl-alt toggle mouse and keyboard grab\n" + "\n" + "When using -nographic, press 'ctrl-a h' to get some help.\n"); exit(exitcode); } @@ -7673,7 +7679,7 @@ int main(int argc, char **argv) const char *gdbstub_port; #endif uint32_t boot_devices_bitmap = 0; - int i; + int i, result; int snapshot, linux_boot, net_boot; const char *initrd_filename; const char *kernel_filename, *kernel_cmdline; @@ -7692,7 +7698,7 @@ int main(int argc, char **argv) const char *parallel_devices[MAX_PARALLEL_PORTS]; int parallel_device_index; const char *loadvm = NULL; - QEMUMachine *machine; + QEMUMachine *machine, *m; const char *cpu_model; const char *usb_devices[MAX_USB_CMDLINE]; int usb_devices_index; @@ -7784,6 +7790,21 @@ int main(int argc, char **argv) /* Treat --foo the same as -foo. */ if (r[1] == '-') r++; + + result = -1; + for (m = first_machine; m != NULL; m = m->next) { + if (m->parse_option) { + result = m->parse_option(r, + (optind < argc) ? argv[optind] : NULL); + if (result >= 0) + break; + } + } + if (result >= 0) { + optind += result; + continue; + } + popt = qemu_options; for(;;) { if (!popt->name) {