16f14ecb4SFrançois Revol /* 29ffc3c3dSIthamar R. Adema * Copyright 2012, Haiku, Inc. 39ffc3c3dSIthamar R. Adema * Distributed under the terms of the MIT License. 49ffc3c3dSIthamar R. Adema * 59ffc3c3dSIthamar R. Adema * Authors: 69ffc3c3dSIthamar R. Adema * François Revol <revol@free.fr> 76f14ecb4SFrançois Revol */ 86f14ecb4SFrançois Revol 96f14ecb4SFrançois Revol #include <OS.h> 106f14ecb4SFrançois Revol 116f14ecb4SFrançois Revol #include <arch_cpu.h> 126f14ecb4SFrançois Revol #include <libroot_private.h> 136f14ecb4SFrançois Revol #include <real_time_data.h> 146f14ecb4SFrançois Revol 159ffc3c3dSIthamar R. Adema static vint32 *sConversionFactor; 169ffc3c3dSIthamar R. Adema 179ffc3c3dSIthamar R. Adema void 189ffc3c3dSIthamar R. Adema __arm_setup_system_time(vint32 *cvFactor) 199ffc3c3dSIthamar R. Adema { 209ffc3c3dSIthamar R. Adema sConversionFactor = cvFactor; 219ffc3c3dSIthamar R. Adema } 229ffc3c3dSIthamar R. Adema 239ffc3c3dSIthamar R. Adema 249ffc3c3dSIthamar R. Adema //XXX: this is a hack 259ffc3c3dSIthamar R. Adema // remove me when platform code works 269ffc3c3dSIthamar R. Adema static int64 279ffc3c3dSIthamar R. Adema __arm_get_time_base(void) 289ffc3c3dSIthamar R. Adema { 299ffc3c3dSIthamar R. Adema static uint64 time_dilation_field = 0; 309ffc3c3dSIthamar R. Adema return time_dilation_field++; 319ffc3c3dSIthamar R. Adema } 326f14ecb4SFrançois Revol 336f14ecb4SFrançois Revol bigtime_t 346f14ecb4SFrançois Revol system_time(void) 356f14ecb4SFrançois Revol { 369ffc3c3dSIthamar R. Adema uint64 timeBase = __arm_get_time_base(); 379ffc3c3dSIthamar R. Adema 38*379aaaabSIthamar R. Adema uint32 cv = sConversionFactor ? *sConversionFactor : 0; 399ffc3c3dSIthamar R. Adema return (timeBase >> 32) * cv + (((timeBase & 0xffffffff) * cv) >> 32); 406f14ecb4SFrançois Revol } 41