1468c1bb5SRichard Henderson/* 2468c1bb5SRichard Henderson * RISC-V linux replacement vdso. 3468c1bb5SRichard Henderson * 4468c1bb5SRichard Henderson * Copyright 2021 Linaro, Ltd. 5468c1bb5SRichard Henderson * 6468c1bb5SRichard Henderson * SPDX-License-Identifier: GPL-2.0-or-later 7468c1bb5SRichard Henderson */ 8468c1bb5SRichard Henderson 9468c1bb5SRichard Henderson#include <asm/unistd.h> 10468c1bb5SRichard Henderson#include <asm/errno.h> 11468c1bb5SRichard Henderson 12468c1bb5SRichard Henderson#if __riscv_xlen == 32 13468c1bb5SRichard Henderson# define TARGET_ABI32 14468c1bb5SRichard Henderson#endif 15468c1bb5SRichard Henderson#include "vdso-asmoffset.h" 16468c1bb5SRichard Henderson 17468c1bb5SRichard Henderson .text 18468c1bb5SRichard Henderson 19468c1bb5SRichard Henderson.macro endf name 20468c1bb5SRichard Henderson .globl \name 21468c1bb5SRichard Henderson .type \name, @function 22468c1bb5SRichard Henderson .size \name, . - \name 23468c1bb5SRichard Henderson.endm 24468c1bb5SRichard Henderson 25468c1bb5SRichard Henderson.macro raw_syscall nr 26468c1bb5SRichard Henderson li a7, \nr 27468c1bb5SRichard Henderson ecall 28468c1bb5SRichard Henderson.endm 29468c1bb5SRichard Henderson 30468c1bb5SRichard Henderson.macro vdso_syscall name, nr 31468c1bb5SRichard Henderson\name: 32468c1bb5SRichard Henderson raw_syscall \nr 33468c1bb5SRichard Henderson ret 34468c1bb5SRichard Hendersonendf \name 35468c1bb5SRichard Henderson.endm 36468c1bb5SRichard Henderson 37468c1bb5SRichard Henderson__vdso_gettimeofday: 38468c1bb5SRichard Henderson .cfi_startproc 39468c1bb5SRichard Henderson#ifdef __NR_gettimeofday 40468c1bb5SRichard Henderson raw_syscall __NR_gettimeofday 41468c1bb5SRichard Henderson ret 42468c1bb5SRichard Henderson#else 43468c1bb5SRichard Henderson /* No gettimeofday, fall back to clock_gettime64. */ 44468c1bb5SRichard Henderson beq a1, zero, 1f 45468c1bb5SRichard Henderson sw zero, 0(a1) /* tz->tz_minuteswest = 0 */ 46468c1bb5SRichard Henderson sw zero, 4(a1) /* tz->tz_dsttime = 0 */ 47468c1bb5SRichard Henderson1: addi sp, sp, -32 48468c1bb5SRichard Henderson .cfi_adjust_cfa_offset 32 49468c1bb5SRichard Henderson sw a0, 16(sp) /* save tv */ 50468c1bb5SRichard Henderson mv a0, sp 51468c1bb5SRichard Henderson raw_syscall __NR_clock_gettime64 52468c1bb5SRichard Henderson lw t0, 0(sp) /* timespec.tv_sec.low */ 53468c1bb5SRichard Henderson lw t1, 4(sp) /* timespec.tv_sec.high */ 54468c1bb5SRichard Henderson lw t2, 8(sp) /* timespec.tv_nsec.low */ 55468c1bb5SRichard Henderson lw a1, 16(sp) /* restore tv */ 56468c1bb5SRichard Henderson addi sp, sp, 32 57468c1bb5SRichard Henderson .cfi_adjust_cfa_offset -32 58468c1bb5SRichard Henderson bne a0, zero, 9f /* syscall error? */ 59468c1bb5SRichard Henderson li a0, -EOVERFLOW 60468c1bb5SRichard Henderson bne t1, zero, 9f /* y2038? */ 61468c1bb5SRichard Henderson li a0, 0 62468c1bb5SRichard Henderson li t3, 1000 63468c1bb5SRichard Henderson divu t2, t2, t3 /* nsec -> usec */ 64468c1bb5SRichard Henderson sw t0, 0(a1) /* tz->tv_sec */ 65468c1bb5SRichard Henderson sw t2, 4(a1) /* tz->tv_usec */ 66468c1bb5SRichard Henderson9: ret 67468c1bb5SRichard Henderson#endif 68468c1bb5SRichard Henderson .cfi_endproc 69468c1bb5SRichard Hendersonendf __vdso_gettimeofday 70468c1bb5SRichard Henderson 71468c1bb5SRichard Henderson .cfi_startproc 72468c1bb5SRichard Henderson 73468c1bb5SRichard Henderson#ifdef __NR_clock_gettime 74468c1bb5SRichard Hendersonvdso_syscall __vdso_clock_gettime, __NR_clock_gettime 75468c1bb5SRichard Henderson#else 76468c1bb5SRichard Hendersonvdso_syscall __vdso_clock_gettime, __NR_clock_gettime64 77468c1bb5SRichard Henderson#endif 78468c1bb5SRichard Henderson 79468c1bb5SRichard Henderson#ifdef __NR_clock_getres 80468c1bb5SRichard Hendersonvdso_syscall __vdso_clock_getres, __NR_clock_getres 81468c1bb5SRichard Henderson#else 82468c1bb5SRichard Hendersonvdso_syscall __vdso_clock_getres, __NR_clock_getres_time64 83468c1bb5SRichard Henderson#endif 84468c1bb5SRichard Henderson 85468c1bb5SRichard Hendersonvdso_syscall __vdso_getcpu, __NR_getcpu 86468c1bb5SRichard Henderson 87468c1bb5SRichard Henderson__vdso_flush_icache: 88468c1bb5SRichard Henderson /* qemu does not need to flush the icache */ 89468c1bb5SRichard Henderson li a0, 0 90468c1bb5SRichard Henderson ret 91468c1bb5SRichard Hendersonendf __vdso_flush_icache 92468c1bb5SRichard Henderson 93468c1bb5SRichard Henderson .cfi_endproc 94468c1bb5SRichard Henderson 95468c1bb5SRichard Henderson/* 96468c1bb5SRichard Henderson * Start the unwind info at least one instruction before the signal 97468c1bb5SRichard Henderson * trampoline, because the unwinder will assume we are returning 98468c1bb5SRichard Henderson * after a call site. 99468c1bb5SRichard Henderson */ 100468c1bb5SRichard Henderson 101468c1bb5SRichard Henderson .cfi_startproc simple 102468c1bb5SRichard Henderson .cfi_signal_frame 103468c1bb5SRichard Henderson 104*1e0f028dSRichard Henderson#define sizeof_reg (__riscv_xlen / 8) 105468c1bb5SRichard Henderson#define sizeof_freg 8 106*1e0f028dSRichard Henderson#define B_GR 0 107*1e0f028dSRichard Henderson#define B_FR offsetof_freg0 108468c1bb5SRichard Henderson 109*1e0f028dSRichard Henderson .cfi_def_cfa 2, offsetof_uc_mcontext 110468c1bb5SRichard Henderson 111468c1bb5SRichard Henderson /* Return address */ 112468c1bb5SRichard Henderson .cfi_return_column 64 113468c1bb5SRichard Henderson .cfi_offset 64, B_GR + 0 /* pc */ 114468c1bb5SRichard Henderson 115468c1bb5SRichard Henderson /* Integer registers */ 116468c1bb5SRichard Henderson .cfi_offset 1, B_GR + 1 * sizeof_reg /* r1 (ra) */ 117468c1bb5SRichard Henderson .cfi_offset 2, B_GR + 2 * sizeof_reg /* r2 (sp) */ 118468c1bb5SRichard Henderson .cfi_offset 3, B_GR + 3 * sizeof_reg 119468c1bb5SRichard Henderson .cfi_offset 4, B_GR + 4 * sizeof_reg 120468c1bb5SRichard Henderson .cfi_offset 5, B_GR + 5 * sizeof_reg 121468c1bb5SRichard Henderson .cfi_offset 6, B_GR + 6 * sizeof_reg 122468c1bb5SRichard Henderson .cfi_offset 7, B_GR + 7 * sizeof_reg 123468c1bb5SRichard Henderson .cfi_offset 8, B_GR + 8 * sizeof_reg 124468c1bb5SRichard Henderson .cfi_offset 9, B_GR + 9 * sizeof_reg 125468c1bb5SRichard Henderson .cfi_offset 10, B_GR + 10 * sizeof_reg 126468c1bb5SRichard Henderson .cfi_offset 11, B_GR + 11 * sizeof_reg 127468c1bb5SRichard Henderson .cfi_offset 12, B_GR + 12 * sizeof_reg 128468c1bb5SRichard Henderson .cfi_offset 13, B_GR + 13 * sizeof_reg 129468c1bb5SRichard Henderson .cfi_offset 14, B_GR + 14 * sizeof_reg 130468c1bb5SRichard Henderson .cfi_offset 15, B_GR + 15 * sizeof_reg 131468c1bb5SRichard Henderson .cfi_offset 16, B_GR + 16 * sizeof_reg 132468c1bb5SRichard Henderson .cfi_offset 17, B_GR + 17 * sizeof_reg 133468c1bb5SRichard Henderson .cfi_offset 18, B_GR + 18 * sizeof_reg 134468c1bb5SRichard Henderson .cfi_offset 19, B_GR + 19 * sizeof_reg 135468c1bb5SRichard Henderson .cfi_offset 20, B_GR + 20 * sizeof_reg 136468c1bb5SRichard Henderson .cfi_offset 21, B_GR + 21 * sizeof_reg 137468c1bb5SRichard Henderson .cfi_offset 22, B_GR + 22 * sizeof_reg 138468c1bb5SRichard Henderson .cfi_offset 23, B_GR + 23 * sizeof_reg 139468c1bb5SRichard Henderson .cfi_offset 24, B_GR + 24 * sizeof_reg 140468c1bb5SRichard Henderson .cfi_offset 25, B_GR + 25 * sizeof_reg 141468c1bb5SRichard Henderson .cfi_offset 26, B_GR + 26 * sizeof_reg 142468c1bb5SRichard Henderson .cfi_offset 27, B_GR + 27 * sizeof_reg 143468c1bb5SRichard Henderson .cfi_offset 28, B_GR + 28 * sizeof_reg 144468c1bb5SRichard Henderson .cfi_offset 29, B_GR + 29 * sizeof_reg 145468c1bb5SRichard Henderson .cfi_offset 30, B_GR + 30 * sizeof_reg 146468c1bb5SRichard Henderson .cfi_offset 31, B_GR + 31 * sizeof_reg /* r31 */ 147468c1bb5SRichard Henderson 148468c1bb5SRichard Henderson .cfi_offset 32, B_FR + 0 /* f0 */ 149468c1bb5SRichard Henderson .cfi_offset 33, B_FR + 1 * sizeof_freg /* f1 */ 150468c1bb5SRichard Henderson .cfi_offset 34, B_FR + 2 * sizeof_freg 151468c1bb5SRichard Henderson .cfi_offset 35, B_FR + 3 * sizeof_freg 152468c1bb5SRichard Henderson .cfi_offset 36, B_FR + 4 * sizeof_freg 153468c1bb5SRichard Henderson .cfi_offset 37, B_FR + 5 * sizeof_freg 154468c1bb5SRichard Henderson .cfi_offset 38, B_FR + 6 * sizeof_freg 155468c1bb5SRichard Henderson .cfi_offset 39, B_FR + 7 * sizeof_freg 156468c1bb5SRichard Henderson .cfi_offset 40, B_FR + 8 * sizeof_freg 157468c1bb5SRichard Henderson .cfi_offset 41, B_FR + 9 * sizeof_freg 158468c1bb5SRichard Henderson .cfi_offset 42, B_FR + 10 * sizeof_freg 159468c1bb5SRichard Henderson .cfi_offset 43, B_FR + 11 * sizeof_freg 160468c1bb5SRichard Henderson .cfi_offset 44, B_FR + 12 * sizeof_freg 161468c1bb5SRichard Henderson .cfi_offset 45, B_FR + 13 * sizeof_freg 162468c1bb5SRichard Henderson .cfi_offset 46, B_FR + 14 * sizeof_freg 163468c1bb5SRichard Henderson .cfi_offset 47, B_FR + 15 * sizeof_freg 164468c1bb5SRichard Henderson .cfi_offset 48, B_FR + 16 * sizeof_freg 165468c1bb5SRichard Henderson .cfi_offset 49, B_FR + 17 * sizeof_freg 166468c1bb5SRichard Henderson .cfi_offset 50, B_FR + 18 * sizeof_freg 167468c1bb5SRichard Henderson .cfi_offset 51, B_FR + 19 * sizeof_freg 168468c1bb5SRichard Henderson .cfi_offset 52, B_FR + 20 * sizeof_freg 169468c1bb5SRichard Henderson .cfi_offset 53, B_FR + 21 * sizeof_freg 170468c1bb5SRichard Henderson .cfi_offset 54, B_FR + 22 * sizeof_freg 171468c1bb5SRichard Henderson .cfi_offset 55, B_FR + 23 * sizeof_freg 172468c1bb5SRichard Henderson .cfi_offset 56, B_FR + 24 * sizeof_freg 173468c1bb5SRichard Henderson .cfi_offset 57, B_FR + 25 * sizeof_freg 174468c1bb5SRichard Henderson .cfi_offset 58, B_FR + 26 * sizeof_freg 175468c1bb5SRichard Henderson .cfi_offset 59, B_FR + 27 * sizeof_freg 176468c1bb5SRichard Henderson .cfi_offset 60, B_FR + 28 * sizeof_freg 177468c1bb5SRichard Henderson .cfi_offset 61, B_FR + 29 * sizeof_freg 178468c1bb5SRichard Henderson .cfi_offset 62, B_FR + 30 * sizeof_freg 179468c1bb5SRichard Henderson .cfi_offset 63, B_FR + 31 * sizeof_freg /* f31 */ 180468c1bb5SRichard Henderson 181468c1bb5SRichard Henderson nop 182468c1bb5SRichard Henderson 183468c1bb5SRichard Henderson__vdso_rt_sigreturn: 184468c1bb5SRichard Henderson raw_syscall __NR_rt_sigreturn 185468c1bb5SRichard Hendersonendf __vdso_rt_sigreturn 186468c1bb5SRichard Henderson 187468c1bb5SRichard Henderson .cfi_endproc 188