xref: /haiku/src/system/libroot/os/arch/m68k/system_time.c (revision d4dcbf95f68d9b1e5aaf9b695713280083289857)
1188b4327SFrançois Revol /*
2188b4327SFrançois Revol  * Copyright 2006, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
3188b4327SFrançois Revol  * All rights reserved. Distributed under the terms of the MIT License.
4188b4327SFrançois Revol  */
5188b4327SFrançois Revol 
6188b4327SFrançois Revol #include <OS.h>
7188b4327SFrançois Revol 
8188b4327SFrançois Revol #include <arch_cpu.h>
9188b4327SFrançois Revol #include <libroot_private.h>
10188b4327SFrançois Revol #include <real_time_data.h>
11188b4327SFrançois Revol 
12188b4327SFrançois Revol 
13188b4327SFrançois Revol static vint32 *sConversionFactor;
14188b4327SFrançois Revol 
15188b4327SFrançois Revol void
__m68k_setup_system_time(vint32 * cvFactor)16fac9743eSFrançois Revol __m68k_setup_system_time(vint32 *cvFactor)
17188b4327SFrançois Revol {
18188b4327SFrançois Revol 	sConversionFactor = cvFactor;
19188b4327SFrançois Revol }
20188b4327SFrançois Revol 
21188b4327SFrançois Revol 
22*d4dcbf95SFrançois Revol //XXX: this is a hack
23*d4dcbf95SFrançois Revol // remove me when platform code works
24*d4dcbf95SFrançois Revol int64
__m68k_get_time_base(void)25*d4dcbf95SFrançois Revol __m68k_get_time_base(void)
26*d4dcbf95SFrançois Revol {
27*d4dcbf95SFrançois Revol 	static uint64 time_dilation_field = 0;
28*d4dcbf95SFrançois Revol 	return time_dilation_field++;
29*d4dcbf95SFrançois Revol }
30*d4dcbf95SFrançois Revol 
31188b4327SFrançois Revol bigtime_t
system_time(void)32188b4327SFrançois Revol system_time(void)
33188b4327SFrançois Revol {
349ce32017SJérôme Duval 	uint64 timeBase = __m68k_get_time_base();
35188b4327SFrançois Revol 
36188b4327SFrançois Revol 	uint32 cv = *sConversionFactor;
37188b4327SFrançois Revol 	return (timeBase >> 32) * cv + (((timeBase & 0xffffffff) * cv) >> 32);
38188b4327SFrançois Revol }
39