malta_io.cc revision 12429:beefb9f5f551
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 "config/the_isa.hh"
48#include "debug/Malta.hh"
49#include "dev/mips/malta.hh"
50#include "dev/mips/malta_cchip.hh"
51#include "dev/mips/maltareg.h"
52#include "dev/rtcreg.h"
53#include "mem/packet.hh"
54#include "mem/packet_access.hh"
55#include "mem/port.hh"
56#include "params/MaltaIO.hh"
57#include "sim/system.hh"
58
59using namespace std;
60using namespace TheISA;
61
62MaltaIO::RTC::RTC(const string &name, const MaltaIOParams *p)
63    : MC146818(p->malta, name, p->time, p->year_is_bcd, p->frequency),
64      malta(p->malta)
65{
66}
67
68MaltaIO::MaltaIO(const Params *p)
69    : BasicPioDevice(p, 0x100), malta(p->malta),
70      pitimer(this, p->name + "pitimer"), rtc(p->name + ".rtc", p)
71{
72    // set the back pointer from malta to myself
73    malta->io = this;
74
75    timerData = 0;
76    picr = 0;
77    picInterrupting = false;
78}
79
80Tick
81MaltaIO::frequency() const
82{
83    return SimClock::Frequency / params()->frequency;
84}
85
86Tick
87MaltaIO::read(PacketPtr pkt)
88{
89    panic("MaltaIO::read(...) not implemented inside malta_io.cc");
90    return pioDelay;
91}
92
93Tick
94MaltaIO::write(PacketPtr pkt)
95{
96    panic("MaltaIO::write(...) not implemented inside malta_io.cc");
97    return pioDelay;
98}
99
100void
101MaltaIO::postIntr(uint8_t interrupt)
102{
103    malta->cchip->postIntr(interrupt);
104    DPRINTF(Malta, "posting pic interrupt to cchip\n");
105}
106
107void
108MaltaIO::clearIntr(uint8_t interrupt)
109{
110    malta->cchip->clearIntr(interrupt);
111    DPRINTF(Malta, "clear pic interrupt to cchip\n");
112}
113
114void
115MaltaIO::serialize(CheckpointOut &cp) const
116{
117    SERIALIZE_SCALAR(timerData);
118    SERIALIZE_SCALAR(mask1);
119    SERIALIZE_SCALAR(mask2);
120    SERIALIZE_SCALAR(mode1);
121    SERIALIZE_SCALAR(mode2);
122    SERIALIZE_SCALAR(picr);
123    SERIALIZE_SCALAR(picInterrupting);
124
125    // Serialize the timers
126    pitimer.serialize("pitimer", cp);
127    rtc.serialize("rtc", cp);
128}
129
130void
131MaltaIO::unserialize(CheckpointIn &cp)
132{
133    UNSERIALIZE_SCALAR(timerData);
134    UNSERIALIZE_SCALAR(mask1);
135    UNSERIALIZE_SCALAR(mask2);
136    UNSERIALIZE_SCALAR(mode1);
137    UNSERIALIZE_SCALAR(mode2);
138    UNSERIALIZE_SCALAR(picr);
139    UNSERIALIZE_SCALAR(picInterrupting);
140
141    // Unserialize the timers
142    pitimer.unserialize("pitimer", cp);
143    rtc.unserialize("rtc", cp);
144}
145
146void
147MaltaIO::startup()
148{
149    rtc.startup();
150    pitimer.startup();
151}
152
153MaltaIO *
154MaltaIOParams::create()
155{
156    return new MaltaIO(this);
157}
158