summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorVisa Hankala <visa@cvs.openbsd.org>2020-07-18 08:37:45 +0000
committerVisa Hankala <visa@cvs.openbsd.org>2020-07-18 08:37:45 +0000
commitb8e39666a5fab838c785939e76bff8c071a6eca8 (patch)
tree92b266dd5fbe763a1b7da28eebce02c3476fba3e /lib/libc
parent0e1dac87e7cfe9d38f19194836f95666c950ef8f (diff)
Userland timecounter implementation for octeon
OK naddy@; no objections from kettenis@
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/arch/mips64/gen/usertc.c33
1 files changed, 30 insertions, 3 deletions
diff --git a/lib/libc/arch/mips64/gen/usertc.c b/lib/libc/arch/mips64/gen/usertc.c
index f73831f742e..be7263e1c46 100644
--- a/lib/libc/arch/mips64/gen/usertc.c
+++ b/lib/libc/arch/mips64/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/18 08:37:43 visa Exp $ */
/*
- * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ * Copyright (c) 2020 Visa Hankala
*
* 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,31 @@
#include <sys/types.h>
#include <sys/timetc.h>
-int (*const _tc_get_timecount)(struct timekeep *, u_int *) = NULL;
+static inline u_int
+get_cp0_count(void)
+{
+ uint32_t count;
+
+ __asm__ volatile (
+ " .set push\n"
+ " .set mips64r2\n"
+ " rdhwr %0, $2\n"
+ " .set pop\n"
+ : "=r" (count));
+
+ return count;
+}
+
+static int
+tc_get_timecount(struct timekeep *tk, u_int *tc)
+{
+ switch (tk->tk_user) {
+ case TC_CP0_COUNT:
+ *tc = get_cp0_count();
+ return 0;
+ }
+
+ return -1;
+}
+
+int (*const _tc_get_timecount)(struct timekeep *, u_int *) = tc_get_timecount;