All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/3] target/m68k: semihosting cleanup
@ 2022-06-07 22:26 Richard Henderson
  2022-06-07 22:26 ` [PATCH v4 1/3] target/m68k: Eliminate m68k_semi_is_fseek Richard Henderson
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Richard Henderson @ 2022-06-07 22:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: laurent

Based-on: <20220607204557.658541-1-richard.henderson@linaro.org>
("[PATCH v4 00/53] semihosting cleanup")

Changes for v4:
  * Split out of v2.
  * Convert host errno to gdb errno, which for m68k is guest errno.


r~


Richard Henderson (3):
  target/m68k: Eliminate m68k_semi_is_fseek
  target/m68k: Make semihosting system only
  target/m68k: Use semihosting/syscalls.h

 linux-user/m68k/cpu_loop.c |   5 -
 target/m68k/m68k-semi.c    | 375 +++++++++----------------------------
 target/m68k/meson.build    |   6 +-
 3 files changed, 92 insertions(+), 294 deletions(-)

-- 
2.34.1



^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v4 1/3] target/m68k: Eliminate m68k_semi_is_fseek
  2022-06-07 22:26 [PATCH v4 0/3] target/m68k: semihosting cleanup Richard Henderson
@ 2022-06-07 22:26 ` Richard Henderson
  2022-06-08  9:25   ` Laurent Vivier
  2022-06-07 22:26 ` [PATCH v4 2/3] target/m68k: Make semihosting system only Richard Henderson
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 13+ messages in thread
From: Richard Henderson @ 2022-06-07 22:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: laurent

Reorg m68k_semi_return_* to gdb_syscall_complete_cb.
Use the 32-bit version normally, and the 64-bit version
for HOSTED_LSEEK.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/m68k/m68k-semi.c | 55 +++++++++++++++++------------------------
 1 file changed, 23 insertions(+), 32 deletions(-)

diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c
index 8c186c0e9f..37b409b0b9 100644
--- a/target/m68k/m68k-semi.c
+++ b/target/m68k/m68k-semi.c
@@ -95,8 +95,11 @@ static void translate_stat(CPUM68KState *env, target_ulong addr, struct stat *s)
     unlock_user(p, addr, sizeof(struct gdb_stat));
 }
 
-static void m68k_semi_return_u32(CPUM68KState *env, uint32_t ret, int err)
+static void m68k_semi_u32_cb(CPUState *cs, uint64_t ret, int err)
 {
+    M68kCPU *cpu = M68K_CPU(cs);
+    CPUM68KState *env = &cpu->env;
+
     target_ulong args = env->dregs[1];
     if (put_user_u32(ret, args) ||
         put_user_u32(err, args + 4)) {
@@ -110,8 +113,11 @@ static void m68k_semi_return_u32(CPUM68KState *env, uint32_t ret, int err)
     }
 }
 
-static void m68k_semi_return_u64(CPUM68KState *env, uint64_t ret, int err)
+static void m68k_semi_u64_cb(CPUState *cs, uint64_t ret, int err)
 {
+    M68kCPU *cpu = M68K_CPU(cs);
+    CPUM68KState *env = &cpu->env;
+
     target_ulong args = env->dregs[1];
     if (put_user_u32(ret >> 32, args) ||
         put_user_u32(ret, args + 4) ||
@@ -122,21 +128,6 @@ static void m68k_semi_return_u64(CPUM68KState *env, uint64_t ret, int err)
     }
 }
 
