From: Alan Cox Date: Fri, 23 Jan 2015 00:23:06 +0000 (+0000) Subject: time_t: Fix up all the time_t stuff in libc for 32bit afflicted platforms X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=a2b17a36758437217f2930c94cee7f0723f51821;p=FUZIX.git time_t: Fix up all the time_t stuff in libc for 32bit afflicted platforms Trying to get the 6502 to do 64bit time_t would be the alterntative for some crazy cc65 hacker --- diff --git a/Kernel/include/syscall_name.h b/Kernel/include/syscall_name.h index e4d182a0..18f05cae 100644 --- a/Kernel/include/syscall_name.h +++ b/Kernel/include/syscall_name.h @@ -31,7 +31,7 @@ char *syscall_name[NR_SYSCALL] = { "setuid", "setgid", "_time", - "stime", + "_stime", "ioctl", "brk", "sbrk", diff --git a/Library/include/sys/types.h b/Library/include/sys/types.h index 6d04f910..ff39a69b 100644 --- a/Library/include/sys/types.h +++ b/Library/include/sys/types.h @@ -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 diff --git a/Library/include/syscalls.h b/Library/include/syscalls.h index c11b0213..6c097a9f 100644 --- a/Library/include/syscalls.h +++ b/Library/include/syscalls.h @@ -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); diff --git a/Library/libs/Makefile b/Library/libs/Makefile index 99f02625..2f5d734f 100644 --- a/Library/libs/Makefile +++ b/Library/libs/Makefile @@ -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 diff --git a/Library/libs/Makefile.6502 b/Library/libs/Makefile.6502 index 7a8c3f65..34816938 100644 --- a/Library/libs/Makefile.6502 +++ b/Library/libs/Makefile.6502 @@ -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 diff --git a/Library/libs/clock_gettime.c b/Library/libs/clock_gettime.c index 08053bfd..cfcdcff6 100644 --- a/Library/libs/clock_gettime.c +++ b/Library/libs/clock_gettime.c @@ -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 */ diff --git a/Library/libs/clock_settime.c b/Library/libs/clock_settime.c index 084fa359..b6fdf18b 100644 --- a/Library/libs/clock_settime.c +++ b/Library/libs/clock_settime.c @@ -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; diff --git a/Library/libs/fuzix/Makefile b/Library/libs/fuzix/Makefile index 4424cf6b..d5ddf5d9 100644 --- a/Library/libs/fuzix/Makefile +++ b/Library/libs/fuzix/Makefile @@ -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) diff --git a/Library/libs/gettimeofday.c b/Library/libs/gettimeofday.c index 22db97f8..38cbec86 100644 --- a/Library/libs/gettimeofday.c +++ b/Library/libs/gettimeofday.c @@ -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) { diff --git a/Library/libs/settimeofday.c b/Library/libs/settimeofday.c index 86115735..ab5c92e0 100644 --- a/Library/libs/settimeofday.c +++ b/Library/libs/settimeofday.c @@ -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; } diff --git a/Library/libs/sleep.c b/Library/libs/sleep.c index 4fe35056..c8153f2b 100644 --- a/Library/libs/sleep.c +++ b/Library/libs/sleep.c @@ -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); } diff --git a/Library/libs/time.c b/Library/libs/time.c index c394c4b7..da90a588 100644 --- a/Library/libs/time.c +++ b/Library/libs/time.c @@ -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; }