1*64bc3019SX512 /* 2*64bc3019SX512 * Copyright 2012-2021, Haiku, Inc. All rights reserved. 3*64bc3019SX512 * Distributed under the terms of the MIT License. 4*64bc3019SX512 * 5*64bc3019SX512 * Authors: 6*64bc3019SX512 * François Revol <revol@free.fr> 7*64bc3019SX512 */ 8*64bc3019SX512 9*64bc3019SX512 #include <OS.h> 10*64bc3019SX512 11*64bc3019SX512 #include <arch_cpu.h> 12*64bc3019SX512 #include <arch_cpu_defs.h> 13*64bc3019SX512 #include <libroot_private.h> 14*64bc3019SX512 #include <real_time_data.h> 15*64bc3019SX512 16*64bc3019SX512 #ifdef _KERNEL_MODE 17*64bc3019SX512 #include <KernelExport.h> 18*64bc3019SX512 #endif 19*64bc3019SX512 20*64bc3019SX512 21*64bc3019SX512 static uint64_t cv_factor = 0; 22*64bc3019SX512 23*64bc3019SX512 24*64bc3019SX512 extern "C" void 25*64bc3019SX512 __riscv64_setup_system_time(uint64 cv) 26*64bc3019SX512 { 27*64bc3019SX512 cv_factor = cv; 28*64bc3019SX512 } 29*64bc3019SX512 30*64bc3019SX512 31*64bc3019SX512 [[gnu::optimize("omit-frame-pointer")]] bigtime_t 32*64bc3019SX512 system_time() 33*64bc3019SX512 { 34*64bc3019SX512 // TODO: Timer unit conversion needs fixed here 35*64bc3019SX512 // QEMU and SiFive boards use diferent timer frequencies 36*64bc3019SX512 return CpuTime(); 37*64bc3019SX512 /* 38*64bc3019SX512 uint64 time = CpuTime(); 39*64bc3019SX512 uint64 lo = (uint32)time; 40*64bc3019SX512 uint64 hi = time >> 32; 41*64bc3019SX512 return ((lo * cv_factor) >> 32) + hi * cv_factor; 42*64bc3019SX512 */ 43*64bc3019SX512 /* 44*64bc3019SX512 __uint128_t time = static_cast<__uint128_t>(CpuTime()) * cv_factor; 45*64bc3019SX512 return time >> 32; 46*64bc3019SX512 */ 47*64bc3019SX512 } 48