RISC-V: Using SYS_clock_gettime64 for rv32 libgloss.

- RISC-V 32 bits linux/glibc didn't provide gettimeofday anymore
   after upstream, because RV32 didn't have backward compatible issue,
   so RV32 only support 64 bits time related system call.

 - So using clock_gettime64 call instead for rv32 libgloss.
This commit is contained in:
Kito Cheng 2021-04-13 17:33:03 +08:00 committed by Corinna Vinschen
parent 436e47584a
commit 20d0081998
2 changed files with 22 additions and 0 deletions

View File

@ -44,6 +44,7 @@
#define SYS_munmap 215 #define SYS_munmap 215
#define SYS_mremap 216 #define SYS_mremap 216
#define SYS_mmap 222 #define SYS_mmap 222
#define SYS_clock_gettime64 403
#define SYS_open 1024 #define SYS_open 1024
#define SYS_link 1025 #define SYS_link 1025
#define SYS_unlink 1026 #define SYS_unlink 1026

View File

@ -1,10 +1,31 @@
#include <machine/syscall.h> #include <machine/syscall.h>
#include <sys/time.h> #include <sys/time.h>
#include <stdint.h>
#include "internal_syscall.h" #include "internal_syscall.h"
/* Get the current time. Only relatively correct. */ /* Get the current time. Only relatively correct. */
int int
_gettimeofday(struct timeval *tp, void *tzp) _gettimeofday(struct timeval *tp, void *tzp)
{ {
#if __riscv_xlen == 32
struct __timespec64
{
int64_t tv_sec; /* Seconds */
# if BYTE_ORDER == BIG_ENDIAN
int32_t __padding; /* Padding */
int32_t tv_nsec; /* Nanoseconds */
# else
int32_t tv_nsec; /* Nanoseconds */
int32_t __padding; /* Padding */
# endif
};
struct __timespec64 ts64;
int rv;
rv = syscall_errno (SYS_clock_gettime64, 2, 0, (long)&ts64, 0, 0, 0, 0);
tp->tv_sec = ts64.tv_sec;
tp->tv_usec = ts64.tv_nsec * 1000;
return rv;
#else
return syscall_errno (SYS_gettimeofday, 1, tp, 0, 0, 0, 0, 0); return syscall_errno (SYS_gettimeofday, 1, tp, 0, 0, 0, 0, 0);
#endif
} }