gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
36namespace gem5
37{
38
39void
41{
42 for (auto *wire: intPin) {
43 wire->raise();
44 //XXX This is a hack.
45 wire->lower();
46 }
47}
48
49Tick
51{
52 assert(pkt->getSize() == 1);
53 switch(pkt->getAddr() - pioAddr)
54 {
55 case 0x0:
56 pkt->setLE(address);
57 break;
58 case 0x1:
59 pkt->setLE(readRegister(address.regNum));
60 break;
61 default:
62 panic("Read from undefined CMOS port.\n");
63 }
64 pkt->makeAtomicResponse();
65 return latency;
66}
67
68Tick
70{
71 assert(pkt->getSize() == 1);
72 switch(pkt->getAddr() - pioAddr)
73 {
74 case 0x0:
75 address = pkt->getLE<uint8_t>();
76 break;
77 case 0x1:
78 // Ignore the NMI mask bit since we never try to generate one anyway.
79 writeRegister(address.regNum, pkt->getLE<uint8_t>());
80 break;
81 default:
82 panic("Write to undefined CMOS port.\n");
83 }
84 pkt->makeAtomicResponse();
85 return latency;
86}
87
88uint8_t
90{
91 assert(reg < numRegs);
92 uint8_t val;
93 if (reg <= 0xD) {
95 DPRINTF(CMOS,
96 "Reading CMOS RTC reg %x as %x.\n", reg, val);
97 } else {
98 val = regs[reg];
99 DPRINTF(CMOS,
100 "Reading non-volitile CMOS address %x as %x.\n", reg, val);
101 }
102 return val;
103}
104
105void
107{
108 assert(reg < numRegs);
109 if (reg <= 0xD) {
110 DPRINTF(CMOS, "Writing CMOS RTC reg %x with %x.\n",
111 reg, val);
113 } else {
114 DPRINTF(CMOS, "Writing non-volitile CMOS address %x with %x.\n",
115 reg, val);
116 regs[reg] = val;
117 }
118}
119
120void
125
126void
128{
129 SERIALIZE_SCALAR(address);
131
132 // Serialize the timer
133 rtc.serialize("rtc", cp);
134}
135
136void
138{
139 UNSERIALIZE_SCALAR(address);
141
142 // Serialize the timer
143 rtc.unserialize("rtc", cp);
144}
145
146} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:210
Addr pioAddr
Address that the device listens to.
Definition io_device.hh:151
virtual void startup()
Start ticking.
Definition mc146818.cc:124
void serialize(const std::string &base, CheckpointOut &cp) const
Serialize this object to the given output stream.
Definition mc146818.cc:267
void unserialize(const std::string &base, CheckpointIn &cp)
Reconstruct the state of this object from a checkpoint.
Definition mc146818.cc:287
uint8_t readData(const uint8_t addr)
RTC read data.
Definition mc146818.cc:229
void writeData(const uint8_t addr, const uint8_t data)
RTC write data.
Definition mc146818.cc:136
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
Addr getAddr() const
Definition packet.hh:807
void setLE(T v)
Set the value in the data pointer to v as little endian.
unsigned getSize() const
Definition packet.hh:817
void makeAtomicResponse()
Definition packet.hh:1074
T getLE() const
Get the data in the packet byte swapped from little endian to host endian.
std::vector< IntSourcePin< X86RTC > * > intPin
Definition cmos.hh:66
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition cmos.cc:69
void startup() override
startup() is the final initialization call before simulation.
Definition cmos.cc:121
gem5::X86ISA::Cmos::X86RTC rtc
static const int numRegs
Definition cmos.hh:56
uint8_t regs[numRegs]
Definition cmos.hh:58
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition cmos.cc:137
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition cmos.cc:50
void writeRegister(uint8_t reg, uint8_t val)
Definition cmos.cc:106
uint8_t readRegister(uint8_t reg)
Definition cmos.cc:89
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition cmos.cc:127
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
#define UNSERIALIZE_ARRAY(member, size)
Definition serialize.hh:618
#define SERIALIZE_ARRAY(member, size)
Definition serialize.hh:610
Bitfield< 5, 3 > reg
Definition types.hh:92
Bitfield< 63 > val
Definition misc.hh:804
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::ostream CheckpointOut
Definition serialize.hh:66
uint64_t Tick
Tick count type.
Definition types.hh:58
#define UNSERIALIZE_SCALAR(scalar)
Definition serialize.hh:575
#define SERIALIZE_SCALAR(scalar)
Definition serialize.hh:568

Generated on Tue Jun 18 2024 16:24:04 for gem5 by doxygen 1.11.0