time_t: Fix up all the time_t stuff in libc for 32bit afflicted platforms
authorAlan Cox <alan@linux.intel.com>
Fri, 23 Jan 2015 00:23:06 +0000 (00:23 +0000)
committerAlan Cox <alan@linux.intel.com>
Fri, 23 Jan 2015 00:23:06 +0000 (00:23 +0000)
Trying to get the 6502 to do 64bit time_t would be the alterntative for some
crazy cc65 hacker

12 files changed:
Kernel/include/syscall_name.h
Library/include/sys/types.h
Library/include/syscalls.h
Library/libs/Makefile
Library/libs/Makefile.6502
Library/libs/clock_gettime.c
Library/libs/clock_settime.c
Library/libs/fuzix/Makefile
Library/libs/gettimeofday.c
Library/libs/settimeofday.c
Library/libs/sleep.c
Library/libs/time.c

index e4d182a..18f05ca 100644 (file)
@@ -31,7 +31,7 @@ char *syscall_name[NR_SYSCALL] = {
        "setuid",
        "setgid",
        "_time",
-       "stime",
+       "_stime",
        "ioctl",
        "brk",
        "sbrk",
index 6d04f91..ff39a69 100644 (file)
@@ -64,8 +64,16 @@ typedef uint16_t ino_t;
 
 #if defined(NO_64BIT)
 typedef uint32_t time_t;
+/* For kernel struct alignment */
+typedef struct {
+  uint32_t time;
+  uint32_t pad;
+} __ktime_t;
 #else
 typedef int64_t time_t;
+typedef struct {
+  uint64_t time;
+} __ktime_t;
 #endif
 typedef int32_t clock_t;
 #endif
index c11b021..6c097a9 100644 (file)
@@ -131,10 +131,10 @@ extern int _getdirent(int fd, void *buf, int len);
 extern int _stat(const char *path, struct _uzistat *s);
 extern int _fstat(int fd, struct _uzistat *s);
 extern int _getfsys(uint16_t dev, struct _uzifilesys *fs);
-extern int _time(time_t *t, uint16_t clock);
-extern int _stime(const time_t *t, uint16_t clock);
+extern int _time(__ktime_t *t, uint16_t clock);
+extern int _stime(const __ktime_t *t, uint16_t clock);
 extern int _times(struct tms *t);
-extern int _utime(const char *file, time_t *buf);
+extern int _utime(const char *file, __ktime_t *buf);
 extern int _uname(struct _uzisysinfoblk *uzib, int len);
 extern int _profil(void *samples, uint16_t offset, uint16_t size, int16_t scale);
 extern int _lseek(int fd, off_t *offset, int mode);
@@ -144,7 +144,7 @@ extern int stat(const char *path, struct stat *s);
 extern int fstat(int fd, struct stat *s);
 extern int alarm(uint16_t seconds);
 extern time_t time(time_t *t);
-extern int stime(time_t *t);
+extern int stime(const time_t *t);
 extern int times(struct tms *tms);
 extern int utime(const char *filename, const struct utimbuf *utim);
 extern int uname(struct utsname *buf);
index 99f0262..2f5d734 100644 (file)
@@ -29,7 +29,8 @@ SRC_C += malloc.c mkfifo.c nanosleep.c opendir.c pause.c perror.c
 SRC_C += popen.c printf.c putenv.c putgetch.c putpwent.c pwent.c qsort.c
 SRC_C += raise.c rand.c readdir.c readlink.c realloc.c regerror.c
 SRC_C += regsub.c remove.c rewind.c rindex.c setbuffer.c setenv.c setjmp.c
-SRC_C += setlocale.c setvbuf.c settimeofday.c sleep.c sprintf.c stat.c stdio0.c
+SRC_C += setlocale.c setvbuf.c settimeofday.c sleep.c sprintf.c 
+SRC_C += stat.c stdio0.c stime.c
 SRC_C += strcasecmp.c strcasestr.c strdup.c stricmp.c strlcpy.c strncasecmp.c
 SRC_C += strnlen.c strnicmp.c strsep.c strxfrm.c strcoll.c
 SRC_C += strtod.c strtol.c system.c time.c tmpnam.c ttyname.c
index 7a8c3f6..3481693 100644 (file)
@@ -47,7 +47,8 @@ SRC_C += malloc.c mkfifo.c nanosleep.c opendir.c pause.c perror.c
 SRC_C += popen.c printf.c putenv.c putgetch.c putpwent.c pwent.c qsort.c
 SRC_C += raise.c rand.c readdir.c readlink.c realloc.c regerror.c
 SRC_C += regsub.c remove.c rewind.c rindex.c setbuffer.c setenv.c setjmp.c
-SRC_C += setlocale.c setvbuf.c settimeofday.c sleep.c sprintf.c stat.c stdio0.c
+SRC_C += setlocale.c setvbuf.c settimeofday.c sleep.c sprintf.c
+SRC_C += stat.c stdio0.c stime.c
 SRC_C += strcasecmp.c strcasestr.c strdup.c stricmp.c strlcpy.c strncasecmp.c
 SRC_C += strnicmp.c strnlen.c strsep.c
 SRC_C += system.c time.c tmpnam.c ttyname.c
index 08053bf..cfcdcff 100644 (file)
@@ -25,13 +25,17 @@ int clock_gettime(clockid_t clk_id, struct timespec *res)
 {
   int r;
   unsigned long d;
+  __ktime_t tmp;
+
   res->tv_nsec = 0;
   switch(clk_id) {
   case CLOCK_REALTIME:
-    _time(&res->tv_sec, 0);
+    _time(&tmp, 0);
+    res->tv_sec = tmp.time;
     return 0;
   case CLOCK_MONOTONIC:
-    _time(&res->tv_sec, 1);
+    _time(&tmp, 1);
+    res->tv_sec = tmp.time;
     d = res->tv_sec;
     /* We know that this wraps at 2^32 ticks which also means we know
        it'll fit 32bits */
index 084fa35..b6fdf18 100644 (file)
@@ -6,7 +6,7 @@ int clock_settime(clockid_t clk_id, const struct timespec *tp)
 {
   switch(clk_id) {
   case CLOCK_REALTIME:
-    _stime(&tp->tv_sec, 0);
+    stime(&tp->tv_sec);
     return 0;
   case CLOCK_MONOTONIC:
     return -EPERM;
index 4424cf6..d5ddf5d 100644 (file)
@@ -33,7 +33,7 @@ ASRCS += syscall__getdirent.s
 ASRCS += syscall_setuid.s
 ASRCS += syscall_setgid.s
 ASRCS += syscall__time.s
-ASRCS += syscall_stime.s
+ASRCS += syscall__stime.s
 ASRCS += syscall_ioctl.s
 ASRCS += syscall_brk.s
 ASRCS += syscall_sbrk.s
@@ -66,6 +66,8 @@ ASRCS += syscall_uadmin.s
 ASRCS += syscall_nice.s
 ASRCS += syscall__sigdisp.s
 ASRCS += syscall_flock.s
+ASRCS += syscall_getpgrp.s
+ASRCS += syscall_yield.s
 
 
 ASRCALL = $(ASRCS) $(ASYS)
index 22db97f..38cbec8 100644 (file)
@@ -6,7 +6,7 @@
 int gettimeofday(struct timeval *tv, struct timezone *tz)
 {
   if (tv) {
-    _time(&tv->tv_sec, 0);
+    time(&tv->tv_sec);
     tv->tv_usec = 0;
   }
   if (tz) {
index 8611573..ab5c92e 100644 (file)
@@ -7,7 +7,7 @@ int settimeofday(struct timeval *tv, const struct timezone *tz)
 {
   int ret = 0;
   if (tv) {
-    ret = _stime(&tv->tv_sec, 0);
+    ret = stime(&tv->tv_sec);
   }
   return ret;
 }
index 4fe3505..c8153f2 100644 (file)
@@ -8,7 +8,7 @@
 /* Divide by ten in shifts. Would be nice if the compiler did that for us 8)
 
    FIXME: probably worth having a Z80 asm version of this */
-static div10quicki(unsigned int i)
+static unsigned int div10quicki(unsigned int i)
 {
        unsigned int q, r;
        q = (i >> 1) + (i >> 2);
@@ -21,11 +21,11 @@ static div10quicki(unsigned int i)
 
 unsigned int sleep(unsigned int seconds)
 {
-       time_t end, now;
+       __ktime_t end, now;
        _time(&end, 1); /* in 1/10ths */
-       end += seconds * 10;
+       end.time += seconds * 10;
        if (_pause(seconds * 10) == 0)
                return 0;
        _time(&now, 1);
-       return div10quicki(end - now);
+       return div10quicki(end.time - now.time);
 }
index c394c4b..da90a58 100644 (file)
@@ -8,11 +8,11 @@
  */
 time_t time(time_t *t)
 {
-  time_t tmp;
-  if (t) {
-    _time(t, 0);
-    return *t;
-  }
+  static time_t tr;
+  __ktime_t tmp;
   _time(&tmp, 0);
-  return tmp;
+  tr = tmp.time;
+  if (t)
+    *t = tr;
+  return tr;
 }