From patchwork Wed Apr 1 13:18:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Alrae X-Patchwork-Id: 457258 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id AEC2F1400B7 for ; Thu, 2 Apr 2015 00:19:01 +1100 (AEDT) Received: from localhost ([::1]:52475 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YdIXr-0001A5-S8 for incoming@patchwork.ozlabs.org; Wed, 01 Apr 2015 09:18:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58439) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YdIXT-0000Z2-CY for qemu-devel@nongnu.org; Wed, 01 Apr 2015 09:18:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YdIXP-000319-73 for qemu-devel@nongnu.org; Wed, 01 Apr 2015 09:18:35 -0400 Received: from mailapp01.imgtec.com ([195.59.15.196]:46870) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YdIXP-0002zl-1w for qemu-devel@nongnu.org; Wed, 01 Apr 2015 09:18:31 -0400 Received: from KLMAIL01.kl.imgtec.org (unknown [192.168.5.35]) by Websense Email Security Gateway with ESMTPS id 9EC827602F2E; Wed, 1 Apr 2015 14:18:24 +0100 (IST) Received: from lalrae-linux.kl.imgtec.org (192.168.14.163) by KLMAIL01.kl.imgtec.org (192.168.5.35) with Microsoft SMTP Server (TLS) id 14.3.195.1; Wed, 1 Apr 2015 14:18:27 +0100 From: Leon Alrae To: Date: Wed, 1 Apr 2015 14:18:03 +0100 Message-ID: <1427894283-31953-1-git-send-email-leon.alrae@imgtec.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 X-Originating-IP: [192.168.14.163] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 195.59.15.196 Cc: peter.maydell@linaro.org, christopher.covington@linaro.org, matthew.fortune@imgtec.com, ilg@livius.net Subject: [Qemu-devel] [RFC PATCH] vl.c: add -semihosting-config "arg" sub-argument X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Leon Alrae --- Hi, Continuing the discussion related to extending QEMU's command line with new argument allowing to pass semi-hosting input arguments to the guest program: https://lists.gnu.org/archive/html/qemu-devel/2015-03/msg05960.html This simple patch adds "arg" sub-argument which in my opinion is flexible enough to satisfy semi-hosting interfaces which allocate buffers at runtime (so it is possible to pass any number of strings of any length) as well as the ones which have limited buffer for a single input string. Highlights: * arg can appear multiple times in -semihosting-config group of sub-arguments and is used to create argc/argv. * Single string cmdline can be still easily created: static void concat_semihosting_args(char *buffer, int buffer_size, const char *separator) { int i; buffer[0] = '\0'; for (i = 0; i < semihosting_argc - 1; i++) { pstrcat(buffer, buffer_size, semihosting_argv[i]); pstrcat(buffer, buffer_size, separator); } pstrcat(buffer, buffer_size, semihosting_argv[i]); } * argv[0] is set by the first occurence of "arg" rather than taking the same string from "-kernel". This might be required in cases where the path is too long and semi-hosting app's buffer for the cmdline is fixed and small. * No altering the parser itself, just traversing the -semihosting-config opts and picking all arg strings. * This patch doesn't fix the need of using double-commas if user want to have a comma in the string. If we agree on this new option then I would like to follow up with a clean up where we've got a semi-hosting specific structure rather than keep generating more semihosting_* variables (I skipped it in this patch to avoid generating clean up related noise in the diff). Any comments? Thanks, Leon --- include/sysemu/sysemu.h | 2 ++ vl.c | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 8a52934..651863f 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -126,6 +126,8 @@ extern int graphic_rotate; extern int no_quit; extern int no_shutdown; extern int semihosting_enabled; +extern const char **semihosting_argv; +extern int semihosting_argc; extern int old_param; extern int boot_menu; extern bool boot_strict; diff --git a/vl.c b/vl.c index 74c2681..640d9da 100644 --- a/vl.c +++ b/vl.c @@ -171,6 +171,8 @@ const char *watchdog; QEMUOptionRom option_rom[MAX_OPTION_ROMS]; int nb_option_roms; int semihosting_enabled = 0; +const char **semihosting_argv; +int semihosting_argc; int old_param = 0; const char *qemu_name; int alt_grab = 0; @@ -485,6 +487,9 @@ static QemuOptsList qemu_semihosting_config_opts = { }, { .name = "target", .type = QEMU_OPT_STRING, + }, { + .name = "arg", + .type = QEMU_OPT_STRING, }, { /* end of list */ } }, @@ -2727,6 +2732,17 @@ static void set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size) } } +static int add_semihosting_arg(const char *name, const char *val, void *opaque) +{ + if (strcmp(name, "arg") == 0) { + semihosting_argc++; + semihosting_argv = g_realloc(semihosting_argv, + semihosting_argc * sizeof(void *)); + semihosting_argv[semihosting_argc - 1] = val; + } + return 0; +} + int main(int argc, char **argv, char **envp) { int i; @@ -3562,6 +3578,8 @@ int main(int argc, char **argv, char **envp) } else { semihosting_target = SEMIHOSTING_TARGET_AUTO; } + /* Set semihosting argument count and vector */ + qemu_opt_foreach(opts, add_semihosting_arg, NULL, 0); } else { fprintf(stderr, "Unsupported semihosting-config %s\n", optarg);