2 * Copyright (c) 2004-2005 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.
30 * Isa Fake Device implementation
33 #include "dev/isa_fake.hh"
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"
41 IsaFake::IsaFake(const Params
&p
)
42 : BasicPioDevice(p
, p
.ret_bad_addr
? 0 : p
.pio_size
)
44 retData8
= p
.ret_data8
;
45 retData16
= p
.ret_data16
;
46 retData32
= p
.ret_data32
;
47 retData64
= p
.ret_data64
;
51 IsaFake::read(PacketPtr pkt
)
53 pkt
->makeAtomicResponse();
55 if (params().warn_access
!= "")
56 warn("Device %s accessed by read to address %#x size=%d\n",
57 name(), pkt
->getAddr(), pkt
->getSize());
58 if (params().ret_bad_addr
) {
59 DPRINTF(IsaFake
, "read to bad address va=%#x size=%d\n",
60 pkt
->getAddr(), pkt
->getSize());
63 assert(pkt
->getAddr() >= pioAddr
&& pkt
->getAddr() < pioAddr
+ pioSize
);
64 DPRINTF(IsaFake
, "read va=%#x size=%d\n",
65 pkt
->getAddr(), pkt
->getSize());
66 switch (pkt
->getSize()) {
67 case sizeof(uint64_t):
68 pkt
->setLE(retData64
);
70 case sizeof(uint32_t):
71 pkt
->setLE(retData32
);
73 case sizeof(uint16_t):
74 pkt
->setLE(retData16
);
80 if (params().fake_mem
)
81 std::memset(pkt
->getPtr
<uint8_t>(), 0, pkt
->getSize());
83 panic("invalid access size! Device being accessed by cache?\n");
90 IsaFake::write(PacketPtr pkt
)
92 pkt
->makeAtomicResponse();
93 if (params().warn_access
!= "") {
95 switch (pkt
->getSize()) {
96 case sizeof(uint64_t):
97 data
= pkt
->getLE
<uint64_t>();
99 case sizeof(uint32_t):
100 data
= pkt
->getLE
<uint32_t>();
102 case sizeof(uint16_t):
103 data
= pkt
->getLE
<uint16_t>();
105 case sizeof(uint8_t):
106 data
= pkt
->getLE
<uint8_t>();
109 panic("invalid access size: %u\n", pkt
->getSize());
111 warn("Device %s accessed by write to address %#x size=%d data=%#x\n",
112 name(), pkt
->getAddr(), pkt
->getSize(), data
);
114 if (params().ret_bad_addr
) {
115 DPRINTF(IsaFake
, "write to bad address va=%#x size=%d \n",
116 pkt
->getAddr(), pkt
->getSize());
117 pkt
->setBadAddress();
119 DPRINTF(IsaFake
, "write - va=%#x size=%d \n",
120 pkt
->getAddr(), pkt
->getSize());
122 if (params().update_data
) {
123 switch (pkt
->getSize()) {
124 case sizeof(uint64_t):
125 retData64
= pkt
->getLE
<uint64_t>();
127 case sizeof(uint32_t):
128 retData32
= pkt
->getLE
<uint32_t>();
130 case sizeof(uint16_t):
131 retData16
= pkt
->getLE
<uint16_t>();
133 case sizeof(uint8_t):
134 retData8
= pkt
->getLE
<uint8_t>();
137 panic("invalid access size!\n");