00001 // _Id: sysgettim.c,v 1.10 2006-04-04 07:26:33 roart Exp $ 00002 // _Locker: $ 00003 00004 // Author. Paul Nankervis. 00005 00006 /* 00007 00008 VMSTIME.C v1.1 00009 00010 Author: Paul Nankervis 00011 00012 Please send bug reports or requests for enhancement 00013 or improvement via email to: PaulNank@au1.ibm.com 00014 00015 00016 This module contains versions of the VMS time routines 00017 sys_numtim(), sys$asctim() and friends... They are 00018 intended to be compatible with the routines of the same 00019 name on a VMS system (so descriptors feature regularly!) 00020 00021 This code relies on being able to manipluate day numbers 00022 and times using 32 bit arithmetic to crack a VMS quadword 00023 byte by byte. If your C compiler doesn't have 32 bit int 00024 fields give up now! On a 64 bit systems this code could 00025 be modified to do 64 bit operations directly.... 00026 00027 One advantage of doing arihmetic byte by byte is that 00028 the code does not depend on what 'endian' the target 00029 machine is - it will always treat bytes in the same order! 00030 (Hopefully VMS time bytes will always be in the same order!) 00031 00032 A couple of stupid questions to go on with:- 00033 o OK, I give up! What is the difference between a zero 00034 date and a zero delta time? 00035 o Anyone notice that the use of 16 bit words in 00036 sys_numtim restricts delta times to 65535 days? 00037 00038 Paul Nankervis 00039 00040 History: 00041 02/12/1998 - Kevin Handy 00042 This funtion returns a time based upon GMT, and 00043 is thus off if you are in the wrong area. 00044 Added use of localtime()/timezone to adjust date 00045 (Probibly did it wrong, but ...). 00046 */ 00047 00048 /* Some mods by Roar Thronęs */ 00049 00050 #include <system_data_cells.h> /* SYS_ header file */ 00051 #include <sys_routines.h> /* SYS$ header file */ 00052 #include <ssdef.h> /* SYS_ header file */ 00053 #include <linux/time.h> /* C header for _GETTIM to find time */ 00054 #include<linux/linkage.h> 00055 #include <linux/string.h> 00056 00057 /* 00058 * Special function that is not really part of SYS_ library 00059 */ 00060 unsigned long sys___combine_date_time(int days, void *timadr,int day_time); 00061 00062 /* 00063 * This variable is set by the Unix localtime() function 00064 * and contains the offset from UTC for the locale. 00065 */ 00066 extern long timezone; 00067 00068 /* sys_gettim() implemented here by getting UNIX time in seconds since 00069 1-Jan-1970 using time() and munging into a quadword... Some run time 00070 systems don't seem to do this properly!!! Note that time() has a 00071 resolution of only one second. */ 00072 00073 #define SECINDAY (24L * 60L * 60L) 00074 #define FUDGEFACTOR 40587 00075 00076 asmlinkage int exe_gettim(unsigned long long *timadr) 00077 { 00078 long * tmp=(long *)&exe_gq_systime, *tmp2=(long *)timadr; 00079 if (!timadr) return SS__ACCVIO; 00080 if (timadr<4096) { 00081 #if 0 00082 printk("gettim got accvio addr\n"); 00083 #endif 00084 return SS__ACCVIO; 00085 } 00086 memcpy(timadr,&exe_gq_systime,8); 00087 #if 0 00088 printk("setime %x %x\n",tmp[0],tmp[1]); 00089 printk("setime %x %x\n",tmp2[0],tmp2[1]); 00090 #endif 00091 return SS__NORMAL; 00092 } 00093