time_t: use a 32bit pair in kernel
authorAlan Cox <alan@etchedpixels.co.uk>
Fri, 28 Nov 2014 22:34:44 +0000 (22:34 +0000)
committerAlan Cox <alan@etchedpixels.co.uk>
Fri, 28 Nov 2014 22:34:44 +0000 (22:34 +0000)
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
Kernel/cpu-6809/cpu.h
Kernel/cpu-z80/cpu.h
Kernel/filesys.c
Kernel/syscall_fs2.c
Kernel/timer.c

index f2cf506..eb39e67 100644 (file)
@@ -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
index bbb83dd..4d676ac 100644 (file)
@@ -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)
index 849bd25..a669a4a 100644 (file)
@@ -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
index 2ea3151..00d1c26 100644 (file)
@@ -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;
index 3342d5f..26d074a 100644 (file)
@@ -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);
index 09acd70..76321f9 100644 (file)
@@ -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 */