Devices: Make the Intel8254Timer device only use pointers to its counters.

This commit is contained in:
Gabe Black
2008-10-11 01:49:39 -07:00
parent 539563e04b
commit a6600fdd88
6 changed files with 62 additions and 35 deletions

View 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>());

View File

@@ -35,15 +35,21 @@
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)

View 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.

View 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

View 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>());

View 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",