xref: /freebsd/lib/libsys/powerpc/__vdso_gettc.c (revision 0d6cc87b18ded879b17574384ce86f119921bc5d)
1*0d6cc87bSBrooks Davis /*-
2*0d6cc87bSBrooks Davis  * SPDX-License-Identifier: BSD-2-Clause
3*0d6cc87bSBrooks Davis  *
4*0d6cc87bSBrooks Davis  * Copyright (c) 2020 Brandon Bergren <bdragon@FreeBSD.org>
5*0d6cc87bSBrooks Davis  *
6*0d6cc87bSBrooks Davis  * This software was developed by Konstantin Belousov
7*0d6cc87bSBrooks Davis  * under sponsorship from the FreeBSD Foundation.
8*0d6cc87bSBrooks Davis  *
9*0d6cc87bSBrooks Davis  * Redistribution and use in source and binary forms, with or without
10*0d6cc87bSBrooks Davis  * modification, are permitted provided that the following conditions
11*0d6cc87bSBrooks Davis  * are met:
12*0d6cc87bSBrooks Davis  * 1. Redistributions of source code must retain the above copyright
13*0d6cc87bSBrooks Davis  *    notice, this list of conditions and the following disclaimer.
14*0d6cc87bSBrooks Davis  * 2. Redistributions in binary form must reproduce the above copyright
15*0d6cc87bSBrooks Davis  *    notice, this list of conditions and the following disclaimer in the
16*0d6cc87bSBrooks Davis  *    documentation and/or other materials provided with the distribution.
17*0d6cc87bSBrooks Davis  *
18*0d6cc87bSBrooks Davis  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19*0d6cc87bSBrooks Davis  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*0d6cc87bSBrooks Davis  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*0d6cc87bSBrooks Davis  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22*0d6cc87bSBrooks Davis  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23*0d6cc87bSBrooks Davis  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24*0d6cc87bSBrooks Davis  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25*0d6cc87bSBrooks Davis  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26*0d6cc87bSBrooks Davis  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27*0d6cc87bSBrooks Davis  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28*0d6cc87bSBrooks Davis  * SUCH DAMAGE.
29*0d6cc87bSBrooks Davis  */
30*0d6cc87bSBrooks Davis 
31*0d6cc87bSBrooks Davis #include <sys/types.h>
32*0d6cc87bSBrooks Davis #include <sys/elf.h>
33*0d6cc87bSBrooks Davis #include <sys/time.h>
34*0d6cc87bSBrooks Davis #include <sys/vdso.h>
35*0d6cc87bSBrooks Davis 
36*0d6cc87bSBrooks Davis #include <machine/cpufunc.h>
37*0d6cc87bSBrooks Davis #include <machine/spr.h>
38*0d6cc87bSBrooks Davis 
39*0d6cc87bSBrooks Davis #include <errno.h>
40*0d6cc87bSBrooks Davis 
41*0d6cc87bSBrooks Davis #include "libc_private.h"
42*0d6cc87bSBrooks Davis 
43*0d6cc87bSBrooks Davis #pragma weak __vdso_gettc
44*0d6cc87bSBrooks Davis int
__vdso_gettc(const struct vdso_timehands * th,u_int * tc)45*0d6cc87bSBrooks Davis __vdso_gettc(const struct vdso_timehands *th, u_int *tc)
46*0d6cc87bSBrooks Davis {
47*0d6cc87bSBrooks Davis 
48*0d6cc87bSBrooks Davis 	if (__predict_false(th->th_algo != VDSO_TH_ALGO_PPC_TB))
49*0d6cc87bSBrooks Davis 	    return (ENOSYS);
50*0d6cc87bSBrooks Davis 	/*
51*0d6cc87bSBrooks Davis 	 * While the timebase is a 64 bit quantity, we are only interested
52*0d6cc87bSBrooks Davis 	 * in the lower 32 bits of it.
53*0d6cc87bSBrooks Davis 	 */
54*0d6cc87bSBrooks Davis 	*tc = mfspr(TBR_TBL);
55*0d6cc87bSBrooks Davis 
56*0d6cc87bSBrooks Davis 	return (0);
57*0d6cc87bSBrooks Davis }
58*0d6cc87bSBrooks Davis 
59*0d6cc87bSBrooks Davis #pragma weak __vdso_gettimekeep
60*0d6cc87bSBrooks Davis int
__vdso_gettimekeep(struct vdso_timekeep ** tk)61*0d6cc87bSBrooks Davis __vdso_gettimekeep(struct vdso_timekeep **tk)
62*0d6cc87bSBrooks Davis {
63*0d6cc87bSBrooks Davis 
64*0d6cc87bSBrooks Davis 	return (_elf_aux_info(AT_TIMEKEEP, tk, sizeof(*tk)));
65*0d6cc87bSBrooks Davis }
66