aboutsummaryrefslogtreecommitdiff
path: root/target
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2022-03-07 11:04:00 +0400
committerPaolo Bonzini <pbonzini@redhat.com>2022-04-06 10:50:37 +0200
commitf793dde0914ae7f2605ee22c5bbc81dc79e23eee (patch)
treeaf62c611c5d4f73d9a87bc8ec84d2ae5265e9d8d /target
parent287698e50fb2340d9f6436976ac701512cb7c383 (diff)
Replace qemu_gettimeofday() with g_get_real_time()
GLib g_get_real_time() is an alternative to gettimeofday() which allows to simplify our code. For semihosting, a few bits are lost on POSIX host, but this shouldn't be a big concern. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Message-Id: <20220307070401.171986-5-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'target')
-rw-r--r--target/m68k/m68k-semi.c22
-rw-r--r--target/nios2/nios2-semi.c23
2 files changed, 20 insertions, 25 deletions
diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c
index c5c164e096..37343d47e2 100644
--- a/target/m68k/m68k-semi.c
+++ b/target/m68k/m68k-semi.c
@@ -378,19 +378,17 @@ void do_m68k_semihosting(CPUM68KState *env, int nr)
arg0, arg1);
return;
} else {
- qemu_timeval tv;
struct gdb_timeval *p;
- result = qemu_gettimeofday(&tv);
- if (result == 0) {
- if (!(p = lock_user(VERIFY_WRITE,
- arg0, sizeof(struct gdb_timeval), 0))) {
- /* FIXME - check error code? */
- result = -1;
- } else {
- p->tv_sec = cpu_to_be32(tv.tv_sec);
- p->tv_usec = cpu_to_be64(tv.tv_usec);
- unlock_user(p, arg0, sizeof(struct gdb_timeval));
- }
+ 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));
}
}
break;
diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c
index 5a7ad0c710..3decf6924c 100644
--- a/target/nios2/nios2-semi.c
+++ b/target/nios2/nios2-semi.c
@@ -400,20 +400,17 @@ void do_nios2_semihosting(CPUNios2State *env)
arg0, 0);
return;
} else {
- qemu_timeval tv;
struct gdb_timeval *p;
- result = qemu_gettimeofday(&tv);
- if (result == 0) {
- p = lock_user(VERIFY_WRITE, arg0, sizeof(struct gdb_timeval),
- 0);
- if (!p) {
- result = -1;
- errno = EFAULT;
- } else {
- p->tv_sec = cpu_to_be32(tv.tv_sec);
- p->tv_usec = cpu_to_be64(tv.tv_usec);
- unlock_user(p, arg0, sizeof(struct gdb_timeval));
- }
+ int64_t rt = g_get_real_time();
+ p = lock_user(VERIFY_WRITE, arg0, sizeof(struct gdb_timeval), 0);
+ if (!p) {
+ result = -1;
+ errno = EFAULT;
+ } 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));
}
}
break;