Devices: Make the Intel8254Timer device only use pointers to its counters.
authorGabe Black <gblack@eecs.umich.edu>
Sat, 11 Oct 2008 08:49:39 +0000 (01:49 -0700)
committerGabe Black <gblack@eecs.umich.edu>
Sat, 11 Oct 2008 08:49:39 +0000 (01:49 -0700)
src/dev/alpha/tsunami_io.cc
src/dev/intel_8254_timer.cc
src/dev/intel_8254_timer.hh
src/dev/x86/pc.cc
src/dev/x86/south_bridge/i8254.cc
src/dev/x86/south_bridge/speaker.cc

index 2aaf323a2ecff8c270e4ef22f9985ab3d197f521..9c88904e32921ddf1012c181b7e33975c5fd46fa 100644 (file)
@@ -114,19 +114,19 @@ TsunamiIO::read(PacketPtr pkt)
               pkt->set(0x00);
               break;
           case TSDEV_TMR0_DATA:
-            pkt->set(pitimer.counter0.read());
+            pkt->set(pitimer.readCounter(0));
             break;
           case TSDEV_TMR1_DATA:
-            pkt->set(pitimer.counter1.read());
+            pkt->set(pitimer.readCounter(1));
             break;
           case TSDEV_TMR2_DATA:
-            pkt->set(pitimer.counter2.read());
+            pkt->set(pitimer.readCounter(2));
             break;
           case TSDEV_RTC_DATA:
             pkt->set(rtc.readData(rtcAddr));
             break;
           case TSDEV_CTRL_PORTB:
-            if (pitimer.counter2.outputHigh())
+            if (pitimer.outputHigh(2))
                 pkt->set(PORTB_SPKR_HIGH);
             else
                 pkt->set(0x00);
@@ -189,13 +189,13 @@ TsunamiIO::write(PacketPtr pkt)
         mode2 = pkt->get<uint8_t>();
         break;
       case TSDEV_TMR0_DATA:
-        pitimer.counter0.write(pkt->get<uint8_t>());
+        pitimer.writeCounter(0, pkt->get<uint8_t>());
         break;
       case TSDEV_TMR1_DATA:
-        pitimer.counter1.write(pkt->get<uint8_t>());
+        pitimer.writeCounter(1, pkt->get<uint8_t>());
         break;
       case TSDEV_TMR2_DATA:
-        pitimer.counter2.write(pkt->get<uint8_t>());
+        pitimer.writeCounter(2, pkt->get<uint8_t>());
         break;
       case TSDEV_TMR_CTRL:
         pitimer.writeControl(pkt->get<uint8_t>());
index 27f55fd9295723717fb272ad6e528d2977eb29ee..35fbd9c38a5aaddecf860a56a064e2ee8634e313 100644 (file)
 
 using namespace std;
 
-Intel8254Timer::Intel8254Timer(EventManager *em, const string &name)
-    : EventManager(em), _name(name),
-      counter0(this, name + ".counter0"),
-      counter1(this, name + ".counter1"),
-      counter2(this, name + ".counter2")
+Intel8254Timer::Intel8254Timer(EventManager *em, const string &name,
+    Counter *counter0, Counter *counter1, Counter *counter2) :
+    EventManager(em), _name(name)
 {
-    counter[0] = &counter0;
-    counter[1] = &counter0;
-    counter[2] = &counter0;
+    counter[0] = counter0;
+    counter[1] = counter1;
+    counter[2] = counter2;
+}
+
+Intel8254Timer::Intel8254Timer(EventManager *em, const string &name) :
+    EventManager(em), _name(name)
+{
+    counter[0] = new Counter(this, name + ".counter0");
+    counter[1] = new Counter(this, name + ".counter1");
+    counter[2] = new Counter(this, name + ".counter2");
 }
 
 void
@@ -67,9 +73,9 @@ void
 Intel8254Timer::serialize(const string &base, ostream &os)
 {
     // serialize the counters
-    counter0.serialize(base + ".counter0", os);
-    counter1.serialize(base + ".counter1", os);
-    counter2.serialize(base + ".counter2", os);
+    counter[0]->serialize(base + ".counter0", os);
+    counter[1]->serialize(base + ".counter1", os);
+    counter[2]->serialize(base + ".counter2", os);
 }
 
 void
@@ -77,9 +83,9 @@ Intel8254Timer::unserialize(const string &base, Checkpoint *cp,
         const string &section)
 {
     // unserialze the counters
-    counter0.unserialize(base + ".counter0", cp, section);
-    counter1.unserialize(base + ".counter1", cp, section);
-    counter2.unserialize(base + ".counter2", cp, section);
+    counter[0]->unserialize(base + ".counter0", cp, section);
+    counter[1]->unserialize(base + ".counter1", cp, section);
+    counter[2]->unserialize(base + ".counter2", cp, section);
 }
 
 Intel8254Timer::Counter::Counter(Intel8254Timer *p, const string &name)
