From patchwork Tue Jul 12 20:53:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 589801 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5817:0:0:0:0 with SMTP id j23csp673658max; Tue, 12 Jul 2022 13:56:12 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vvJ+ySCYINg0FaxT4Wa9vw7BWw2JmrBOJKX3rdEL+HrVLXxe1CbAEPnVJKtHOT7p4k73WZ X-Received: by 2002:a05:620a:3725:b0:6af:4f5e:de00 with SMTP id de37-20020a05620a372500b006af4f5ede00mr117583qkb.754.1657659372677; Tue, 12 Jul 2022 13:56:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657659372; cv=none; d=google.com; s=arc-20160816; b=bkqlk7NMDt7eHiSZWrCgFEzvMCzz6GZRMJw66KapH0593jNLjqK4fqEd0mSZXHA7ly J1sKeiJAHkhpTPtJ3j7D4wxtHpvm6dOlrKTkGLwJ9E/kiKOspQ74tUMNH4B9I3X1PDBx CElYrmzxniB7SIMvWoVXpIR3ZuXKbG0upSykEw5d0iNtOGlJWr91+PTRFGBfpqp4Ypax Wz+1kYNpomAJNV3c04TxUgitSO5LQnGCzYMgqRoTN4Li+AJHQje6g9TeuTX87xwjUuxt PgikLK1pkLRY+mjJ9q4yjenQteE0fqpWaAxlA5QY9xWeEqy7V3OJ+GjqwpB4Mgbng8Ek UHOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=from:reply-to:sender:errors-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dkim-signature; bh=jkHITop9GlZLzDollgFX8D+ZcnqZzYe+NeYjkL5aFv4=; b=cwClyYrUiIZNVWKRfeK+PjsTk67NhQ2FX+8qxKipTbtn2U/GyWs4BycEqM0EwrAUZW 9IWWtJfIm7yGlksjm3o0UeMxEFIn4Lg680VHismF8VwZAZlD4muYNSijQBXbnh52VI8s bgvOeu/VX5R+KTaKFWDhjivi4LIHbDIiKmU3S1fP3gHKKdGMN5jee74hp5eVRwWWYgyL j+L2mpFzKDikOuNku4rh9MXyBTo/i3LEZiey/s6JfWrHZy68K45+fAdt+2XBbXuJgBeG z/NktuG06wga7w4JRHrXo5mHbv6j6sJdghssxepIvvhV3cZwLmKaBgMSZptNMaxqU/XC f1/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=cgzyr9IR; 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=pass (p=NONE sp=NONE dis=NONE) header.from=nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k5-20020ac81405000000b0031e9aecc2fesi6097733qtj.672.2022.07.12.13.56.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Jul 2022 13:56:12 -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=@gmail.com header.s=20210112 header.b=cgzyr9IR; 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=pass (p=NONE sp=NONE dis=NONE) header.from=nongnu.org Received: from localhost ([::1]:37544 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBMvU-0006G6-87 for patch@linaro.org; Tue, 12 Jul 2022 16:56:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58028) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBMtw-0006AW-Va for qemu-devel@nongnu.org; Tue, 12 Jul 2022 16:54:36 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:37876) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oBMtu-0007Cw-6P for qemu-devel@nongnu.org; Tue, 12 Jul 2022 16:54:35 -0400 Received: by mail-wr1-x42c.google.com with SMTP id r10so6669775wrv.4 for ; Tue, 12 Jul 2022 13:54:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jkHITop9GlZLzDollgFX8D+ZcnqZzYe+NeYjkL5aFv4=; b=cgzyr9IR8kz7WfwftTT5XfynA3NoPljzKZqsqrx4iIkQvASso4DuOZnN0YVdX8f0uU cncxfbHgFQ0MO9wbGvvF7pKsb3kli7/3xfVQbZ/U4FrfKa2xAc3YcU28zqBaeJaoLcyo HHPrXMfl5/fQGQJUEBZR1necKKutEKvtOTiqmwr2qCMNp/T7AgP+d1v7CIZV/Yt1W8qD y051+l1Y+dwR6b6gvm+4BYZHHO7cLvgyGUZDx7LHrcECWOFa8hubMI5PxuFJ4W0fZvuf 6FlJENicNENz99f5blx7OJAq1gDc1o5aVDz2xLQKLQVNBCg7d2zRDk8jdjKS0hRqOxYX HNvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=jkHITop9GlZLzDollgFX8D+ZcnqZzYe+NeYjkL5aFv4=; b=mCQk6egE01mdCahbasQMA5fuKxmcqkQht33yUPXxi01qF3gAw2x6SnUt89drh6dzR8 DsofZKfJN+hNr70oFa2IZDPNke58o94J+OnB1SMOc5a3Y/x96AKFaiAskJ3qFG9LZ6SM w8c6eI185ka2662peJXqWWFZPmchrwtRDGxI50snxY5LRpNt2jcquMcZyUr5rdeI+H97 FR8NRF4LhF7AxN7rIT57qLpajLFC0yCa9mB96p9XMrAEqebqqcmKMIblbFKYoWblK1dE K67H3ikgdopVPyu3X6ZI5rgh82H/ipRlp7ZC7Tt7PcvmQ+rDVWgFL5hbcdpB7HI8zhtX c7pA== X-Gm-Message-State: AJIora9yA9BsXEtBVstLKqg+uoakOo3M783UWTXhlnJFvZ9mf4EclqAC eLPrOt0V2U+/pJs6p1PmsoKELPoeez6qcLLu X-Received: by 2002:a5d:4345:0:b0:21a:3b82:ad57 with SMTP id u5-20020a5d4345000000b0021a3b82ad57mr24301603wrr.176.1657659272999; Tue, 12 Jul 2022 13:54:32 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id v6-20020adfe4c6000000b0021d7799cf4csm9124227wrm.61.2022.07.12.13.54.31 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 12 Jul 2022 13:54:32 -0700 (PDT) To: qemu-devel@nongnu.org Cc: Aurelien Jarno , Jiaxun Yang , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , =?utf-8?q?Alex_Benn=C3=A9e?= , Aleksandar Rikalo , Richard Henderson Subject: [PULL 08/12] target/mips: Avoid qemu_semihosting_log_out for UHI_plog Date: Tue, 12 Jul 2022 22:53:43 +0200 Message-Id: <20220712205347.58372-9-f4bug@amsat.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220712205347.58372-1-f4bug@amsat.org> References: <20220712205347.58372-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x42c.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Reply-to: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Original-From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= via From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= From: Richard Henderson Use semihost_sys_write and/or qemu_semihosting_console_write for implementing plog. When using gdbstub, copy the temp string below the stack so that gdb has a guest address from which to perform the log. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20220628111701.677216-5-richard.henderson@linaro.org> Signed-off-by: Philippe Mathieu-Daudé --- target/mips/tcg/sysemu/mips-semi.c | 52 +++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/target/mips/tcg/sysemu/mips-semi.c b/target/mips/tcg/sysemu/mips-semi.c index 5b78cf21a7..ad11a46820 100644 --- a/target/mips/tcg/sysemu/mips-semi.c +++ b/target/mips/tcg/sysemu/mips-semi.c @@ -310,20 +310,50 @@ void mips_semihosting(CPUMIPSState *env) } gpr[2] = copy_argn_to_target(env, gpr[4], gpr[5]); break; + case UHI_plog: - GET_TARGET_STRING(p, gpr[4]); - p2 = strstr(p, "%d"); - if (p2) { - int char_num = p2 - p; - 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] = qemu_semihosting_log_out(p, strlen(p)); + { + target_ulong addr = gpr[4]; + ssize_t len = target_strlen(addr); + GString *str; + char *pct_d; + + if (len < 0) { + report_fault(env); + } + p = lock_user(VERIFY_READ, addr, len, 1); + if (!p) { + report_fault(env); + } + + pct_d = strstr(p, "%d"); + if (!pct_d) { + FREE_TARGET_STRING(p, addr); + semihost_sys_write(cs, uhi_cb, 2, addr, len); + break; + } + + str = g_string_new_len(p, pct_d - p); + g_string_append_printf(str, "%d%s", (int)gpr[5], pct_d + 2); + FREE_TARGET_STRING(p, addr); + + /* + * When we're using gdb, we need a guest address, so + * drop the string onto the stack below the stack pointer. + */ + if (use_gdb_syscalls()) { + addr = gpr[29] - str->len; + p = lock_user(VERIFY_WRITE, addr, str->len, 0); + memcpy(p, str->str, str->len); + unlock_user(p, addr, str->len); + semihost_sys_write(cs, uhi_cb, 2, addr, str->len); + } else { + gpr[2] = qemu_semihosting_console_write(str->str, str->len); + } + g_string_free(str, true); } - FREE_TARGET_STRING(p, gpr[4]); break; + case UHI_assert: GET_TARGET_STRINGS_2(p, gpr[4], p2, gpr[5]); printf("assertion '");