The real_time_data structure contains an architecture specific
substructure now (that's the only member actually). The system time offset is therefore accessed via architecture specific accessor functions. Note, that this commit breaks the PPC build. Since I want to rename at least one file I've already changed, I can't avoid that. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15835 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
3a6add495c
commit
09bb4e9ac5
@ -25,6 +25,12 @@ void arch_rtc_set_hw_time(uint32 seconds);
|
||||
uint32 arch_rtc_get_hw_time(void);
|
||||
// Returns number of seconds since 1/1/1970 as stored in HW
|
||||
|
||||
void arch_rtc_set_system_time_offset(struct real_time_data *data,
|
||||
bigtime_t offset);
|
||||
// Set the system time offset in data.
|
||||
bigtime_t arch_rtc_get_system_time_offset(struct real_time_data *data);
|
||||
// Return the system time offset as stored in data.
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -97,7 +97,7 @@ extern "C" {
|
||||
|
||||
struct arch_thread;
|
||||
|
||||
void setup_system_time(uint32 cv_factor);
|
||||
void __x86_setup_system_time(uint32 cv_factor);
|
||||
void i386_context_switch(struct arch_thread *old_state, struct arch_thread *new_state, addr_t new_pgdir);
|
||||
void i386_enter_uspace(addr_t entry, void *args1, void *args2, addr_t ustack_top);
|
||||
void i386_set_tss_and_kstack(addr_t kstack);
|
||||
|
17
headers/private/kernel/arch/x86/arch_real_time_data.h
Normal file
17
headers/private/kernel/arch/x86/arch_real_time_data.h
Normal file
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2006, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _KERNEL_ARCH_REAL_TIME_DATA_H
|
||||
#define _KERNEL_ARCH_REAL_TIME_DATA_H
|
||||
|
||||
#include <StorageDefs.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
struct arch_real_time_data {
|
||||
bigtime_t system_time_offset;
|
||||
uint32 system_time_conversion_factor;
|
||||
};
|
||||
|
||||
#endif /* _KERNEL_ARCH_REAL_TIME_DATA_H */
|
@ -8,13 +8,11 @@
|
||||
#include <StorageDefs.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
#include <arch_real_time_data.h>
|
||||
|
||||
// ToDo: most of this is probably arch dependent. When the PPC port comes
|
||||
// to this, it should be properly separated and moved into the arch tree.
|
||||
|
||||
struct real_time_data {
|
||||
bigtime_t system_time_offset;
|
||||
uint32 system_time_conversion_factor;
|
||||
struct arch_real_time_data arch_data;
|
||||
};
|
||||
|
||||
#endif /* _KERNEL_REAL_TIME_DATA_H */
|
||||
|
@ -21,7 +21,8 @@ void __init_env(const struct uspace_program_args *args);
|
||||
void __init_heap(void);
|
||||
|
||||
void __init_time(void);
|
||||
void __arch_init_time(struct real_time_data *data);
|
||||
void __arch_init_time(struct real_time_data *data, bool setDefaults);
|
||||
bigtime_t __arch_get_system_time_offset(struct real_time_data *data);
|
||||
|
||||
|
||||
extern char _single_threaded;
|
||||
|
@ -212,7 +212,7 @@ arch_cpu_preboot_init(kernel_args *args)
|
||||
status_t
|
||||
arch_cpu_init(kernel_args *args)
|
||||
{
|
||||
setup_system_time(args->arch_args.system_time_cv_factor);
|
||||
__x86_setup_system_time(args->arch_args.system_time_cv_factor);
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
@ -178,7 +178,8 @@ secs_to_cmos(uint32 seconds, cmos_time *cmos)
|
||||
status_t
|
||||
arch_rtc_init(struct kernel_args *args, struct real_time_data *data)
|
||||
{
|
||||
data->system_time_conversion_factor = args->arch_args.system_time_cv_factor;
|
||||
data->arch_data.system_time_conversion_factor
|
||||
= args->arch_args.system_time_cv_factor;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@ -214,3 +215,17 @@ arch_rtc_set_hw_time(uint32 seconds)
|
||||
secs_to_cmos(seconds, &cmos);
|
||||
write_cmos_clock(&cmos);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
arch_rtc_set_system_time_offset(struct real_time_data *data, bigtime_t offset)
|
||||
{
|
||||
atomic_set64(&data->arch_data.system_time_offset, offset);
|
||||
}
|
||||
|
||||
|
||||
bigtime_t
|
||||
arch_rtc_get_system_time_offset(struct real_time_data *data)
|
||||
{
|
||||
return atomic_get64(&data->arch_data.system_time_offset);
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ rtc_system_to_hw(void)
|
||||
{
|
||||
uint32 seconds;
|
||||
|
||||
seconds = (sRealTimeData->system_time_offset + system_time()
|
||||
seconds = (arch_rtc_get_system_time_offset(sRealTimeData) + system_time()
|
||||
- (sIsGMT ? 0 : sTimezoneOffset)) / 1000000;
|
||||
|
||||
arch_rtc_set_hw_time(seconds);
|
||||
@ -58,7 +58,7 @@ rtc_hw_to_system(void)
|
||||
bigtime_t
|
||||
rtc_boot_time(void)
|
||||
{
|
||||
return sRealTimeData->system_time_offset;
|
||||
return arch_rtc_get_system_time_offset(sRealTimeData);
|
||||
}
|
||||
|
||||
|
||||
@ -68,10 +68,12 @@ rtc_debug(int argc, char **argv)
|
||||
if (argc < 2) {
|
||||
// If no arguments were given, output all useful data.
|
||||
uint32 currentTime;
|
||||
bigtime_t systemTimeOffset
|
||||
= arch_rtc_get_system_time_offset(sRealTimeData);
|
||||
|
||||
currentTime = (sRealTimeData->system_time_offset + system_time()) / 1000000;
|
||||
currentTime = (systemTimeOffset + system_time()) / 1000000;
|
||||
dprintf("system_time: %Ld\n", system_time());
|
||||
dprintf("system_time_offset: %Ld\n", sRealTimeData->system_time_offset);
|
||||
dprintf("system_time_offset: %Ld\n", systemTimeOffset);
|
||||
dprintf("current_time: %lu\n", currentTime);
|
||||
} else {
|
||||
// If there was an argument, reset the system and hw time.
|
||||
@ -122,7 +124,8 @@ rtc_init(kernel_args *args)
|
||||
void
|
||||
set_real_time_clock(uint32 currentTime)
|
||||
{
|
||||
atomic_set64(&sRealTimeData->system_time_offset, currentTime * 1000000LL - system_time());
|
||||
arch_rtc_set_system_time_offset(sRealTimeData,
|
||||
currentTime * 1000000LL - system_time());
|
||||
rtc_system_to_hw();
|
||||
}
|
||||
|
||||
@ -130,14 +133,15 @@ set_real_time_clock(uint32 currentTime)
|
||||
uint32
|
||||
real_time_clock(void)
|
||||
{
|
||||
return (sRealTimeData->system_time_offset + system_time()) / 1000000;
|
||||
return (arch_rtc_get_system_time_offset(sRealTimeData) + system_time())
|
||||
/ 1000000;
|
||||
}
|
||||
|
||||
|
||||
bigtime_t
|
||||
real_time_clock_usecs(void)
|
||||
{
|
||||
return sRealTimeData->system_time_offset + system_time();
|
||||
return arch_rtc_get_system_time_offset(sRealTimeData) + system_time();
|
||||
}
|
||||
|
||||
|
||||
@ -315,18 +319,23 @@ _user_set_timezone(time_t timezoneOffset, bool daylightSavingTime)
|
||||
if (geteuid() != 0)
|
||||
return B_NOT_ALLOWED;
|
||||
|
||||
TRACE(("old system_time_offset %Ld old %Ld new %Ld gmt %d\n", sRealTimeData->system_time_offset, sTimezoneOffset, offset, sIsGMT));
|
||||
TRACE(("old system_time_offset %Ld old %Ld new %Ld gmt %d\n",
|
||||
arch_rtc_get_system_time_offset(sRealTimeData), sTimezoneOffset, offset,
|
||||
sIsGMT));
|
||||
|
||||
// We only need to update our time offset if the hardware clock
|
||||
// does not run in the local timezone.
|
||||
// Since this is shared data, we need to update it atomically.
|
||||
if (!sIsGMT)
|
||||
atomic_add64(&sRealTimeData->system_time_offset, sTimezoneOffset - offset);
|
||||
if (!sIsGMT) {
|
||||
arch_rtc_set_system_time_offset(sRealTimeData,
|
||||
sTimezoneOffset - offset);
|
||||
}
|
||||
|
||||
sTimezoneOffset = offset;
|
||||
sDaylightSavingTime = daylightSavingTime;
|
||||
|
||||
TRACE(("new system_time_offset %Ld\n", sRealTimeData->system_time_offset));
|
||||
TRACE(("new system_time_offset %Ld\n",
|
||||
arch_rtc_get_system_time_offset(sRealTimeData)));
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
|
||||
** Copyright 2003, Axel D<EFBFBD>fler, axeld@pinc-software.de. All rights reserved.
|
||||
** Distributed under the terms of the OpenBeOS License.
|
||||
*/
|
||||
|
||||
@ -7,16 +7,11 @@
|
||||
|
||||
.text
|
||||
|
||||
// ToDo: note, this function absolutely doesn't do what it should do.
|
||||
// It only reads out the time base register, but it doesn't compute
|
||||
// the real system time from its value.
|
||||
// To do so, the kernel has to provide the appropriate system dependent
|
||||
// conversion factors.
|
||||
|
||||
/* uint64 system_time(void)
|
||||
/* int64 __ppc_get_time_base(void)
|
||||
* r3/r4
|
||||
*/
|
||||
FUNCTION(system_time):
|
||||
FUNCTION(__ppc_get_time_base):
|
||||
/* get TB (time base) register */
|
||||
carry: mftbu %r3
|
||||
mftb %r4
|
||||
mftbu %r5 // read the upper half again
|
||||
|
@ -3,15 +3,21 @@
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include <OS.h>
|
||||
|
||||
#include <arch_cpu.h>
|
||||
#include <libroot_private.h>
|
||||
#include <real_time_data.h>
|
||||
#include <arch_cpu.h>
|
||||
|
||||
|
||||
void
|
||||
__arch_init_time(struct real_time_data *data)
|
||||
__arch_init_time(struct real_time_data *data, bool setDefaults)
|
||||
{
|
||||
// TODO: Implement!
|
||||
}
|
||||
if (setDefaults) {
|
||||
data->arch_data.data[0].system_time_offset = 0;
|
||||
data->arch_data.system_time_conversion_factor = 1000000000LL;
|
||||
data->arch_data.version = 0;
|
||||
}
|
||||
|
||||
__ppc_setup_system_time(&data->arch_data.system_time_conversion_factor);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
cv_factor:
|
||||
.word 0
|
||||
|
||||
FUNCTION(setup_system_time):
|
||||
FUNCTION(__x86_setup_system_time):
|
||||
movl 4(%esp),%eax
|
||||
movl %eax,cv_factor
|
||||
ret
|
||||
|
@ -10,10 +10,21 @@
|
||||
|
||||
|
||||
void
|
||||
__arch_init_time(struct real_time_data *data)
|
||||
__arch_init_time(struct real_time_data *data, bool setDefaults)
|
||||
{
|
||||
if (setDefaults) {
|
||||
data->arch_data.system_time_offset = 0;
|
||||
data->arch_data.system_time_conversion_factor = 100000;
|
||||
}
|
||||
|
||||
// ToDo: this should only store a pointer to that value
|
||||
// ToDo: this function should not clobber the global name space
|
||||
setup_system_time(data->system_time_conversion_factor);
|
||||
__x86_setup_system_time(data->arch_data.system_time_conversion_factor);
|
||||
}
|
||||
|
||||
|
||||
bigtime_t
|
||||
__arch_get_system_time_offset(struct real_time_data *data)
|
||||
{
|
||||
return atomic_get64(&data->arch_data.system_time_offset);
|
||||
}
|
||||
|
||||
|
@ -14,16 +14,14 @@
|
||||
#include <syscalls.h>
|
||||
|
||||
|
||||
static struct real_time_data sRealTimeDefaults = {
|
||||
0,
|
||||
100000
|
||||
};
|
||||
static struct real_time_data sRealTimeDefaults;
|
||||
static struct real_time_data *sRealTimeData;
|
||||
|
||||
|
||||
void
|
||||
__init_time(void)
|
||||
{
|
||||
bool setDefaults = false;
|
||||
area_id dataArea;
|
||||
area_info info;
|
||||
|
||||
@ -31,24 +29,26 @@ __init_time(void)
|
||||
if (dataArea < 0 || get_area_info(dataArea, &info) < B_OK) {
|
||||
syslog(LOG_ERR, "error finding real time data area: %s\n", strerror(dataArea));
|
||||
sRealTimeData = &sRealTimeDefaults;
|
||||
setDefaults = true;
|
||||
} else
|
||||
sRealTimeData = (struct real_time_data *)info.address;
|
||||
|
||||
__arch_init_time(sRealTimeData);
|
||||
__arch_init_time(sRealTimeData, setDefaults);
|
||||
}
|
||||
|
||||
|
||||
uint32
|
||||
real_time_clock(void)
|
||||
{
|
||||
return (sRealTimeData->system_time_offset + system_time()) / 1000000;
|
||||
return (__arch_get_system_time_offset(sRealTimeData) + system_time())
|
||||
/ 1000000;
|
||||
}
|
||||
|
||||
|
||||
bigtime_t
|
||||
real_time_clock_usecs(void)
|
||||
{
|
||||
return sRealTimeData->system_time_offset + system_time();
|
||||
return __arch_get_system_time_offset(sRealTimeData) + system_time();
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user