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.
32 * Isa Fake Device implementation
35 #include "dev/isa_fake.hh"
37 #include "base/trace.hh"
38 #include "debug/IsaFake.hh"
39 #include "mem/packet.hh"
40 #include "mem/packet_access.hh"
41 #include "sim/system.hh"
45 IsaFake::IsaFake(Params
*p
)
46 : BasicPioDevice(p
, p
->ret_bad_addr
? 0 : p
->pio_size
)
48 retData8
= p
->ret_data8
;
49 retData16
= p
->ret_data16
;
50 retData32
= p
->ret_data32
;
51 retData64
= p
->ret_data64
;
55 IsaFake::read(PacketPtr pkt
)
57 pkt
->makeAtomicResponse();
59 if (params()->warn_access
!= "")
60 warn("Device %s accessed by read to address %#x size=%d\n",
61 name(), pkt
->getAddr(), pkt
->getSize());
62 if (params()->ret_bad_addr
) {
63 DPRINTF(IsaFake
, "read to bad address va=%#x size=%d\n",
64 pkt
->getAddr(), pkt
->getSize());
67 assert(pkt
->getAddr() >= pioAddr
&& pkt
->getAddr() < pioAddr
+ pioSize
);
68 DPRINTF(IsaFake
, "read va=%#x size=%d\n",
69 pkt
->getAddr(), pkt
->getSize());
70 switch (pkt
->getSize()) {
71 case sizeof(uint64_t):
74 case sizeof(uint32_t):
77 case sizeof(uint16_t):
84 if (params()->fake_mem
)
85 std::memset(pkt
->getPtr
<uint8_t>(), 0, pkt
->getSize());
87 panic("invalid access size! Device being accessed by cache?\n");
94 IsaFake::write(PacketPtr pkt
)
96 pkt
->makeAtomicResponse();
97 if (params()->warn_access
!= "") {
99 switch (pkt
->getSize()) {
100 case sizeof(uint64_t):
101 data
= pkt
->get
<uint64_t>();
103 case sizeof(uint32_t):
104 data
= pkt
->get
<uint32_t>();
106 case sizeof(uint16_t):
107 data
= pkt
->get
<uint16_t>();
109 case sizeof(uint8_t):
110 data
= pkt
->get
<uint8_t>();
113 panic("invalid access size: %u\n", pkt
->getSize());
115 warn("Device %s accessed by write to address %#x size=%d data=%#x\n",
116 name(), pkt
->getAddr(), pkt
->getSize(), data
);
118 if (params()->ret_bad_addr
) {
119 DPRINTF(IsaFake
, "write to bad address va=%#x size=%d \n",
120 pkt
->getAddr(), pkt
->getSize());
121 pkt
->setBadAddress();
123 DPRINTF(IsaFake
, "write - va=%#x size=%d \n",
124 pkt
->getAddr(), pkt
->getSize());
126 if (params()->update_data
) {
127 switch (pkt
->getSize()) {
128 case sizeof(uint64_t):
129 retData64
= pkt
->get
<uint64_t>();
131 case sizeof(uint32_t):
132 retData32
= pkt
->get
<uint32_t>();
134 case sizeof(uint16_t):
135 retData16
= pkt
->get
<uint16_t>();
137 case sizeof(uint8_t):
138 retData8
= pkt
->get
<uint8_t>();
141 panic("invalid access size!\n");
149 IsaFakeParams::create()
151 return new IsaFake(this);