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 "debug/Intel8254Timer.hh"
42 #include "sim/eventq.hh"
43 #include "sim/serialize.hh"
45 /** Programmable Interval Timer (Intel 8254) */
46 class Intel8254Timer : public EventManager
79 /** Counter element for PIT */
82 /** Event for counter interrupt */
83 class CounterEvent : public Event
86 /** Pointer back to Counter */
91 CounterEvent(Counter*);
96 /** Event description */
97 virtual const char *description() const;
101 void setTo(int clocks);
108 const std::string &name() const { return _name; }
114 /** Initial count value */
115 uint16_t initial_count;
118 uint16_t latched_count;
120 /** Interrupt period */
123 /** Current mode of operation */
126 /** Output goes high when the counter reaches zero */
129 /** State of the count latch */
132 /** Set of values for read_byte and write_byte */
135 /** Determine which byte of a 16-bit count value to read/write */
136 uint8_t read_byte, write_byte;
138 /** Pointer to container */
139 Intel8254Timer *parent;
142 Counter(Intel8254Timer *p, const std::string &name, unsigned int num);
144 /** Latch the current count (if one is not already latched) */
147 /** Get the current count for this counter */
150 /** Set the read/write mode */
151 void setRW(int rw_val);
153 /** Set operational mode */
154 void setMode(int mode_val);
156 /** Set count encoding */
157 void setBCD(int bcd_val);
159 /** Read a count byte */
162 /** Write a count byte */
163 void write(const uint8_t data);
165 /** Is the output high? */
169 * Serialize this object to the given output stream.
170 * @param base The base name of the counter object.
171 * @param os The stream to serialize to.
173 void serialize(const std::string &base, std::ostream &os);
176 * Reconstruct the state of this object from a checkpoint.
177 * @param base The base name of the counter object.
178 * @param cp The checkpoint use.
179 * @param section The section name of this object
181 void unserialize(const std::string &base, Checkpoint *cp,
182 const std::string §ion);
187 const std::string &name() const { return _name; }
189 /** PIT has three seperate counters */
193 counterInterrupt(unsigned int num)
195 DPRINTF(Intel8254Timer, "Timer interrupt from counter %d.\n", num);
204 Intel8254Timer(EventManager *em, const std::string &name,
205 Counter *counter0, Counter *counter1, Counter *counter2);
207 Intel8254Timer(EventManager *em, const std::string &name);
209 /** Write control word */
210 void writeControl(const CtrlReg data);
213 readCounter(unsigned int num)
216 return counter[num]->read();
220 writeCounter(unsigned int num, const uint8_t data)
223 counter[num]->write(data);
227 outputHigh(unsigned int num)
230 return counter[num]->outputHigh();
234 * Serialize this object to the given output stream.
235 * @param base The base name of the counter object.
236 * @param os The stream to serialize to.
238 void serialize(const std::string &base, std::ostream &os);
241 * Reconstruct the state of this object from a checkpoint.
242 * @param base The base name of the counter object.
243 * @param cp The checkpoint use.
244 * @param section The section name of this object
246 void unserialize(const std::string &base, Checkpoint *cp,
247 const std::string §ion);
250 #endif // __DEV_8254_HH__