-static int m68k_semi_is_fseek;
-
-static void m68k_semi_cb(CPUState *cs, uint64_t ret, int err)
-{
-    M68kCPU *cpu = M68K_CPU(cs);
-    CPUM68KState *env = &cpu->env;
-
-    if (m68k_semi_is_fseek) {
-        m68k_semi_return_u64(env, ret, err);
-        m68k_semi_is_fseek = 0;
-    } else {
-        m68k_semi_return_u32(env, ret, err);
-    }
-}
-
 /*
  * Read the input value from the argument block; fail the semihosting
  * call if the memory read fails.
@@ -151,6 +142,7 @@ static void m68k_semi_cb(CPUState *cs, uint64_t ret, int err)
 
 void do_m68k_semihosting(CPUM68KState *env, int nr)
 {
+    CPUState *cs = env_cpu(env);
     uint32_t args;
     target_ulong arg0, arg1, arg2, arg3;
     void *p;
@@ -169,7 +161,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr)
         GET_ARG(2);
         GET_ARG(3);
         if (use_gdb_syscalls()) {
-            gdb_do_syscall(m68k_semi_cb, "open,%s,%x,%x", arg0, (int)arg1,
+            gdb_do_syscall(m68k_semi_u32_cb, "open,%s,%x,%x", arg0, (int)arg1,
                            arg2, arg3);
             return;
         } else {
@@ -190,7 +182,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr)
             int fd = arg0;
             if (fd > 2) {
                 if (use_gdb_syscalls()) {
-                    gdb_do_syscall(m68k_semi_cb, "close,%x", arg0);
+                    gdb_do_syscall(m68k_semi_u32_cb, "close,%x", arg0);
                     return;
                 } else {
                     result = close(fd);
@@ -206,7 +198,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr)
         GET_ARG(2);
         len = arg2;
         if (use_gdb_syscalls()) {
-            gdb_do_syscall(m68k_semi_cb, "read,%x,%x,%x",
+            gdb_do_syscall(m68k_semi_u32_cb, "read,%x,%x,%x",
                            arg0, arg1, len);
             return;
         } else {
@@ -226,7 +218,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr)
         GET_ARG(2);
         len = arg2;
         if (use_gdb_syscalls()) {
-            gdb_do_syscall(m68k_semi_cb, "write,%x,%x,%x",
+            gdb_do_syscall(m68k_semi_u32_cb, "write,%x,%x,%x",
                            arg0, arg1, len);
             return;
         } else {
@@ -249,12 +241,11 @@ void do_m68k_semihosting(CPUM68KState *env, int nr)
             GET_ARG(3);
             off = (uint32_t)arg2 | ((uint64_t)arg1 << 32);
             if (use_gdb_syscalls()) {
-                m68k_semi_is_fseek = 1;
-                gdb_do_syscall(m68k_semi_cb, "fseek,%x,%lx,%x",
+                gdb_do_syscall(m68k_semi_u64_cb, "fseek,%x,%lx,%x",
                                arg0, off, arg3);
             } else {
                 off = lseek(arg0, off, arg3);
-                m68k_semi_return_u64(env, off, errno);
+                m68k_semi_u64_cb(cs, off, errno);
             }
             return;
         }
@@ -264,7 +255,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr)
         GET_ARG(2);
         GET_ARG(3);
         if (use_gdb_syscalls()) {
-            gdb_do_syscall(m68k_semi_cb, "rename,%s,%s",
+            gdb_do_syscall(m68k_semi_u32_cb, "rename,%s,%s",
                            arg0, (int)arg1, arg2, (int)arg3);
             return;
         } else {
@@ -284,7 +275,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr)
         GET_ARG(0);
         GET_ARG(1);
         if (use_gdb_syscalls()) {
-            gdb_do_syscall(m68k_semi_cb, "unlink,%s",
+            gdb_do_syscall(m68k_semi_u32_cb, "unlink,%s",
                            arg0, (int)arg1);
             return;
         } else {
@@ -303,7 +294,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr)
         GET_ARG(1);
         GET_ARG(2);
         if (use_gdb_syscalls()) {
-            gdb_do_syscall(m68k_semi_cb, "stat,%s,%x",
+            gdb_do_syscall(m68k_semi_u32_cb, "stat,%s,%x",
                            arg0, (int)arg1, arg2);
             return;
         } else {
@@ -325,7 +316,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr)
         GET_ARG(0);
         GET_ARG(1);
         if (use_gdb_syscalls()) {
-            gdb_do_syscall(m68k_semi_cb, "fstat,%x,%x",
+            gdb_do_syscall(m68k_semi_u32_cb, "fstat,%x,%x",
                            arg0, arg1);
             return;
         } else {
@@ -340,7 +331,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr)
         GET_ARG(0);
         GET_ARG(1);
         if (use_gdb_syscalls()) {
-            gdb_do_syscall(m68k_semi_cb, "gettimeofday,%x,%x",
+            gdb_do_syscall(m68k_semi_u32_cb, "gettimeofday,%x,%x",
                            arg0, arg1);
             return;
         } else {
@@ -361,7 +352,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr)
     case HOSTED_ISATTY:
         GET_ARG(0);
         if (use_gdb_syscalls()) {
-            gdb_do_syscall(m68k_semi_cb, "isatty,%x", arg0);
+            gdb_do_syscall(m68k_semi_u32_cb, "isatty,%x", arg0);
             return;
         } else {
             result = isatty(arg0);
@@ -371,7 +362,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr)
         GET_ARG(0);
         GET_ARG(1);
         if (use_gdb_syscalls()) {
-            gdb_do_syscall(m68k_semi_cb, "system,%s",
+            gdb_do_syscall(m68k_semi_u32_cb, "system,%s",
                            arg0, (int)arg1);
             return;
         } else {
@@ -429,5 +420,5 @@ void do_m68k_semihosting(CPUM68KState *env, int nr)
         result = 0;
     }
 failed:
-    m68k_semi_return_u32(env, result, errno);
+    m68k_semi_u32_cb(cs, result, errno);
 }
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v4 2/3] target/m68k: Make semihosting system only
  2022-06-07 22:26 [PATCH v4 0/3] target/m68k: semihosting cleanup Richard Henderson
  2022-06-07 22:26 ` [PATCH v4 1/3] target/m68k: Eliminate m68k_semi_is_fseek Richard Henderson
@ 2022-06-07 22:26 ` Richard Henderson
  2022-06-08  9:29   ` Laurent Vivier
  2022-06-07 22:26 ` [PATCH v4 3/3] target/m68k: Use semihosting/syscalls.h Richard Henderson
  2022-06-08  9:36 ` [PATCH v4 0/3] target/m68k: semihosting cleanup Laurent Vivier
  3 siblings, 1 reply; 13+ messages in thread
From: Richard Henderson @ 2022-06-07 22:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: laurent

While we had a call to do_m68k_semihosting in linux-user, it
wasn't actually reachable.  We don't include DISAS_INSN(halt)
as an instruction unless system mode.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/m68k/cpu_loop.c |  5 -----
 target/m68k/m68k-semi.c    | 36 ------------------------------------
 target/m68k/meson.build    |  6 ++++--
 3 files changed, 4 insertions(+), 43 deletions(-)

diff --git a/linux-user/m68k/cpu_loop.c b/linux-user/m68k/cpu_loop.c
index 3d3033155f..caead1cb74 100644
--- a/linux-user/m68k/cpu_loop.c
+++ b/linux-user/m68k/cpu_loop.c
@@ -36,11 +36,6 @@ void cpu_loop(CPUM68KState *env)
         process_queued_cpu_work(cs);
 
         switch(trapnr) {
-        case EXCP_HALT_INSN:
-            /* Semihosing syscall.  */
-            env->pc += 4;
-            do_m68k_semihosting(env, env->dregs[0]);
-            break;
         case EXCP_ILLEGAL:
         case EXCP_LINEA:
         case EXCP_LINEF:
diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c
index 37b409b0b9..d0697ddbd1 100644
--- a/target/m68k/m68k-semi.c
+++ b/target/m68k/m68k-semi.c
@@ -21,13 +21,8 @@
 
 #include "cpu.h"
 #include "exec/gdbstub.h"
-#if defined(CONFIG_USER_ONLY)
-#include "qemu.h"
-#define SEMIHOSTING_HEAP_SIZE (128 * 1024 * 1024)
-#else
 #include "semihosting/softmmu-uaccess.h"
 #include "hw/boards.h"
-#endif
 #include "qemu/log.h"
 
 #define HOSTED_EXIT  0
@@ -377,43 +372,12 @@ void do_m68k_semihosting(CPUM68KState *env, int nr)
         }
         break;
     case HOSTED_INIT_SIM:
-#if defined(CONFIG_USER_ONLY)
-        {
-        CPUState *cs = env_cpu(env);
-        TaskState *ts = cs->opaque;
-        /* Allocate the heap using sbrk.  */
-        if (!ts->heap_limit) {
-            abi_ulong ret;
-            uint32_t size;
-            uint32_t base;
-
-            base = do_brk(0);
-            size = SEMIHOSTING_HEAP_SIZE;
-            /* Try a big heap, and reduce the size if that fails.  */
-            for (;;) {
-                ret = do_brk(base + size);
-                if (ret >= (base + size)) {
-                    break;
-                }
-                size >>= 1;
-            }
-            ts->heap_limit = base + size;
-        }
-        /*
-         * This call may happen before we have writable memory, so return
-         * values directly in registers.
-         */
-        env->dregs[1] = ts->heap_limit;
-        env->aregs[7] = ts->stack_base;
-        }
-#else
         /*
          * FIXME: This is wrong for boards where RAM does not start at
          * address zero.
          */
         env->dregs[1] = current_machine->ram_size;
         env->aregs[7] = current_machine->ram_size;
-#endif
         return;
     default:
         cpu_abort(env_cpu(env), "Unsupported semihosting syscall %d\n", nr);
diff --git a/target/m68k/meson.build b/target/m68k/meson.build
index 05cd9fbd1e..27d2d7ba87 100644
--- a/target/m68k/meson.build
+++ b/target/m68k/meson.build
@@ -4,14 +4,16 @@ m68k_ss.add(files(
   'fpu_helper.c',
   'gdbstub.c',
   'helper.c',
-  'm68k-semi.c',
   'op_helper.c',
   'softfloat.c',
   'translate.c',
 ))
 
 m68k_softmmu_ss = ss.source_set()
-m68k_softmmu_ss.add(files('monitor.c'))
+m68k_softmmu_ss.add(files(
+  'm68k-semi.c',
+  'monitor.c'
+))
 
 target_arch += {'m68k': m68k_ss}
 target_softmmu_arch += {'m68k': m68k_softmmu_ss}
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v4 3/3] target/m68k: Use semihosting/syscalls.h
  2022-06-07 22:26 [PATCH v4 0/3] target/m68k: semihosting cleanup Richard Henderson
  2022-06-07 22:26 ` [PATCH v4 1/3] target/m68k: Eliminate m68k_semi_is_fseek Richard Henderson
  2022-06-07 22:26 ` [PATCH v4 2/3] target/m68k: Make semihosting system only Richard Henderson
