[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 63/74] target/mips: Simplify UHI_argnlen and UHI_argn
From: |
Richard Henderson |
Subject: |
[PATCH v2 63/74] target/mips: Simplify UHI_argnlen and UHI_argn |
Date: |
Tue, 3 May 2022 12:48:32 -0700 |
With semihosting_get_arg, we already have a check vs argc, so
there's no point replicating it -- just check the result vs NULL.
Merge copy_argn_to_target into its caller.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
target/mips/tcg/sysemu/mips-semi.c | 44 ++++++++++++++----------------
1 file changed, 21 insertions(+), 23 deletions(-)
diff --git a/target/mips/tcg/sysemu/mips-semi.c
b/target/mips/tcg/sysemu/mips-semi.c
index df1747aafe..0f5b509ce2 100644
--- a/target/mips/tcg/sysemu/mips-semi.c
+++ b/target/mips/tcg/sysemu/mips-semi.c
@@ -198,21 +198,6 @@ static void uhi_fstat_cb(CPUState *cs, uint64_t ret, int
err)
uhi_cb(cs, ret, err);
}
-static int copy_argn_to_target(CPUMIPSState *env, int arg_num,
- target_ulong vaddr)
-{
- int strsize = strlen(semihosting_get_arg(arg_num)) + 1;
- char *dst = lock_user(VERIFY_WRITE, vaddr, strsize, 0);
- if (!dst) {
- report_fault(env);
- }
-
- strcpy(dst, semihosting_get_arg(arg_num));
-
- unlock_user(dst, vaddr, strsize);
- return 0;
-}
-
#define GET_TARGET_STRING(p, addr) \
do { \
p = lock_user_string(addr); \
@@ -285,18 +270,31 @@ void mips_semihosting(CPUMIPSState *env)
gpr[2] = semihosting_get_argc();
break;
case UHI_argnlen:
- if (gpr[4] >= semihosting_get_argc()) {
- gpr[2] = -1;
- return;
+ {
+ const char *s = semihosting_get_arg(gpr[4]);
+ gpr[2] = s ? strlen(s) : -1;
}
- gpr[2] = strlen(semihosting_get_arg(gpr[4]));
break;
case UHI_argn:
- if (gpr[4] >= semihosting_get_argc()) {
- gpr[2] = -1;
- return;
+ {
+ const char *s = semihosting_get_arg(gpr[4]);
+ target_ulong addr;
+ size_t len;
+
+ if (!s) {
+ gpr[2] = -1;
+ break;
+ }
+ len = strlen(s) + 1;
+ addr = gpr[5];
+ p = lock_user(VERIFY_WRITE, addr, len, 0);
+ if (!p) {
+ report_fault(env);
+ }
+ memcpy(p, s, len);
+ unlock_user(p, addr, len);
+ gpr[2] = 0;
}
- gpr[2] = copy_argn_to_target(env, gpr[4], gpr[5]);
break;
case UHI_plog:
--
2.34.1
- [PATCH v2 52/74] target/nios2: Move nios2-semi.c to nios2_softmmu_ss, (continued)
- [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, 2022/05/03
- [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 <=
- [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
- [PATCH v2 71/74] target/rx: Consolidate exception helpers, Richard Henderson, 2022/05/03
- [PATCH v2 74/74] tests/tcg/rx: Enable semihosting multiarch tests, Richard Henderson, 2022/05/03
- [PATCH v2 62/74] semihosting: Remove qemu_semihosting_log_out, Richard Henderson, 2022/05/03
- [PATCH v2 66/74] target/xtensa: Use semihosting/syscalls.h, Richard Henderson, 2022/05/03