cmos.cc revision 10631
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: Gabe Black
29 */
30
31#include "debug/CMOS.hh"
32#include "dev/x86/cmos.hh"
33#include "dev/x86/intdev.hh"
34#include "mem/packet_access.hh"
35
36void
37X86ISA::Cmos::X86RTC::handleEvent()
38{
39    assert(intPin);
40    intPin->raise();
41    //XXX This is a hack.
42    intPin->lower();
43}
44
45Tick
46X86ISA::Cmos::read(PacketPtr pkt)
47{
48    assert(pkt->getSize() == 1);
49    switch(pkt->getAddr() - pioAddr)
50    {
51      case 0x0:
52        pkt->set(address);
53        break;
54      case 0x1:
55        pkt->set(readRegister(address));
56        break;
57      default:
58        panic("Read from undefined CMOS port.\n");
59    }
60    pkt->makeAtomicResponse();
61    return latency;
62}
63
64Tick
65X86ISA::Cmos::write(PacketPtr pkt)
66{
67    assert(pkt->getSize() == 1);
68    switch(pkt->getAddr() - pioAddr)
69    {
70      case 0x0:
71        address = pkt->get<uint8_t>();
72        break;
73      case 0x1:
74        writeRegister(address, pkt->get<uint8_t>());
75        break;
76      default:
77        panic("Write to undefined CMOS port.\n");
78    }
79    pkt->makeAtomicResponse();
80    return latency;
81}
82
83uint8_t
84X86ISA::Cmos::readRegister(uint8_t reg)
85{
86    assert(reg < numRegs);
87    uint8_t val;
88    if (reg <= 0xD) {
89        val = rtc.readData(reg);
90        DPRINTF(CMOS,
91            "Reading CMOS RTC reg %x as %x.\n", reg, val);
92    } else {
93        val = regs[reg];
94        DPRINTF(CMOS,
95            "Reading non-volitile CMOS address %x as %x.\n", reg, val);
96    }
97    return val;
98}
99
100void
101X86ISA::Cmos::writeRegister(uint8_t reg, uint8_t val)
102{
103    assert(reg < numRegs);
104    if (reg <= 0xD) {
105        DPRINTF(CMOS, "Writing CMOS RTC reg %x with %x.\n",
106                reg, val);
107        rtc.writeData(reg, val);
108    } else {
109        DPRINTF(CMOS, "Writing non-volitile CMOS address %x with %x.\n",
110                reg, val);
111        regs[reg] = val;
112    }
113}
114
115void
116X86ISA::Cmos::startup()
117{
118    rtc.startup();
119}
120
121void
122X86ISA::Cmos::serialize(std::ostream &os)
123{
124    SERIALIZE_SCALAR(address);
125    SERIALIZE_ARRAY(regs, numRegs);
126
127    // Serialize the timer
128    rtc.serialize("rtc", os);
129}
130
131void
132X86ISA::Cmos::unserialize(Checkpoint *cp, const std::string &section)
133{
134    UNSERIALIZE_SCALAR(address);
135    UNSERIALIZE_ARRAY(regs, numRegs);
136
137    // Serialize the timer
138    rtc.unserialize("rtc", cp, section);
139}
140
141X86ISA::Cmos *
142CmosParams::create()
143{
144    return new X86ISA::Cmos(this);
145}
146