[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 60/74] target/mips: Avoid qemu_semihosting_log_out for UHI_plo
From: |
Richard Henderson |
Subject: |
[PATCH v2 60/74] target/mips: Avoid qemu_semihosting_log_out for UHI_plog |
Date: |
Tue, 3 May 2022 12:48:29 -0700 |
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>
---
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 2704177a95..d8c9be5e9f 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.34.1
- [PATCH v2 45/74] semihosting: Use console_out_gf for SYS_WRITE0, (continued)
- [PATCH v2 45/74] semihosting: Use console_out_gf for SYS_WRITE0, Richard Henderson, 2022/05/03
- [PATCH v2 48/74] target/m68k: Eliminate m68k_semi_is_fseek, Richard Henderson, 2022/05/03
- [PATCH v2 55/74] target/mips: Add UHI errno values, Richard Henderson, 2022/05/03
- [PATCH v2 49/74] target/m68k: Make semihosting system only, Richard Henderson, 2022/05/03
- [PATCH v2 52/74] target/nios2: Move nios2-semi.c to nios2_softmmu_ss, Richard Henderson, 2022/05/03
- [PATCH v2 50/74] target/m68k: Use semihosting/syscalls.h, Richard Henderson, 2022/05/03
- [PATCH v2 51/74] target/nios2: Eliminate nios2_semi_is_lseek, Richard Henderson, 2022/05/03
- [PATCH v2 57/74] target/mips: Drop link syscall from semihosting, Richard Henderson, 2022/05/03
- [PATCH v2 53/74] target/nios2: Use semihosting/syscalls.h, Richard Henderson, 2022/05/03
- [PATCH v2 54/74] target/mips: Use an exception for semihosting, Richard Henderson, 2022/05/03
- [PATCH v2 60/74] target/mips: Avoid qemu_semihosting_log_out for UHI_plog,
Richard Henderson <=
- [PATCH v2 56/74] target/mips: Create report_fault for semihosting, Richard Henderson, 2022/05/03
- [PATCH v2 58/74] target/mips: Drop pread and pwrite syscalls from semihosting, Richard Henderson, 2022/05/03
- [PATCH v2 59/74] target/mips: Use semihosting/syscalls.h, Richard Henderson, 2022/05/03
- [PATCH v2 63/74] target/mips: Simplify UHI_argnlen and UHI_argn, Richard Henderson, 2022/05/03
- [PATCH v2 65/74] target/xtensa: Use an exception for semihosting, Richard Henderson, 2022/05/03
- [PATCH v2 61/74] target/mips: Use error_report for UHI_assert, Richard Henderson, 2022/05/03
- [PATCH v2 67/74] tests/docker: Add debian-rx-cross image, Richard Henderson, 2022/05/03
- [PATCH v2 64/74] target/mips: Remove GET_TARGET_STRING and FREE_TARGET_STRING, Richard Henderson, 2022/05/03
- [PATCH v2 69/74] target/rx: Fix the base of the fixed vector table, Richard Henderson, 2022/05/03
- [PATCH v2 73/74] target/rx: Implement libgloss semihosting, Richard Henderson, 2022/05/03