cmos.hh revision 5629:1565c13d1483
1/*
2 * Copyright (c) 2008 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#ifndef __DEV_X86_CMOS_HH__
32#define __DEV_X86_CMOS_HH__
33
34#include "dev/io_device.hh"
35#include "dev/mc146818.hh"
36#include "params/Cmos.hh"
37
38namespace X86ISA
39{
40
41class Cmos : public BasicPioDevice
42{
43  protected:
44    Tick latency;
45
46    uint8_t address;
47
48    static const int numRegs = 128;
49
50    uint8_t regs[numRegs];
51
52    uint8_t readRegister(uint8_t reg);
53    void writeRegister(uint8_t reg, uint8_t val);
54
55    class X86RTC : public MC146818
56    {
57      public:
58        X86RTC(EventManager *em, const std::string &n, const struct tm time,
59                bool bcd, Tick frequency) :
60            MC146818(em, n, time, bcd, frequency)
61        {
62        }
63      protected:
64        void handleEvent()
65        {
66            return;
67        }
68    } rtc;
69
70  public:
71    typedef CmosParams Params;
72
73    Cmos(const Params *p) : BasicPioDevice(p), latency(p->pio_latency),
74        rtc(this, "rtc", p->time, true, ULL(5000000000))
75    {
76        pioSize = 2;
77        memset(regs, 0, numRegs * sizeof(uint8_t));
78        address = 0;
79    }
80
81    Tick read(PacketPtr pkt);
82
83    Tick write(PacketPtr pkt);
84};
85
86}; // namespace X86ISA
87
88#endif //__DEV_X86_CMOS_HH__
89