From 397e7db6df91520c6406e51fe155dd88f2e2fbb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 18 Nov 2004 03:08:36 +0000 Subject: [PATCH] Brought the userland time initialization into more or less final shape: - renamed setup_rtc_boottime() to __init_time() - __init_time() is now initialized at libroot.so startup - introduced new __arch_init_time() that does the arch dependent stuff, for now it just sets the system_time() conversion factor (that's the part that will change later on) - os/time.c now keeps a pointer to the real_time_data around, not only to the boot time - maybe we'll it for other stuff as well later. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9995 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/libroot/libroot_init.c | 9 +-- src/kernel/libroot/os/arch/x86/Jamfile | 18 +++--- src/kernel/libroot/os/arch/x86/time.c | 19 +++++++ src/kernel/libroot/os/time.c | 78 +++++++++++--------------- 4 files changed, 65 insertions(+), 59 deletions(-) create mode 100644 src/kernel/libroot/os/arch/x86/time.c diff --git a/src/kernel/libroot/libroot_init.c b/src/kernel/libroot/libroot_init.c index d9da5d32a5..77b625d030 100644 --- a/src/kernel/libroot/libroot_init.c +++ b/src/kernel/libroot/libroot_init.c @@ -1,7 +1,7 @@ -/* -** Copyright 2003-2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. -** Distributed under the terms of the Haiku License. -*/ +/* + * Copyright 2003-2004, Axel Dörfler, axeld@pinc-software.de. + * Distributed under the terms of the MIT License. + */ #include @@ -37,6 +37,7 @@ initialize_before(image_id imageID, struct uspace_program_args const *args) __progname++; } + __init_time(); __init_image(args); __init_dlfcn(args); __init_fork(); diff --git a/src/kernel/libroot/os/arch/x86/Jamfile b/src/kernel/libroot/os/arch/x86/Jamfile index fafee12999..067ad0b68f 100644 --- a/src/kernel/libroot/os/arch/x86/Jamfile +++ b/src/kernel/libroot/os/arch/x86/Jamfile @@ -1,15 +1,15 @@ SubDir OBOS_TOP src kernel libroot os arch x86 ; KernelMergeObject os_arch_$(OBOS_ARCH).o : - <$(SOURCE_GRIST)>atomic.S - <$(SOURCE_GRIST)>byteorder.S - <$(SOURCE_GRIST)>cpuid.S - <$(SOURCE_GRIST)>systeminfo.c - <$(SOURCE_GRIST)>system_time.S - <$(SOURCE_GRIST)>thread.c - <$(SOURCE_GRIST)>tls.c - : - -fPIC -DPIC + atomic.S + byteorder.S + cpuid.S + systeminfo.c + system_time.S + thread.c + time.c + tls.c + : -fPIC -DPIC ; MergeObjectFromObjects kernel_os_arch_$(OBOS_ARCH).o : diff --git a/src/kernel/libroot/os/arch/x86/time.c b/src/kernel/libroot/os/arch/x86/time.c new file mode 100644 index 0000000000..80c312d1a3 --- /dev/null +++ b/src/kernel/libroot/os/arch/x86/time.c @@ -0,0 +1,19 @@ +/* + * Copyright 2004, Axel Dörfler, axeld@pinc-software.de. + * Distributed under the terms of the MIT License. + */ + + +#include +#include +#include + + +void +__arch_init_time(struct real_time_data *data) +{ + // 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); +} + diff --git a/src/kernel/libroot/os/time.c b/src/kernel/libroot/os/time.c index 5de2fb9b8a..8fd8b28a8a 100644 --- a/src/kernel/libroot/os/time.c +++ b/src/kernel/libroot/os/time.c @@ -1,48 +1,54 @@ /* -** Copyright 2002-2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ + * Copyright 2002-2004, Axel Dörfler, axeld@pinc-software.de. + * Distributed under the terms of the MIT License. + */ #include + #include -#include "syscalls.h" -#include "real_time_data.h" +#include -static volatile bigtime_t *sBootTime = NULL; +#include +#include +#include -static status_t -setup_rtc_boottime() + +static struct real_time_data sRealTimeDefaults = { + 0, + 100000 +}; +static struct real_time_data *sRealTimeData; + + +void +__init_time(void) { area_id dataArea; area_info info; - status_t err; dataArea = find_area("real time data userland"); - - if (dataArea < 0) { - printf("setup_rtc_boottime: error finding real time data area %s\n", - strerror(dataArea)); - return dataArea; - } + 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; + } else + sRealTimeData = (struct real_time_data *)info.address; - err = get_area_info(dataArea, &info); - if (err < B_OK) { - printf("setup_rtc_boottime: error getting real time data info\n"); - return err; - } - - sBootTime = &(((struct real_time_data *)info.address)->boot_time); - return B_OK; + __arch_init_time(sRealTimeData); } uint32 real_time_clock(void) { - if (!sBootTime && (setup_rtc_boottime()!=B_OK)) - return 0; - return (*sBootTime + system_time()) / 1000000; + return (sRealTimeData->boot_time + system_time()) / 1000000; +} + + +bigtime_t +real_time_clock_usecs(void) +{ + return sRealTimeData->boot_time + system_time(); } @@ -53,15 +59,6 @@ set_real_time_clock(uint32 secs) } -bigtime_t -real_time_clock_usecs(void) -{ - if (!sBootTime && (setup_rtc_boottime() != B_OK)) - return 0; - return *sBootTime + system_time(); -} - - status_t set_timezone(char *timezone) { @@ -70,17 +67,6 @@ set_timezone(char *timezone) } -/* -// ToDo: currently defined in atomic.S - but should be in its own file time.S -bigtime_t -system_time(void) -{ - // time since booting in microseconds - return sys_system_time(); -} -*/ - - bigtime_t set_alarm(bigtime_t when, uint32 flags) {