Tested by gkoehler@.
ok gkoehler@
-/* $OpenBSD: usertc.c,v 1.1 2020/07/11 16:21:29 kettenis Exp $ */
+/* $OpenBSD: usertc.c,v 1.2 2022/11/05 16:23:02 cheloha Exp $ */
/*
* Copyright (c) 2020 Paul Irofti <paul@irofti.net>
*
#include <sys/types.h>
#include <sys/timetc.h>
-int (*const _tc_get_timecount)(struct timekeep *, u_int *) = NULL;
+static u_int
+mftbl(void)
+{
+ uint64_t value;
+ __asm volatile ("mftb %0" : "=r"(value));
+ return value;
+}
+
+static int
+tc_get_timecount(struct timekeep *tk, u_int *tc)
+{
+ switch (tk->tk_user) {
+ case TC_TB:
+ *tc = mftbl();
+ return 0;
+ }
+ return -1;
+}
+
+int (*const _tc_get_timecount)(struct timekeep *, u_int *) = tc_get_timecount;
-/* $OpenBSD: timetc.h,v 1.1 2020/07/06 13:33:08 pirofti Exp $ */
+/* $OpenBSD: timetc.h,v 1.2 2022/11/05 16:23:02 cheloha Exp $ */
/*
* Copyright (c) 2020 Paul Irofti <paul@irofti.net>
*
#ifndef _MACHINE_TIMETC_H_
#define _MACHINE_TIMETC_H_
-#define TC_LAST 0
+#define TC_TB 1
#endif /* _MACHINE_TIMETC_H_ */
-/* $OpenBSD: clock.c,v 1.5 2022/08/11 17:15:21 cheloha Exp $ */
+/* $OpenBSD: clock.c,v 1.6 2022/11/05 16:23:02 cheloha Exp $ */
/*
* Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org>
.tc_name = "tb",
.tc_quality = 0,
.tc_priv = NULL,
+ .tc_user = TC_TB,
};
void cpu_startclock(void);