gem5  v20.1.0.0
isa_fake.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004-2005 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 
33 #include "dev/isa_fake.hh"
34 
35 #include "base/trace.hh"
36 #include "debug/IsaFake.hh"
37 #include "mem/packet.hh"
38 #include "mem/packet_access.hh"
39 #include "sim/system.hh"
40 
41 using namespace std;
42 
44  : BasicPioDevice(p, p->ret_bad_addr ? 0 : p->pio_size)
45 {
46  retData8 = p->ret_data8;
47  retData16 = p->ret_data16;
48  retData32 = p->ret_data32;
49  retData64 = p->ret_data64;
50 }
51 
52 Tick
54 {
55  pkt->makeAtomicResponse();
56 
57  if (params()->warn_access != "")
58  warn("Device %s accessed by read to address %#x size=%d\n",
59  name(), pkt->getAddr(), pkt->getSize());
60  if (params()->ret_bad_addr) {
61  DPRINTF(IsaFake, "read to bad address va=%#x size=%d\n",
62  pkt->getAddr(), pkt->getSize());
63  pkt->setBadAddress();
64  } else {
65  assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
66  DPRINTF(IsaFake, "read va=%#x size=%d\n",
67  pkt->getAddr(), pkt->getSize());
68  switch (pkt->getSize()) {
69  case sizeof(uint64_t):
70  pkt->setLE(retData64);
71  break;
72  case sizeof(uint32_t):
73  pkt->setLE(retData32);
74  break;
75  case sizeof(uint16_t):
76  pkt->setLE(retData16);
77  break;
78  case sizeof(uint8_t):
79  pkt->setLE(retData8);
80  break;
81  default:
82  if (params()->fake_mem)
83  std::memset(pkt->getPtr<uint8_t>(), 0, pkt->getSize());
84  else
85  panic("invalid access size! Device being accessed by cache?\n");
86  }
87  }
88  return pioDelay;
89 }
90 
91 Tick
93 {
94  pkt->makeAtomicResponse();
95  if (params()->warn_access != "") {
96  uint64_t data;
97  switch (pkt->getSize()) {
98  case sizeof(uint64_t):
99  data = pkt->getLE<uint64_t>();
100  break;
101  case sizeof(uint32_t):
102  data = pkt->getLE<uint32_t>();
103  break;
104  case sizeof(uint16_t):
105  data = pkt->getLE<uint16_t>();
106  break;
107  case sizeof(uint8_t):
108  data = pkt->getLE<uint8_t>();
109  break;
110  default:
111  panic("invalid access size: %u\n", pkt->getSize());
112  }
113  warn("Device %s accessed by write to address %#x size=%d data=%#x\n",
114  name(), pkt->getAddr(), pkt->getSize(), data);
115  }
116  if (params()->ret_bad_addr) {
117  DPRINTF(IsaFake, "write to bad address va=%#x size=%d \n",
118  pkt->getAddr(), pkt->getSize());
119  pkt->setBadAddress();
120  } else {
121  DPRINTF(IsaFake, "write - va=%#x size=%d \n",
122  pkt->getAddr(), pkt->getSize());
123 
124  if (params()->update_data) {
125  switch (pkt->getSize()) {
126  case sizeof(uint64_t):
127  retData64 = pkt->getLE<uint64_t>();
128  break;
129  case sizeof(uint32_t):
130  retData32 = pkt->getLE<uint32_t>();
131  break;
132  case sizeof(uint16_t):
133  retData16 = pkt->getLE<uint16_t>();
134  break;
135  case sizeof(uint8_t):
136  retData8 = pkt->getLE<uint8_t>();
137  break;
138  default:
139  panic("invalid access size!\n");
140  }
141  }
142  }
143  return pioDelay;
144 }
145 
146 IsaFake *
147 IsaFakeParams::create()
148 {
149  return new IsaFake(this);
150 }
Packet::makeAtomicResponse
void makeAtomicResponse()
Definition: packet.hh:1016
BasicPioDevice::pioAddr
Addr pioAddr
Address that the device listens to.
Definition: io_device.hh:154
warn
#define warn(...)
Definition: logging.hh:239
system.hh
data
const char data[]
Definition: circlebuf.test.cc:42
Packet::getAddr
Addr getAddr() const
Definition: packet.hh:754
isa_fake.hh
IsaFake::retData8
uint8_t retData8
Definition: isa_fake.hh:52
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
IsaFake::params
const Params * params() const
Definition: isa_fake.hh:60
Packet::getSize
unsigned getSize() const
Definition: packet.hh:764
packet.hh
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
IsaFake::IsaFake
IsaFake(Params *p)
The constructor for Isa Fake just registers itself with the MMU.
Definition: isa_fake.cc:43
IsaFake::read
virtual Tick read(PacketPtr pkt)
This read always returns -1.
Definition: isa_fake.cc:53
IsaFake::write
virtual Tick write(PacketPtr pkt)
All writes are simply ignored.
Definition: isa_fake.cc:92
PioDevice::Params
PioDeviceParams Params
Definition: io_device.hh:131
BasicPioDevice::pioSize
Addr pioSize
Size that the device's address range.
Definition: io_device.hh:157
IsaFake::retData32
uint32_t retData32
Definition: isa_fake.hh:54
IsaFake
IsaFake is a device that returns, BadAddr, 1 or 0 on all reads and rites.
Definition: isa_fake.hh:49
packet_access.hh
SimObject::name
virtual const std::string name() const
Definition: sim_object.hh:133
IsaFake::retData16
uint16_t retData16
Definition: isa_fake.hh:53
Packet::getLE
T getLE() const
Get the data in the packet byte swapped from little endian to host endian.
Definition: packet_access.hh:75
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
Packet::setBadAddress
void setBadAddress()
Definition: packet.hh:746
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
IsaFake::retData64
uint64_t retData64
Definition: isa_fake.hh:55
BasicPioDevice::pioDelay
Tick pioDelay
Delay that the device experinces on an access.
Definition: io_device.hh:160
Packet::setLE
void setLE(T v)
Set the value in the data pointer to v as little endian.
Definition: packet_access.hh:105
Packet::getPtr
T * getPtr()
get a pointer to the data ptr.
Definition: packet.hh:1157
trace.hh
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
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