From patchwork Tue May 28 09:49:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 165276 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp8251851ili; Tue, 28 May 2019 02:55:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqyBMAhA+54uygOQBsSZgbSvWJcw7CYK/dlXwV2UvuP4kMElVSm5wcecGHVuTBKmG6zdaedF X-Received: by 2002:a0c:e90a:: with SMTP id a10mr1438322qvo.17.1559037327953; Tue, 28 May 2019 02:55:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559037327; cv=none; d=google.com; s=arc-20160816; b=AxirMWtlPqp7SZP+A2RAQMBPN/K18Jh9j/dwnzCDrFDmFGESPmDm1KRB80w6e64Y+9 kFBud3l8fJaCcxSOYHXpAgx2bIApyVXfCrCGsYWLbmZ3waPTNgaVZQM7CH3kytZK8BBg fSzR1mWyTGENmL144TOGeTahi+W8LZF9LsXo3Pr5bGboHsMpwba24P2AhnwxFRVCWZHm 3vi0xqj9UtaqQuMDbb6NfMelUjlXeBJSt4uQZ709E+Ni5zxtFRaFKYCT4QnILzXgVZA/ yAVy36cB0UUwQPIv7JQOF0J98j2ed28JBC1Mu93H0fGYRJM3MjRfbOpiu9Rw5vylACk1 pNPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=xTfU1HgK0Yu+Mt8wiwSgiAOdcAiaYW/8Jaw7M5Np27U=; b=jXSSw2zgMFagJLD/nPjp0lvwtrq1L5BIhZZTpE4QmfVuEvxofYYP+VOpdzZbs6HGii cMJ3URIc+KKvelQomU+phChgQ10opxipJ6JWEZkF+RF1XnULXmoDWf8ZIp7R9t6mse4b G8MmW0aKfU1fV91jEgr6fYaZrRU7c0cngb8v547GMLcMj6Ay5rdJyI3W9c7b9his9kMg Vi4oLHNVsBAijPN72GM+LL7OofxrfZLkF7SCy9fq5F7lad6A/N94K341PBIzMT/MuwMn u8Oi7E3mOzPyv2ZpvNzoRJ22WqJldRokHNH1NspVnAQbuygNPdRhbHu/b6P1fW1NEfGt 4Tyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=xrqP2ZLF; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x10si5113617qth.137.2019.05.28.02.55.27 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 28 May 2019 02:55:27 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=xrqP2ZLF; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:59994 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hVYpL-00028m-FD for patch@linaro.org; Tue, 28 May 2019 05:55:27 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40811) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hVYk7-0006EV-OJ for qemu-devel@nongnu.org; Tue, 28 May 2019 05:50:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hVYk4-0008WI-Da for qemu-devel@nongnu.org; Tue, 28 May 2019 05:50:02 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:38434) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hVYk4-0008VJ-6t for qemu-devel@nongnu.org; Tue, 28 May 2019 05:50:00 -0400 Received: by mail-wm1-x344.google.com with SMTP id t5so2090269wmh.3 for ; Tue, 28 May 2019 02:50:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xTfU1HgK0Yu+Mt8wiwSgiAOdcAiaYW/8Jaw7M5Np27U=; b=xrqP2ZLF1RQm05hRnkS4H3RsDflCKr4NLGZCVHQxxRCKUM9pMmnkGFLisIFYmmQyqz KdYtiTWrjvgDOAdE+sc6M88XgHNSTjyBiP+f9PZVIdcALVKCyk2hcxVw5KLJkOtBktXr NltHWTMhrl0QneFICQ9lQC7fgHaIB8qD6V85UQJhh4PV7KOGbA+yN5eAktj7p87/uMMi X2eEzsUGQvCZzUsHkB6ex5VOdW7fjlf36fNuTrV+DHBN4iLmovQ1U5yEjLHY4GSt87kE Z6TqUtvfQn6bPIUtf2VJyQYinMbv46aR0AysUTeJViIPXuWbHhoDuEocCK6T+a7H3rg8 ioeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xTfU1HgK0Yu+Mt8wiwSgiAOdcAiaYW/8Jaw7M5Np27U=; b=sqdxkl7zd2WCq0pCL/uM+HITPipyMcZzLve8w0kMs1Bb4xj+Y1zm3FNrk40Qv8X2/Z iDEcZaBBqWunJPK9HNnNiw6LHvcREutU8xF/T3N+5tOK5XHVjiRk1ObwmGrBQZDdiPre mjIKYxIPnoW1Y2u1j+li3tQF/s/eJ3XvmYk2gUVSdqGUOzuFp5vRzOMwyxqBpQoRM2bs Zd5g+75DxUeVgdwWeyloNYckvMoO/J5NbYkJkRaj67zimHsfV0rtfPHFGjUCacaNwdBU QccdMCPOzYf9lyiNWyjXPRvopIq6HkKFeA0CSsX8AcC1OW3bduvXDgd2dnEupTDeFUpl aHvQ== X-Gm-Message-State: APjAAAX6H5gUpSPMRs42fZLWlhbPtovdT2mPx6xOKel9Na83IHAWa5tC 8Sli8YrqkKlyqrA9NWFpV1SRhA== X-Received: by 2002:a1c:eb0c:: with SMTP id j12mr2454551wmh.55.1559036999128; Tue, 28 May 2019 02:49:59 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id j123sm3589694wmb.32.2019.05.28.02.49.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 May 2019 02:49:56 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 029EC1FF93; Tue, 28 May 2019 10:49:54 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Tue, 28 May 2019 10:49:31 +0100 Message-Id: <20190528094953.14898-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190528094953.14898-1-alex.bennee@linaro.org> References: <20190528094953.14898-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::344 Subject: [Qemu-devel] [PULL 06/28] target/arm: use the common interface for WRITE0/WRITEC in arm-semi X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , Richard Henderson , qemu-devel@nongnu.org, Laurent Vivier , "open list:ARM" , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Now we have a common semihosting console interface use that for our string output. However ARM is currently unique in also supporting semihosting for linux-user so we need to replicate the API in linux-user. If other architectures gain this support we can move the file later. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson -- 2.20.1 diff --git a/linux-user/Makefile.objs b/linux-user/Makefile.objs index 769b8d83362..285c5dfa17a 100644 --- a/linux-user/Makefile.objs +++ b/linux-user/Makefile.objs @@ -6,4 +6,6 @@ obj-y = main.o syscall.o strace.o mmap.o signal.o \ obj-$(TARGET_HAS_BFLT) += flatload.o obj-$(TARGET_I386) += vm86.o obj-$(TARGET_ARM) += arm/nwfpe/ +obj-$(TARGET_ARM) += arm/semihost.o +obj-$(TARGET_AARCH64) += arm/semihost.o obj-$(TARGET_M68K) += m68k-sim.o diff --git a/linux-user/arm/semihost.c b/linux-user/arm/semihost.c new file mode 100644 index 00000000000..9554102a855 --- /dev/null +++ b/linux-user/arm/semihost.c @@ -0,0 +1,24 @@ +/* + * ARM Semihosting Console Support + * + * Copyright (c) 2019 Linaro Ltd + * + * Currently ARM is unique in having support for semihosting support + * in linux-user. So for now we implement the common console API but + * just for arm linux-user. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "hw/semihosting/console.h" +#include "qemu.h" + +int qemu_semihosting_console_out(CPUArchState *env, target_ulong addr, int len) +{ + void *s = lock_user_string(addr); + len = write(STDERR_FILENO, s, len ? len : strlen(s)); + unlock_user(s, addr, 0); + return len; +} diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index d812eef1519..384b01124e1 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -27,6 +27,7 @@ #include "cpu.h" #include "hw/semihosting/semihost.h" +#include "hw/semihosting/console.h" #ifdef CONFIG_USER_ONLY #include "qemu.h" @@ -313,32 +314,10 @@ target_ulong do_arm_semihosting(CPUARMState *env) return set_swi_errno(ts, close(arg0)); } case TARGET_SYS_WRITEC: - { - char c; - - if (get_user_u8(c, args)) - /* FIXME - should this error code be -TARGET_EFAULT ? */ - return (uint32_t)-1; - /* Write to debug console. stderr is near enough. */ - if (use_gdb_syscalls()) { - return arm_gdb_syscall(cpu, arm_semi_cb, "write,2,%x,1", args); - } else { - return write(STDERR_FILENO, &c, 1); - } - } + qemu_semihosting_console_out(env, args, 1); + return 0xdeadbeef; case TARGET_SYS_WRITE0: - if (!(s = lock_user_string(args))) - /* FIXME - should this error code be -TARGET_EFAULT ? */ - return (uint32_t)-1; - len = strlen(s); - if (use_gdb_syscalls()) { - return arm_gdb_syscall(cpu, arm_semi_cb, "write,2,%x,%x", - args, len); - } else { - ret = write(STDERR_FILENO, s, len); - } - unlock_user(s, args, 0); - return ret; + return qemu_semihosting_console_out(env, args, 0); case TARGET_SYS_WRITE: GET_ARG(0); GET_ARG(1);