Major changes to how SimObjects are created and initialized. Almost all
[gem5.git] / src / dev / sparc / dtod.cc
index 30c7baaf5fd88ddbfb46d17c99669d0d4b508f66..7e948085e2d6b7bbb8ccdbf7a53e03279dfd9c64 100644 (file)
 #include <string>
 #include <vector>
 
+#include "base/time.hh"
 #include "base/trace.hh"
 #include "dev/sparc/dtod.hh"
 #include "dev/platform.hh"
 #include "mem/packet_access.hh"
 #include "mem/port.hh"
-#include "sim/builder.hh"
 #include "sim/system.hh"
 
 using namespace std;
 using namespace TheISA;
 
-DumbTOD::DumbTOD(Params *p)
-    : BasicPioDevice(p), todTime(p->init_time)
+DumbTOD::DumbTOD(const Params *p)
+    : BasicPioDevice(p)
 {
+    struct tm tm = p->time;
+    char *tz;
+
     pioSize = 0x08;
 
-    struct tm tm;
-    gmtime_r((time_t*)&todTime, &tm);
+    tz = getenv("TZ");
+    setenv("TZ", "", 1);
+    tzset();
+    todTime = mktime(&tm);
+    if (tz)
+        setenv("TZ", tz, 1);
+    else
+        unsetenv("TZ");
+    tzset();
+
     DPRINTFN("Real-time clock set to %s\n", asctime(&tm));
     DPRINTFN("Real-time clock set to %d\n", todTime);
 }
@@ -80,36 +91,20 @@ DumbTOD::write(PacketPtr pkt)
     panic("Dumb tod device doesn't support writes\n");
 }
 
-BEGIN_DECLARE_SIM_OBJECT_PARAMS(DumbTOD)
-
-    Param<Addr> pio_addr;
-    Param<Tick> pio_latency;
-    SimObjectParam<Platform *> platform;
-    SimObjectParam<System *> system;
-    Param<time_t> time;
-
-END_DECLARE_SIM_OBJECT_PARAMS(DumbTOD)
-
-BEGIN_INIT_SIM_OBJECT_PARAMS(DumbTOD)
-
-    INIT_PARAM(pio_addr, "Device Address"),
-    INIT_PARAM(pio_latency, "Programmed IO latency"),
-    INIT_PARAM(platform, "platform"),
-    INIT_PARAM(system, "system object"),
-    INIT_PARAM(time, "System time to use (0 for actual time")
-
-END_INIT_SIM_OBJECT_PARAMS(DumbTOD)
+void
+DumbTOD::serialize(std::ostream &os)
+{
+    SERIALIZE_SCALAR(todTime);
+}
 
-CREATE_SIM_OBJECT(DumbTOD)
+void
+DumbTOD::unserialize(Checkpoint *cp, const std::string &section)
 {
-    DumbTOD::Params *p = new DumbTOD::Params;
-    p->name =getInstanceName();
-    p->pio_addr = pio_addr;
-    p->pio_delay = pio_latency;
-    p->platform = platform;
-    p->system = system;
-    p->init_time = time;
-    return new DumbTOD(p);
+    UNSERIALIZE_SCALAR(todTime);
 }
 
-REGISTER_SIM_OBJECT("DumbTOD", DumbTOD)
+DumbTOD *
+DumbTODParams::create()
+{
+    return new DumbTOD(this);
+}