From patchwork Tue May 28 09:49:35 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: 165283 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp8255301ili; Tue, 28 May 2019 02:59:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqxxZV65UGhsi8Jswp6CoYxnfYiWADGr5x2ayNrNf4s3DQEzM91KdUrykFWpcZSMo3Qlt9yt X-Received: by 2002:a05:620a:1e6:: with SMTP id x6mr64987152qkn.179.1559037553533; Tue, 28 May 2019 02:59:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559037553; cv=none; d=google.com; s=arc-20160816; b=0WS06RBXK9t4ZIYgjV6oYh9K8/jumZV5aEY2L0U0fZZ5xHG8vFF+0F7hSh7kNyVzQ6 5juIR4wQloQQFP7WrOL7+V9919fZDUjb2WT1C7kah2ytFSOPUwef61eHEHm0xi899gmx tYxqIkV80anJwLC002uFYCFTWJvB/IrvhKUSZL5lJ51Ra26i+hqn8TgjTK9o07xAPDAA DlCNoFAh34YRGKKw+x5VLiwU5xLTmCqXYVm7oMOlQWWYsfql6woyHuID0cF9Y1SQP+y3 6jmM5I212m4p9ezg70wyRDgtKU1kWQW3oLfrVcRP81st99kownR8S+7Xm5z1gSURmhgp rIHw== 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=FxtIkdXbzo6iNDE4yzISIpBWlKoNafWnhJfmMbMyOVk=; b=SDQ3D+LLmsnpkA0nj5djaRKSZb3r3Nw27Rp7ZqVQTvJ2CBN+Xjqob6tMcL7dGjuwIz J4FreqmJ42zlH9aZyJjlN/NwCX3HU+iCsoZKX7MD7iZeQ+LAUlKxPCF1NYtbIJfyTYuE wRJ0WOPCFh1nEWBtRzZpWZUua8vL5kTWI8zC6PUYd1boqi4aR7H+9ELYbSh8e+ECKruU spKyEpOgKjoz8/sTp/m5o/E45IYSy7iIuYIgfK6o5M3SwX74u/JAGBvGPri2JjLGuwvu feH2Cms7ZamVhxZig6XbEGrs8wA9yqPEFLVPcmaXgtzoHyYNewPsjW/KIIXx20s/QIDx s0Mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=tFV4Wu3g; 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 x14si2081665qkh.42.2019.05.28.02.59.13 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 28 May 2019 02:59:13 -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=tFV4Wu3g; 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]:60056 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hVYsz-0005hO-1s for patch@linaro.org; Tue, 28 May 2019 05:59:13 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40859) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hVYkA-0006IE-V1 for qemu-devel@nongnu.org; Tue, 28 May 2019 05:50:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hVYk7-00008Q-1d for qemu-devel@nongnu.org; Tue, 28 May 2019 05:50:06 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:54674) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hVYk6-00006u-SZ for qemu-devel@nongnu.org; Tue, 28 May 2019 05:50:02 -0400 Received: by mail-wm1-x344.google.com with SMTP id i3so2135790wml.4 for ; Tue, 28 May 2019 02:50:02 -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=FxtIkdXbzo6iNDE4yzISIpBWlKoNafWnhJfmMbMyOVk=; b=tFV4Wu3gOK1SXwpfKHf9Q64GJQVZY2N4sQ0G1Y2Jmu+ZuSK6vjGnOGi0nYY0k56qLQ yo/zJJYHkh85jb+iQShglTTZMz8yzchNcwhf61pKnH16ZZJAUiWBzVQ1E0XVkC7zTbzW Ob6+T+pXAcKDvEGodicmrlm9Da7Kg+DdFK5gFc0dSWNfoNS+2IdPVKxOdfnFBkELYOXZ Q4TzfJd177gBKE8EsO9FZ2sAFSBDrhBEN+FkbsNSXa51Thc8tAIp+g9ekwSFAeWG9kKe GbjIp2MHKsu0MP/US0UvyaVOMan8kf/M4/x+Oterpd1drpgy61KywPCb/kKgASzEkiB/ eyDQ== 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=FxtIkdXbzo6iNDE4yzISIpBWlKoNafWnhJfmMbMyOVk=; b=RQUeKVEf4/cgz90tOp+dcrqvjtw+5OhJ2eJWXQcc9qd+a9C3aE7wb3pBFW1Ww6C9dq RsXILjHJ0t57JPpCqqD4SkLj+SVXOrrECf+QhWb7BJHe4qNImVuUUtASGLssHhB2Mag5 AsBHanpJB77n/lx5gf96JMGZqSQ+lP5OdfTazTyKkVOJPD1u6ol3JEpb45nrDDLQyhIY bhkVwevw5bQHtW3QFocOE9mhSp0wqfTMuSwWtlp7l68fU9KjJjJRTuNaTkRxu0KObhKU EnOXL0ILsp3WVNw5OkrwQrlrxuRB1MVGN6rZ/V0EA6FvMZrs9lPqkdDSGk/JKluY6ezW 5JvQ== X-Gm-Message-State: APjAAAUYsV9mVcWHDYR0rBK/K2dfJQcdfGmya//iK6UikIE+7dMRJOMs gpB8kYN3VKplwt0keuNm8jLDempjbD0= X-Received: by 2002:a7b:c181:: with SMTP id y1mr2633514wmi.14.1559037001479; Tue, 28 May 2019 02:50:01 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id f197sm2272921wme.39.2019.05.28.02.49.55 (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 5A4071FF99; 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:35 +0100 Message-Id: <20190528094953.14898-11-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 10/28] target/mips: convert UHI_plog to use common semihosting code 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: Aleksandar Rikalo , Aurelien Jarno , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org, Aleksandar Markovic Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Rather than printing directly to stdout lets use our common semihosting code. There is one minor difference in that the output currently defaults to stderr instead of stdout however this can be controlled by connecting semihosting to a chardev. Signed-off-by: Alex Bennée Reviewed-by: Aleksandar Markovic -- 2.20.1 diff --git a/target/mips/mips-semi.c b/target/mips/mips-semi.c index eac8374fb34..35bdfd7c77e 100644 --- a/target/mips/mips-semi.c +++ b/target/mips/mips-semi.c @@ -23,6 +23,7 @@ #include "exec/helper-proto.h" #include "exec/softmmu-semi.h" #include "hw/semihosting/semihost.h" +#include "hw/semihosting/console.h" typedef enum UHIOp { UHI_exit = 1, @@ -329,13 +330,12 @@ void helper_do_semihosting(CPUMIPSState *env) p2 = strstr(p, "%d"); if (p2) { int char_num = p2 - p; - char *buf = g_malloc(char_num + 1); - strncpy(buf, p, char_num); - buf[char_num] = '\0'; - gpr[2] = printf("%s%d%s", buf, (int)gpr[5], p2 + 2); - g_free(buf); + GString *s = g_string_new_len(p, char_num); + g_string_append_printf(s, "%d%s", (int)gpr[5], p2 + 2); + gpr[2] = qemu_semihosting_log_out(s->str, s->len); + g_string_free(s, true); } else { - gpr[2] = printf("%s", p); + gpr[2] = qemu_semihosting_log_out(p, strlen(p)); } FREE_TARGET_STRING(p, gpr[4]); break;