d5dd043e1d7d9168b39445612834efea489efed8
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 #include "base/misc.hh"
34 #include "dev/intel_8254_timer.hh"
38 Intel8254Timer::Intel8254Timer(EventManager
*em
, const string
&name
,
39 Counter
*counter0
, Counter
*counter1
, Counter
*counter2
) :
40 EventManager(em
), _name(name
)
42 counter
[0] = counter0
;
43 counter
[1] = counter1
;
44 counter
[2] = counter2
;
47 Intel8254Timer::Intel8254Timer(EventManager
*em
, const string
&name
) :
48 EventManager(em
), _name(name
)
50 counter
[0] = new Counter(this, name
+ ".counter0", 0);
51 counter
[1] = new Counter(this, name
+ ".counter1", 1);
52 counter
[2] = new Counter(this, name
+ ".counter2", 2);
56 Intel8254Timer::writeControl(const CtrlReg data
)
60 if (sel
== ReadBackCommand
)
61 panic("PITimer Read-Back Command is not implemented.\n");
63 if (data
.rw
== LatchCommand
)
64 counter
[sel
]->latchCount();
66 counter
[sel
]->setRW(data
.rw
);
67 counter
[sel
]->setMode(data
.mode
);
68 counter
[sel
]->setBCD(data
.bcd
);
73 Intel8254Timer::serialize(const string
&base
, ostream
&os
)
75 // serialize the counters
76 counter
[0]->serialize(base
+ ".counter0", os
);
77 counter
[1]->serialize(base
+ ".counter1", os
);
78 counter
[2]->serialize(base
+ ".counter2", os
);
82 Intel8254Timer::unserialize(const string
&base
, Checkpoint
*cp
,
83 const string
§ion
)
85 // unserialze the counters
86 counter
[0]->unserialize(base
+ ".counter0", cp
, section
);
87 counter
[1]->unserialize(base
+ ".counter1", cp
, section
);
88 counter
[2]->unserialize(base
+ ".counter2", cp
, section
);
91 Intel8254Timer::Counter::Counter(Intel8254Timer
*p
,
92 const string
&name
, unsigned int _num
)
93 : _name(name
), num(_num
), event(this), count(0),
94 latched_count(0), period(0), mode(0), output_high(false),
95 latch_on(false), read_byte(LSB
), write_byte(LSB
), parent(p
)
101 Intel8254Timer::Counter::latchCount()
103 // behave like a real latch
107 latched_count
= count
;
112 Intel8254Timer::Counter::read()
118 return (uint8_t)latched_count
;
123 return latched_count
>> 8;
126 panic("Shouldn't be here");
132 return (uint8_t)count
;
139 panic("Shouldn't be here");
145 Intel8254Timer::Counter::write(const uint8_t data
)
147 switch (write_byte
) {
149 count
= (count
& 0xFF00) | data
;
151 if (event
.scheduled())
152 parent
->deschedule(event
);
158 count
= (count
& 0x00FF) | (data
<< 8);
159 // In the RateGen or SquareWave modes, the timer wraps around and
160 // triggers on a value of 1, not 0.
161 if (mode
== RateGen
|| mode
== SquareWave
)
175 Intel8254Timer::Counter::setRW(int rw_val
)
177 if (rw_val
!= TwoPhase
)
178 panic("Only LSB/MSB read/write is implemented.\n");
182 Intel8254Timer::Counter::setMode(int mode_val
)
184 if(mode_val
!= InitTc
&& mode_val
!= RateGen
&&
185 mode_val
!= SquareWave
)
186 panic("PIT mode %#x is not implemented: \n", mode_val
);
192 Intel8254Timer::Counter::setBCD(int bcd_val
)
195 panic("PITimer does not implement BCD counts.\n");
199 Intel8254Timer::Counter::outputHigh()
205 Intel8254Timer::Counter::serialize(const string
&base
, ostream
&os
)
207 paramOut(os
, base
+ ".count", count
);
208 paramOut(os
, base
+ ".latched_count", latched_count
);
209 paramOut(os
, base
+ ".period", period
);
210 paramOut(os
, base
+ ".mode", mode
);
211 paramOut(os
, base
+ ".output_high", output_high
);
212 paramOut(os
, base
+ ".latch_on", latch_on
);
213 paramOut(os
, base
+ ".read_byte", read_byte
);
214 paramOut(os
, base
+ ".write_byte", write_byte
);
217 if (event
.scheduled())
218 event_tick
= event
.when();
219 paramOut(os
, base
+ ".event_tick", event_tick
);
223 Intel8254Timer::Counter::unserialize(const string
&base
, Checkpoint
*cp
,
224 const string
§ion
)
226 paramIn(cp
, section
, base
+ ".count", count
);
227 paramIn(cp
, section
, base
+ ".latched_count", latched_count
);
228 paramIn(cp
, section
, base
+ ".period", period
);
229 paramIn(cp
, section
, base
+ ".mode", mode
);
230 paramIn(cp
, section
, base
+ ".output_high", output_high
);
231 paramIn(cp
, section
, base
+ ".latch_on", latch_on
);
232 paramIn(cp
, section
, base
+ ".read_byte", read_byte
);
233 paramIn(cp
, section
, base
+ ".write_byte", write_byte
);
236 paramIn(cp
, section
, base
+ ".event_tick", event_tick
);
238 parent
->schedule(event
, event_tick
);
241 Intel8254Timer::Counter::CounterEvent::CounterEvent(Counter
* c_ptr
)
243 interval
= (Tick
)(Clock::Float::s
/ 1193180.0);
248 Intel8254Timer::Counter::CounterEvent::process()
250 switch (counter
->mode
) {
252 counter
->output_high
= true;
256 setTo(counter
->period
);
259 panic("Unimplemented PITimer mode.\n");
261 counter
->parent
->counterInterrupt(counter
->num
);
265 Intel8254Timer::Counter::CounterEvent::setTo(int clocks
)
268 panic("Timer can't be set to go off instantly.\n");
269 DPRINTF(Intel8254Timer
, "Timer set to curTick + %d\n",
271 counter
->parent
->schedule(this, curTick
+ clocks
* interval
);
275 Intel8254Timer::Counter::CounterEvent::description() const
277 return "Intel 8254 Interval timer";