sparc: Use big endian packet accessors.
[gem5.git] / src / dev / mips / malta_io.cc
1 /*
2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Ali Saidi
29 * Andrew Schultz
30 * Miguel Serrano
31 */
32
33 /** @file
34 * Malta I/O including PIC, PIT, RTC, DMA
35 */
36
37 #include "dev/mips/malta_io.hh"
38
39 #include <sys/time.h>
40
41 #include <deque>
42 #include <string>
43 #include <vector>
44
45 #include "base/time.hh"
46 #include "base/trace.hh"
47 #include "debug/Malta.hh"
48 #include "dev/mips/malta.hh"
49 #include "dev/mips/malta_cchip.hh"
50 #include "dev/mips/maltareg.h"
51 #include "dev/rtcreg.h"
52 #include "mem/packet.hh"
53 #include "mem/packet_access.hh"
54 #include "mem/port.hh"
55 #include "params/MaltaIO.hh"
56 #include "sim/system.hh"
57
58 using namespace std;
59
60 MaltaIO::RTC::RTC(const string &name, const MaltaIOParams *p)
61 : MC146818(p->malta, name, p->time, p->year_is_bcd, p->frequency),
62 malta(p->malta)
63 {
64 }
65
66 MaltaIO::MaltaIO(const Params *p)
67 : BasicPioDevice(p, 0x100), malta(p->malta),
68 pitimer(this, p->name + "pitimer"), rtc(p->name + ".rtc", p)
69 {
70 // set the back pointer from malta to myself
71 malta->io = this;
72
73 timerData = 0;
74 picr = 0;
75 picInterrupting = false;
76 }
77
78 Tick
79 MaltaIO::frequency() const
80 {
81 return SimClock::Frequency / params()->frequency;
82 }
83
84 Tick
85 MaltaIO::read(PacketPtr pkt)
86 {
87 panic("MaltaIO::read(...) not implemented inside malta_io.cc");
88 return pioDelay;
89 }
90
91 Tick
92 MaltaIO::write(PacketPtr pkt)
93 {
94 panic("MaltaIO::write(...) not implemented inside malta_io.cc");
95 return pioDelay;
96 }
97
98 void
99 MaltaIO::postIntr(uint8_t interrupt)
100 {
101 malta->cchip->postIntr(interrupt);
102 DPRINTF(Malta, "posting pic interrupt to cchip\n");
103 }
104
105 void
106 MaltaIO::clearIntr(uint8_t interrupt)
107 {
108 malta->cchip->clearIntr(interrupt);
109 DPRINTF(Malta, "clear pic interrupt to cchip\n");
110 }
111
112 void
113 MaltaIO::serialize(CheckpointOut &cp) const
114 {
115 SERIALIZE_SCALAR(timerData);
116 SERIALIZE_SCALAR(mask1);
117 SERIALIZE_SCALAR(mask2);
118 SERIALIZE_SCALAR(mode1);
119 SERIALIZE_SCALAR(mode2);
120 SERIALIZE_SCALAR(picr);
121 SERIALIZE_SCALAR(picInterrupting);
122
123 // Serialize the timers
124 pitimer.serialize("pitimer", cp);
125 rtc.serialize("rtc", cp);
126 }
127
128 void
129 MaltaIO::unserialize(CheckpointIn &cp)
130 {
131 UNSERIALIZE_SCALAR(timerData);
132 UNSERIALIZE_SCALAR(mask1);
133 UNSERIALIZE_SCALAR(mask2);
134 UNSERIALIZE_SCALAR(mode1);
135 UNSERIALIZE_SCALAR(mode2);
136 UNSERIALIZE_SCALAR(picr);
137 UNSERIALIZE_SCALAR(picInterrupting);
138
139 // Unserialize the timers
140 pitimer.unserialize("pitimer", cp);
141 rtc.unserialize("rtc", cp);
142 }
143
144 void
145 MaltaIO::startup()
146 {
147 rtc.startup();
148 pitimer.startup();
149 }
150
151 MaltaIO *
152 MaltaIOParams::create()
153 {
154 return new MaltaIO(this);
155 }