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