2 * Copyright (c) 2001-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 #include "base/chunk_generator.hh"
31 #include "mem/port.hh"
32 #include "mem/translating_port.hh"
33 #include "mem/page_table.hh"
35 using namespace TheISA
;
37 TranslatingPort::TranslatingPort(const std::string
&_name
,
38 PageTable
*p_table
, bool alloc
)
39 : FunctionalPort(_name
), pTable(p_table
), allocating(alloc
)
42 TranslatingPort::~TranslatingPort()
46 TranslatingPort::tryReadBlob(Addr addr
, uint8_t *p
, int size
)
51 for (ChunkGenerator
gen(addr
, size
, VMPageSize
); !gen
.done(); gen
.next()) {
53 if (!pTable
->translate(gen
.addr(),paddr
))
56 Port::readBlob(paddr
, p
+ prevSize
, gen
.size());
57 prevSize
+= gen
.size();
64 TranslatingPort::readBlob(Addr addr
, uint8_t *p
, int size
)
66 if (!tryReadBlob(addr
, p
, size
))
67 fatal("readBlob(0x%x, ...) failed", addr
);
72 TranslatingPort::tryWriteBlob(Addr addr
, uint8_t *p
, int size
)
78 for (ChunkGenerator
gen(addr
, size
, VMPageSize
); !gen
.done(); gen
.next()) {
80 if (!pTable
->translate(gen
.addr(), paddr
)) {
82 pTable
->allocate(roundDown(gen
.addr(), VMPageSize
),
84 pTable
->translate(gen
.addr(), paddr
);
90 Port::writeBlob(paddr
, p
+ prevSize
, gen
.size());
91 prevSize
+= gen
.size();
99 TranslatingPort::writeBlob(Addr addr
, uint8_t *p
, int size
)
101 if (!tryWriteBlob(addr
, p
, size
))
102 fatal("writeBlob(0x%x, ...) failed", addr
);
106 TranslatingPort::tryMemsetBlob(Addr addr
, uint8_t val
, int size
)
110 for (ChunkGenerator
gen(addr
, size
, VMPageSize
); !gen
.done(); gen
.next()) {
112 if (!pTable
->translate(gen
.addr(), paddr
)) {
114 pTable
->allocate(roundDown(gen
.addr(), VMPageSize
),
116 pTable
->translate(gen
.addr(), paddr
);
122 Port::memsetBlob(paddr
, val
, gen
.size());
129 TranslatingPort::memsetBlob(Addr addr
, uint8_t val
, int size
)
131 if (!tryMemsetBlob(addr
, val
, size
))
132 fatal("memsetBlob(0x%x, ...) failed", addr
);
137 TranslatingPort::tryWriteString(Addr addr
, const char *str
)
146 if (!pTable
->translate(vaddr
++,paddr
))
149 Port::writeBlob(paddr
, &c
, 1);
156 TranslatingPort::writeString(Addr addr
, const char *str
)
158 if (!tryWriteString(addr
, str
))
159 fatal("writeString(0x%x, ...) failed", addr
);
163 TranslatingPort::tryReadString(std::string
&str
, Addr addr
)
171 if (!pTable
->translate(vaddr
++,paddr
))
174 Port::readBlob(paddr
, &c
, 1);
182 TranslatingPort::readString(std::string
&str
, Addr addr
)
184 if (!tryReadString(str
, addr
))
185 fatal("readString(0x%x, ...) failed", addr
);