From patchwork Wed May 6 14:57:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Alrae X-Patchwork-Id: 468985 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 EFE29140295 for ; Thu, 7 May 2015 00:58:48 +1000 (AEST) Received: from localhost ([::1]:45614 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yq0md-0006sL-A7 for incoming@patchwork.ozlabs.org; Wed, 06 May 2015 10:58:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33241) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yq0lP-0004mj-14 for qemu-devel@nongnu.org; Wed, 06 May 2015 10:57:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yq0lN-0005AW-7a for qemu-devel@nongnu.org; Wed, 06 May 2015 10:57:30 -0400 Received: from mailapp01.imgtec.com ([195.59.15.196]:28039) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yq0lM-0005AM-Uc for qemu-devel@nongnu.org; Wed, 06 May 2015 10:57:29 -0400 Received: from KLMAIL01.kl.imgtec.org (unknown [192.168.5.35]) by Websense Email Security Gateway with ESMTPS id D67F68C3EA840; Wed, 6 May 2015 15:57: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, 6 May 2015 15:57:26 +0100 From: Leon Alrae To: Date: Wed, 6 May 2015 15:57:06 +0100 Message-ID: <1430924229-20469-2-git-send-email-leon.alrae@imgtec.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1430924229-20469-1-git-send-email-leon.alrae@imgtec.com> References: <1430924229-20469-1-git-send-email-leon.alrae@imgtec.com> 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] [PATCH 1/4] semihosting: remove semihosting_enabled declaration from sysemu.h 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 Remove extern int semihosting_enabled declaration from sysemu.h and create equivalent semihosting_enabled() function. Also introduce semihost.h containing things related to semihosting config. Suggested-by: Peter Maydell Signed-off-by: Leon Alrae --- include/exec/semihost.h | 32 ++++++++++++++++++++++++++++++++ include/sysemu/sysemu.h | 1 - target-arm/helper.c | 7 ++++--- target-lm32/helper.c | 3 ++- target-m68k/op_helper.c | 5 ++--- target-xtensa/translate.c | 3 ++- vl.c | 18 ++++++++++++++---- 7 files changed, 56 insertions(+), 13 deletions(-) create mode 100644 include/exec/semihost.h diff --git a/include/exec/semihost.h b/include/exec/semihost.h new file mode 100644 index 0000000..5d9a916 --- /dev/null +++ b/include/exec/semihost.h @@ -0,0 +1,32 @@ +/* + * Semihosting support + * + * Copyright (c) 2015 Imagination Technologies + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef SEMIHOST_H +#define SEMIHOST_H + +#ifdef CONFIG_USER_ONLY +static inline bool semihosting_enabled(void) +{ + return true; +} +#else +bool semihosting_enabled(void); +#endif + +#endif diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 8a52934..bf552a7 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -125,7 +125,6 @@ extern int cursor_hide; extern int graphic_rotate; extern int no_quit; extern int no_shutdown; -extern int semihosting_enabled; extern int old_param; extern int boot_menu; extern bool boot_strict; diff --git a/target-arm/helper.c b/target-arm/helper.c index f8f8d76..f5a9897 100644 --- a/target-arm/helper.c +++ b/target-arm/helper.c @@ -10,6 +10,7 @@ #include "exec/cpu_ldst.h" #include "arm_ldst.h" #include /* For crc32 */ +#include "exec/semihost.h" #ifndef CONFIG_USER_ONLY static inline int get_phys_addr(CPUARMState *env, target_ulong address, @@ -4401,7 +4402,7 @@ void arm_v7m_cpu_do_interrupt(CPUState *cs) armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_MEM); return; case EXCP_BKPT: - if (semihosting_enabled) { + if (semihosting_enabled()) { int nr; nr = arm_lduw_code(env, env->regs[15], env->bswap_code) & 0xff; if (nr == 0xab) { @@ -4713,7 +4714,7 @@ void arm_cpu_do_interrupt(CPUState *cs) offset = 4; break; case EXCP_SWI: - if (semihosting_enabled) { + if (semihosting_enabled()) { /* Check for semihosting interrupt. */ if (env->thumb) { mask = arm_lduw_code(env, env->regs[15] - 2, env->bswap_code) @@ -4740,7 +4741,7 @@ void arm_cpu_do_interrupt(CPUState *cs) break; case EXCP_BKPT: /* See if this is a semihosting syscall. */ - if (env->thumb && semihosting_enabled) { + if (env->thumb && semihosting_enabled()) { mask = arm_lduw_code(env, env->regs[15], env->bswap_code) & 0xff; if (mask == 0xab && (env->uncached_cpsr & CPSR_M) != ARM_CPU_MODE_USR) { diff --git a/target-lm32/helper.c b/target-lm32/helper.c index 7a41f29..a88aa5a 100644 --- a/target-lm32/helper.c +++ b/target-lm32/helper.c @@ -20,6 +20,7 @@ #include "cpu.h" #include "qemu/host-utils.h" #include "sysemu/sysemu.h" +#include "exec/semihost.h" int lm32_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int rw, int mmu_idx) @@ -162,7 +163,7 @@ void lm32_cpu_do_interrupt(CPUState *cs) switch (cs->exception_index) { case EXCP_SYSTEMCALL: - if (unlikely(semihosting_enabled)) { + if (unlikely(semihosting_enabled())) { /* do_semicall() returns true if call was handled. Otherwise * do the normal exception handling. */ if (lm32_cpu_do_semihosting(cs)) { diff --git a/target-m68k/op_helper.c b/target-m68k/op_helper.c index 06661f5..4f8fabb 100644 --- a/target-m68k/op_helper.c +++ b/target-m68k/op_helper.c @@ -19,6 +19,7 @@ #include "cpu.h" #include "exec/helper-proto.h" #include "exec/cpu_ldst.h" +#include "exec/semihost.h" #if defined(CONFIG_USER_ONLY) @@ -33,8 +34,6 @@ static inline void do_interrupt_m68k_hardirq(CPUM68KState *env) #else -extern int semihosting_enabled; - /* Try to fill the TLB and return an exception if error. If retaddr is NULL, it means that the function was called in C code (i.e. not from generated code or from helper.c) */ @@ -85,7 +84,7 @@ static void do_interrupt_all(CPUM68KState *env, int is_hw) do_rte(env); return; case EXCP_HALT_INSN: - if (semihosting_enabled + if (semihosting_enabled() && (env->sr & SR_S) != 0 && (env->pc & 3) == 0 && cpu_lduw_code(env, env->pc - 4) == 0x4e71 diff --git a/target-xtensa/translate.c b/target-xtensa/translate.c index 6e5096c..3d52079 100644 --- a/target-xtensa/translate.c +++ b/target-xtensa/translate.c @@ -37,6 +37,7 @@ #include "qemu/log.h" #include "sysemu/sysemu.h" #include "exec/cpu_ldst.h" +#include "exec/semihost.h" #include "exec/helper-proto.h" #include "exec/helper-gen.h" @@ -1216,7 +1217,7 @@ static void disas_xtensa_insn(CPUXtensaState *env, DisasContext *dc) break; case 1: /*SIMCALL*/ - if (semihosting_enabled) { + if (semihosting_enabled()) { if (gen_check_privilege(dc)) { gen_helper_simcall(cpu_env); } diff --git a/vl.c b/vl.c index 15bccc4..5a8040d 100644 --- a/vl.c +++ b/vl.c @@ -119,6 +119,7 @@ int main(int argc, char **argv) #include "qapi/opts-visitor.h" #include "qom/object_interfaces.h" #include "qapi-event.h" +#include "exec/semihost.h" #define DEFAULT_RAM_SIZE 128 @@ -171,7 +172,6 @@ int graphic_rotate = 0; const char *watchdog; QEMUOptionRom option_rom[MAX_OPTION_ROMS]; int nb_option_roms; -int semihosting_enabled = 0; int old_param = 0; const char *qemu_name; int alt_grab = 0; @@ -1225,6 +1225,16 @@ static void configure_msg(QemuOpts *opts) } /***********************************************************/ +/* Semihosting */ + +static bool semihosting_allowed; + +bool semihosting_enabled(void) +{ + return semihosting_allowed; +} + +/***********************************************************/ /* USB devices */ static int usb_device_add(const char *devname) @@ -3545,15 +3555,15 @@ int main(int argc, char **argv, char **envp) nb_option_roms++; break; case QEMU_OPTION_semihosting: - semihosting_enabled = 1; + semihosting_allowed = true; semihosting_target = SEMIHOSTING_TARGET_AUTO; break; case QEMU_OPTION_semihosting_config: - semihosting_enabled = 1; + semihosting_allowed = true; opts = qemu_opts_parse(qemu_find_opts("semihosting-config"), optarg, 0); if (opts != NULL) { - semihosting_enabled = qemu_opt_get_bool(opts, "enable", + semihosting_allowed = qemu_opt_get_bool(opts, "enable", true); const char *target = qemu_opt_get(opts, "target"); if (target != NULL) {