@ 2022-06-07 22:26 ` Richard Henderson
  2022-06-08  9:31   ` Laurent Vivier
  2022-06-08  9:36 ` [PATCH v4 0/3] target/m68k: semihosting cleanup Laurent Vivier
  3 siblings, 1 reply; 13+ messages in thread
From: Richard Henderson @ 2022-06-07 22:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: laurent

This separates guest file descriptors from host file descriptors,
and utilizes shared infrastructure for integration with gdbstub.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/m68k/m68k-semi.c | 306 ++++++++++------------------------------
 1 file changed, 76 insertions(+), 230 deletions(-)

diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c
index d0697ddbd1..87b1314925 100644
--- a/target/m68k/m68k-semi.c
+++ b/target/m68k/m68k-semi.c
@@ -21,6 +21,7 @@
 
 #include "cpu.h"
 #include "exec/gdbstub.h"
+#include "semihosting/syscalls.h"
 #include "semihosting/softmmu-uaccess.h"
 #include "hw/boards.h"
 #include "qemu/log.h"
@@ -40,54 +41,33 @@
 #define HOSTED_ISATTY 12
 #define HOSTED_SYSTEM 13
 
-static int translate_openflags(int flags)
+static int host_to_gdb_errno(int err)
 {
-    int hf;
-
-    if (flags & GDB_O_WRONLY)
-        hf = O_WRONLY;
-    else if (flags & GDB_O_RDWR)
-        hf = O_RDWR;
-    else
-        hf = O_RDONLY;
-
-    if (flags & GDB_O_APPEND) hf |= O_APPEND;
-    if (flags & GDB_O_CREAT) hf |= O_CREAT;
-    if (flags & GDB_O_TRUNC) hf |= O_TRUNC;
-    if (flags & GDB_O_EXCL) hf |= O_EXCL;
-
-    return hf;
-}
-
-static void translate_stat(CPUM68KState *env, target_ulong addr, struct stat *s)
-{
-    struct gdb_stat *p;
-
-    p = lock_user(VERIFY_WRITE, addr, sizeof(struct gdb_stat), 0);
-    if (!p) {
-        /* FIXME - should this return an error code? */
-        return;
+#define E(X)  case E##X: return GDB_E##X
+    switch (err) {
+    E(PERM);
+    E(NOENT);
+    E(INTR);
+    E(BADF);
+    E(ACCES);
+    E(FAULT);
+    E(BUSY);
+    E(EXIST);
+    E(NODEV);
+    E(NOTDIR);
+    E(ISDIR);
+    E(INVAL);
+    E(NFILE);
+    E(MFILE);
+    E(FBIG);
+    E(NOSPC);
+    E(SPIPE);
+    E(ROFS);
+    E(NAMETOOLONG);
+    default:
+        return GDB_EUNKNOWN;
     }
-    p->gdb_st_dev = cpu_to_be32(s->st_dev);
-    p->gdb_st_ino = cpu_to_be32(s->st_ino);
-    p->gdb_st_mode = cpu_to_be32(s->st_mode);
-    p->gdb_st_nlink = cpu_to_be32(s->st_nlink);
-    p->gdb_st_uid = cpu_to_be32(s->st_uid);
-    p->gdb_st_gid = cpu_to_be32(s->st_gid);
-    p->gdb_st_rdev = cpu_to_be32(s->st_rdev);
-    p->gdb_st_size = cpu_to_be64(s->st_size);
-#ifdef _WIN32
-    /* Windows stat is missing some fields.  */
-    p->gdb_st_blksize = 0;
-    p->gdb_st_blocks = 0;
-#else
-    p->gdb_st_blksize = cpu_to_be64(s->st_blksize);
-    p->gdb_st_blocks = cpu_to_be64(s->st_blocks);
-#endif
-    p->gdb_st_atime = cpu_to_be32(s->st_atime);
-    p->gdb_st_mtime = cpu_to_be32(s->st_mtime);
-    p->gdb_st_ctime = cpu_to_be32(s->st_ctime);
-    unlock_user(p, addr, sizeof(struct gdb_stat));
+#undef E
 }
 
 static void m68k_semi_u32_cb(CPUState *cs, uint64_t ret, int err)
@@ -97,7 +77,7 @@ static void m68k_semi_u32_cb(CPUState *cs, uint64_t ret, int err)
 
     target_ulong args = env->dregs[1];
     if (put_user_u32(ret, args) ||
-        put_user_u32(err, args + 4)) {
+        put_user_u32(host_to_gdb_errno(err), args + 4)) {
         /*
          * The m68k semihosting ABI does not provide any way to report this
          * error to the guest, so the best we can do is log it in qemu.
@@ -116,7 +96,7 @@ static void m68k_semi_u64_cb(CPUState *cs, uint64_t ret, int err)
     target_ulong args = env->dregs[1];
     if (put_user_u32(ret >> 32, args) ||
         put_user_u32(ret, args + 4) ||
-        put_user_u32(err, args + 8)) {
+        put_user_u32(host_to_gdb_errno(err), args + 8)) {
         /* No way to report this via m68k semihosting ABI; just log it */
         qemu_log_mask(LOG_GUEST_ERROR, "m68k-semihosting: return value "
                       "discarded because argument block not writable\n");
@@ -129,248 +109,109 @@ static void m68k_semi_u64_cb(CPUState *cs, uint64_t ret, int err)
  */
 #define GET_ARG(n) do {                                 \
     if (get_user_ual(arg ## n, args + (n) * 4)) {       \
-        result = -1;                                    \
-        errno = EFAULT;                                 \
         goto failed;                                    \
     }                                                   \
 } while (0)
 
+#define GET_ARG64(n) do {                               \
+    if (get_user_ual(arg ## n, args + (n) * 4)) {       \
+        goto failed64;                                  \
+    }                                                   \
+} while (0)
+
+
 void do_m68k_semihosting(CPUM68KState *env, int nr)
 {
     CPUState *cs = env_cpu(env);
     uint32_t args;
     target_ulong arg0, arg1, arg2, arg3;
-    void *p;
-    void *q;
-    uint32_t len;
-    uint32_t result;
 
     args = env->dregs[1];
     switch (nr) {
     case HOSTED_EXIT:
         gdb_exit(env->dregs[0]);
         exit(env->dregs[0]);
+
     case HOSTED_OPEN:
         GET_ARG(0);
         GET_ARG(1);
         GET_ARG(2);
         GET_ARG(3);
-        if (use_gdb_syscalls()) {
-            gdb_do_syscall(m68k_semi_u32_cb, "open,%s,%x,%x", arg0, (int)arg1,
-                           arg2, arg3);
-            return;
-        } else {
-            p = lock_user_string(arg0);
-            if (!p) {
-                /* FIXME - check error code? */
-                result = -1;
-            } else {
-                result = open(p, translate_openflags(arg2), arg3);
-                unlock_user(p, arg0, 0);
-            }
-        }
+        semihost_sys_open(cs, m68k_semi_u32_cb, arg0, arg1, arg2, arg3);
         break;
+
     case HOSTED_CLOSE:
-        {
-            /* Ignore attempts to close stdin/out/err.  */
-            GET_ARG(0);
-            int fd = arg0;
-            if (fd > 2) {
-                if (use_gdb_syscalls()) {
-                    gdb_do_syscall(m68k_semi_u32_cb, "close,%x", arg0);
-                    return;
-                } else {
-                    result = close(fd);
-                }
-            } else {
-                result = 0;
-            }
-            break;
-        }
+        GET_ARG(0);
+        semihost_sys_close(cs, m68k_semi_u32_cb, arg0);
+        break;
+
     case HOSTED_READ:
         GET_ARG(0);
         GET_ARG(1);
         GET_ARG(2);
-        len = arg2;
-        if (use_gdb_syscalls()) {
-            gdb_do_syscall(m68k_semi_u32_cb, "read,%x,%x,%x",
-                           arg0, arg1, len);
-            return;
-        } else {
-            p = lock_user(VERIFY_WRITE, arg1, len, 0);
-            if (!p) {
-                /* FIXME - check error code? */
-                result = -1;
-            } else {
-                result = read(arg0, p, len);
-                unlock_user(p, arg1, len);
-            }
-        }
+        semihost_sys_read(cs, m68k_semi_u32_cb, arg0, arg1, arg2);
         break;
+
     case HOSTED_WRITE:
         GET_ARG(0);
         GET_ARG(1);
         GET_ARG(2);
-        len = arg2;
-        if (use_gdb_syscalls()) {
-            gdb_do_syscall(m68k_semi_u32_cb, "write,%x,%x,%x",
-                           arg0, arg1, len);
-            return;
-        } else {
-            p = lock_user(VERIFY_READ, arg1, len, 1);
-            if (!p) {
-                /* FIXME - check error code? */
-                result = -1;
-            } else {
-                result = write(arg0, p, len);
-                unlock_user(p, arg0, 0);
-            }
-        }
+        semihost_sys_write(cs, m68k_semi_u32_cb, arg0, arg1, arg2);
         break;
+
     case HOSTED_LSEEK:
-        {
-            uint64_t off;
-            GET_ARG(0);
-            GET_ARG(1);
-            GET_ARG(2);
-            GET_ARG(3);
-            off = (uint32_t)arg2 | ((uint64_t)arg1 << 32);
-            if (use_gdb_syscalls()) {
-                gdb_do_syscall(m68k_semi_u64_cb, "fseek,%x,%lx,%x",
-                               arg0, off, arg3);
-            } else {
-                off = lseek(arg0, off, arg3);
-                m68k_semi_u64_cb(cs, off, errno);
-            }
-            return;
-        }
+        GET_ARG64(0);
+        GET_ARG64(1);
+        GET_ARG64(2);
+        GET_ARG64(3);
+        semihost_sys_lseek(cs, m68k_semi_u64_cb, arg0,
+                           deposit64(arg2, arg1, 32, 32), arg3);
+        break;
+
     case HOSTED_RENAME:
         GET_ARG(0);
         GET_ARG(1);
         GET_ARG(2);
         GET_ARG(3);
-        if (use_gdb_syscalls()) {
-            gdb_do_syscall(m68k_semi_u32_cb, "rename,%s,%s",
-                           arg0, (int)arg1, arg2, (int)arg3);
-            return;
-        } else {
-            p = lock_user_string(arg0);
-            q = lock_user_string(arg2);
-            if (!p || !q) {
-                /* FIXME - check error code? */
-                result = -1;
-            } else {
-                result = rename(p, q);
-            }
-            unlock_user(p, arg0, 0);
-            unlock_user(q, arg2, 0);
-        }
+        semihost_sys_rename(cs, m68k_semi_u32_cb, arg0, arg1, arg2, arg3);
         break;
+
     case HOSTED_UNLINK:
         GET_ARG(0);
         GET_ARG(1);
-        if (use_gdb_syscalls()) {
-            gdb_do_syscall(m68k_semi_u32_cb, "unlink,%s",
-                           arg0, (int)arg1);
-            return;
-        } else {
-            p = lock_user_string(arg0);
-            if (!p) {
-                /* FIXME - check error code? */
-                result = -1;
-            } else {
-                result = unlink(p);
-                unlock_user(p, arg0, 0);
-            }
-        }
+        semihost_sys_remove(cs, m68k_semi_u32_cb, arg0, arg1);
         break;
+
     case HOSTED_STAT:
         GET_ARG(0);
         GET_ARG(1);
         GET_ARG(2);
-        if (use_gdb_syscalls()) {
-            gdb_do_syscall(m68k_semi_u32_cb, "stat,%s,%x",
-                           arg0, (int)arg1, arg2);
-            return;
-        } else {
-            struct stat s;
-            p = lock_user_string(arg0);
-            if (!p) {
-                /* FIXME - check error code? */
-                result = -1;
-            } else {
-                result = stat(p, &s);
-                unlock_user(p, arg0, 0);
-            }
-            if (result == 0) {
-                translate_stat(env, arg2, &s);
-            }
-        }
+        semihost_sys_stat(cs, m68k_semi_u32_cb, arg0, arg1, arg2);
         break;
+
     case HOSTED_FSTAT:
         GET_ARG(0);
         GET_ARG(1);
-        if (use_gdb_syscalls()) {
-            gdb_do_syscall(m68k_semi_u32_cb, "fstat,%x,%x",
-                           arg0, arg1);
-            return;
-        } else {
-            struct stat s;
-            result = fstat(arg0, &s);
-            if (result == 0) {
-                translate_stat(env, arg1, &s);
-            }
-        }
+        semihost_sys_fstat(cs, m68k_semi_u32_cb, arg0, arg1);
         break;
+
     case HOSTED_GETTIMEOFDAY:
         GET_ARG(0);
         GET_ARG(1);
-        if (use_gdb_syscalls()) {
-            gdb_do_syscall(m68k_semi_u32_cb, "gettimeofday,%x,%x",
-                           arg0, arg1);
-            return;
-        } else {
-            struct gdb_timeval *p;
-            int64_t rt = g_get_real_time();
-            p = lock_user(VERIFY_WRITE, arg0, sizeof(struct gdb_timeval), 0);
-            if (!p) {
-                /* FIXME - check error code? */
-                result = -1;
-            } else {
-                result = 0;
-                p->tv_sec = cpu_to_be32(rt / G_USEC_PER_SEC);
-                p->tv_usec = cpu_to_be64(rt % G_USEC_PER_SEC);
-                unlock_user(p, arg0, sizeof(struct gdb_timeval));
-            }
-        }
+        semihost_sys_gettimeofday(cs, m68k_semi_u32_cb, arg0, arg1);
         break;
+
     case HOSTED_ISATTY:
         GET_ARG(0);
-        if (use_gdb_syscalls()) {
-            gdb_do_syscall(m68k_semi_u32_cb, "isatty,%x", arg0);
-            return;
-        } else {
-            result = isatty(arg0);
-        }
+        semihost_sys_isatty(cs, m68k_semi_u32_cb, arg0);
         break;
+
     case HOSTED_SYSTEM:
         GET_ARG(0);
         GET_ARG(1);
-        if (use_gdb_syscalls()) {
-            gdb_do_syscall(m68k_semi_u32_cb, "system,%s",
-                           arg0, (int)arg1);
-            return;
-        } else {
-            p = lock_user_string(arg0);
-            if (!p) {
-                /* FIXME - check error code? */
-                result = -1;
-            } else {
-                result = system(p);
-                unlock_user(p, arg0, 0);
-            }
-        }
+        semihost_sys_system(cs, m68k_semi_u32_cb, arg0, arg1);
         break;
+
     case HOSTED_INIT_SIM:
         /*
          * FIXME: This is wrong for boards where RAM does not start at
@@ -379,10 +220,15 @@ void do_m68k_semihosting(CPUM68KState *env, int nr)
         env->dregs[1] = current_machine->ram_size;
         env->aregs[7] = current_machine->ram_size;
         return;
+
     default:
         cpu_abort(env_cpu(env), "Unsupported semihosting syscall %d\n", nr);
-        result = 0;
+
+    failed:
+        m68k_semi_u32_cb(cs, -1, EFAULT);
+        break;
+    failed64:
+        m68k_semi_u64_cb(cs, -1, EFAULT);
+        break;
     }
-failed:
-    m68k_semi_u32_cb(cs, result, errno);
 }
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 1/3] target/m68k: Eliminate m68k_semi_is_fseek
  2022-06-07 22:26 ` [PATCH v4 1/3] target/m68k: Eliminate m68k_semi_is_fseek Richard Henderson
