2 * Copyright (c) 2004, 2005
3 * The Regents of The University of Michigan
6 * This code is part of the M5 simulator.
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.
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
28 * Authors: Ali G. Saidi
33 #ifndef __DEV_8254_HH__
34 #define __DEV_8254_HH__
39 #include "base/bitunion.hh"
40 #include "base/types.hh"
41 #include "sim/eventq.hh"
42 #include "sim/serialize.hh"
44 /** Programmable Interval Timer (Intel 8254) */
45 class Intel8254Timer : public EventManager
78 /** Counter element for PIT */
81 /** Event for counter interrupt */
82 class CounterEvent : public Event
85 /** Pointer back to Counter */
90 CounterEvent(Counter*);
95 /** Event description */
96 virtual const char *description() const;
100 void setTo(int clocks);
107 const std::string &name() const { return _name; }
113 /** Initial count value */
114 uint16_t initial_count;
117 uint16_t latched_count;
119 /** Interrupt period */
122 /** Current mode of operation */
125 /** Output goes high when the counter reaches zero */
128 /** State of the count latch */
131 /** Set of values for read_byte and write_byte */
134 /** Determine which byte of a 16-bit count value to read/write */
135 uint8_t read_byte, write_byte;
137 /** Pointer to container */
138 Intel8254Timer *parent;
141 Counter(Intel8254Timer *p, const std::string &name, unsigned int num);
143 /** Latch the current count (if one is not already latched) */
146 /** Get the current count for this counter */
149 /** Set the read/write mode */
150 void setRW(int rw_val);
152 /** Set operational mode */
153 void setMode(int mode_val);
155 /** Set count encoding */
156 void setBCD(int bcd_val);
158 /** Read a count byte */
161 /** Write a count byte */
162 void write(const uint8_t data);
164 /** Is the output high? */
168 * Serialize this object to the given output stream.
169 * @param base The base name of the counter object.
170 * @param os The stream to serialize to.
172 void serialize(const std::string &base, std::ostream &os);
175 * Reconstruct the state of this object from a checkpoint.
176 * @param base The base name of the counter object.
177 * @param cp The checkpoint use.
178 * @param section The section name of this object
180 void unserialize(const std::string &base, Checkpoint *cp,
181 const std::string §ion);
186 const std::string &name() const { return _name; }
188 /** PIT has three seperate counters */
192 counterInterrupt(unsigned int num)
194 DPRINTF(Intel8254Timer, "Timer interrupt from counter %d.\n", num);
203 Intel8254Timer(EventManager *em, const std::string &name,
204 Counter *counter0, Counter *counter1, Counter *counter2);
206 Intel8254Timer(EventManager *em, const std::string &name);
208 /** Write control word */
209 void writeControl(const CtrlReg data);
212 readCounter(unsigned int num)
215 return counter[num]->read();
219 writeCounter(unsigned int num, const uint8_t data)
222 counter[num]->write(data);
226 outputHigh(unsigned int num)
229 return counter[num]->outputHigh();
233 * Serialize this object to the given output stream.
234 * @param base The base name of the counter object.
235 * @param os The stream to serialize to.
237 void serialize(const std::string &base, std::ostream &os);
240 * Reconstruct the state of this object from a checkpoint.
241 * @param base The base name of the counter object.
242 * @param cp The checkpoint use.
243 * @param section The section name of this object
245 void unserialize(const std::string &base, Checkpoint *cp,
246 const std::string §ion);
249 #endif // __DEV_8254_HH__