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

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