@ 2022-06-08  9:25   ` Laurent Vivier
  0 siblings, 0 replies; 13+ messages in thread
From: Laurent Vivier @ 2022-06-08  9:25 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel

Le 08/06/2022 à 00:26, Richard Henderson a écrit :
> Reorg m68k_semi_return_* to gdb_syscall_complete_cb.
> Use the 32-bit version normally, and the 64-bit version
> for HOSTED_LSEEK.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   target/m68k/m68k-semi.c | 55 +++++++++++++++++------------------------
>   1 file changed, 23 insertions(+), 32 deletions(-)
> 

Reviewed-by: Laurent Vivier <laurent@vivier.eu>



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 2/3] target/m68k: Make semihosting system only
  2022-06-07 22:26 ` [PATCH v4 2/3] target/m68k: Make semihosting system only Richard Henderson
@ 2022-06-08  9:29   ` Laurent Vivier
  0 siblings, 0 replies; 13+ messages in thread
From: Laurent Vivier @ 2022-06-08  9:29 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel

Le 08/06/2022 à 00:26, Richard Henderson a écrit :
> While we had a call to do_m68k_semihosting in linux-user, it
> wasn't actually reachable.  We don't include DISAS_INSN(halt)
> as an instruction unless system mode.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   linux-user/m68k/cpu_loop.c |  5 -----
>   target/m68k/m68k-semi.c    | 36 ------------------------------------
>   target/m68k/meson.build    |  6 ++++--
>   3 files changed, 4 insertions(+), 43 deletions(-)

Reviewed-by: Laurent Vivier <laurent@vivier.eu>



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 3/3] target/m68k: Use semihosting/syscalls.h
  2022-06-07 22:26 ` [PATCH v4 3/3] target/m68k: Use semihosting/syscalls.h Richard Henderson
