gem5  v20.1.0.0
cmos.cc
Go to the documentation of this file.
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 
29 #include "dev/x86/cmos.hh"
30 
31 #include "base/trace.hh"
32 #include "debug/CMOS.hh"
33 #include "dev/x86/intdev.hh"
34 #include "mem/packet_access.hh"
35 
36 void
38 {
39  for (auto *wire: intPin) {
40  wire->raise();
41  //XXX This is a hack.
42  wire->lower();
43  }
44 }
45 
46 Tick
48 {
49  assert(pkt->getSize() == 1);
50  switch(pkt->getAddr() - pioAddr)
51  {
52  case 0x0:
53  pkt->setLE(address);
54  break;
55  case 0x1:
56  pkt->setLE(readRegister(address));
57  break;
58  default:
59  panic("Read from undefined CMOS port.\n");
60  }
61  pkt->makeAtomicResponse();
62  return latency;
63 }
64 
65 Tick
67 {
68  assert(pkt->getSize() == 1);
69  switch(pkt->getAddr() - pioAddr)
70  {
71  case 0x0:
72  address = pkt->getLE<uint8_t>();
73  break;
74  case 0x1:
75  writeRegister(address, pkt->getLE<uint8_t>());
76  break;
77  default:
78  panic("Write to undefined CMOS port.\n");
79  }
80  pkt->makeAtomicResponse();
81  return latency;
82 }
83 
84 uint8_t
86 {
87  assert(reg < numRegs);
88  uint8_t val;
89  if (reg <= 0xD) {
90  val = rtc.readData(reg);
91  DPRINTF(CMOS,
92  "Reading CMOS RTC reg %x as %x.\n", reg, val);
93  } else {
94  val = regs[reg];
95  DPRINTF(CMOS,
96  "Reading non-volitile CMOS address %x as %x.\n", reg, val);
97  }
98  return val;
99 }
100 
101 void
103 {
104  assert(reg < numRegs);
105  if (reg <= 0xD) {
106  DPRINTF(CMOS, "Writing CMOS RTC reg %x with %x.\n",
107  reg, val);
108  rtc.writeData(reg, val);
109  } else {
110  DPRINTF(CMOS, "Writing non-volitile CMOS address %x with %x.\n",
111  reg, val);
112  regs[reg] = val;
113  }
114 }
115 
116 void
118 {
119  rtc.startup();
120 }
121 
122 void
124 {
127 
128  // Serialize the timer
129  rtc.serialize("rtc", cp);
130 }
131 
132 void
134 {
137 
138  // Serialize the timer
139  rtc.unserialize("rtc", cp);
140 }
141 
142 X86ISA::Cmos *
143 CmosParams::create()
144 {
145  return new X86ISA::Cmos(this);
146 }
Packet::makeAtomicResponse
void makeAtomicResponse()
Definition: packet.hh:1016
X86ISA::Cmos::numRegs
static const int numRegs
Definition: cmos.hh:47
BasicPioDevice::pioAddr
Addr pioAddr
Address that the device listens to.
Definition: io_device.hh:154
MC146818::unserialize
void unserialize(const std::string &base, CheckpointIn &cp)
Reconstruct the state of this object from a checkpoint.
Definition: mc146818.cc:285
UNSERIALIZE_SCALAR
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:797
Packet::getAddr
Addr getAddr() const
Definition: packet.hh:754
X86ISA::Cmos::readRegister
uint8_t readRegister(uint8_t reg)
Definition: cmos.cc:85
X86ISA::Cmos::X86RTC::handleEvent
void handleEvent()
Definition: cmos.cc:37
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
X86ISA::Cmos::writeRegister
void writeRegister(uint8_t reg, uint8_t val)
Definition: cmos.cc:102
X86ISA::Cmos::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: cmos.cc:133
Packet::getSize
unsigned getSize() const
Definition: packet.hh:764
X86ISA::reg
Bitfield< 5, 3 > reg
Definition: types.hh:87
MC146818::serialize
void serialize(const std::string &base, CheckpointOut &cp) const
Serialize this object to the given output stream.
Definition: mc146818.cc:265
cp
Definition: cprintf.cc:40
X86ISA::Cmos::latency
Tick latency
Definition: cmos.hh:43
intdev.hh
MC146818::readData
uint8_t readData(const uint8_t addr)
RTC read data.
Definition: mc146818.cc:228
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
X86ISA::Cmos::read
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: cmos.cc:47
X86ISA::Cmos::startup
void startup() override
startup() is the final initialization call before simulation.
Definition: cmos.cc:117
cmos.hh
SERIALIZE_ARRAY
#define SERIALIZE_ARRAY(member, size)
Definition: serialize.hh:832
X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:769
SERIALIZE_SCALAR
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:790
packet_access.hh
X86ISA::Cmos::write
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: cmos.cc:66
Packet::getLE
T getLE() const
Get the data in the packet byte swapped from little endian to host endian.
Definition: packet_access.hh:75
X86ISA::Cmos::address
uint8_t address
Definition: cmos.hh:45
X86ISA::Cmos
Definition: cmos.hh:40
X86ISA::Cmos::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: cmos.cc:123
MC146818::writeData
void writeData(const uint8_t addr, const uint8_t data)
RTC write data.
Definition: mc146818.cc:135
UNSERIALIZE_ARRAY
#define UNSERIALIZE_ARRAY(member, size)
Definition: serialize.hh:840
X86ISA::Cmos::regs
uint8_t regs[numRegs]
Definition: cmos.hh:49
X86ISA::Cmos::rtc
X86ISA::Cmos::X86RTC rtc
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
Packet::setLE
void setLE(T v)
Set the value in the data pointer to v as little endian.
Definition: packet_access.hh:105
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:63
trace.hh
CheckpointIn
Definition: serialize.hh:67
X86ISA::Cmos::X86RTC::intPin
std::vector< IntSourcePin< X86RTC > * > intPin
Definition: cmos.hh:57
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
MC146818::startup
virtual void startup()
Start ticking.
Definition: mc146818.cc:123

Generated on Wed Sep 30 2020 14:02:11 for gem5 by doxygen 1.8.17