From patchwork Tue Nov 18 19:00:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liviu Ionescu X-Patchwork-Id: 412135 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 DAE9314012B for ; Wed, 19 Nov 2014 06:30:24 +1100 (AEDT) Received: from localhost ([::1]:54945 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XqoTl-00015y-78 for incoming@patchwork.ozlabs.org; Tue, 18 Nov 2014 14:30:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40397) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XqoTD-0000Dk-96 for qemu-devel@nongnu.org; Tue, 18 Nov 2014 14:29:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XqoT8-0000u8-29 for qemu-devel@nongnu.org; Tue, 18 Nov 2014 14:29:47 -0500 Received: from [109.99.239.84] (port=44870 helo=ilg-mbp.local) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XqoT7-0000tq-MJ for qemu-devel@nongnu.org; Tue, 18 Nov 2014 14:29:41 -0500 Received: by ilg-mbp.local (Postfix, from userid 501) id 3C2D22E04F30; Tue, 18 Nov 2014 21:00:37 +0200 (EET) From: Liviu Ionescu To: qemu-devel@nongnu.org Date: Tue, 18 Nov 2014 21:00:10 +0200 Message-Id: <1416337210-90793-2-git-send-email-ilg@livius.net> X-Mailer: git-send-email 1.9.3 (Apple Git-50) In-Reply-To: <1416337210-90793-1-git-send-email-ilg@livius.net> References: <1416337210-90793-1-git-send-email-ilg@livius.net> X-detected-operating-system: by eggs.gnu.org: iOS iPhone or iPad X-Received-From: 109.99.239.84 Cc: peter.maydell@linaro.org, ilg@livius.net Subject: [Qemu-devel] [PATCH] add semihosting-config option 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 - allow to define where the semihosting calls will be addressed Signed-off-by: Liviu Ionescu --- gdbstub.c | 12 ++++++++++++ include/sysemu/sysemu.h | 6 ++++++ qemu-options.hx | 12 +++++++++++- vl.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 1 deletion(-) diff --git a/gdbstub.c b/gdbstub.c index 0faca56..372aa67 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -355,6 +355,18 @@ static enum { remote gdb syscalls. Otherwise use native file IO. */ int use_gdb_syscalls(void) { + if (semihosting_target == SEMIHOSTING_TARGET_NATIVE) { + if (gdb_syscall_mode == GDB_SYS_UNKNOWN) { + gdb_syscall_mode = GDB_SYS_DISABLED; + } + return FALSE; + } else if (semihosting_target == SEMIHOSTING_TARGET_GDB) { + if (gdb_syscall_mode == GDB_SYS_UNKNOWN) { + gdb_syscall_mode = GDB_SYS_ENABLED; + } + return TRUE; + } + if (gdb_syscall_mode == GDB_SYS_UNKNOWN) { gdb_syscall_mode = (gdbserver_state ? GDB_SYS_ENABLED : GDB_SYS_DISABLED); diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 9fea3bc..c145d94 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -127,7 +127,13 @@ extern int cursor_hide; extern int graphic_rotate; extern int no_quit; extern int no_shutdown; + extern int semihosting_enabled; +extern int semihosting_target; +#define SEMIHOSTING_TARGET_AUTO 0 +#define SEMIHOSTING_TARGET_NATIVE 1 +#define SEMIHOSTING_TARGET_GDB 2 + extern int old_param; extern int boot_menu; extern bool boot_strict; diff --git a/qemu-options.hx b/qemu-options.hx index da9851d..3e81222 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3216,7 +3216,17 @@ DEF("semihosting", 0, QEMU_OPTION_semihosting, STEXI @item -semihosting @findex -semihosting -Semihosting mode (ARM, M68K, Xtensa only). +Enable semihosting mode (ARM, M68K, Xtensa only). +ETEXI +DEF("semihosting-config", HAS_ARG, QEMU_OPTION_semihosting_config, + "-semihosting-config [enable=on|off,]target=native|gdb|auto semihosting configuration\n", +QEMU_ARCH_ARM | QEMU_ARCH_M68K | QEMU_ARCH_XTENSA | QEMU_ARCH_LM32) +STEXI +@item -semihosting-config [enable=on|off,]target=native|gdb|auto +@findex -semihosting-config +Enable semihosting and define where the semihosting calls will be addressed, +to QEMU (@code{native}) or to GDB (@code{gdb}). The default is @code{auto}, which means +@code{gdb} during debug sessions and @code{native} otherwise (ARM, M68K, Xtensa only). ETEXI DEF("old-param", 0, QEMU_OPTION_old_param, "-old-param old param mode\n", QEMU_ARCH_ARM) diff --git a/vl.c b/vl.c index f4a6e5e..8844983 100644 --- a/vl.c +++ b/vl.c @@ -172,6 +172,7 @@ const char *watchdog; QEMUOptionRom option_rom[MAX_OPTION_ROMS]; int nb_option_roms; int semihosting_enabled = 0; +int semihosting_target = SEMIHOSTING_TARGET_AUTO; int old_param = 0; const char *qemu_name; int alt_grab = 0; @@ -554,6 +555,22 @@ static QemuOptsList qemu_icount_opts = { }, }; +static QemuOptsList qemu_semihosting_config_opts = { + .name = "semihosting-config", + .implied_opt_name = "enable", + .head = QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts.head), + .desc = { + { + .name = "enable", + .type = QEMU_OPT_BOOL, + }, { + .name = "target", + .type = QEMU_OPT_STRING, + }, + { /* end of list */ } + }, +}; + /** * Get machine options * @@ -2811,6 +2828,7 @@ int main(int argc, char **argv, char **envp) qemu_add_opts(&qemu_name_opts); qemu_add_opts(&qemu_numa_opts); qemu_add_opts(&qemu_icount_opts); + qemu_add_opts(&qemu_semihosting_config_opts); runstate_init(); @@ -3618,6 +3636,37 @@ int main(int argc, char **argv, char **envp) break; case QEMU_OPTION_semihosting: semihosting_enabled = 1; + semihosting_target = SEMIHOSTING_TARGET_AUTO; + break; + case QEMU_OPTION_semihosting_config: + semihosting_enabled = 1; + opts = qemu_opts_parse(qemu_find_opts("semihosting-config"), + optarg, 0); + if (opts != NULL) { + semihosting_enabled = qemu_opt_get_bool(opts, "enable", + true); + const char *target = qemu_opt_get(opts, "target"); + if (target != NULL) { + if (strcmp("native", target) == 0) { + semihosting_target = SEMIHOSTING_TARGET_NATIVE; + } else if (strcmp("gdb", target) == 0) { + semihosting_target = SEMIHOSTING_TARGET_GDB; + } else if (strcmp("auto", target) == 0) { + semihosting_target = SEMIHOSTING_TARGET_AUTO; + } else { + fprintf(stderr, "Unsupported semihosting-config" + " %s\n", + optarg); + exit(1); + } + } else { + semihosting_target = SEMIHOSTING_TARGET_AUTO; + } + } else { + fprintf(stderr, "Unsupported semihosting-config %s\n", + optarg); + exit(1); + } break; case QEMU_OPTION_tdf: fprintf(stderr, "Warning: user space PIT time drift fix "