mm_disk.cc (8229:78bf55f23338) mm_disk.cc (8232:b28d06a175be)
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 * Authors: Ali Saidi
29 */
30
31/** @file
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.
34 */
35
36#include <cstring>
37
38#include "base/trace.hh"
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 * Authors: Ali Saidi
29 */
30
31/** @file
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.
34 */
35
36#include <cstring>
37
38#include "base/trace.hh"
39#include "debug/IdeDisk.hh"
39#include "dev/sparc/mm_disk.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
46MmDisk::MmDisk(const Params *p)
47 : BasicPioDevice(p), image(p->image), curSector((off_t)-1), dirty(false)
48{
49 std::memset(&diskData, 0, SectorSize);
50 pioSize = image->size() * SectorSize;
51}
52
53Tick
54MmDisk::read(PacketPtr pkt)
55{
56 Addr accessAddr;
57 off_t sector;
58 off_t bytes_read;
59 uint16_t d16;
60 uint32_t d32;
61 uint64_t d64;
62
63 assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
64 accessAddr = pkt->getAddr() - pioAddr;
65
66 sector = accessAddr / SectorSize;
67
68 if (sector != curSector) {
69 if (dirty) {
70 bytes_read = image->write(diskData, curSector);
71 assert(bytes_read == SectorSize);
72 }
73 bytes_read = image->read(diskData, sector);
74 assert(bytes_read == SectorSize);
75 curSector = sector;
76 }
77 switch (pkt->getSize()) {
78 case sizeof(uint8_t):
79 pkt->set(diskData[accessAddr % SectorSize]);
80 DPRINTF(IdeDisk, "reading byte %#x value= %#x\n", accessAddr, diskData[accessAddr %
81 SectorSize]);
82 break;
83 case sizeof(uint16_t):
84 memcpy(&d16, diskData + (accessAddr % SectorSize), 2);
85 pkt->set(htobe(d32));
86 DPRINTF(IdeDisk, "reading word %#x value= %#x\n", accessAddr, d16);
87 break;
88 case sizeof(uint32_t):
89 memcpy(&d32, diskData + (accessAddr % SectorSize), 4);
90 pkt->set(htobe(d32));
91 DPRINTF(IdeDisk, "reading dword %#x value= %#x\n", accessAddr, d32);
92 break;
93 case sizeof(uint64_t):
94 memcpy(&d64, diskData + (accessAddr % SectorSize), 8);
95 pkt->set(htobe(d64));
96 DPRINTF(IdeDisk, "reading qword %#x value= %#x\n", accessAddr, d64);
97 break;
98 default:
99 panic("Invalid access size\n");
100 }
101
102 pkt->makeAtomicResponse();
103 return pioDelay;
104}
105
106Tick
107MmDisk::write(PacketPtr pkt)
108{
109 Addr accessAddr;
110 off_t sector;
111 off_t bytes_read;
112 uint16_t d16;
113 uint32_t d32;
114 uint64_t d64;
115
116 assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
117 accessAddr = pkt->getAddr() - pioAddr;
118
119 sector = accessAddr / SectorSize;
120
121 if (sector != curSector) {
122 if (dirty) {
123 bytes_read = image->write(diskData, curSector);
124 assert(bytes_read == SectorSize);
125 }
126 bytes_read = image->read(diskData, sector);
127 assert(bytes_read == SectorSize);
128 curSector = sector;
129 }
130 dirty = true;
131
132 switch (pkt->getSize()) {
133 case sizeof(uint8_t):
134 diskData[accessAddr % SectorSize] = htobe(pkt->get<uint8_t>());
135 DPRINTF(IdeDisk, "writing byte %#x value= %#x\n", accessAddr, diskData[accessAddr %
136 SectorSize]);
137 break;
138 case sizeof(uint16_t):
139 d16 = htobe(pkt->get<uint16_t>());
140 memcpy(diskData + (accessAddr % SectorSize), &d16, 2);
141 DPRINTF(IdeDisk, "writing word %#x value= %#x\n", accessAddr, d16);
142 break;
143 case sizeof(uint32_t):
144 d32 = htobe(pkt->get<uint32_t>());
145 memcpy(diskData + (accessAddr % SectorSize), &d32, 4);
146 DPRINTF(IdeDisk, "writing dword %#x value= %#x\n", accessAddr, d32);
147 break;
148 case sizeof(uint64_t):
149 d64 = htobe(pkt->get<uint64_t>());
150 memcpy(diskData + (accessAddr % SectorSize), &d64, 8);
151 DPRINTF(IdeDisk, "writing qword %#x value= %#x\n", accessAddr, d64);
152 break;
153 default:
154 panic("Invalid access size\n");
155 }
156
157 pkt->makeAtomicResponse();
158 return pioDelay;
159}
160
161void
162MmDisk::serialize(std::ostream &os)
163{
164 // just write any dirty changes to the cow layer it will take care of
165 // serialization
166 int bytes_read;
167 if (dirty) {
168 bytes_read = image->write(diskData, curSector);
169 assert(bytes_read == SectorSize);
170 }
171}
172
173MmDisk *
174MmDiskParams::create()
175{
176 return new MmDisk(this);
177}
40#include "dev/sparc/mm_disk.hh"
41#include "dev/platform.hh"
42#include "mem/packet_access.hh"
43#include "mem/port.hh"
44#include "sim/byteswap.hh"
45#include "sim/system.hh"
46
47MmDisk::MmDisk(const Params *p)
48 : BasicPioDevice(p), image(p->image), curSector((off_t)-1), dirty(false)
49{
50 std::memset(&diskData, 0, SectorSize);
51 pioSize = image->size() * SectorSize;
52}
53
54Tick
55MmDisk::read(PacketPtr pkt)
56{
57 Addr accessAddr;
58 off_t sector;
59 off_t bytes_read;
60 uint16_t d16;
61 uint32_t d32;
62 uint64_t d64;
63
64 assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
65 accessAddr = pkt->getAddr() - pioAddr;
66
67 sector = accessAddr / SectorSize;
68
69 if (sector != curSector) {
70 if (dirty) {
71 bytes_read = image->write(diskData, curSector);
72 assert(bytes_read == SectorSize);
73 }
74 bytes_read = image->read(diskData, sector);
75 assert(bytes_read == SectorSize);
76 curSector = sector;
77 }
78 switch (pkt->getSize()) {
79 case sizeof(uint8_t):
80 pkt->set(diskData[accessAddr % SectorSize]);
81 DPRINTF(IdeDisk, "reading byte %#x value= %#x\n", accessAddr, diskData[accessAddr %
82 SectorSize]);
83 break;
84 case sizeof(uint16_t):
85 memcpy(&d16, diskData + (accessAddr % SectorSize), 2);
86 pkt->set(htobe(d32));
87 DPRINTF(IdeDisk, "reading word %#x value= %#x\n", accessAddr, d16);
88 break;
89 case sizeof(uint32_t):
90 memcpy(&d32, diskData + (accessAddr % SectorSize), 4);
91 pkt->set(htobe(d32));
92 DPRINTF(IdeDisk, "reading dword %#x value= %#x\n", accessAddr, d32);
93 break;
94 case sizeof(uint64_t):
95 memcpy(&d64, diskData + (accessAddr % SectorSize), 8);
96 pkt->set(htobe(d64));
97 DPRINTF(IdeDisk, "reading qword %#x value= %#x\n", accessAddr, d64);
98 break;
99 default:
100 panic("Invalid access size\n");
101 }
102
103 pkt->makeAtomicResponse();
104 return pioDelay;
105}
106
107Tick
108MmDisk::write(PacketPtr pkt)
109{
110 Addr accessAddr;
111 off_t sector;
112 off_t bytes_read;
113 uint16_t d16;
114 uint32_t d32;
115 uint64_t d64;
116
117 assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
118 accessAddr = pkt->getAddr() - pioAddr;
119
120 sector = accessAddr / SectorSize;
121
122 if (sector != curSector) {
123 if (dirty) {
124 bytes_read = image->write(diskData, curSector);
125 assert(bytes_read == SectorSize);
126 }
127 bytes_read = image->read(diskData, sector);
128 assert(bytes_read == SectorSize);
129 curSector = sector;
130 }
131 dirty = true;
132
133 switch (pkt->getSize()) {
134 case sizeof(uint8_t):
135 diskData[accessAddr % SectorSize] = htobe(pkt->get<uint8_t>());
136 DPRINTF(IdeDisk, "writing byte %#x value= %#x\n", accessAddr, diskData[accessAddr %
137 SectorSize]);
138 break;
139 case sizeof(uint16_t):
140 d16 = htobe(pkt->get<uint16_t>());
141 memcpy(diskData + (accessAddr % SectorSize), &d16, 2);
142 DPRINTF(IdeDisk, "writing word %#x value= %#x\n", accessAddr, d16);
143 break;
144 case sizeof(uint32_t):
145 d32 = htobe(pkt->get<uint32_t>());
146 memcpy(diskData + (accessAddr % SectorSize), &d32, 4);
147 DPRINTF(IdeDisk, "writing dword %#x value= %#x\n", accessAddr, d32);
148 break;
149 case sizeof(uint64_t):
150 d64 = htobe(pkt->get<uint64_t>());
151 memcpy(diskData + (accessAddr % SectorSize), &d64, 8);
152 DPRINTF(IdeDisk, "writing qword %#x value= %#x\n", accessAddr, d64);
153 break;
154 default:
155 panic("Invalid access size\n");
156 }
157
158 pkt->makeAtomicResponse();
159 return pioDelay;
160}
161
162void
163MmDisk::serialize(std::ostream &os)
164{
165 // just write any dirty changes to the cow layer it will take care of
166 // serialization
167 int bytes_read;
168 if (dirty) {
169 bytes_read = image->write(diskData, curSector);
170 assert(bytes_read == SectorSize);
171 }
172}
173
174MmDisk *
175MmDiskParams::create()
176{
177 return new MmDisk(this);
178}