2 * Copyright (c) 2006 The Regents of The University of Michigan
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.
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.
32 * This device acts as a disk similar to the memory mapped disk device
33 * in legion. Any access is translated to an offset in the disk image.
36 #include "dev/sparc/mm_disk.hh"
40 #include "base/trace.hh"
41 #include "debug/IdeDisk.hh"
42 #include "dev/platform.hh"
43 #include "mem/packet_access.hh"
44 #include "mem/port.hh"
45 #include "sim/byteswap.hh"
46 #include "sim/system.hh"
48 MmDisk::MmDisk(const Params
*p
)
49 : BasicPioDevice(p
, p
->image
->size() * SectorSize
),
50 image(p
->image
), curSector((off_t
)-1), dirty(false)
52 std::memset(&diskData
, 0, SectorSize
);
56 MmDisk::read(PacketPtr pkt
)
64 assert(pkt
->getAddr() >= pioAddr
&& pkt
->getAddr() < pioAddr
+ pioSize
);
65 accessAddr
= pkt
->getAddr() - pioAddr
;
67 sector
= accessAddr
/ SectorSize
;
69 if (sector
!= curSector
) {
74 image
->write(diskData
, curSector
);
75 assert(bytes_written
== SectorSize
);
80 image
->read(diskData
, sector
);
81 assert(bytes_read
== SectorSize
);
84 switch (pkt
->getSize()) {
86 pkt
->setRaw(diskData
[accessAddr
% SectorSize
]);
87 DPRINTF(IdeDisk
, "reading byte %#x value= %#x\n",
88 accessAddr
, diskData
[accessAddr
% SectorSize
]);
90 case sizeof(uint16_t):
91 memcpy(&d16
, diskData
+ (accessAddr
% SectorSize
), 2);
93 DPRINTF(IdeDisk
, "reading word %#x value= %#x\n", accessAddr
, d16
);
95 case sizeof(uint32_t):
96 memcpy(&d32
, diskData
+ (accessAddr
% SectorSize
), 4);
98 DPRINTF(IdeDisk
, "reading dword %#x value= %#x\n", accessAddr
, d32
);
100 case sizeof(uint64_t):
101 memcpy(&d64
, diskData
+ (accessAddr
% SectorSize
), 8);
103 DPRINTF(IdeDisk
, "reading qword %#x value= %#x\n", accessAddr
, d64
);
106 panic("Invalid access size\n");
109 pkt
->makeAtomicResponse();
114 MmDisk::write(PacketPtr pkt
)
122 assert(pkt
->getAddr() >= pioAddr
&& pkt
->getAddr() < pioAddr
+ pioSize
);
123 accessAddr
= pkt
->getAddr() - pioAddr
;
125 sector
= accessAddr
/ SectorSize
;
127 if (sector
!= curSector
) {
130 off_t bytes_written
=
132 image
->write(diskData
, curSector
);
133 assert(bytes_written
== SectorSize
);
138 image
->read(diskData
, sector
);
139 assert(bytes_read
== SectorSize
);
144 switch (pkt
->getSize()) {
145 case sizeof(uint8_t):
146 diskData
[accessAddr
% SectorSize
] = htobe(pkt
->getRaw
<uint8_t>());
147 DPRINTF(IdeDisk
, "writing byte %#x value= %#x\n",
148 accessAddr
, diskData
[accessAddr
% SectorSize
]);
150 case sizeof(uint16_t):
151 d16
= pkt
->getRaw
<uint16_t>();
152 memcpy(diskData
+ (accessAddr
% SectorSize
), &d16
, 2);
153 DPRINTF(IdeDisk
, "writing word %#x value= %#x\n", accessAddr
, d16
);
155 case sizeof(uint32_t):
156 d32
= pkt
->getRaw
<uint32_t>();
157 memcpy(diskData
+ (accessAddr
% SectorSize
), &d32
, 4);
158 DPRINTF(IdeDisk
, "writing dword %#x value= %#x\n", accessAddr
, d32
);
160 case sizeof(uint64_t):
161 d64
= pkt
->getRaw
<uint64_t>();
162 memcpy(diskData
+ (accessAddr
% SectorSize
), &d64
, 8);
163 DPRINTF(IdeDisk
, "writing qword %#x value= %#x\n", accessAddr
, d64
);
166 panic("Invalid access size\n");
169 pkt
->makeAtomicResponse();
174 MmDisk::serialize(CheckpointOut
&cp
) const
176 // just write any dirty changes to the cow layer it will take care of
182 image
->write(diskData
, curSector
);
183 assert(bytes_read
== SectorSize
);
185 ClockedObject::serialize(cp
);
189 MmDiskParams::create()
191 return new MmDisk(this);