xref: /haiku/src/system/libroot/os/arch/x86/time.cpp (revision 2b76973fa2401f7a5edf68e6470f3d3210cbcff3)
1 /*
2  * Copyright 2004, Axel Dörfler, axeld@pinc-software.de.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include <libroot_private.h>
8 #include <real_time_data.h>
9 #include <arch_cpu.h>
10 
11 
12 void
13 __arch_init_time(struct real_time_data *data, bool setDefaults)
14 {
15 	uint32 conversionFactor;
16 	uint64 conversionFactorNsecs;
17 
18 	if (setDefaults) {
19 		data->arch_data.system_time_offset = 0;
20 		data->arch_data.system_time_conversion_factor = 100000;
21 	}
22 
23 	// TODO: this should only store a pointer to that value
24 	// When resolving this TODO, also resolve the one in the Jamfile.
25 
26 	conversionFactor = data->arch_data.system_time_conversion_factor;
27 	conversionFactorNsecs = (uint64)conversionFactor * 1000;
28 
29 	if (conversionFactorNsecs >> 32 != 0) {
30 		// the TSC frequency is < 1 GHz, which forces us to shift the factor
31 		__x86_setup_system_time(conversionFactor, conversionFactorNsecs >> 16,
32 			true);
33 	} else {
34 		// the TSC frequency is >= 1 GHz
35 		__x86_setup_system_time(conversionFactor, conversionFactorNsecs, false);
36 	}
37 }
38 
39 
40 bigtime_t
41 __arch_get_system_time_offset(struct real_time_data *data)
42 {
43 	//we don't use atomic_get64 because memory is read-only, maybe find another way to lock
44 	return data->arch_data.system_time_offset;
45 }
46 
47