isa_fake.cc revision 4762:c94e103c83ad
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 * Authors: Ali Saidi
29 */
30
31/** @file
32 * Isa Fake Device implementation
33 */
34
35#include "base/trace.hh"
36#include "dev/isa_fake.hh"
37#include "mem/packet.hh"
38#include "mem/packet_access.hh"
39#include "sim/system.hh"
40
41using namespace std;
42
43IsaFake::IsaFake(Params *p)
44    : BasicPioDevice(p)
45{
46    if (!p->ret_bad_addr)
47        pioSize = p->pio_size;
48
49    retData8 = p->ret_data8;
50    retData16 = p->ret_data16;
51    retData32 = p->ret_data32;
52    retData64 = p->ret_data64;
53}
54
55Tick
56IsaFake::read(PacketPtr pkt)
57{
58    assert(pkt->result == Packet::Unknown);
59
60    if (params()->warn_access != "")
61        warn("Device %s accessed by read to address %#x size=%d\n",
62                name(), pkt->getAddr(), pkt->getSize());
63    if (params()->ret_bad_addr) {
64        DPRINTF(Tsunami, "read to bad address va=%#x size=%d\n",
65                pkt->getAddr(), pkt->getSize());
66        pkt->result = Packet::BadAddress;
67    } else {
68        assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
69        DPRINTF(Tsunami, "read  va=%#x size=%d\n",
70                pkt->getAddr(), pkt->getSize());
71        switch (pkt->getSize()) {
72          case sizeof(uint64_t):
73             pkt->set(retData64);
74             break;
75          case sizeof(uint32_t):
76             pkt->set(retData32);
77             break;
78          case sizeof(uint16_t):
79             pkt->set(retData16);
80             break;
81          case sizeof(uint8_t):
82             pkt->set(retData8);
83             break;
84          default:
85            panic("invalid access size!\n");
86        }
87        pkt->result = Packet::Success;
88    }
89    return pioDelay;
90}
91
92Tick
93IsaFake::write(PacketPtr pkt)
94{
95    if (params()->warn_access != "") {
96        uint64_t data;
97        switch (pkt->getSize()) {
98          case sizeof(uint64_t):
99            data = pkt->get<uint64_t>();
100            break;
101          case sizeof(uint32_t):
102            data = pkt->get<uint32_t>();
103            break;
104          case sizeof(uint16_t):
105            data = pkt->get<uint16_t>();
106            break;
107          case sizeof(uint8_t):
108            data = pkt->get<uint8_t>();
109            break;
110          default:
111            panic("invalid access size!\n");
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(Tsunami, "write to bad address va=%#x size=%d \n",
118                pkt->getAddr(), pkt->getSize());
119        pkt->result = Packet::BadAddress;
120    } else {
121        DPRINTF(Tsunami, "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->get<uint64_t>();
128                break;
129              case sizeof(uint32_t):
130                retData32 = pkt->get<uint32_t>();
131                break;
132              case sizeof(uint16_t):
133                retData16 = pkt->get<uint16_t>();
134                break;
135              case sizeof(uint8_t):
136                retData8 = pkt->get<uint8_t>();
137                break;
138              default:
139                panic("invalid access size!\n");
140            }
141        }
142        pkt->result = Packet::Success;
143    }
144    return pioDelay;
145}
146
147IsaFake *
148IsaFakeParams::create()
149{
150    return new IsaFake(this);
151}
152