@ 2022-06-08  9:31   ` Laurent Vivier
  0 siblings, 0 replies; 13+ messages in thread
From: Laurent Vivier @ 2022-06-08  9:31 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel

Le 08/06/2022 à 00:26, Richard Henderson a écrit :
> This separates guest file descriptors from host file descriptors,
> and utilizes shared infrastructure for integration with gdbstub.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   target/m68k/m68k-semi.c | 306 ++++++++++------------------------------
>   1 file changed, 76 insertions(+), 230 deletions(-)
> 

Reviewed-by: Laurent Vivier <laurent@vivier.eu>



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 0/3] target/m68k: semihosting cleanup
  2022-06-07 22:26 [PATCH v4 0/3] target/m68k: semihosting cleanup Richard Henderson
                   ` (2 preceding siblings ...)
  2022-06-07 22:26 ` [PATCH v4 3/3] target/m68k: Use semihosting/syscalls.h Richard Henderson
@ 2022-06-08  9:36 ` Laurent Vivier
  2022-06-08 14:53   ` Richard Henderson
  3 siblings, 1 reply; 13+ messages in thread
From: Laurent Vivier @ 2022-06-08  9:36 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel

Le 08/06/2022 à 00:26, Richard Henderson a écrit :
> Based-on: <20220607204557.658541-1-richard.henderson@linaro.org>
> ("[PATCH v4 00/53] semihosting cleanup")
> 
> Changes for v4:
>    * Split out of v2.
>    * Convert host errno to gdb errno, which for m68k is guest errno.
> 

How do you test semihosting on m68k?

Thanks,
Laurent


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 0/3] target/m68k: semihosting cleanup
  2022-06-08  9:36 ` [PATCH v4 0/3] target/m68k: semihosting cleanup Laurent Vivier
