1/* SPDX-License-Identifier: GPL-2.0-or-later */ 2/* 3 * Userland implementation of gettimeofday() for processes 4 * for use in the vDSO 5 * 6 * Copyright (C) 2004 Benjamin Herrenschmuidt (benh@kernel.crashing.org, 7 * IBM Corp. 8 */ 9#include <asm/processor.h> 10#include <asm/ppc_asm.h> 11#include <asm/vdso.h> 12#include <asm/vdso_datapage.h> 13#include <asm/asm-offsets.h> 14#include <asm/unistd.h> 15 16/* 17 * The macro sets two stack frames, one for the caller and one for the callee 18 * because there are no requirement for the caller to set a stack frame when 19 * calling VDSO so it may have omitted to set one, especially on PPC64 20 */ 21 22.macro cvdso_call funct call_time=0 23 .cfi_startproc 24 PPC_STLU r1, -PPC_MIN_STKFRM(r1) 25 .cfi_adjust_cfa_offset PPC_MIN_STKFRM 26 mflr r0 27 PPC_STLU r1, -PPC_MIN_STKFRM(r1) 28 .cfi_adjust_cfa_offset PPC_MIN_STKFRM 29 PPC_STL r0, PPC_MIN_STKFRM + PPC_LR_STKOFF(r1) 30 .cfi_rel_offset lr, PPC_MIN_STKFRM + PPC_LR_STKOFF 31#ifdef __powerpc64__ 32 PPC_STL r2, PPC_MIN_STKFRM + STK_GOT(r1) 33 .cfi_rel_offset r2, PPC_MIN_STKFRM + STK_GOT 34#endif 35 .ifeq \call_time 36 get_datapage r5 vdso_u_time_data 37 .else 38 get_datapage r4 vdso_u_time_data 39 .endif 40 bl CFUNC(DOTSYM(\funct)) 41 PPC_LL r0, PPC_MIN_STKFRM + PPC_LR_STKOFF(r1) 42#ifdef __powerpc64__ 43 PPC_LL r2, PPC_MIN_STKFRM + STK_GOT(r1) 44 .cfi_restore r2 45#endif 46 .ifeq \call_time 47 cmpwi r3, 0 48 .endif 49 mtlr r0 50 addi r1, r1, 2 * PPC_MIN_STKFRM 51 .cfi_restore lr 52 .cfi_def_cfa_offset 0 53 crclr so 54 .ifeq \call_time 55 beqlr+ 56 crset so 57 neg r3, r3 58 .endif 59 blr 60 .cfi_endproc 61.endm 62 63 .text 64/* 65 * Exact prototype of gettimeofday 66 * 67 * int __kernel_gettimeofday(struct timeval *tv, struct timezone *tz); 68 * 69 */ 70#if defined(__powerpc64__) || defined(CONFIG_COMPAT_32BIT_TIME) 71V_FUNCTION_BEGIN(__kernel_gettimeofday) 72 cvdso_call __c_kernel_gettimeofday 73V_FUNCTION_END(__kernel_gettimeofday) 74#endif 75 76/* 77 * Exact prototype of clock_gettime() 78 * 79 * int __kernel_clock_gettime(clockid_t clock_id, struct timespec *tp); 80 * 81 */ 82#if defined(__powerpc64__) || defined(CONFIG_COMPAT_32BIT_TIME) 83V_FUNCTION_BEGIN(__kernel_clock_gettime) 84 cvdso_call __c_kernel_clock_gettime 85V_FUNCTION_END(__kernel_clock_gettime) 86#endif 87 88/* 89 * Exact prototype of clock_gettime64() 90 * 91 * int __kernel_clock_gettime64(clockid_t clock_id, struct __timespec64 *ts); 92 * 93 */ 94#ifndef __powerpc64__ 95V_FUNCTION_BEGIN(__kernel_clock_gettime64) 96 cvdso_call __c_kernel_clock_gettime64 97V_FUNCTION_END(__kernel_clock_gettime64) 98#endif 99 100/* 101 * Exact prototype of clock_getres() 102 * 103 * int __kernel_clock_getres(clockid_t clock_id, struct timespec *res); 104 * 105 */ 106#if defined(__powerpc64__) || defined(CONFIG_COMPAT_32BIT_TIME) 107V_FUNCTION_BEGIN(__kernel_clock_getres) 108 cvdso_call __c_kernel_clock_getres 109V_FUNCTION_END(__kernel_clock_getres) 110#endif 111 112/* 113 * Exact prototype of clock_getres_time64() 114 * 115 * int __kernel_clock_getres(clockid_t clock_id, struct __timespec64 *res); 116 * 117 */ 118#ifndef __powerpc64__ 119V_FUNCTION_BEGIN(__kernel_clock_getres_time64) 120 cvdso_call __c_kernel_clock_getres_time64 121V_FUNCTION_END(__kernel_clock_getres_time64) 122#endif 123 124 125/* 126 * Exact prototype of time() 127 * 128 * time_t time(time *t); 129 * 130 */ 131#if defined(__powerpc64__) || defined(CONFIG_COMPAT_32BIT_TIME) 132V_FUNCTION_BEGIN(__kernel_time) 133 cvdso_call __c_kernel_time call_time=1 134V_FUNCTION_END(__kernel_time) 135#endif 136