gem5  v22.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 <array>
33 #include <iostream>
34 #include <string>
35 
36 #include "base/bitunion.hh"
37 #include "base/types.hh"
38 #include "base/trace.hh"
39 #include "debug/Intel8254Timer.hh"
40 #include "sim/eventq.hh"
41 #include "sim/serialize.hh"
42 
43 namespace gem5
44 {
45 
48 {
49  protected:
50  BitUnion8(CtrlReg)
51  Bitfield<7, 6> sel;
52  Bitfield<5, 4> rw;
53  Bitfield<3, 1> mode;
54  Bitfield<0> bcd;
55  EndBitUnion(CtrlReg)
56 
57  BitUnion8(ReadBackCommandVal)
58  Bitfield<4> status; // Active low.
59  Bitfield<5> count; // Active low.
60  SubBitUnion(select, 3, 1)
61  Bitfield<3> cnt2;
62  Bitfield<2> cnt1;
63  Bitfield<1> cnt0;
65  EndBitUnion(ReadBackCommandVal)
66 
67  enum SelectVal
68  {
69  SelectCounter0,
70  SelectCounter1,
71  SelectCounter2,
72  ReadBackCommand
73  };
74 
76  {
80  TwoPhase
81  };
82 
83  enum ModeVal
84  {
91  };
92 
94  class Counter
95  {
97  class CounterEvent : public Event
98  {
99  private:
103 
104  public:
106 
108  void process();
109 
111  virtual const char *description() const;
112 
113  friend class Counter;
114 
115  void setTo(int clocks);
116 
117  int clocksLeft();
118 
119  Tick getInterval();
120  };
121 
122  private:
123  std::string _name;
124  const std::string &name() const { return _name; }
125 
126  unsigned int num;
127 
129 
131  bool running;
132 
134  uint16_t initial_count;
135 
137  uint16_t latched_count;
138 
140  uint16_t period;
141 
144 
146  uint8_t mode;
147 
150 
152  bool latch_on;
153 
155  enum {LSB, MSB};
156 
159 
162 
163  public:
164  Counter(Intel8254Timer *p, const std::string &name, unsigned int num);
165 
166  unsigned int index() const { return num; }
167 
169  void latchCount();
170 
172  int currentCount();
173 
175  void setRW(int rw_val);
176 
178  void setMode(int mode_val);
179 
181  void setBCD(int bcd_val);
182 
184  uint8_t read();
185 
187  void write(const uint8_t data);
188 
190  bool outputHigh();
191 
197  void serialize(const std::string &base, CheckpointOut &cp) const;
198 
205  void unserialize(const std::string &base, CheckpointIn &cp);
206 
208  void startup();
209  };
210 
211  protected:
212  std::string _name;
213  const std::string &name() const { return _name; }
214 
216  std::array<Counter, 3> counters;
217 
218  virtual void
219  counterInterrupt(unsigned int num)
220  {
221  DPRINTF(Intel8254Timer, "Timer interrupt from counter %d.\n", num);
222  }
223 
224  public:
225 
226  virtual
228  {}
229 
230  Intel8254Timer(EventManager *em, const std::string &name);
231 
233  void writeControl(const CtrlReg data);
234 
235  uint8_t
236  readCounter(unsigned int num)
237  {
238  assert(num < 3);
239  return counters[num].read();
240  }
241 
242  void
243  writeCounter(unsigned int num, const uint8_t data)
244  {
245  assert(num < 3);
246  counters[num].write(data);
247  }
248 
249  bool
250  outputHigh(unsigned int num)
251  {
252  assert(num < 3);
253  return counters[num].outputHigh();
254  }
255 
261  void serialize(const std::string &base, CheckpointOut &cp) const;
262 
269  void unserialize(const std::string &base, CheckpointIn &cp);
270 
272  void startup();
273 };
274 
275 } // namespace gem5
276 
277 #endif // __DEV_8254_HH__
#define DPRINTF(x,...)
Definition: trace.hh:186
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
const char data[]
Counter * counter
Pointer back to Counter.
virtual const char * description() const
Event description.
Counter element for PIT.
uint16_t initial_count
Initial count value.
uint8_t read()
Read a count byte.
void setMode(int mode_val)
Set operational mode.
void serialize(const std::string &base, CheckpointOut &cp) const
Serialize this object to the given output stream.
uint16_t period
Interrupt period.
void unserialize(const std::string &base, CheckpointIn &cp)
Reconstruct the state of this object from a checkpoint.
uint16_t latched_count
Latched count.
const std::string & name() const
uint8_t read_byte
Determine which byte of a 16-bit count value to read/write.
Intel8254Timer * parent
Pointer to container.
bool output_high
Output goes high when the counter reaches zero.
void setBCD(int bcd_val)
Set count encoding.
bool latch_on
State of the count latch.
void latchCount()
Latch the current count (if one is not already latched)
bool outputHigh()
Is the output high?
Counter(Intel8254Timer *p, const std::string &name, unsigned int num)
uint8_t mode
Current mode of operation.
bool running
True after startup is called.
Tick offset
When to start ticking.
int currentCount()
Get the current count for this counter.
void setRW(int rw_val)
Set the read/write mode.
void write(const uint8_t data)
Write a count byte.
Programmable Interval Timer (Intel 8254)
bool outputHigh(unsigned int num)
void writeCounter(unsigned int num, const uint8_t data)
EndBitUnion(CtrlReg) BitUnion8(ReadBackCommandVal) Bitfield< 4 > status
Intel8254Timer(EventManager *em, const std::string &name)
virtual void counterInterrupt(unsigned int num)
void serialize(const std::string &base, CheckpointOut &cp) const
Serialize this object to the given output stream.
std::array< Counter, 3 > counters
PIT has three seperate counters.
Bitfield< 3, 1 > mode
void startup()
Start ticking.
BitUnion8(CtrlReg) Bitfield< 7
void unserialize(const std::string &base, CheckpointIn &cp)
Reconstruct the state of this object from a checkpoint.
const std::string & name() const
uint8_t readCounter(unsigned int num)
void writeControl(const CtrlReg data)
Write control word.
SubBitUnion(select, 3, 1) Bitfield< 3 > cnt2
EndSubBitUnion(select) EndBitUnion(ReadBackCommandVal) enum SelectVal
Bitfield< 5, 4 > rw
Bitfield< 5, 0 > status
Definition: misc_types.hh:429
Bitfield< 54 > p
Definition: pagetable.hh:70
Bitfield< 51, 12 > base
Definition: pagetable.hh:141
Bitfield< 2 > em
Definition: misc.hh:607
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::ostream CheckpointOut
Definition: serialize.hh:66
uint64_t Tick
Tick count type.
Definition: types.hh:58

Generated on Wed Dec 21 2022 10:22:33 for gem5 by doxygen 1.9.1