1*8e8a48abSgkoehler /* $OpenBSD: usertc.c,v 1.2 2020/07/17 20:15:43 gkoehler Exp $ */
2d82e6535Spirofti /*
3d82e6535Spirofti * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
4d82e6535Spirofti *
5d82e6535Spirofti * Permission to use, copy, modify, and distribute this software for any
6d82e6535Spirofti * purpose with or without fee is hereby granted, provided that the above
7d82e6535Spirofti * copyright notice and this permission notice appear in all copies.
8d82e6535Spirofti *
9d82e6535Spirofti * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10d82e6535Spirofti * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11d82e6535Spirofti * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12d82e6535Spirofti * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13d82e6535Spirofti * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14d82e6535Spirofti * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15d82e6535Spirofti * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16d82e6535Spirofti */
17d82e6535Spirofti
18d82e6535Spirofti #include <sys/types.h>
19d82e6535Spirofti #include <sys/timetc.h>
20d82e6535Spirofti
21*8e8a48abSgkoehler static __inline u_int32_t
ppc_mftbl(void)22*8e8a48abSgkoehler ppc_mftbl (void)
23*8e8a48abSgkoehler {
24*8e8a48abSgkoehler int ret;
25*8e8a48abSgkoehler __asm volatile ("mftb %0" : "=r" (ret));
26*8e8a48abSgkoehler return ret;
27*8e8a48abSgkoehler }
28*8e8a48abSgkoehler
29*8e8a48abSgkoehler static int
tc_get_timecount(struct timekeep * tk,u_int * tc)30*8e8a48abSgkoehler tc_get_timecount(struct timekeep *tk, u_int *tc)
31*8e8a48abSgkoehler {
32*8e8a48abSgkoehler switch (tk->tk_user) {
33*8e8a48abSgkoehler case TC_TB:
34*8e8a48abSgkoehler *tc = ppc_mftbl();
35*8e8a48abSgkoehler return 0;
36*8e8a48abSgkoehler }
37*8e8a48abSgkoehler
38*8e8a48abSgkoehler return -1;
39*8e8a48abSgkoehler }
40*8e8a48abSgkoehler
41*8e8a48abSgkoehler int (*const _tc_get_timecount)(struct timekeep *, u_int *) = tc_get_timecount;
42