gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  * Authors: Ali Saidi
29  */
30 
36 #include "dev/sparc/mm_disk.hh"
37 
38 #include <cstring>
39 
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"
47 
49  : BasicPioDevice(p, p->image->size() * SectorSize),
50  image(p->image), curSector((off_t)-1), dirty(false)
51 {
52  std::memset(&diskData, 0, SectorSize);
53 }
54 
55 Tick
57 {
58  Addr accessAddr;
59  off_t sector;
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 #ifndef NDEBUG
72  off_t bytes_written =
73 #endif
75  assert(bytes_written == SectorSize);
76  }
77 #ifndef NDEBUG
78  off_t bytes_read =
79 #endif
80  image->read(diskData, sector);
81  assert(bytes_read == SectorSize);
82  curSector = sector;
83  }
84  switch (pkt->getSize()) {
85  case sizeof(uint8_t):
86  pkt->set(diskData[accessAddr % SectorSize]);
87  DPRINTF(IdeDisk, "reading byte %#x value= %#x\n", accessAddr, diskData[accessAddr %
88  SectorSize]);
89  break;
90  case sizeof(uint16_t):
91  memcpy(&d16, diskData + (accessAddr % SectorSize), 2);
92  pkt->set(htobe(d16));
93  DPRINTF(IdeDisk, "reading word %#x value= %#x\n", accessAddr, d16);
94  break;
95  case sizeof(uint32_t):
96  memcpy(&d32, diskData + (accessAddr % SectorSize), 4);
97  pkt->set(htobe(d32));
98  DPRINTF(IdeDisk, "reading dword %#x value= %#x\n", accessAddr, d32);
99  break;
100  case sizeof(uint64_t):
101  memcpy(&d64, diskData + (accessAddr % SectorSize), 8);
102  pkt->set(htobe(d64));
103  DPRINTF(IdeDisk, "reading qword %#x value= %#x\n", accessAddr, d64);
104  break;
105  default:
106  panic("Invalid access size\n");
107  }
108 
109  pkt->makeAtomicResponse();
110  return pioDelay;
111 }
112 
113 Tick
115 {
116  Addr accessAddr;
117  off_t sector;
118  uint16_t d16;
119  uint32_t d32;
120  uint64_t d64;
121 
122  assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
123  accessAddr = pkt->getAddr() - pioAddr;
124 
125  sector = accessAddr / SectorSize;
126 
127  if (sector != curSector) {
128  if (dirty) {
129 #ifndef NDEBUG
130  off_t bytes_written =
131 #endif
133  assert(bytes_written == SectorSize);
134  }
135 #ifndef NDEBUG
136  off_t bytes_read =
137 #endif
138  image->read(diskData, sector);
139  assert(bytes_read == SectorSize);
140  curSector = sector;
141  }
142  dirty = true;
143 
144  switch (pkt->getSize()) {
145  case sizeof(uint8_t):
146  diskData[accessAddr % SectorSize] = htobe(pkt->get<uint8_t>());
147  DPRINTF(IdeDisk, "writing byte %#x value= %#x\n", accessAddr, diskData[accessAddr %
148  SectorSize]);
149  break;
150  case sizeof(uint16_t):
151  d16 = htobe(pkt->get<uint16_t>());
152  memcpy(diskData + (accessAddr % SectorSize), &d16, 2);
153  DPRINTF(IdeDisk, "writing word %#x value= %#x\n", accessAddr, d16);
154  break;
155  case sizeof(uint32_t):
156  d32 = htobe(pkt->get<uint32_t>());
157  memcpy(diskData + (accessAddr % SectorSize), &d32, 4);
158  DPRINTF(IdeDisk, "writing dword %#x value= %#x\n", accessAddr, d32);
159  break;
160  case sizeof(uint64_t):
161  d64 = htobe(pkt->get<uint64_t>());
162  memcpy(diskData + (accessAddr % SectorSize), &d64, 8);
163  DPRINTF(IdeDisk, "writing qword %#x value= %#x\n", accessAddr, d64);
164  break;
165  default:
166  panic("Invalid access size\n");
167  }
168 
169  pkt->makeAtomicResponse();
170  return pioDelay;
171 }
172 
173 void
175 {
176  // just write any dirty changes to the cow layer it will take care of
177  // serialization
178  if (dirty) {
179 #ifndef NDEBUG
180  int bytes_read =
181 #endif
183  assert(bytes_read == SectorSize);
184  }
185 }
186 
187 MmDisk *
188 MmDiskParams::create()
189 {
190  return new MmDisk(this);
191 }
#define DPRINTF(x,...)
Definition: trace.hh:212
void set(T v, ByteOrder endian)
Set the value in the data pointer to v using the specified endianness.
MmDisk(const Params *p)
Definition: mm_disk.cc:48
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: mm_disk.cc:114
#define panic(...)
Definition: misc.hh:153
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: mm_disk.cc:174
PioDeviceParams Params
Definition: io_device.hh:116
off_t curSector
Definition: mm_disk.hh:47
Port Object Declaration.
This device acts as a disk similar to the memory mapped disk device in legion.
T get(ByteOrder endian) const
Get the data in the packet byte swapped from the specified endianness.
bool dirty
Definition: mm_disk.hh:48
Addr pioSize
Size that the device's address range.
Definition: io_device.hh:142
void makeAtomicResponse()
Definition: packet.hh:857
uint64_t Tick
Tick count type.
Definition: types.hh:63
virtual std::streampos write(const uint8_t *data, std::streampos offset)=0
#define SectorSize
Definition: disk_image.hh:46
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:245
uint8_t diskData[SectorSize]
Definition: mm_disk.hh:49
Generic interface for platforms.
int size()
Definition: pagetable.hh:146
IDE Disk device model.
Definition: ide_disk.hh:207
T htobe(T value)
Definition: byteswap.hh:153
std::ostream CheckpointOut
Definition: serialize.hh:67
virtual std::streampos read(uint8_t *data, std::streampos offset) const =0
Tick pioDelay
Delay that the device experinces on an access.
Definition: io_device.hh:145
DiskImage * image
Definition: mm_disk.hh:46
unsigned getSize() const
Definition: packet.hh:649
Bitfield< 0 > p
Addr pioAddr
Address that the device listens to.
Definition: io_device.hh:139
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: mm_disk.cc:56
Addr getAddr() const
Definition: packet.hh:639

Generated on Fri Jun 9 2017 13:03:47 for gem5 by doxygen 1.8.6