xref: /haiku/src/system/libroot/os/arch/x86_64/time.cpp (revision e81a954787e50e56a7f06f72705b7859b6ab06d1)
1 /*
2  * Copyright 2004, Axel Dörfler, axeld@pinc-software.de.
3  * Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
4  * Distributed under the terms of the MIT License.
5  */
6 
7 
8 #include <libroot_private.h>
9 #include <real_time_data.h>
10 #include <arch_cpu.h>
11 
12 
13 void
14 __arch_init_time(real_time_data* data, bool setDefaults)
15 {
16 	uint32 conversionFactor;
17 	uint64 conversionFactorNsecs;
18 
19 	if (setDefaults) {
20 		data->arch_data.system_time_offset = 0;
21 		data->arch_data.system_time_conversion_factor = 100000;
22 	}
23 
24 	// TODO: this should only store a pointer to that value
25 	// When resolving this TODO, also resolve the one in the Jamfile.
26 
27 	conversionFactor = data->arch_data.system_time_conversion_factor;
28 	conversionFactorNsecs = (uint64)conversionFactor * 1000;
29 
30 	// The x86_64 system_time() implementation uses 64-bit multiplication and
31 	// therefore shifting is not necessary for low frequencies (it's also not
32 	// too likely that there'll be any x86_64 CPUs clocked under 1GHz).
33 	__x86_setup_system_time((uint64)conversionFactor << 32,
34 		conversionFactorNsecs);
35 }
36 
37 
38 bigtime_t
39 __arch_get_system_time_offset(struct real_time_data *data)
40 {
41 	//we don't use atomic_get64 because memory is read-only, maybe find another way to lock
42 	return data->arch_data.system_time_offset;
43 }
44 
45