haiku/src/system/libroot/os/time.c

101 lines
1.8 KiB
C
Raw Normal View History

/*
* Copyright 2002-2006, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License.
*/
#include <commpage_defs.h>
#include <libroot_private.h>
#include <real_time_data.h>
#include <syscalls.h>
#include <FindDirectory.h>
#include <OS.h>
#include <stdio.h>
#include <string.h>
#include <syslog.h>
static struct real_time_data *sRealTimeData;
void
__init_time(void)
{
Merged branch haiku/branches/developer/bonefish/optimization revision 23139 into trunk, with roughly the following changes (for details svn log the branch): * The int 99 syscall handler is now fully in assembly. * Added a sysenter/sysexit handler and use it on Pentiums that support it (via commpage). * Got rid of i386_handle_trap(). A bit of functionality was moved into the assembly handler which now uses a jump table to call C functions handling the respective interrupt. * Some optimizations to get user debugger support code out of the interrupt handling path. * Introduced a thread::flags fields which allows to skip handling of rare events (signals, user debug enabling/disabling) on the common interrupt handling path. * Got rid of the explicit iframe stack. The iframes can still be retrieved by iterating through the stack frames. * Made the commpage an architecture independent feature. It's used for the real time data stuff (instead of creating a separate area). * The x86 CPU modules can now provide processor optimized versions for common functions (currently memcpy() only). They are used in the kernel and are provided to the userland via commpage entries. * Introduced build system feature allowing easy use of C structure member offsets in assembly code. Changes after merging: * Fixed merge conflict in src/system/kernel/arch/x86/arch_debug.cpp (caused by refactoring and introduction of "call" debugger command). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23370 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-01-11 03:36:44 +03:00
sRealTimeData = (struct real_time_data*)
USER_COMMPAGE_TABLE[COMMPAGE_ENTRY_REAL_TIME_DATA];
__arch_init_time(sRealTimeData, false);
}
uint32
real_time_clock(void)
{
return (__arch_get_system_time_offset(sRealTimeData) + system_time())
/ 1000000;
}
bigtime_t
real_time_clock_usecs(void)
{
return __arch_get_system_time_offset(sRealTimeData) + system_time();
}
void
set_real_time_clock(uint32 secs)
{
_kern_set_real_time_clock(secs);
}
status_t
set_timezone(char *timezone)
{
char path[B_PATH_NAME_LENGTH];
char tzfilename[B_PATH_NAME_LENGTH];
bool isGMT;
status_t err;
struct tm *tm;
time_t t;
if ((err = find_directory(B_USER_SETTINGS_DIRECTORY, -1, true, path, B_PATH_NAME_LENGTH)) != B_OK) {
fprintf(stderr, "can't find settings directory: %s\n", strerror(err));
return err;
}
strcat(path, "/timezone");
err = unlink(path);
if (err != B_OK) {
fprintf(stderr, "can't unlink: %s\n", strerror(err));
return err;
}
err = symlink(timezone, path);
if (err != B_OK) {
fprintf(stderr, "can't symlink: %s\n", strerror(err));
return err;
}
_kern_get_tzfilename(tzfilename, sizeof(tzfilename), &isGMT);
_kern_set_tzfilename(timezone, strlen(timezone), isGMT);
tzset();
time(&t);
tm = localtime(&t);
if ((err = _kern_set_timezone(tm->tm_gmtoff, tm->tm_isdst)) < B_OK)
return err;
return B_OK;
}
bigtime_t
set_alarm(bigtime_t when, uint32 mode)
{
return _kern_set_alarm(when, mode);
}