summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2020-07-08 09:20:29 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2020-07-08 09:20:29 +0000
commit33ce6e8cb8e18ca6c1483abc55156c4ba092e6c9 (patch)
treea35f3fe2e15cc0424be655582556b96313ebfe80 /lib/libc
parentad6e3f092baf0748207a570c75cda83949a13b6b (diff)
Userland timecounter implementation for sparc64.
ok deraadt@, pirofti@
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/arch/sparc64/gen/Makefile.inc4
-rw-r--r--lib/libc/arch/sparc64/gen/usertc.c41
2 files changed, 41 insertions, 4 deletions
diff --git a/lib/libc/arch/sparc64/gen/Makefile.inc b/lib/libc/arch/sparc64/gen/Makefile.inc
index cbad435a89c..6d19faf9502 100644
--- a/lib/libc/arch/sparc64/gen/Makefile.inc
+++ b/lib/libc/arch/sparc64/gen/Makefile.inc
@@ -1,7 +1,9 @@
-# $OpenBSD: Makefile.inc,v 1.15 2020/07/06 13:33:05 pirofti Exp $
+# $OpenBSD: Makefile.inc,v 1.16 2020/07/08 09:20:28 kettenis Exp $
SRCS+= _setjmp.S fabs.S fixunsdfsi.S flt_rounds.c fpclassifyl.c \
fpgetmask.c fpgetround.c fpgetsticky.c fpsetmask.c \
fpsetround.c fpsetsticky.c infinity.c isfinitel.c \
isinfl.c isnanl.c isnormall.c ldexp.c usertc.c modf.S \
mul.S nan.c setjmp.S signbitl.c sigsetjmp.S umul.S
+
+CFLAGS += -Wa,-Av9b
diff --git a/lib/libc/arch/sparc64/gen/usertc.c b/lib/libc/arch/sparc64/gen/usertc.c
index f73831f742e..c45374aa82d 100644
--- a/lib/libc/arch/sparc64/gen/usertc.c
+++ b/lib/libc/arch/sparc64/gen/usertc.c
@@ -1,6 +1,6 @@
-/* $OpenBSD: usertc.c,v 1.1 2020/07/06 13:33:05 pirofti Exp $ */
+/* $OpenBSD: usertc.c,v 1.2 2020/07/08 09:20:28 kettenis Exp $ */
/*
- * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ * Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -18,4 +18,39 @@
#include <sys/types.h>
#include <sys/timetc.h>
-int (*const _tc_get_timecount)(struct timekeep *, u_int *) = NULL;
+static inline u_int
+tick_get_timecount(struct timecounter *tc)
+{
+ u_int64_t tick;
+
+ __asm volatile("rd %%tick, %0" : "=r" (tick));
+
+ return (tick & ~0u);
+}
+
+static inline u_int
+sys_tick_get_timecount(struct timecounter *tc)
+{
+ u_int64_t tick;
+
+ __asm volatile("rd %%sys_tick, %0" : "=r" (tick));
+
+ return (tick & ~0u);
+}
+
+static int
+tc_get_timecount(struct timekeep *tk, u_int *tc)
+{
+ switch (tk->tk_user) {
+ case TC_TICK:
+ *tc = tick_get_timecount(NULL);
+ return 0;
+ case TC_SYS_TICK:
+ *tc = sys_tick_get_timecount(NULL);
+ return 0;
+ }
+
+ return -1;
+}
+
+int (*const _tc_get_timecount)(struct timekeep *, u_int *) = tc_get_timecount;