diff options
author | 2020-07-18 08:37:43 +0000 | |
---|---|---|
committer | 2020-07-18 08:37:43 +0000 | |
commit | 757e7193da1ad8d8af37ecc1f0d1b5f3524cd05c (patch) | |
tree | 950187801f7b5825dd09f19f4c4e959922497f9a /lib/libc | |
parent | replace stat collection with the kstat api. (diff) | |
download | wireguard-openbsd-757e7193da1ad8d8af37ecc1f0d1b5f3524cd05c.tar.xz wireguard-openbsd-757e7193da1ad8d8af37ecc1f0d1b5f3524cd05c.zip |
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.c | 33 |
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; |