@ 2022-06-08 14:53   ` Richard Henderson
  2022-06-08 18:08     ` Laurent Vivier
  0 siblings, 1 reply; 13+ messages in thread
From: Richard Henderson @ 2022-06-08 14:53 UTC (permalink / raw)
  To: Laurent Vivier, qemu-devel

On 6/8/22 02:36, Laurent Vivier wrote:
> Le 08/06/2022 à 00:26, Richard Henderson a écrit :
>> Based-on: <20220607204557.658541-1-richard.henderson@linaro.org>
>> ("[PATCH v4 00/53] semihosting cleanup")
>>
>> Changes for v4:
>>    * Split out of v2.
>>    * Convert host errno to gdb errno, which for m68k is guest errno.
>>
> 
> How do you test semihosting on m68k?

I have only compiled this.  I had been working on adding something to tests/tcg/m68k/, 
which is where those halt patches came from, but haven't finished.


r~


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 0/3] target/m68k: semihosting cleanup
  2022-06-08 14:53   ` Richard Henderson
@ 2022-06-08 18:08     ` Laurent Vivier
  2022-06-08 19:05       ` Richard Henderson
  0 siblings, 1 reply; 13+ messages in thread
From: Laurent Vivier @ 2022-06-08 18:08 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel

Le 08/06/2022 à 16:53, Richard Henderson a écrit :
> On 6/8/22 02:36, Laurent Vivier wrote:
>> Le 08/06/2022 à 00:26, Richard Henderson a écrit :
>>> Based-on: <20220607204557.658541-1-richard.henderson@linaro.org>
>>> ("[PATCH v4 00/53] semihosting cleanup")
>>>
>>> Changes for v4:
>>>    * Split out of v2.
>>>    * Convert host errno to gdb errno, which for m68k is guest errno.
>>>
>>
>> How do you test semihosting on m68k?
> 
> I have only compiled this.  I had been working on adding something to tests/tcg/m68k/, which is 
> where those halt patches came from, but haven't finished.
> 

But what is the use case of semihosting on m68k?
Is there a kernel implementation available for that?

Thanks,
Laurent



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 0/3] target/m68k: semihosting cleanup
  2022-06-08 18:08     ` Laurent Vivier
