From patchwork Thu May 23 10:25:10 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: 164957 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1990088ili; Thu, 23 May 2019 03:31:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqwPV6qChPOq/f1KIwm+Qkk2h/xhlHM29grUQuaN2o1pJS27Kt3BZ5p9+B7tRTifM19Fap3I X-Received: by 2002:a17:906:60c7:: with SMTP id f7mr49532160ejk.107.1558607505346; Thu, 23 May 2019 03:31:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558607505; cv=none; d=google.com; s=arc-20160816; b=U9nQiUkrUm56G1oga3fx4y+YcB61IzyOXR4C9BnT9NpEVeq75R6aTgjMvnHZNQKpz5 3Lmx5zcODQp5nnaw1W14DmbOJsmuXnS+DUn7N915UUxU9wH1Jbk+BRujQpy3wOiXWh0V 0xIsQ+vmVfgD4sWWSwPeThpNvNCrdOzoyEABkTSlyC2t6qEAvOvqNU5OzKWrZQpiGWHB H0wLBLbRRmPuqA/M9v0gOAx8lkWY7KOov4Z6TAvo2KNn1ZDeW0fv6Brnok5P641WXpDz qIWIK8CRmHaJL+2tfqw9GMMyFGuInzXpckRY1q6ar01c7n9QrhhmO88yPfsSqavaH/pw HJVw== 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=3N082WaIffsJbYXIZ0a/9GfiR46w16xaqgWtZJxN1co=; b=NMJa6KzqdM8E+sUo7E/GBDQvvi6qU1p3VQCDu/AfmmvH8HEYqg7YNVb8eMm2N70xWr AJh7URcACpBcbMBZwVaCqwPfQvGYaIyk45IW5uQIYAMhjbshXefV7qjRnBcKNEtsmWe5 p2BVLTthhMT1zQ1yz9cEK4bqOhXLUeC6AD46gJBZPQvpLqsh/Rjhzav76M7T4f8iypuy Rijw/BYYPL7CfJKWdXzSR/BkiAkERw/9LV19F9Xg8AJWuadD4o88pCO2lT/v3tFXHPBM v+86onD/oINn7EpUj9nVYcgRDsUVb83stTjigq72hOyBjN11twqEcNeZ5YrNkfaXvzEa e0VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=k2BX6BdL; 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 d34si5835504eda.58.2019.05.23.03.31.45 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 23 May 2019 03:31:45 -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=k2BX6BdL; 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]:33146 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTl0i-0002sC-4w for patch@linaro.org; Thu, 23 May 2019 06:31:44 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49127) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTkuy-0005SL-4U for qemu-devel@nongnu.org; Thu, 23 May 2019 06:25:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTkut-0000z7-Dq for qemu-devel@nongnu.org; Thu, 23 May 2019 06:25:47 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:37894) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTkuo-0000uC-5Z for qemu-devel@nongnu.org; Thu, 23 May 2019 06:25:41 -0400 Received: by mail-wr1-x441.google.com with SMTP id d18so5650892wrs.5 for ; Thu, 23 May 2019 03:25:37 -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=3N082WaIffsJbYXIZ0a/9GfiR46w16xaqgWtZJxN1co=; b=k2BX6BdL7AfVBVZGvxR6I1W5YQyw97rfN8y982CROeZA6WA5nEUyu0LNZ381uVK3mK TEtZ0H7yj/B/AYZ7U3O24ZAej2MQM+RmX6gq6keUVDmGPEobLe1afslliZWeUcudmPFO epO9GMf3Nbtq7cf9pryxXssNASaX2oR16yfEvQ3SPnI5AyrS12XSLGTDN3LuVxP+q/OL hdI+/2zIUl1DiG6/Fn9UYaxCbybEHlTVeGrUKoLVvGGAxttNVkHxcqz48YVsR/HbWvpz f3hj8UrsvPotAGg9UsxjNbAV/G5k+BesvT95b1BFgf2yS+TO4PA3UDR3YxqRl7WAyyjC 83nA== 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=3N082WaIffsJbYXIZ0a/9GfiR46w16xaqgWtZJxN1co=; b=P3PheMlv5H0QaZBHz52Zz3MCmBi8iJwGfyz1cr48OGtI1tzT+eL2/gGkef2ceu3t2c AXKUHHn+hueENVZv3pbTq8OvXkV5tsXpDKH2i3UR2UjG9Quvo+n2Ov4gqy12Rr/mBKdq 4YmoRm1OKcuFZDvuH+ylbLG61u+ByNvB+M6jitbrMeDI93LHwbXKGw1MknNF4pYW2Cek WeCGgCbhPPsDmCO71GS6ZtPpRSsbJgmqQ1+wDjb4GLmSqEFAsuOWu/5l5SGM4Brjo2Cu dwHB2mUxOmwCjqM6rLwRAxJkZljJy9xxn0Uc2gHf7KgqgiGOmGO01xkiyhws7wzEuRPl FELQ== X-Gm-Message-State: APjAAAWaHNyEl1+AzucP7LEVYfeASoL1GwRmpcYCaOrLTbC+Zgh9fcAp TI9QfhUBFPYtt2LUr2e7GqSdWQ== X-Received: by 2002:adf:ce07:: with SMTP id p7mr44958922wrn.241.1558607136866; Thu, 23 May 2019 03:25:36 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id 19sm9345962wmk.3.2019.05.23.03.25.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 23 May 2019 03:25:35 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 0B3E71FF93; Thu, 23 May 2019 11:25:33 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Thu, 23 May 2019 11:25:10 +0100 Message-Id: <20190523102532.10486-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190523102532.10486-1-alex.bennee@linaro.org> References: <20190523102532.10486-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::441 Subject: [Qemu-devel] [PATCH v2 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: Peter Maydell , Riku Voipio , qemu-arm@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Laurent Vivier 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 --- linux-user/Makefile.objs | 2 ++ linux-user/arm/semihost.c | 24 ++++++++++++++++++++++++ target/arm/arm-semi.c | 31 ++++++------------------------- 3 files changed, 32 insertions(+), 25 deletions(-) create mode 100644 linux-user/arm/semihost.c -- 2.20.1 Reviewed-by: Richard Henderson 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 9e5a414dd89..253c66b172a 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" @@ -314,32 +315,12 @@ 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);