gem5  v20.1.0.0
intel_8254_timer.hh
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 #ifndef __DEV_8254_HH__
30 #define __DEV_8254_HH__
31 
32 #include <iostream>
33 #include <string>
34 
35 #include "base/bitunion.hh"
36 #include "base/types.hh"
37 #include "base/trace.hh"
38 #include "debug/Intel8254Timer.hh"
39 #include "sim/eventq.hh"
40 #include "sim/serialize.hh"
41 
44 {
45  protected:
46  BitUnion8(CtrlReg)
47  Bitfield<7, 6> sel;
48  Bitfield<5, 4> rw;
49  Bitfield<3, 1> mode;
50  Bitfield<0> bcd;
51  EndBitUnion(CtrlReg)
52 
53  enum SelectVal {
54  SelectCounter0,
55  SelectCounter1,
56  SelectCounter2,
57  ReadBackCommand
58  };
59 
60  enum ReadWriteVal {
65  };
66 
67  enum ModeVal {
74  };
75 
77  class Counter
78  {
80  class CounterEvent : public Event
81  {
82  private:
86 
87  public:
89 
91  void process();
92 
94  virtual const char *description() const;
95 
96  friend class Counter;
97 
98  void setTo(int clocks);
99 
100  int clocksLeft();
101 
102  Tick getInterval();
103  };
104 
105  private:
106  std::string _name;
107  const std::string &name() const { return _name; }
108 
109  unsigned int num;
110 
112 
114  bool running;
115 
117  uint16_t initial_count;
118 
120  uint16_t latched_count;
121 
123  uint16_t period;
124 
127 
129  uint8_t mode;
130 
133 
135  bool latch_on;
136 
138  enum {LSB, MSB};
139 
142 
145 
146  public:
147  Counter(Intel8254Timer *p, const std::string &name, unsigned int num);
148 
150  void latchCount();
151 
153  int currentCount();
154 
156  void setRW(int rw_val);
157 
159  void setMode(int mode_val);
160 
162  void setBCD(int bcd_val);
163 
165  uint8_t read();
166 
168  void write(const uint8_t data);
169 
171  bool outputHigh();
172 
178  void serialize(const std::string &base, CheckpointOut &cp) const;
179 
186  void unserialize(const std::string &base, CheckpointIn &cp);
187 
189  void startup();
190  };
191 
192  protected:
193  std::string _name;
194  const std::string &name() const { return _name; }
195 
198 
199  virtual void
200  counterInterrupt(unsigned int num)
201  {
202  DPRINTF(Intel8254Timer, "Timer interrupt from counter %d.\n", num);
203  }
204 
205  public:
206 
207  virtual
209  {}
210 
211  Intel8254Timer(EventManager *em, const std::string &name,
212  Counter *counter0, Counter *counter1, Counter *counter2);
213 
214  Intel8254Timer(EventManager *em, const std::string &name);
215 
217  void writeControl(const CtrlReg data);
218 
219  uint8_t
220  readCounter(unsigned int num)
221  {
222  assert(num < 3);
223  return counter[num]->read();
224  }
225 
226  void
227  writeCounter(unsigned int num, const uint8_t data)
228  {
229  assert(num < 3);
230  counter[num]->write(data);
231  }
232 
233  bool
234  outputHigh(unsigned int num)
235  {
236  assert(num < 3);
237  return counter[num]->outputHigh();
238  }
239 
245  void serialize(const std::string &base, CheckpointOut &cp) const;
246 
253  void unserialize(const std::string &base, CheckpointIn &cp);
254 
256  void startup();
257 };
258 
259 #endif // __DEV_8254_HH__
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::readCounter
uint8_t readCounter(unsigned int num)
Definition: intel_8254_timer.hh:220
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
Intel8254Timer::~Intel8254Timer
virtual ~Intel8254Timer()
Definition: intel_8254_timer.hh:208
Intel8254Timer::Counter::write_byte
uint8_t write_byte
Definition: intel_8254_timer.hh:141
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
serialize.hh
Intel8254Timer::Counter::CounterEvent
Event for counter interrupt.
Definition: intel_8254_timer.hh:80
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
Intel8254Timer::Counter::latch_on
bool latch_on
State of the count latch.
Definition: intel_8254_timer.hh:135
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::writeCounter
void writeCounter(unsigned int num, const uint8_t data)
Definition: intel_8254_timer.hh:227
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
Intel8254Timer::Counter::LSB
@ LSB
Definition: intel_8254_timer.hh:138
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::read_byte
uint8_t read_byte
Determine which byte of a 16-bit count value to read/write.
Definition: intel_8254_timer.hh:141
Intel8254Timer::rw
Bitfield< 5, 4 > rw
Definition: intel_8254_timer.hh:48
Intel8254Timer::Counter::CounterEvent::setTo
void setTo(int clocks)
Definition: intel_8254_timer.cc:297
Intel8254Timer::outputHigh
bool outputHigh(unsigned int num)
Definition: intel_8254_timer.hh:234
Intel8254Timer::Counter::event
CounterEvent event
Definition: intel_8254_timer.hh:111
Intel8254Timer::EndBitUnion
EndBitUnion(CtrlReg) enum SelectVal
Definition: intel_8254_timer.hh:51
Intel8254Timer::Counter::CounterEvent::process
void process()
Event process.
Definition: intel_8254_timer.cc:280
Intel8254Timer::name
const std::string & name() const
Definition: intel_8254_timer.hh:194
Intel8254Timer::Counter::setMode
void setMode(int mode_val)
Set operational mode.
Definition: intel_8254_timer.cc:205
Intel8254Timer::bcd
Bitfield< 0 > bcd
Definition: intel_8254_timer.hh:50
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
Intel8254Timer::Counter::startup
void startup()
Start ticking.
Definition: intel_8254_timer.cc:264
Intel8254Timer::BitUnion8
BitUnion8(CtrlReg) Bitfield< 7
Event
Definition: eventq.hh:246
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
bitunion.hh
Intel8254Timer
Programmable Interval Timer (Intel 8254)
Definition: intel_8254_timer.hh:43
Intel8254Timer::HardwareStrobe
@ HardwareStrobe
Definition: intel_8254_timer.hh:73
Intel8254Timer::LatchCommand
@ LatchCommand
Definition: intel_8254_timer.hh:61
Intel8254Timer::Counter::CounterEvent::counter
Counter * counter
Pointer back to Counter.
Definition: intel_8254_timer.hh:84
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::Counter::MSB
@ MSB
Definition: intel_8254_timer.hh:138
Intel8254Timer::sel
sel
Definition: intel_8254_timer.hh:47
Intel8254Timer::LsbOnly
@ LsbOnly
Definition: intel_8254_timer.hh:62
Intel8254Timer::MsbOnly
@ MsbOnly
Definition: intel_8254_timer.hh:63
Intel8254Timer::TwoPhase
@ TwoPhase
Definition: intel_8254_timer.hh:64
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
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
Intel8254Timer::Counter::name
const std::string & name() const
Definition: intel_8254_timer.hh:107
Intel8254Timer::SoftwareStrobe
@ SoftwareStrobe
Definition: intel_8254_timer.hh:72
Intel8254Timer::Counter::running
bool running
True after startup is called.
Definition: intel_8254_timer.hh:114
Intel8254Timer::ReadWriteVal
ReadWriteVal
Definition: intel_8254_timer.hh:60
types.hh
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::_name
std::string _name
Definition: intel_8254_timer.hh:106
Intel8254Timer::Counter::latched_count
uint16_t latched_count
Latched count.
Definition: intel_8254_timer.hh:120
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
Intel8254Timer::ModeVal
ModeVal
Definition: intel_8254_timer.hh:67
Intel8254Timer::OneShot
@ OneShot
Definition: intel_8254_timer.hh:69
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:63
EventManager
Definition: eventq.hh:973
trace.hh
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
CheckpointIn
Definition: serialize.hh:67
Intel8254Timer::_name
std::string _name
Definition: intel_8254_timer.hh:193
Intel8254Timer::Counter::CounterEvent::interval
Tick interval
Definition: intel_8254_timer.hh:85
Intel8254Timer::Counter::initial_count
uint16_t initial_count
Initial count value.
Definition: intel_8254_timer.hh:117
eventq.hh

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