From e70a35920597d81aa69b20fa17a844b89f843cf5 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 28 Nov 2014 22:34:44 +0000 Subject: [PATCH] time_t: use a 32bit pair in kernel While SDCC has a full 64bit longlong the other compilers are sadly lacking at the moment. For the kernel the easiest thing to do is to work in 32bit chunks, it's not as if the CPU can do better than 16bits at a go anyway --- Kernel/cpu-6502/cpu.h | 6 ++++-- Kernel/cpu-6809/cpu.h | 5 ++++- Kernel/cpu-z80/cpu.h | 6 +++++- Kernel/filesys.c | 4 ++-- Kernel/syscall_fs2.c | 4 ++-- Kernel/timer.c | 5 +++-- 6 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Kernel/cpu-6502/cpu.h b/Kernel/cpu-6502/cpu.h index f2cf5069..eb39e672 100644 --- a/Kernel/cpu-6502/cpu.h +++ b/Kernel/cpu-6502/cpu.h @@ -24,8 +24,10 @@ extern size_t strlen(const char *); #define staticfast static -/* FIXME: need to add 64bit helper/struct magic for this compiler */ -typedef unsigned long time_t; +typedef struct { + uint32_t low; + uint32_t high; +} time_t; /* We don't yet have bank attributes and banking for Z80 */ #define CODE1 diff --git a/Kernel/cpu-6809/cpu.h b/Kernel/cpu-6809/cpu.h index bbb83dd6..4d676aca 100644 --- a/Kernel/cpu-6809/cpu.h +++ b/Kernel/cpu-6809/cpu.h @@ -28,7 +28,10 @@ extern uint16_t swab(uint16_t); #define staticfast auto /* FIXME: should be 64bits - need to add helpers and struct variants */ -typedef unsigned long long time_t; +typedef struct { + uint32_t low; + uint32_t high; +} time_t; #define cpu_to_le16(x) swab(x) #define le16_to_cpu(x) swab(x) diff --git a/Kernel/cpu-z80/cpu.h b/Kernel/cpu-z80/cpu.h index 849bd258..a669a4a6 100644 --- a/Kernel/cpu-z80/cpu.h +++ b/Kernel/cpu-z80/cpu.h @@ -31,7 +31,11 @@ extern int16_t strlen(const char *p); #define staticfast static -typedef unsigned long long time_t; +/* Must match native ordering of long long */ +typedef struct { + uint32_t low; + uint32_t high; +} time_t; /* We don't yet have bank attributes and banking for Z80 */ #define CODE1 diff --git a/Kernel/filesys.c b/Kernel/filesys.c index 2ea31512..00d1c260 100644 --- a/Kernel/filesys.c +++ b/Kernel/filesys.c @@ -444,8 +444,8 @@ fsptr getdev(uint16_t dev) return NULL; } rdtime(&t); - devfs->s_time = (uint32_t)t; - devfs->s_timeh = (uint8_t)(t >> 32); + devfs->s_time = t.low; + devfs->s_timeh = t.high; devfs->s_fmod = true; ((bufptr)devfs)->bf_dirty = true; return devfs; diff --git a/Kernel/syscall_fs2.c b/Kernel/syscall_fs2.c index 3342d5f9..26d074a5 100644 --- a/Kernel/syscall_fs2.c +++ b/Kernel/syscall_fs2.c @@ -321,8 +321,8 @@ int16_t _utime(void) uget(buf, t, 2 * sizeof(time_t)); /* FIXME: needs updating once we pack top bits elsewhere in the inode */ - ino->c_node.i_atime = t[0]; - ino->c_node.i_mtime = t[1]; + ino->c_node.i_atime = t[0].low; + ino->c_node.i_mtime = t[1].low; setftime(ino, C_TIME); i_deref(ino); return (0); diff --git a/Kernel/timer.c b/Kernel/timer.c index 09acd709..76321f99 100644 --- a/Kernel/timer.c +++ b/Kernel/timer.c @@ -35,7 +35,7 @@ void rdtime(time_t *tloc) void rdtime32(uint32_t *tloc) { irqflags_t irq = di(); - *tloc = (uint32_t)tod; + *tloc = tod.low; irqrestore(irq); } @@ -58,6 +58,7 @@ void updatetod(void) if (++tod_deci != 10) return; tod_deci = 0; - tod++; + if (!++tod.low) + ++tod.high; } #endif /* NO_RTC */ -- 2.34.1