gem5  v20.1.0.0
intel_8254_timer.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004, 2005
3  * The Regents of The University of Michigan
4  * All Rights Reserved
5  *
6  * This code is part of the M5 simulator.
7  *
8  * Permission is granted to use, copy, create derivative works and
9  * redistribute this software and such derivative works for any
10  * purpose, so long as the copyright notice above, this grant of
11  * permission, and the disclaimer below appear in all copies made; and
12  * so long as the name of The University of Michigan is not used in
13  * any advertising or publicity pertaining to the use or distribution
14  * of this software without specific, written prior authorization.
15  *
16  * THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION FROM THE
17  * UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY PURPOSE, AND
18  * WITHOUT WARRANTY BY THE UNIVERSITY OF MICHIGAN OF ANY KIND, EITHER
19  * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE. THE REGENTS OF THE UNIVERSITY OF MICHIGAN SHALL NOT BE
22  * LIABLE FOR ANY DAMAGES, INCLUDING DIRECT, SPECIAL, INDIRECT,
23  * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WITH RESPECT TO ANY CLAIM
24  * ARISING OUT OF OR IN CONNECTION WITH THE USE OF THE SOFTWARE, EVEN
25  * IF IT HAS BEEN OR IS HEREAFTER ADVISED OF THE POSSIBILITY OF SUCH
26  * DAMAGES.
27  */
28 
29 #include "dev/intel_8254_timer.hh"
30 
31 #include "base/logging.hh"
32 #include "debug/Intel8254Timer.hh"
33 
34 using namespace std;
35 
37  Counter *counter0, Counter *counter1, Counter *counter2) :
38  EventManager(em), _name(name)
39 {
40  counter[0] = counter0;
41  counter[1] = counter1;
42  counter[2] = counter2;
43 }
44 
46  EventManager(em), _name(name)
47 {
48  counter[0] = new Counter(this, name + ".counter0", 0);
49  counter[1] = new Counter(this, name + ".counter1", 1);
50  counter[2] = new Counter(this, name + ".counter2", 2);
51 }
52 
53 void
55 {
56  int sel = data.sel;
57 
58  if (sel == ReadBackCommand)
59  panic("PITimer Read-Back Command is not implemented.\n");
60 
61  if (data.rw == LatchCommand)
63  else {
64  counter[sel]->setRW(data.rw);
65  counter[sel]->setMode(data.mode);
66  counter[sel]->setBCD(data.bcd);
67  }
68 }
69 
70 void
72 {
73  // serialize the counters
74  counter[0]->serialize(base + ".counter0", cp);
75  counter[1]->serialize(base + ".counter1", cp);
76  counter[2]->serialize(base + ".counter2", cp);
77 }
78 
79 void
81 {
82  // unserialze the counters
83  counter[0]->unserialize(base + ".counter0", cp);
84  counter[1]->unserialize(base + ".counter1", cp);
85  counter[2]->unserialize(base + ".counter2", cp);
86 }
87 
88 void
90 {
91  counter[0]->startup();
92  counter[1]->startup();
93  counter[2]->startup();
94 }
95 
97  const string &name, unsigned int _num)
98  : _name(name), num(_num), event(this), running(false),
99  initial_count(0), latched_count(0), period(0), mode(0),
100  output_high(false), latch_on(false), read_byte(LSB),
101  write_byte(LSB), parent(p)
102 {
103  offset = period * event.getInterval();
104 }
105 
106 void
108 {
109  // behave like a real latch
110  if (!latch_on) {
111  latch_on = true;
112  read_byte = LSB;
113  latched_count = currentCount();
114  }
115 }
116 
117 int
119 {
120  int clocks = event.clocksLeft();
121  if (clocks == -1) {
122  warn_once("Reading current count from inactive timer.\n");
123  return 0;
124  }
125  if (mode == RateGen || mode == SquareWave)
126  return clocks + 1;
127  else
128  return clocks;
129 }
130 
131 uint8_t
133 {
134  if (latch_on) {
135  switch (read_byte) {
136  case LSB:
137  read_byte = MSB;
138  return (uint8_t)latched_count;
139  break;
140  case MSB:
141  read_byte = LSB;
142  latch_on = false;
143  return latched_count >> 8;
144  break;
145  default:
146  panic("Shouldn't be here");
147  }
148  } else {
149  uint16_t count = currentCount();
150  switch (read_byte) {
151  case LSB:
152  read_byte = MSB;
153  return (uint8_t)count;
154  break;
155  case MSB:
156  read_byte = LSB;
157  return count >> 8;
158  break;
159  default:
160  panic("Shouldn't be here");
161  }
162  }
163 }
164 
165 void
167 {
168  switch (write_byte) {
169  case LSB:
170  initial_count = (initial_count & 0xFF00) | data;
171 
172  if (event.scheduled())
173  parent->deschedule(event);
174  output_high = false;
175  write_byte = MSB;
176  break;
177 
178  case MSB:
179  initial_count = (initial_count & 0x00FF) | (data << 8);
180  // In the RateGen or SquareWave modes, the timer wraps around and
181  // triggers on a value of 1, not 0.
182  if (mode == RateGen || mode == SquareWave)
183  period = initial_count - 1;
184  else
185  period = initial_count;
186 
187  offset = period * event.getInterval();
188 
189  if (running && (period > 0))
190  event.setTo(period);
191 
192  write_byte = LSB;
193  break;
194  }
195 }
196 
197 void
199 {
200  if (rw_val != TwoPhase)
201  panic("Only LSB/MSB read/write is implemented.\n");
202 }
203 
204 void
206 {
207  if (mode_val != InitTc && mode_val != RateGen &&
208  mode_val != SquareWave)
209  panic("PIT mode %#x is not implemented: \n", mode_val);
210 
211  mode = mode_val;
212 }
213 
214 void
216 {
217  if (bcd_val)
218  panic("PITimer does not implement BCD counts.\n");
219 }
220 
221 bool
223 {
224  return output_high;
225 }
226 
227 void
229 {
230  paramOut(cp, base + ".initial_count", initial_count);
231  paramOut(cp, base + ".latched_count", latched_count);
232  paramOut(cp, base + ".period", period);
233  paramOut(cp, base + ".mode", mode);
234  paramOut(cp, base + ".output_high", output_high);
235  paramOut(cp, base + ".latch_on", latch_on);
236  paramOut(cp, base + ".read_byte", read_byte);
237  paramOut(cp, base + ".write_byte", write_byte);
238 
239  Tick event_tick_offset = 0;
240  if (event.scheduled())
241  event_tick_offset = event.when() - curTick();
242  paramOut(cp, base + ".event_tick_offset", event_tick_offset);
243 }
244 
245 void
247 {
248  paramIn(cp, base + ".initial_count", initial_count);
249  paramIn(cp, base + ".latched_count", latched_count);
250  paramIn(cp, base + ".period", period);
251  paramIn(cp, base + ".mode", mode);
252  paramIn(cp, base + ".output_high", output_high);
253  paramIn(cp, base + ".latch_on", latch_on);
254  paramIn(cp, base + ".read_byte", read_byte);
255  paramIn(cp, base + ".write_byte", write_byte);
256 
257  Tick event_tick_offset = 0;
258  assert(!event.scheduled());
259  paramIn(cp, base + ".event_tick_offset", event_tick_offset);
260  offset = event_tick_offset;
261 }
262 
263 void
265 {
266  running = true;
267  if ((period > 0) && (offset > 0))
268  {
269  parent->schedule(event, curTick() + offset);
270  }
271 }
272 
274 {
275  interval = (Tick)(SimClock::Float::s / 1193180.0);
276  counter = c_ptr;
277 }
278 
279 void
281 {
282  switch (counter->mode) {
283  case InitTc:
284  counter->output_high = true;
285  break;
286  case RateGen:
287  case SquareWave:
288  setTo(counter->period);
289  break;
290  default:
291  panic("Unimplemented PITimer mode.\n");
292  }
294 }
295 
296 void
298 {
299  if (clocks == 0)
300  panic("Timer can't be set to go off instantly.\n");
301  DPRINTF(Intel8254Timer, "Timer set to curTick() + %d\n",
302  clocks * interval);
303  counter->parent->schedule(this, curTick() + clocks * interval);
304 }
305 
306 int
308 {
309  if (!scheduled())
310  return -1;
311  return (when() - curTick() + interval - 1) / interval;
312 }
313 
314 const char *
316 {
317  return "Intel 8254 Interval timer";
318 }
319 
320 Tick
322 {
323  return interval;
324 }
325 
Intel8254Timer::counter
Counter * counter[3]
PIT has three seperate counters.
Definition: intel_8254_timer.hh:197
Intel8254Timer::unserialize
void unserialize(const std::string &base, CheckpointIn &cp)
Reconstruct the state of this object from a checkpoint.
Definition: intel_8254_timer.cc:80
Intel8254Timer::Counter::read
uint8_t read()
Read a count byte.
Definition: intel_8254_timer.cc:132
Intel8254Timer::Counter::CounterEvent::getInterval
Tick getInterval()
Definition: intel_8254_timer.cc:321
SimClock::Float::s
double s
These variables equal the number of ticks in the unit of time they're named after in a double.
Definition: core.cc:49
Intel8254Timer::Counter::currentCount
int currentCount()
Get the current count for this counter.
Definition: intel_8254_timer.cc:118
Intel8254Timer::Intel8254Timer
Intel8254Timer(EventManager *em, const std::string &name, Counter *counter0, Counter *counter1, Counter *counter2)
data
const char data[]
Definition: circlebuf.test.cc:42
Intel8254Timer::Counter::period
uint16_t period
Interrupt period.
Definition: intel_8254_timer.hh:123
Intel8254Timer::serialize
void serialize(const std::string &base, CheckpointOut &cp) const
Serialize this object to the given output stream.
Definition: intel_8254_timer.cc:71
warn_once
#define warn_once(...)
Definition: logging.hh:243
Intel8254Timer::Counter::setBCD
void setBCD(int bcd_val)
Set count encoding.
Definition: intel_8254_timer.cc:215
Intel8254Timer::Counter::CounterEvent::CounterEvent
CounterEvent(Counter *)
Definition: intel_8254_timer.cc:273
Intel8254Timer::startup
void startup()
Start ticking.
Definition: intel_8254_timer.cc:89
Intel8254Timer::Counter::latchCount
void latchCount()
Latch the current count (if one is not already latched)
Definition: intel_8254_timer.cc:107
Intel8254Timer::Counter::setRW
void setRW(int rw_val)
Set the read/write mode.
Definition: intel_8254_timer.cc:198
Intel8254Timer::Counter::num
unsigned int num
Definition: intel_8254_timer.hh:109
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
Intel8254Timer::InitTc
@ InitTc
Definition: intel_8254_timer.hh:68
Intel8254Timer::writeControl
void writeControl(const CtrlReg data)
Write control word.
Definition: intel_8254_timer.cc:54
X86ISA::base
Bitfield< 51, 12 > base
Definition: pagetable.hh:141
Intel8254Timer::Counter::parent
Intel8254Timer * parent
Pointer to container.
Definition: intel_8254_timer.hh:144
Intel8254Timer::Counter::CounterEvent::setTo
void setTo(int clocks)
Definition: intel_8254_timer.cc:297
X86ISA::count
count
Definition: misc.hh:703
paramOut
void paramOut(CheckpointOut &cp, const string &name, ExtMachInst const &machInst)
Definition: types.cc:38
Intel8254Timer::Counter::CounterEvent::process
void process()
Event process.
Definition: intel_8254_timer.cc:280
Intel8254Timer::Counter::setMode
void setMode(int mode_val)
Set operational mode.
Definition: intel_8254_timer.cc:205
Intel8254Timer::RateGen
@ RateGen
Definition: intel_8254_timer.hh:70
Counter
int64_t Counter
Statistics counter type.
Definition: types.hh:58
Intel8254Timer::Counter::output_high
bool output_high
Output goes high when the counter reaches zero.
Definition: intel_8254_timer.hh:132
Intel8254Timer::Counter::unserialize
void unserialize(const std::string &base, CheckpointIn &cp)
Reconstruct the state of this object from a checkpoint.
Definition: intel_8254_timer.cc:246
cp
Definition: cprintf.cc:40
EventManager::schedule
void schedule(Event &event, Tick when)
Definition: eventq.hh:1005
Intel8254Timer::Counter::startup
void startup()
Start ticking.
Definition: intel_8254_timer.cc:264
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
Intel8254Timer::mode
Bitfield< 3, 1 > mode
Definition: intel_8254_timer.hh:49
Intel8254Timer::Counter::offset
Tick offset
When to start ticking.
Definition: intel_8254_timer.hh:126
MipsISA::event
Bitfield< 10, 5 > event
Definition: pra_constants.hh:297
Intel8254Timer
Programmable Interval Timer (Intel 8254)
Definition: intel_8254_timer.hh:43
Intel8254Timer::LatchCommand
@ LatchCommand
Definition: intel_8254_timer.hh:61
ArmISA::mode
Bitfield< 4, 0 > mode
Definition: miscregs_types.hh:70
Intel8254Timer::Counter::mode
uint8_t mode
Current mode of operation.
Definition: intel_8254_timer.hh:129
X86ISA::em
Bitfield< 2 > em
Definition: misc.hh:602
Intel8254Timer::Counter::Counter
Counter(Intel8254Timer *p, const std::string &name, unsigned int num)
Definition: intel_8254_timer.cc:96
Intel8254Timer::sel
sel
Definition: intel_8254_timer.hh:47
name
const std::string & name()
Definition: trace.cc:50
Intel8254Timer::TwoPhase
@ TwoPhase
Definition: intel_8254_timer.hh:64
intel_8254_timer.hh
Intel8254Timer::SquareWave
@ SquareWave
Definition: intel_8254_timer.hh:71
Intel8254Timer::Counter::write
void write(const uint8_t data)
Write a count byte.
Definition: intel_8254_timer.cc:166
Intel8254Timer::Counter
Counter element for PIT.
Definition: intel_8254_timer.hh:77
SimObject::name
virtual const std::string name() const
Definition: sim_object.hh:133
Intel8254Timer::Counter::CounterEvent::description
virtual const char * description() const
Event description.
Definition: intel_8254_timer.cc:315
Intel8254Timer::counterInterrupt
virtual void counterInterrupt(unsigned int num)
Definition: intel_8254_timer.hh:200
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
Intel8254Timer::Counter::outputHigh
bool outputHigh()
Is the output high?
Definition: intel_8254_timer.cc:222
Intel8254Timer::Counter::CounterEvent::clocksLeft
int clocksLeft()
Definition: intel_8254_timer.cc:307
Intel8254Timer::Counter::serialize
void serialize(const std::string &base, CheckpointOut &cp) const
Serialize this object to the given output stream.
Definition: intel_8254_timer.cc:228
paramIn
void paramIn(CheckpointIn &cp, const string &name, ExtMachInst &machInst)
Definition: types.cc:69
logging.hh
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:63
EventManager
Definition: eventq.hh:973
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
CheckpointIn
Definition: serialize.hh:67
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
curTick
Tick curTick()
The current simulated tick.
Definition: core.hh:45
ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:153

Generated on Wed Sep 30 2020 14:02:11 for gem5 by doxygen 1.8.17