X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fdev%2Fintel_8254_timer.cc;h=5a0174d77311f79b5b7cd8bfc3d0e0a9458a260a;hb=abd33d6fd26bb69d3bf53ceb6c2dc8f90d893e34;hp=35fbd9c38a5aaddecf860a56a064e2ee8634e313;hpb=a6600fdd8885f9765c859935a5c97d9017653745;p=gem5.git diff --git a/src/dev/intel_8254_timer.cc b/src/dev/intel_8254_timer.cc index 35fbd9c38..5a0174d77 100644 --- a/src/dev/intel_8254_timer.cc +++ b/src/dev/intel_8254_timer.cc @@ -30,9 +30,11 @@ * Miguel J. Serrano */ -#include "base/misc.hh" #include "dev/intel_8254_timer.hh" +#include "base/logging.hh" +#include "debug/Intel8254Timer.hh" + using namespace std; Intel8254Timer::Intel8254Timer(EventManager *em, const string &name, @@ -47,9 +49,9 @@ Intel8254Timer::Intel8254Timer(EventManager *em, const string &name, 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"); + counter[0] = new Counter(this, name + ".counter0", 0); + counter[1] = new Counter(this, name + ".counter1", 1); + counter[2] = new Counter(this, name + ".counter2", 2); } void @@ -70,43 +72,66 @@ Intel8254Timer::writeControl(const CtrlReg data) } void -Intel8254Timer::serialize(const string &base, ostream &os) +Intel8254Timer::serialize(const string &base, CheckpointOut &cp) const { // serialize the counters - counter[0]->serialize(base + ".counter0", os); - counter[1]->serialize(base + ".counter1", os); - counter[2]->serialize(base + ".counter2", os); + counter[0]->serialize(base + ".counter0", cp); + counter[1]->serialize(base + ".counter1", cp); + counter[2]->serialize(base + ".counter2", cp); } void -Intel8254Timer::unserialize(const string &base, Checkpoint *cp, - const string §ion) +Intel8254Timer::unserialize(const string &base, CheckpointIn &cp) { // unserialze the counters - counter[0]->unserialize(base + ".counter0", cp, section); - counter[1]->unserialize(base + ".counter1", cp, section); - counter[2]->unserialize(base + ".counter2", cp, section); + counter[0]->unserialize(base + ".counter0", cp); + counter[1]->unserialize(base + ".counter1", cp); + counter[2]->unserialize(base + ".counter2", cp); } -Intel8254Timer::Counter::Counter(Intel8254Timer *p, const string &name) - : _name(name), event(this), count(0), latched_count(0), period(0), - mode(0), output_high(false), latch_on(false), read_byte(LSB), - write_byte(LSB), parent(p) +void +Intel8254Timer::startup() { + counter[0]->startup(); + counter[1]->startup(); + counter[2]->startup(); +} +Intel8254Timer::Counter::Counter(Intel8254Timer *p, + const string &name, unsigned int _num) + : _name(name), num(_num), event(this), running(false), + initial_count(0), latched_count(0), period(0), mode(0), + output_high(false), latch_on(false), read_byte(LSB), + write_byte(LSB), parent(p) +{ + offset = period * event.getInterval(); } void Intel8254Timer::Counter::latchCount() { // behave like a real latch - if(!latch_on) { + if (!latch_on) { latch_on = true; read_byte = LSB; - latched_count = count; + latched_count = currentCount(); } } +int +Intel8254Timer::Counter::currentCount() +{ + int clocks = event.clocksLeft(); + if (clocks == -1) { + warn_once("Reading current count from inactive timer.\n"); + return 0; + } + if (mode == RateGen || mode == SquareWave) + return clocks + 1; + else + return clocks; +} + uint8_t Intel8254Timer::Counter::read() { @@ -125,6 +150,7 @@ Intel8254Timer::Counter::read() panic("Shouldn't be here"); } } else { + uint16_t count = currentCount(); switch (read_byte) { case LSB: read_byte = MSB; @@ -145,7 +171,7 @@ Intel8254Timer::Counter::write(const uint8_t data) { switch (write_byte) { case LSB: - count = (count & 0xFF00) | data; + initial_count = (initial_count & 0xFF00) | data; if (event.scheduled()) parent->deschedule(event); @@ -154,15 +180,17 @@ Intel8254Timer::Counter::write(const uint8_t data) break; case MSB: - count = (count & 0x00FF) | (data << 8); + initial_count = (initial_count & 0x00FF) | (data << 8); // In the RateGen or SquareWave modes, the timer wraps around and // triggers on a value of 1, not 0. if (mode == RateGen || mode == SquareWave) - period = count - 1; + period = initial_count - 1; else - period = count; + period = initial_count; - if (period > 0) + offset = period * event.getInterval(); + + if (running && (period > 0)) event.setTo(period); write_byte = LSB; @@ -180,7 +208,7 @@ Intel8254Timer::Counter::setRW(int rw_val) void Intel8254Timer::Counter::setMode(int mode_val) { - if(mode_val != InitTc && mode_val != RateGen && + if (mode_val != InitTc && mode_val != RateGen && mode_val != SquareWave) panic("PIT mode %#x is not implemented: \n", mode_val); @@ -201,52 +229,60 @@ Intel8254Timer::Counter::outputHigh() } void -Intel8254Timer::Counter::serialize(const string &base, ostream &os) +Intel8254Timer::Counter::serialize(const string &base, CheckpointOut &cp) const { - paramOut(os, base + ".count", count); - paramOut(os, base + ".latched_count", latched_count); - paramOut(os, base + ".period", period); - paramOut(os, base + ".mode", mode); - paramOut(os, base + ".output_high", output_high); - paramOut(os, base + ".latch_on", latch_on); - paramOut(os, base + ".read_byte", read_byte); - paramOut(os, base + ".write_byte", write_byte); - - Tick event_tick = 0; + paramOut(cp, base + ".initial_count", initial_count); + paramOut(cp, base + ".latched_count", latched_count); + paramOut(cp, base + ".period", period); + paramOut(cp, base + ".mode", mode); + paramOut(cp, base + ".output_high", output_high); + paramOut(cp, base + ".latch_on", latch_on); + paramOut(cp, base + ".read_byte", read_byte); + paramOut(cp, base + ".write_byte", write_byte); + + Tick event_tick_offset = 0; if (event.scheduled()) - event_tick = event.when(); - paramOut(os, base + ".event_tick", event_tick); + event_tick_offset = event.when() - curTick(); + paramOut(cp, base + ".event_tick_offset", event_tick_offset); } void -Intel8254Timer::Counter::unserialize(const string &base, Checkpoint *cp, - const string §ion) +Intel8254Timer::Counter::unserialize(const string &base, CheckpointIn &cp) { - paramIn(cp, section, base + ".count", count); - paramIn(cp, section, base + ".latched_count", latched_count); - paramIn(cp, section, base + ".period", period); - paramIn(cp, section, base + ".mode", mode); - paramIn(cp, section, base + ".output_high", output_high); - paramIn(cp, section, base + ".latch_on", latch_on); - paramIn(cp, section, base + ".read_byte", read_byte); - paramIn(cp, section, base + ".write_byte", write_byte); - - Tick event_tick; - paramIn(cp, section, base + ".event_tick", event_tick); - if (event_tick) - parent->schedule(event, event_tick); + paramIn(cp, base + ".initial_count", initial_count); + paramIn(cp, base + ".latched_count", latched_count); + paramIn(cp, base + ".period", period); + paramIn(cp, base + ".mode", mode); + paramIn(cp, base + ".output_high", output_high); + paramIn(cp, base + ".latch_on", latch_on); + paramIn(cp, base + ".read_byte", read_byte); + paramIn(cp, base + ".write_byte", write_byte); + + Tick event_tick_offset = 0; + assert(!event.scheduled()); + paramIn(cp, base + ".event_tick_offset", event_tick_offset); + offset = event_tick_offset; +} + +void +Intel8254Timer::Counter::startup() +{ + running = true; + if ((period > 0) && (offset > 0)) + { + parent->schedule(event, curTick() + offset); + } } Intel8254Timer::Counter::CounterEvent::CounterEvent(Counter* c_ptr) { - interval = (Tick)(Clock::Float::s / 1193180.0); + interval = (Tick)(SimClock::Float::s / 1193180.0); counter = c_ptr; } void Intel8254Timer::Counter::CounterEvent::process() { - DPRINTF(Intel8254Timer, "Timer Interrupt\n"); switch (counter->mode) { case InitTc: counter->output_high = true; @@ -258,6 +294,7 @@ Intel8254Timer::Counter::CounterEvent::process() default: panic("Unimplemented PITimer mode.\n"); } + counter->parent->counterInterrupt(counter->num); } void @@ -265,13 +302,28 @@ Intel8254Timer::Counter::CounterEvent::setTo(int clocks) { if (clocks == 0) panic("Timer can't be set to go off instantly.\n"); - DPRINTF(Intel8254Timer, "Timer set to curTick + %d\n", + DPRINTF(Intel8254Timer, "Timer set to curTick() + %d\n", clocks * interval); - counter->parent->schedule(this, curTick + clocks * interval); + counter->parent->schedule(this, curTick() + clocks * interval); +} + +int +Intel8254Timer::Counter::CounterEvent::clocksLeft() +{ + if (!scheduled()) + return -1; + return (when() - curTick() + interval - 1) / interval; } const char * Intel8254Timer::Counter::CounterEvent::description() const { - return "tsunami 8254 Interval timer"; + return "Intel 8254 Interval timer"; +} + +Tick +Intel8254Timer::Counter::CounterEvent::getInterval() +{ + return interval; } +