/*- * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2012 Konstantin Belousov * Copyright (c) 2021 Dmitry Chagin * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include #include #include #include #define _KERNEL #include #undef _KERNEL #include #include #include #include #include #include #include /* The kernel fixup this at vDSO install */ uintptr_t *kern_timekeep_base = NULL; uint32_t kern_tsc_selector = 0; /* * Fallback trampolines for when the vDSO fast path cannot satisfy the * request. linux_set_syscall_retval() leaves errno in r3 whenever it * sets cr0.SO, so there is no need to test SO here. */ static int __vdso_clock_gettime_fallback(clockid_t clock_id, struct l_timespec *lts) { register long r0 __asm__("r0") = LINUX_SYS_linux_clock_gettime; register long r3 __asm__("r3") = (long)clock_id; register long r4 __asm__("r4") = (long)lts; __asm__ __volatile__("sc" : "+r"(r3) : "r"(r0), "r"(r4) : "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "cr0", "ctr", "xer", "memory"); return ((int)r3); } static int __vdso_gettimeofday_fallback(l_timeval *ltv, struct timezone *ltz) { register long r0 __asm__("r0") = LINUX_SYS_gettimeofday; register long r3 __asm__("r3") = (long)ltv; register long r4 __asm__("r4") = (long)ltz; __asm__ __volatile__("sc" : "+r"(r3) : "r"(r0), "r"(r4) : "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "cr0", "ctr", "xer", "memory"); return ((int)r3); } static int __vdso_clock_getres_fallback(clockid_t clock_id, struct l_timespec *lts) { register long r0 __asm__("r0") = LINUX_SYS_linux_clock_getres; register long r3 __asm__("r3") = (long)clock_id; register long r4 __asm__("r4") = (long)lts; __asm__ __volatile__("sc" : "+r"(r3) : "r"(r0), "r"(r4) : "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "cr0", "ctr", "xer", "memory"); return ((int)r3); } /* * copied from lib/libc/powerpc64/sys/__vdso_gettc.c */ int __vdso_gettc(const struct vdso_timehands *th, u_int *tc) { u_quad_t tb; if (__predict_false(th->th_algo != VDSO_TH_ALGO_PPC_TB)) return (ENOSYS); __asm __volatile ("mftb %0" : "=r"(tb)); *tc = tb; return (0); } #include