[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 35/49] semihosting: Create semihost_sys_gettimeofday
From: |
Richard Henderson |
Subject: |
[PATCH v3 35/49] semihosting: Create semihost_sys_gettimeofday |
Date: |
Fri, 20 May 2022 17:03:46 -0700 |
This syscall will be used by m68k and nios2 semihosting.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/semihosting/syscalls.h | 3 +++
semihosting/syscalls.c | 42 ++++++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+)
diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h
index ecc97751a9..347200cb9f 100644
--- a/include/semihosting/syscalls.h
+++ b/include/semihosting/syscalls.h
@@ -66,4 +66,7 @@ void semihost_sys_rename(CPUState *cs,
gdb_syscall_complete_cb complete,
void semihost_sys_system(CPUState *cs, gdb_syscall_complete_cb complete,
target_ulong cmd, target_ulong cmd_len);
+void semihost_sys_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete,
+ target_ulong tv_addr, target_ulong tz_addr);
+
#endif /* SEMIHOSTING_SYSCALLS_H */
diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c
index 7bc2640512..269f750d98 100644
--- a/semihosting/syscalls.c
+++ b/semihosting/syscalls.c
@@ -266,6 +266,12 @@ static void gdb_system(CPUState *cs,
gdb_syscall_complete_cb complete,
gdb_do_syscall(complete, "system,%s", cmd, len);
}
+static void gdb_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete,
+ target_ulong tv_addr, target_ulong tz_addr)
+{
+ gdb_do_syscall(complete, "gettimeofday,%x,%x", tv_addr, tz_addr);
+}
+
/*
* Host semihosting syscall implementations.
*/
@@ -517,6 +523,32 @@ static void host_system(CPUState *cs,
gdb_syscall_complete_cb complete,
unlock_user(p, cmd, 0);
}
+static void host_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete,
+ target_ulong tv_addr, target_ulong tz_addr)
+{
+ CPUArchState *env G_GNUC_UNUSED = cs->env_ptr;
+ struct gdb_timeval *p;
+ int64_t rt;
+
+ /* GDB fails on non-null TZ, so be consistent. */
+ if (tz_addr != 0) {
+ complete(cs, -1, GDB_EINVAL);
+ return;
+ }
+
+ p = lock_user(VERIFY_WRITE, tv_addr, sizeof(struct gdb_timeval), 0);
+ if (!p) {
+ complete(cs, -1, GDB_EFAULT);
+ return;
+ }
+
+ /* TODO: Like stat, gdb always produces big-endian results; match it. */
+ rt = g_get_real_time();
+ 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, tv_addr, sizeof(struct gdb_timeval));
+}
+
/*
* Static file semihosting syscall implementations.
*/
@@ -826,3 +858,13 @@ void semihost_sys_system(CPUState *cs,
gdb_syscall_complete_cb complete,
host_system(cs, complete, cmd, cmd_len);
}
}
+
+void semihost_sys_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete,
+ target_ulong tv_addr, target_ulong tz_addr)
+{
+ if (use_gdb_syscalls()) {
+ gdb_gettimeofday(cs, complete, tv_addr, tz_addr);
+ } else {
+ host_gettimeofday(cs, complete, tv_addr, tz_addr);
+ }
+}
--
2.34.1
- Re: [PATCH v3 37/49] semihosting: Fix docs comment for qemu_semihosting_console_inc, (continued)
- [PATCH v3 29/49] semihosting: Split out semihost_sys_isatty, Richard Henderson, 2022/05/20
- [PATCH v3 31/49] semihosting: Split out semihost_sys_remove, Richard Henderson, 2022/05/20
- [PATCH v3 17/49] semihosting: Use struct gdb_stat in common_semi_flen_cb, Richard Henderson, 2022/05/20
- [PATCH v3 21/49] semihosting: Use env more often in do_common_semihosting, Richard Henderson, 2022/05/20
- [PATCH v3 28/49] semihosting: Split out semihost_sys_lseek, Richard Henderson, 2022/05/20
- [PATCH v3 34/49] semihosting: Create semihost_sys_{stat,fstat}, Richard Henderson, 2022/05/20
- [PATCH v3 35/49] semihosting: Create semihost_sys_gettimeofday,
Richard Henderson <=
- [PATCH v3 14/49] include/exec: Move gdb open flags to gdbstub.h, Richard Henderson, 2022/05/20
- [PATCH v3 20/49] semihosting: Split out common_semi_has_synccache, Richard Henderson, 2022/05/20
- [PATCH v3 19/49] semihosting: Split common_semi_flen_buf per target, Richard Henderson, 2022/05/20
- [PATCH v3 27/49] semihosting: Bound length for semihost_sys_{read, write}, Richard Henderson, 2022/05/20
- [PATCH v3 33/49] semihosting: Split out semihost_sys_system, Richard Henderson, 2022/05/20
- [PATCH v3 36/49] gdbstub: Widen gdb_syscall_complete_cb return value, Richard Henderson, 2022/05/20