From 33ce6e8cb8e18ca6c1483abc55156c4ba092e6c9 Mon Sep 17 00:00:00 2001 From: Mark Kettenis Date: Wed, 8 Jul 2020 09:20:29 +0000 Subject: Userland timecounter implementation for sparc64. ok deraadt@, pirofti@ --- lib/libc/arch/sparc64/gen/Makefile.inc | 4 +++- lib/libc/arch/sparc64/gen/usertc.c | 41 +++++++++++++++++++++++++++++++--- 2 files changed, 41 insertions(+), 4 deletions(-) (limited to 'lib/libc/arch') diff --git a/lib/libc/arch/sparc64/gen/Makefile.inc b/lib/libc/arch/sparc64/gen/Makefile.inc index cbad435a89c..6d19faf9502 100644 --- a/lib/libc/arch/sparc64/gen/Makefile.inc +++ b/lib/libc/arch/sparc64/gen/Makefile.inc @@ -1,7 +1,9 @@ -# $OpenBSD: Makefile.inc,v 1.15 2020/07/06 13:33:05 pirofti Exp $ +# $OpenBSD: Makefile.inc,v 1.16 2020/07/08 09:20:28 kettenis Exp $ SRCS+= _setjmp.S fabs.S fixunsdfsi.S flt_rounds.c fpclassifyl.c \ fpgetmask.c fpgetround.c fpgetsticky.c fpsetmask.c \ fpsetround.c fpsetsticky.c infinity.c isfinitel.c \ isinfl.c isnanl.c isnormall.c ldexp.c usertc.c modf.S \ mul.S nan.c setjmp.S signbitl.c sigsetjmp.S umul.S + +CFLAGS += -Wa,-Av9b diff --git a/lib/libc/arch/sparc64/gen/usertc.c b/lib/libc/arch/sparc64/gen/usertc.c index f73831f742e..c45374aa82d 100644 --- a/lib/libc/arch/sparc64/gen/usertc.c +++ b/lib/libc/arch/sparc64/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/08 09:20:28 kettenis Exp $ */ /* - * Copyright (c) 2020 Paul Irofti + * Copyright (c) 2020 Mark Kettenis * * 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,39 @@ #include #include -int (*const _tc_get_timecount)(struct timekeep *, u_int *) = NULL; +static inline u_int +tick_get_timecount(struct timecounter *tc) +{ + u_int64_t tick; + + __asm volatile("rd %%tick, %0" : "=r" (tick)); + + return (tick & ~0u); +} + +static inline u_int +sys_tick_get_timecount(struct timecounter *tc) +{ + u_int64_t tick; + + __asm volatile("rd %%sys_tick, %0" : "=r" (tick)); + + return (tick & ~0u); +} + +static int +tc_get_timecount(struct timekeep *tk, u_int *tc) +{ + switch (tk->tk_user) { + case TC_TICK: + *tc = tick_get_timecount(NULL); + return 0; + case TC_SYS_TICK: + *tc = sys_tick_get_timecount(NULL); + return 0; + } + + return -1; +} + +int (*const _tc_get_timecount)(struct timekeep *, u_int *) = tc_get_timecount; -- cgit v1.2.3