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 "sim/eventq.hh"
41 #include "sim/host.hh"
42 #include "sim/serialize.hh"
44 /** Programmable Interval Timer (Intel 8254) */
45 class Intel8254Timer : public EventManager
77 /** Counter element for PIT */
80 /** Event for counter interrupt */
81 class CounterEvent : public Event
84 /** Pointer back to Counter */
89 CounterEvent(Counter*);
92 virtual void process();
94 /** Event description */
95 virtual const char *description() const;
99 void setTo(int clocks);
104 const std::string &name() const { return _name; }
108 /** Current count value */
112 uint16_t latched_count;
114 /** Interrupt period */
117 /** Current mode of operation */
120 /** Output goes high when the counter reaches zero */
123 /** State of the count latch */
126 /** Set of values for read_byte and write_byte */
129 /** Determine which byte of a 16-bit count value to read/write */
130 uint8_t read_byte, write_byte;
132 /** Pointer to container */
133 Intel8254Timer *parent;
136 Counter(Intel8254Timer *p, const std::string &name);
138 /** Latch the current count (if one is not already latched) */
141 /** Set the read/write mode */
142 void setRW(int rw_val);
144 /** Set operational mode */
145 void setMode(int mode_val);
147 /** Set count encoding */
148 void setBCD(int bcd_val);
150 /** Read a count byte */
153 /** Write a count byte */
154 void write(const uint8_t data);
156 /** Is the output high? */
160 * Serialize this object to the given output stream.
161 * @param base The base name of the counter object.
162 * @param os The stream to serialize to.
164 void serialize(const std::string &base, std::ostream &os);
167 * Reconstruct the state of this object from a checkpoint.
168 * @param base The base name of the counter object.
169 * @param cp The checkpoint use.
170 * @param section The section name of this object
172 void unserialize(const std::string &base, Checkpoint *cp,
173 const std::string §ion);
178 const std::string &name() const { return _name; }
180 /** PIT has three seperate counters */
184 /** Public way to access individual counters (avoid array accesses) */
189 Intel8254Timer(EventManager *em, const std::string &name);
191 /** Write control word */
192 void writeControl(const CtrlReg data);
195 * Serialize this object to the given output stream.
196 * @param base The base name of the counter object.
197 * @param os The stream to serialize to.
199 void serialize(const std::string &base, std::ostream &os);
202 * Reconstruct the state of this object from a checkpoint.
203 * @param base The base name of the counter object.
204 * @param cp The checkpoint use.
205 * @param section The section name of this object
207 void unserialize(const std::string &base, Checkpoint *cp,
208 const std::string §ion);
211 #endif // __DEV_8254_HH__