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

Generated on Fri Jul 3 2020 15:53:02 for gem5 by doxygen 1.8.13