qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé via" <qemu-devel@nongnu.org>
To: qemu-devel@nongnu.org
Cc: "Aurelien Jarno" <aurelien@aurel32.net>,
	"Jiaxun Yang" <jiaxun.yang@flygoat.com>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Aleksandar Rikalo" <aleksandar.rikalo@syrmia.com>,
	"Richard Henderson" <richard.henderson@linaro.org>
Subject: [PULL 08/12] target/mips: Avoid qemu_semihosting_log_out for UHI_plog
Date: Tue, 12 Jul 2022 22:53:43 +0200	[thread overview]
Message-ID: <20220712205347.58372-9-f4bug@amsat.org> (raw)
In-Reply-To: <20220712205347.58372-1-f4bug@amsat.org>

From: Richard Henderson <richard.henderson@linaro.org>

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 <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20220628111701.677216-5-richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 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 '");
-- 
2.36.1



  parent reply	other threads:[~2022-07-12 20:57 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-12 20:53 [PULL 00/12] MIPS patches for 2022-07-12 Philippe Mathieu-Daudé via
2022-07-12 20:53 ` [PULL 01/12] target/mips: introduce decodetree structure for Cavium Octeon extension Philippe Mathieu-Daudé via
2022-07-12 20:53 ` [PULL 02/12] target/mips: implement Octeon-specific BBIT instructions Philippe Mathieu-Daudé via
2022-07-12 20:53 ` [PULL 03/12] target/mips: implement Octeon-specific arithmetic instructions Philippe Mathieu-Daudé via
2022-07-12 20:53 ` [PULL 04/12] target/mips: introduce Cavium Octeon CPU model Philippe Mathieu-Daudé via
2022-07-12 20:53 ` [PULL 05/12] target/mips: Create report_fault for semihosting Philippe Mathieu-Daudé via
2022-07-12 20:53 ` [PULL 06/12] target/mips: Drop link syscall from semihosting Philippe Mathieu-Daudé via
2022-07-12 20:53 ` [PULL 07/12] target/mips: Use semihosting/syscalls.h Philippe Mathieu-Daudé via
2022-07-12 20:53 ` Philippe Mathieu-Daudé via [this message]
2022-07-12 20:53 ` [PULL 09/12] target/mips: Use error_report for UHI_assert Philippe Mathieu-Daudé via
2022-07-12 20:53 ` [PULL 10/12] semihosting: Remove qemu_semihosting_log_out Philippe Mathieu-Daudé via
2022-07-12 20:53 ` [PULL 11/12] target/mips: Simplify UHI_argnlen and UHI_argn Philippe Mathieu-Daudé via
2022-07-12 20:53 ` [PULL 12/12] target/mips: Remove GET_TARGET_STRING and FREE_TARGET_STRING Philippe Mathieu-Daudé via
2022-07-14  8:30 ` [PULL 00/12] MIPS patches for 2022-07-12 Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220712205347.58372-9-f4bug@amsat.org \
    --to=qemu-devel@nongnu.org \
    --cc=aleksandar.rikalo@syrmia.com \
    --cc=alex.bennee@linaro.org \
    --cc=aurelien@aurel32.net \
    --cc=f4bug@amsat.org \
    --cc=jiaxun.yang@flygoat.com \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).