intel_8254_timer.hh (8232:b28d06a175be) intel_8254_timer.hh (9356:b279bad40aa3)
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 * Authors: Ali G. Saidi
29 * Andrew L. Schultz
30 * Miguel J. Serrano
31 */
32
33#ifndef __DEV_8254_HH__
34#define __DEV_8254_HH__
35
36#include <iostream>
37#include <string>
38
39#include "base/bitunion.hh"
40#include "base/types.hh"
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 * Authors: Ali G. Saidi
29 * Andrew L. Schultz
30 * Miguel J. Serrano
31 */
32
33#ifndef __DEV_8254_HH__
34#define __DEV_8254_HH__
35
36#include <iostream>
37#include <string>
38
39#include "base/bitunion.hh"
40#include "base/types.hh"
41#include "base/trace.hh"
41#include "debug/Intel8254Timer.hh"
42#include "debug/Intel8254Timer.hh"
42#include "sim/eventq.hh"
43#include "sim/eventq_impl.hh"
43#include "sim/serialize.hh"
44
45/** Programmable Interval Timer (Intel 8254) */
46class Intel8254Timer : public EventManager
47{
48 protected:
49 BitUnion8(CtrlReg)
50 Bitfield<7, 6> sel;
51 Bitfield<5, 4> rw;
52 Bitfield<3, 1> mode;
53 Bitfield<0> bcd;
54 EndBitUnion(CtrlReg)
55
56 enum SelectVal {
57 SelectCounter0,
58 SelectCounter1,
59 SelectCounter2,
60 ReadBackCommand
61 };
62
63 enum ReadWriteVal {
64 LatchCommand,
65 LsbOnly,
66 MsbOnly,
67 TwoPhase
68 };
69
70 enum ModeVal {
71 InitTc,
72 OneShot,
73 RateGen,
74 SquareWave,
75 SoftwareStrobe,
76 HardwareStrobe
77 };
78
79 /** Counter element for PIT */
80 class Counter
81 {
82 /** Event for counter interrupt */
83 class CounterEvent : public Event
84 {
85 private:
86 /** Pointer back to Counter */
87 Counter* counter;
88 Tick interval;
89
90 public:
91 CounterEvent(Counter*);
92
93 /** Event process */
94 void process();
95
96 /** Event description */
97 virtual const char *description() const;
98
99 friend class Counter;
100
101 void setTo(int clocks);
102
103 int clocksLeft();
104 };
105
106 private:
107 std::string _name;
108 const std::string &name() const { return _name; }
109
110 unsigned int num;
111
112 CounterEvent event;
113
114 /** Initial count value */
115 uint16_t initial_count;
116
117 /** Latched count */
118 uint16_t latched_count;
119
120 /** Interrupt period */
121 uint16_t period;
122
123 /** Current mode of operation */
124 uint8_t mode;
125
126 /** Output goes high when the counter reaches zero */
127 bool output_high;
128
129 /** State of the count latch */
130 bool latch_on;
131
132 /** Set of values for read_byte and write_byte */
133 enum {LSB, MSB};
134
135 /** Determine which byte of a 16-bit count value to read/write */
136 uint8_t read_byte, write_byte;
137
138 /** Pointer to container */
139 Intel8254Timer *parent;
140
141 public:
142 Counter(Intel8254Timer *p, const std::string &name, unsigned int num);
143
144 /** Latch the current count (if one is not already latched) */
145 void latchCount();
146
147 /** Get the current count for this counter */
148 int currentCount();
149
150 /** Set the read/write mode */
151 void setRW(int rw_val);
152
153 /** Set operational mode */
154 void setMode(int mode_val);
155
156 /** Set count encoding */
157 void setBCD(int bcd_val);
158
159 /** Read a count byte */
160 uint8_t read();
161
162 /** Write a count byte */
163 void write(const uint8_t data);
164
165 /** Is the output high? */
166 bool outputHigh();
167
168 /**
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.
172 */
173 void serialize(const std::string &base, std::ostream &os);
174
175 /**
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
180 */
181 void unserialize(const std::string &base, Checkpoint *cp,
182 const std::string &section);
183 };
184
185 protected:
186 std::string _name;
187 const std::string &name() const { return _name; }
188
189 /** PIT has three seperate counters */
190 Counter *counter[3];
191
192 virtual void
193 counterInterrupt(unsigned int num)
194 {
195 DPRINTF(Intel8254Timer, "Timer interrupt from counter %d.\n", num);
196 }
197
198 public:
199
200 virtual
201 ~Intel8254Timer()
202 {}
203
204 Intel8254Timer(EventManager *em, const std::string &name,
205 Counter *counter0, Counter *counter1, Counter *counter2);
206
207 Intel8254Timer(EventManager *em, const std::string &name);
208
209 /** Write control word */
210 void writeControl(const CtrlReg data);
211
212 uint8_t
213 readCounter(unsigned int num)
214 {
215 assert(num < 3);
216 return counter[num]->read();
217 }
218
219 void
220 writeCounter(unsigned int num, const uint8_t data)
221 {
222 assert(num < 3);
223 counter[num]->write(data);
224 }
225
226 bool
227 outputHigh(unsigned int num)
228 {
229 assert(num < 3);
230 return counter[num]->outputHigh();
231 }
232
233 /**
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.
237 */
238 void serialize(const std::string &base, std::ostream &os);
239
240 /**
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
245 */
246 void unserialize(const std::string &base, Checkpoint *cp,
247 const std::string &section);
248};
249
250#endif // __DEV_8254_HH__
44#include "sim/serialize.hh"
45
46/** Programmable Interval Timer (Intel 8254) */
47class Intel8254Timer : public EventManager
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 enum SelectVal {
58 SelectCounter0,
59 SelectCounter1,
60 SelectCounter2,
61 ReadBackCommand
62 };
63
64 enum ReadWriteVal {
65 LatchCommand,
66 LsbOnly,
67 MsbOnly,
68 TwoPhase
69 };
70
71 enum ModeVal {
72 InitTc,
73 OneShot,
74 RateGen,
75 SquareWave,
76 SoftwareStrobe,
77 HardwareStrobe
78 };
79
80 /** Counter element for PIT */
81 class Counter
82 {
83 /** Event for counter interrupt */
84 class CounterEvent : public Event
85 {
86 private:
87 /** Pointer back to Counter */
88 Counter* counter;
89 Tick interval;
90
91 public:
92 CounterEvent(Counter*);
93
94 /** Event process */
95 void process();
96
97 /** Event description */
98 virtual const char *description() const;
99
100 friend class Counter;
101
102 void setTo(int clocks);
103
104 int clocksLeft();
105 };
106
107 private:
108 std::string _name;
109 const std::string &name() const { return _name; }
110
111 unsigned int num;
112
113 CounterEvent event;
114
115 /** Initial count value */
116 uint16_t initial_count;
117
118 /** Latched count */
119 uint16_t latched_count;
120
121 /** Interrupt period */
122 uint16_t period;
123
124 /** Current mode of operation */
125 uint8_t mode;
126
127 /** Output goes high when the counter reaches zero */
128 bool output_high;
129
130 /** State of the count latch */
131 bool latch_on;
132
133 /** Set of values for read_byte and write_byte */
134 enum {LSB, MSB};
135
136 /** Determine which byte of a 16-bit count value to read/write */
137 uint8_t read_byte, write_byte;
138
139 /** Pointer to container */
140 Intel8254Timer *parent;
141
142 public:
143 Counter(Intel8254Timer *p, const std::string &name, unsigned int num);
144
145 /** Latch the current count (if one is not already latched) */
146 void latchCount();
147
148 /** Get the current count for this counter */
149 int currentCount();
150
151 /** Set the read/write mode */
152 void setRW(int rw_val);
153
154 /** Set operational mode */
155 void setMode(int mode_val);
156
157 /** Set count encoding */
158 void setBCD(int bcd_val);
159
160 /** Read a count byte */
161 uint8_t read();
162
163 /** Write a count byte */
164 void write(const uint8_t data);
165
166 /** Is the output high? */
167 bool outputHigh();
168
169 /**
170 * Serialize this object to the given output stream.
171 * @param base The base name of the counter object.
172 * @param os The stream to serialize to.
173 */
174 void serialize(const std::string &base, std::ostream &os);
175
176 /**
177 * Reconstruct the state of this object from a checkpoint.
178 * @param base The base name of the counter object.
179 * @param cp The checkpoint use.
180 * @param section The section name of this object
181 */
182 void unserialize(const std::string &base, Checkpoint *cp,
183 const std::string &section);
184 };
185
186 protected:
187 std::string _name;
188 const std::string &name() const { return _name; }
189
190 /** PIT has three seperate counters */
191 Counter *counter[3];
192
193 virtual void
194 counterInterrupt(unsigned int num)
195 {
196 DPRINTF(Intel8254Timer, "Timer interrupt from counter %d.\n", num);
197 }
198
199 public:
200
201 virtual
202 ~Intel8254Timer()
203 {}
204
205 Intel8254Timer(EventManager *em, const std::string &name,
206 Counter *counter0, Counter *counter1, Counter *counter2);
207
208 Intel8254Timer(EventManager *em, const std::string &name);
209
210 /** Write control word */
211 void writeControl(const CtrlReg data);
212
213 uint8_t
214 readCounter(unsigned int num)
215 {
216 assert(num < 3);
217 return counter[num]->read();
218 }
219
220 void
221 writeCounter(unsigned int num, const uint8_t data)
222 {
223 assert(num < 3);
224 counter[num]->write(data);
225 }
226
227 bool
228 outputHigh(unsigned int num)
229 {
230 assert(num < 3);
231 return counter[num]->outputHigh();
232 }
233
234 /**
235 * Serialize this object to the given output stream.
236 * @param base The base name of the counter object.
237 * @param os The stream to serialize to.
238 */
239 void serialize(const std::string &base, std::ostream &os);
240
241 /**
242 * Reconstruct the state of this object from a checkpoint.
243 * @param base The base name of the counter object.
244 * @param cp The checkpoint use.
245 * @param section The section name of this object
246 */
247 void unserialize(const std::string &base, Checkpoint *cp,
248 const std::string &section);
249};
250
251#endif // __DEV_8254_HH__