From patchwork Fri Jun 19 13:47:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 50108 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4AB3B22903 for ; Fri, 19 Jun 2015 13:52:11 +0000 (UTC) Received: by laka10 with SMTP id a10sf29489998lak.2 for ; Fri, 19 Jun 2015 06:52:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=UTlgPq2WSqTKmpcCXCYj360IwZBI5nUpAY80dNhNUnI=; b=OQpEpb8G+Yu+vPp6GPCUkjy23K9vbg7sKtMguYJhZ5DjkJlunrFJQjOcoSwGJVlagY pq2CaBpkLrrX3wFLslH2aR/cv+Ae7hYnTpBXNgaMryVkZLz8SnZuQZL0sKlR8z5B2aQM PvprjZk7uojYb60AMZs6h/YHnh5QjZ1U0TcEHQ1sgvlU3ttDQeIySNVRsyoilsKO/7Jr 5wmqOFhzgKd0sR9KBhotx2ygVJSKK2b1rp9mmNq8HFPUukPEGcxzZJKDifc5/CHM8N4L BDcrO7lu3xZVVeoPU+Z45McKDEqkzlW3JDWaU8bC9n0llicuCSJRtRACs+nVjPeaHBwh R3eg== X-Gm-Message-State: ALoCoQlM79omUs8JoksU33WlYZYfHtHgR5FWxCuqsTopockTB+Y/4v/jPTR6mbGTtyLR5sfM4SJt X-Received: by 10.194.58.164 with SMTP id s4mr7781735wjq.3.1434721930274; Fri, 19 Jun 2015 06:52:10 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.8.111 with SMTP id q15ls526390laa.28.gmail; Fri, 19 Jun 2015 06:52:10 -0700 (PDT) X-Received: by 10.112.83.135 with SMTP id q7mr18124210lby.13.1434721930079; Fri, 19 Jun 2015 06:52:10 -0700 (PDT) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id ro2si9216272lbb.135.2015.06.19.06.52.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Jun 2015 06:52:10 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by lacny3 with SMTP id ny3so74573149lac.3 for ; Fri, 19 Jun 2015 06:52:10 -0700 (PDT) X-Received: by 10.152.179.234 with SMTP id dj10mr11338707lac.73.1434721929948; Fri, 19 Jun 2015 06:52:09 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp609149lbb; Fri, 19 Jun 2015 06:52:08 -0700 (PDT) X-Received: by 10.140.107.228 with SMTP id h91mr21595965qgf.1.1434721926987; Fri, 19 Jun 2015 06:52:06 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id dh6si10951378qcb.15.2015.06.19.06.52.06 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 19 Jun 2015 06:52:06 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:58190 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5wiE-00075O-44 for patch@linaro.org; Fri, 19 Jun 2015 09:52:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35754) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5wdd-0006Gy-Mw for qemu-devel@nongnu.org; Fri, 19 Jun 2015 09:47:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z5wda-0001IZ-QR for qemu-devel@nongnu.org; Fri, 19 Jun 2015 09:47:21 -0400 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:34490) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5wda-0001Hr-G4 for qemu-devel@nongnu.org; Fri, 19 Jun 2015 09:47:18 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1Z5wdZ-0006cK-0j for qemu-devel@nongnu.org; Fri, 19 Jun 2015 14:47:17 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 19 Jun 2015 14:47:15 +0100 Message-Id: <1434721636-25357-12-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1434721636-25357-1-git-send-email-peter.maydell@linaro.org> References: <1434721636-25357-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Subject: [Qemu-devel] [PULL 11/12] semihosting: create SemihostingConfig structure and semihost.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Leon Alrae Remove semihosting_enabled and semihosting_target and replace them with SemihostingConfig structure containing equivalent fields. The structure is defined in vl.c where it is actually set. Also introduce separate header file include/exec/semihost.h allowing to access semihosting config related stuff from target specific semihosting code. Signed-off-by: Leon Alrae Reviewed-by: Peter Maydell Message-id: 1434643256-16858-2-git-send-email-leon.alrae@imgtec.com Signed-off-by: Peter Maydell --- gdbstub.c | 8 ++++---- include/exec/gdbstub.h | 6 ------ include/exec/semihost.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 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 | 38 +++++++++++++++++++++++++++++--------- 9 files changed, 87 insertions(+), 28 deletions(-) create mode 100644 include/exec/semihost.h diff --git a/gdbstub.c b/gdbstub.c index 75563db..cea2a84 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -40,6 +40,7 @@ #include "cpu.h" #include "qemu/sockets.h" #include "sysemu/kvm.h" +#include "exec/semihost.h" #ifdef CONFIG_USER_ONLY #define GDB_ATTACHED "0" @@ -323,8 +324,6 @@ static GDBState *gdbserver_state; bool gdb_has_xml; -int semihosting_target = SEMIHOSTING_TARGET_AUTO; - #ifdef CONFIG_USER_ONLY /* XXX: This is not thread safe. Do we care? */ static int gdbserver_fd = -1; @@ -362,10 +361,11 @@ static enum { /* Decide if either remote gdb syscalls or native file IO should be used. */ int use_gdb_syscalls(void) { - if (semihosting_target == SEMIHOSTING_TARGET_NATIVE) { + SemihostingTarget target = semihosting_get_target(); + if (target == SEMIHOSTING_TARGET_NATIVE) { /* -semihosting-config target=native */ return false; - } else if (semihosting_target == SEMIHOSTING_TARGET_GDB) { + } else if (target == SEMIHOSTING_TARGET_GDB) { /* -semihosting-config target=gdb */ return true; } diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index c633248..a608a26 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -95,10 +95,4 @@ extern bool gdb_has_xml; /* in gdbstub-xml.c, generated by scripts/feature_to_c.sh */ extern const char *const xml_builtin[][2]; -/* Command line option defining whether semihosting should go via gdb or not */ -extern int semihosting_target; -#define SEMIHOSTING_TARGET_AUTO 0 -#define SEMIHOSTING_TARGET_NATIVE 1 -#define SEMIHOSTING_TARGET_GDB 2 - #endif diff --git a/include/exec/semihost.h b/include/exec/semihost.h new file mode 100644 index 0000000..c2f0bcb --- /dev/null +++ b/include/exec/semihost.h @@ -0,0 +1,44 @@ +/* + * 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 + +typedef enum SemihostingTarget { + SEMIHOSTING_TARGET_AUTO = 0, + SEMIHOSTING_TARGET_NATIVE, + SEMIHOSTING_TARGET_GDB +} SemihostingTarget; + +#ifdef CONFIG_USER_ONLY +static inline bool semihosting_enabled(void) +{ + return true; +} + +static inline SemihostingTarget semihosting_get_target(void) +{ + return SEMIHOSTING_TARGET_AUTO; +} +#else +bool semihosting_enabled(void); +SemihostingTarget semihosting_get_target(void); +#endif + +#endif diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 0304aa7..df80951 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -126,7 +126,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 efce6cd..aa34159 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 bool get_phys_addr(CPUARMState *env, target_ulong address, @@ -4554,7 +4555,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) { @@ -4866,7 +4867,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) @@ -4893,7 +4894,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 2201e27..a286877 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 MAX_VIRTIO_CONSOLES 1 #define MAX_SCLP_CONSOLES 1 @@ -169,7 +170,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; @@ -1246,6 +1246,26 @@ static void configure_msg(QemuOpts *opts) } /***********************************************************/ +/* Semihosting */ + +typedef struct SemihostingConfig { + bool enabled; + SemihostingTarget target; +} SemihostingConfig; + +static SemihostingConfig semihosting; + +bool semihosting_enabled(void) +{ + return semihosting.enabled; +} + +SemihostingTarget semihosting_get_target(void) +{ + return semihosting.target; +} + +/***********************************************************/ /* USB devices */ static int usb_device_add(const char *devname) @@ -3622,24 +3642,24 @@ int main(int argc, char **argv, char **envp) nb_option_roms++; break; case QEMU_OPTION_semihosting: - semihosting_enabled = 1; - semihosting_target = SEMIHOSTING_TARGET_AUTO; + semihosting.enabled = true; + semihosting.target = SEMIHOSTING_TARGET_AUTO; break; case QEMU_OPTION_semihosting_config: - semihosting_enabled = 1; + semihosting.enabled = true; opts = qemu_opts_parse(qemu_find_opts("semihosting-config"), optarg, 0); if (opts != NULL) { - semihosting_enabled = qemu_opt_get_bool(opts, "enable", + 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; + semihosting.target = SEMIHOSTING_TARGET_NATIVE; } else if (strcmp("gdb", target) == 0) { - semihosting_target = SEMIHOSTING_TARGET_GDB; + semihosting.target = SEMIHOSTING_TARGET_GDB; } else if (strcmp("auto", target) == 0) { - semihosting_target = SEMIHOSTING_TARGET_AUTO; + semihosting.target = SEMIHOSTING_TARGET_AUTO; } else { fprintf(stderr, "Unsupported semihosting-config" " %s\n", @@ -3647,7 +3667,7 @@ int main(int argc, char **argv, char **envp) exit(1); } } else { - semihosting_target = SEMIHOSTING_TARGET_AUTO; + semihosting.target = SEMIHOSTING_TARGET_AUTO; } } else { fprintf(stderr, "Unsupported semihosting-config %s\n",