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