@ 2022-06-08 19:05       ` Richard Henderson
  2022-06-08 20:36         ` Richard Henderson
  2022-06-08 21:51         ` Laurent Vivier
  0 siblings, 2 replies; 13+ messages in thread
From: Richard Henderson @ 2022-06-08 19:05 UTC (permalink / raw)
  To: Laurent Vivier, qemu-devel

On 6/8/22 11:08, Laurent Vivier wrote:
> Le 08/06/2022 à 16:53, Richard Henderson a écrit :
>> On 6/8/22 02:36, Laurent Vivier wrote:
>>> Le 08/06/2022 à 00:26, Richard Henderson a écrit :
>>>> Based-on: <20220607204557.658541-1-richard.henderson@linaro.org>
>>>> ("[PATCH v4 00/53] semihosting cleanup")
>>>>
>>>> Changes for v4:
>>>>    * Split out of v2.
>>>>    * Convert host errno to gdb errno, which for m68k is guest errno.
>>>>
>>>
>>> How do you test semihosting on m68k?
>>
>> I have only compiled this.  I had been working on adding something to tests/tcg/m68k/, 
>> which is where those halt patches came from, but haven't finished.
>>
> 
> But what is the use case of semihosting on m68k?
> Is there a kernel implementation available for that?

Not that I'm aware of.  Do you want to remove it entirely instead?
Leaving it as-is should not be an option...


r~


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 0/3] target/m68k: semihosting cleanup
  2022-06-08 19:05       ` Richard Henderson
@ 2022-06-08 20:36         ` Richard Henderson
  2022-06-08 21:51         ` Laurent Vivier
  1 sibling, 0 replies; 13+ messages in thread
From: Richard Henderson @ 2022-06-08 20:36 UTC (permalink / raw)
  To: Laurent Vivier, qemu-devel

On 6/8/22 12:05, Richard Henderson wrote:
>> But what is the use case of semihosting on m68k?
>> Is there a kernel implementation available for that?
> 
> Not that I'm aware of.  Do you want to remove it entirely instead?
> Leaving it as-is should not be an option...

Oh, duh.  The "kernel" implementation is libgloss itself.
The use-case is running the gcc testsuite for coldfire under qemu.


r~


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 0/3] target/m68k: semihosting cleanup
  2022-06-08 19:05       ` Richard Henderson
  2022-06-08 20:36         ` Richard Henderson
@ 2022-06-08 21:51         ` Laurent Vivier
  1 sibling, 0 replies; 13+ messages in thread
From: Laurent Vivier @ 2022-06-08 21:51 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel

Le 08/06/2022 à 21:05, Richard Henderson a écrit :
> On 6/8/22 11:08, Laurent Vivier wrote:
>> Le 08/06/2022 à 16:53, Richard Henderson a écrit :
>>> On 6/8/22 02:36, Laurent Vivier wrote:
>>>> Le 08/06/2022 à 00:26, Richard Henderson a écrit :
>>>>> Based-on: <20220607204557.658541-1-richard.henderson@linaro.org>
>>>>> ("[PATCH v4 00/53] semihosting cleanup")
>>>>>
>>>>> Changes for v4:
>>>>>    * Split out of v2.
>>>>>    * Convert host errno to gdb errno, which for m68k is guest errno.
>>>>>
>>>>
>>>> How do you test semihosting on m68k?
>>>
>>> I have only compiled this.  I had been working on adding something to tests/tcg/m68k/, which is 
>>> where those halt patches came from, but haven't finished.
>>>
>>
>> But what is the use case of semihosting on m68k?
>> Is there a kernel implementation available for that?
> 
> Not that I'm aware of.  Do you want to remove it entirely instead?

No, while you fix it I have no problem to keep it.

Thanks,
Laurent


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-06-08 21:52 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-07 22:26 [PATCH v4 0/3] target/m68k: semihosting cleanup Richard Henderson
2022-06-07 22:26 ` [PATCH v4 1/3] target/m68k: Eliminate m68k_semi_is_fseek Richard Henderson
2022-06-08  9:25   ` Laurent Vivier
2022-06-07 22:26 ` [PATCH v4 2/3] target/m68k: Make semihosting system only Richard Henderson
2022-06-08  9:29   ` Laurent Vivier
2022-06-07 22:26 ` [PATCH v4 3/3] target/m68k: Use semihosting/syscalls.h Richard Henderson
2022-06-08  9:31   ` Laurent Vivier
2022-06-08  9:36 ` [PATCH v4 0/3] target/m68k: semihosting cleanup Laurent Vivier
2022-06-08 14:53   ` Richard Henderson
2022-06-08 18:08     ` Laurent Vivier
2022-06-08 19:05       ` Richard Henderson
2022-06-08 20:36         ` Richard Henderson
2022-06-08 21:51         ` Laurent Vivier

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.