gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  * Authors: Gabe Black
29  */
30 
31 #include "dev/x86/cmos.hh"
32 
33 #include "debug/CMOS.hh"
34 #include "dev/x86/intdev.hh"
35 #include "mem/packet_access.hh"
36 
37 void
39 {
40  assert(intPin);
41  intPin->raise();
42  //XXX This is a hack.
43  intPin->lower();
44 }
45 
46 Tick
48 {
49  assert(pkt->getSize() == 1);
50  switch(pkt->getAddr() - pioAddr)
51  {
52  case 0x0:
53  pkt->set(address);
54  break;
55  case 0x1:
56  pkt->set(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->get<uint8_t>();
73  break;
74  case 0x1:
75  writeRegister(address, pkt->get<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 }
void writeRegister(uint8_t reg, uint8_t val)
Definition: cmos.cc:102
#define DPRINTF(x,...)
Definition: trace.hh:212
void set(T v, ByteOrder endian)
Set the value in the data pointer to v using the specified endianness.
Bitfield< 5, 3 > reg
Definition: types.hh:89
uint8_t readData(const uint8_t addr)
RTC read data.
Definition: mc146818.cc:232
#define panic(...)
Definition: misc.hh:153
static const int numRegs
Definition: cmos.hh:50
uint8_t readRegister(uint8_t reg)
Definition: cmos.cc:85
void writeData(const uint8_t addr, const uint8_t data)
RTC write data.
Definition: mc146818.cc:139
Tick latency
Definition: cmos.hh:46
IntSourcePin * intPin
Definition: cmos.hh:60
void serialize(const std::string &base, CheckpointOut &cp) const
Serialize this object to the given output stream.
Definition: mc146818.cc:269
X86ISA::Cmos::X86RTC rtc
T get(ByteOrder endian) const
Get the data in the packet byte swapped from the specified endianness.
Bitfield< 63 > val
Definition: misc.hh:770
void handleEvent()
Definition: cmos.cc:38
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:145
void makeAtomicResponse()
Definition: packet.hh:857
uint64_t Tick
Tick count type.
Definition: types.hh:63
#define SERIALIZE_ARRAY(member, size)
Definition: serialize.hh:158
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: cmos.cc:47
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: cmos.cc:133
void startup() override
startup() is the final initialization call before simulation.
Definition: cmos.cc:117
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:245
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:143
#define UNSERIALIZE_ARRAY(member, size)
Definition: serialize.hh:161
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: cmos.cc:66
std::ostream CheckpointOut
Definition: serialize.hh:67
virtual void startup()
Start ticking.
Definition: mc146818.cc:127
void unserialize(const std::string &base, CheckpointIn &cp)
Reconstruct the state of this object from a checkpoint.
Definition: mc146818.cc:289
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: cmos.cc:123
uint8_t address
Definition: cmos.hh:48
unsigned getSize() const
Definition: packet.hh:649
Addr pioAddr
Address that the device listens to.
Definition: io_device.hh:139
uint8_t regs[numRegs]
Definition: cmos.hh:52
Addr getAddr() const
Definition: packet.hh:639

Generated on Fri Jun 9 2017 13:03:47 for gem5 by doxygen 1.8.6