index 439432aed429ee4cc47feb495f7fb96a32d25312..9391b0f9efc9400276f5d599bfa517de170d935a 100644 (file)
@@ -44,6 +44,7 @@
 /** Programmable Interval Timer (Intel 8254) */
 class Intel8254Timer : public EventManager
 {
+  protected:
     BitUnion8(CtrlReg)
         Bitfield<7, 6> sel;
         Bitfield<5, 4> rw;
@@ -173,7 +174,7 @@ class Intel8254Timer : public EventManager
                          const std::string &section);
     };
 
-  private:
+  protected:
     std::string _name;
     const std::string &name() const { return _name; }
 
@@ -181,16 +182,36 @@ class Intel8254Timer : public EventManager
     Counter *counter[3];
 
   public:
-    /** Public way to access individual counters (avoid array accesses) */
-    Counter counter0;
-    Counter counter1;
-    Counter counter2;
+
+    Intel8254Timer(EventManager *em, const std::string &name,
+            Counter *counter0, Counter *counter1, Counter *counter2);
 
     Intel8254Timer(EventManager *em, const std::string &name);
 
     /** Write control word */
     void writeControl(const CtrlReg data);
 
+    uint8_t
+    readCounter(unsigned int num)
+    {
+        assert(num < 3);
+        return counter[num]->read();
+    }
+
+    void
+    writeCounter(unsigned int num, const uint8_t data)
+    {
+        assert(num < 3);
+        counter[num]->write(data);
+    }
+
+    bool
+    outputHigh(unsigned int num)
+    {
+        assert(num < 3);
+        return counter[num]->outputHigh();
+    }
+
     /**
      * Serialize this object to the given output stream.
      * @param base The base name of the counter object.
index d04529ab9bfa5e4bf93d3e0c85c7ed4f4d517eb3..3de28bce5585b38e3c68c4f10bb61f2e046ab9a8 100644 (file)
@@ -64,8 +64,8 @@ PC::init()
     //Timer 0, latch command
     timer.writeControl(0x00);
     //Write a 16 bit count of 0
-    timer.counter0.write(0);
-    timer.counter0.write(0);
+    timer.writeCounter(0, 0);
+    timer.writeCounter(0, 0);
 }
 
 Tick
index 7c3501c373f30a316ff9625850e60664c1c1f57c..c9c0d625a443880e416de6e9a7be5782d23f8b12 100644 (file)
@@ -38,13 +38,13 @@ X86ISA::I8254::read(PacketPtr pkt)
     switch(pkt->getAddr() - addrRange.start)
     {
       case 0x0:
-        pkt->set(pit.counter0.read());
+        pkt->set(pit.readCounter(0));
         break;
       case 0x1:
-        pkt->set(pit.counter1.read());
+        pkt->set(pit.readCounter(1));
         break;
       case 0x2:
-        pkt->set(pit.counter2.read());
+        pkt->set(pit.readCounter(2));
         break;
       case 0x3:
         pkt->set(uint8_t(-1));
@@ -62,13 +62,13 @@ X86ISA::I8254::write(PacketPtr pkt)
     switch(pkt->getAddr() - addrRange.start)
     {
       case 0x0:
-        pit.counter0.write(pkt->get<uint8_t>());
+        pit.writeCounter(0, pkt->get<uint8_t>());
         break;
       case 0x1:
-        pit.counter1.write(pkt->get<uint8_t>());
+        pit.writeCounter(1, pkt->get<uint8_t>());
         break;
       case 0x2:
-        pit.counter2.write(pkt->get<uint8_t>());
+        pit.writeCounter(2, pkt->get<uint8_t>());
         break;
       case 0x3:
         pit.writeControl(pkt->get<uint8_t>());
index 784c9504b7259ac4b9035823978448f4488380bc..59a86c634afc954ca61348e54ec90dcfecdf3262 100644 (file)
@@ -39,7 +39,7 @@ X86ISA::Speaker::read(PacketPtr pkt)
 {
     assert(pkt->getAddr() == addrRange.start);
     assert(pkt->getSize() == 1);
-    controlVal.timer = timer->pit.counter2.outputHigh() ? 1 : 0;
+    controlVal.timer = timer->pit.outputHigh(2) ? 1 : 0;
     DPRINTF(PCSpeaker,
             "Reading from speaker device: gate %s, speaker %s, output %s.\n",
             controlVal.gate ? "on" : "off",