summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorgkoehler <gkoehler@cvs.openbsd.org>2020-07-17 20:15:44 +0000
committergkoehler <gkoehler@cvs.openbsd.org>2020-07-17 20:15:44 +0000
commitcc14c1d792208df0fc7e4a840eaca6abac8951d6 (patch)
tree20d55b8fc87c2192d790ca8d799b4cfa4ee05023 /lib/libc
parentfc0ebbb30495e18368e2e4918de48783ebb96e34 (diff)
Userland timecounter for macppc
Tested by cwen@ and myself. Thanks to pirofti@ for creating the userland timecounter feature. ok kettenis@ pirofti@ deraadt@ cheloha@
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/arch/powerpc/gen/usertc.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/libc/arch/powerpc/gen/usertc.c b/lib/libc/arch/powerpc/gen/usertc.c
index f73831f742e..108fff0f54f 100644
--- a/lib/libc/arch/powerpc/gen/usertc.c
+++ b/lib/libc/arch/powerpc/gen/usertc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: usertc.c,v 1.1 2020/07/06 13:33:05 pirofti Exp $ */
+/* $OpenBSD: usertc.c,v 1.2 2020/07/17 20:15:43 gkoehler Exp $ */
/*
* Copyright (c) 2020 Paul Irofti <paul@irofti.net>
*
@@ -18,4 +18,24 @@
#include <sys/types.h>
#include <sys/timetc.h>
-int (*const _tc_get_timecount)(struct timekeep *, u_int *) = NULL;
+static __inline u_int32_t
+ppc_mftbl (void)
+{
+ int ret;
+ __asm volatile ("mftb %0" : "=r" (ret));
+ return ret;
+}
+
+static int
+tc_get_timecount(struct timekeep *tk, u_int *tc)
+{
+ switch (tk->tk_user) {
+ case TC_TB:
+ *tc = ppc_mftbl();
+ return 0;
+ }
+
+ return -1;
+}
+
+int (*const _tc_get_timecount)(struct timekeep *, u_int *) = tc_get_timecount;