gem5 v24.0.0.0
Loading...
Searching...
No Matches
mm_disk.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006 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
34#include "dev/sparc/mm_disk.hh"
35
36#include <cstring>
37
38#include "base/trace.hh"
39#include "debug/IdeDisk.hh"
40#include "dev/platform.hh"
41#include "mem/packet_access.hh"
42#include "mem/port.hh"
43#include "sim/byteswap.hh"
44#include "sim/system.hh"
45
46namespace gem5
47{
48
50 : BasicPioDevice(p, p.image->size() * SectorSize),
51 image(p.image), curSector((off_t)-1), dirty(false)
52{
53 std::memset(&diskData, 0, SectorSize);
54}
55
56Tick
58{
59 Addr accessAddr;
60 off_t sector;
61 uint16_t d16;
62 uint32_t d32;
63 uint64_t d64;
64
65 assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
66 accessAddr = pkt->getAddr() - pioAddr;
67
68 sector = accessAddr / SectorSize;
69
70 if (sector != curSector) {
71 if (dirty) {
72#ifndef NDEBUG
73 off_t bytes_written =
74#endif
76 assert(bytes_written == SectorSize);
77 }
78#ifndef NDEBUG
79 off_t bytes_read =
80#endif
81 image->read(diskData, sector);
82 assert(bytes_read == SectorSize);
83 curSector = sector;
84 }
85 switch (pkt->getSize()) {
86 case sizeof(uint8_t):
87 pkt->setRaw(diskData[accessAddr % SectorSize]);
88 DPRINTF(IdeDisk, "reading byte %#x value= %#x\n",
89 accessAddr, diskData[accessAddr % SectorSize]);
90 break;
91 case sizeof(uint16_t):
92 memcpy(&d16, diskData + (accessAddr % SectorSize), 2);
93 pkt->setRaw(d16);
94 DPRINTF(IdeDisk, "reading word %#x value= %#x\n", accessAddr, d16);
95 break;
96 case sizeof(uint32_t):
97 memcpy(&d32, diskData + (accessAddr % SectorSize), 4);
98 pkt->setRaw(d32);
99 DPRINTF(IdeDisk, "reading dword %#x value= %#x\n", accessAddr, d32);
100 break;
101 case sizeof(uint64_t):
102 memcpy(&d64, diskData + (accessAddr % SectorSize), 8);
103 pkt->setRaw(d64);
104 DPRINTF(IdeDisk, "reading qword %#x value= %#x\n", accessAddr, d64);
105 break;
106 default:
107 panic("Invalid access size\n");
108 }
109
110 pkt->makeAtomicResponse();
111 return pioDelay;
112}
113
114Tick
116{
117 Addr accessAddr;
118 off_t sector;
119 uint16_t d16;
120 uint32_t d32;
121 uint64_t d64;
122
123 assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
124 accessAddr = pkt->getAddr() - pioAddr;
125
126 sector = accessAddr / SectorSize;
127
128 if (sector != curSector) {
129 if (dirty) {
130#ifndef NDEBUG
131 off_t bytes_written =
132#endif
134 assert(bytes_written == SectorSize);
135 }
136#ifndef NDEBUG
137 off_t bytes_read =
138#endif
139 image->read(diskData, sector);
140 assert(bytes_read == SectorSize);
141 curSector = sector;
142 }
143 dirty = true;
144
145 switch (pkt->getSize()) {
146 case sizeof(uint8_t):
147 diskData[accessAddr % SectorSize] = htobe(pkt->getRaw<uint8_t>());
148 DPRINTF(IdeDisk, "writing byte %#x value= %#x\n",
149 accessAddr, diskData[accessAddr % SectorSize]);
150 break;
151 case sizeof(uint16_t):
152 d16 = pkt->getRaw<uint16_t>();
153 memcpy(diskData + (accessAddr % SectorSize), &d16, 2);
154 DPRINTF(IdeDisk, "writing word %#x value= %#x\n", accessAddr, d16);
155 break;
156 case sizeof(uint32_t):
157 d32 = pkt->getRaw<uint32_t>();
158 memcpy(diskData + (accessAddr % SectorSize), &d32, 4);
159 DPRINTF(IdeDisk, "writing dword %#x value= %#x\n", accessAddr, d32);
160 break;
161 case sizeof(uint64_t):
162 d64 = pkt->getRaw<uint64_t>();
163 memcpy(diskData + (accessAddr % SectorSize), &d64, 8);
164 DPRINTF(IdeDisk, "writing qword %#x value= %#x\n", accessAddr, d64);
165 break;
166 default:
167 panic("Invalid access size\n");
168 }
169
170 pkt->makeAtomicResponse();
171 return pioDelay;
172}
173
174void
176{
177 // just write any dirty changes to the cow layer it will take care of
178 // serialization
179 if (dirty) {
180#ifndef NDEBUG
181 int bytes_read =
182#endif
184 assert(bytes_read == SectorSize);
185 }
187}
188
189} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:210
Addr pioAddr
Address that the device listens to.
Definition io_device.hh:151
Tick pioDelay
Delay that the device experinces on an access.
Definition io_device.hh:157
Addr pioSize
Size that the device's address range.
Definition io_device.hh:154
void serialize(CheckpointOut &cp) const override
Serialize an object.
virtual std::streampos write(const uint8_t *data, std::streampos offset)=0
virtual std::streampos read(uint8_t *data, std::streampos offset) const =0
IDE Disk device model.
Definition ide_disk.hh:217
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition mm_disk.cc:115
MmDisk(const Params &p)
Definition mm_disk.cc:49
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition mm_disk.cc:57
MmDiskParams Params
Definition mm_disk.hh:53
DiskImage * image
Definition mm_disk.hh:47
uint8_t diskData[SectorSize]
Definition mm_disk.hh:50
off_t curSector
Definition mm_disk.hh:48
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition mm_disk.cc:175
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 setRaw(T v)
Set the value in the data pointer to v without byte swapping.
unsigned getSize() const
Definition packet.hh:817
T getRaw() const
Get the data in the packet without byte swapping.
void makeAtomicResponse()
Definition packet.hh:1074
#define SectorSize
Definition disk_image.hh:44
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
Port Object Declaration.
This device acts as a disk similar to the memory mapped disk device in legion.
Bitfield< 0 > p
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 Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
uint64_t Tick
Tick count type.
Definition types.hh:58
T htobe(T value)
Definition byteswap.hh:174
Generic interface for platforms.

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