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.
28 * Authors: Ron Dreslinski
34 #include "base/chunk_generator.hh"
35 #include "config/the_isa.hh"
36 #include "mem/port.hh"
37 #include "mem/translating_port.hh"
38 #include "mem/page_table.hh"
39 #include "sim/process.hh"
41 using namespace TheISA
;
43 TranslatingPort::TranslatingPort(const std::string
&_name
,
44 Process
*p
, AllocType alloc
)
45 : FunctionalPort(_name
), pTable(p
->pTable
), process(p
),
49 TranslatingPort::~TranslatingPort()
53 TranslatingPort::tryReadBlob(Addr addr
, uint8_t *p
, int size
)
58 for (ChunkGenerator
gen(addr
, size
, VMPageSize
); !gen
.done(); gen
.next()) {
60 if (!pTable
->translate(gen
.addr(),paddr
))
63 Port::readBlob(paddr
, p
+ prevSize
, gen
.size());
64 prevSize
+= gen
.size();
71 TranslatingPort::readBlob(Addr addr
, uint8_t *p
, int size
)
73 if (!tryReadBlob(addr
, p
, size
))
74 fatal("readBlob(0x%x, ...) failed", addr
);
79 TranslatingPort::tryWriteBlob(Addr addr
, uint8_t *p
, int size
)
85 for (ChunkGenerator
gen(addr
, size
, VMPageSize
); !gen
.done(); gen
.next()) {
87 if (!pTable
->translate(gen
.addr(), paddr
)) {
88 if (allocating
== Always
) {
89 pTable
->allocate(roundDown(gen
.addr(), VMPageSize
),
91 } else if (allocating
== NextPage
) {
92 // check if we've accessed the next page on the stack
93 if (!process
->checkAndAllocNextPage(gen
.addr()))
94 panic("Page table fault when accessing virtual address %#x "
95 "during functional write\n", gen
.addr());
99 pTable
->translate(gen
.addr(), paddr
);
102 Port::writeBlob(paddr
, p
+ prevSize
, gen
.size());
103 prevSize
+= gen
.size();
111 TranslatingPort::writeBlob(Addr addr
, uint8_t *p
, int size
)
113 if (!tryWriteBlob(addr
, p
, size
))
114 fatal("writeBlob(0x%x, ...) failed", addr
);
118 TranslatingPort::tryMemsetBlob(Addr addr
, uint8_t val
, int size
)
122 for (ChunkGenerator
gen(addr
, size
, VMPageSize
); !gen
.done(); gen
.next()) {
124 if (!pTable
->translate(gen
.addr(), paddr
)) {
125 if (allocating
== Always
) {
126 pTable
->allocate(roundDown(gen
.addr(), VMPageSize
),
128 pTable
->translate(gen
.addr(), paddr
);
134 Port::memsetBlob(paddr
, val
, gen
.size());
141 TranslatingPort::memsetBlob(Addr addr
, uint8_t val
, int size
)
143 if (!tryMemsetBlob(addr
, val
, size
))
144 fatal("memsetBlob(0x%x, ...) failed", addr
);
149 TranslatingPort::tryWriteString(Addr addr
, const char *str
)
158 if (!pTable
->translate(vaddr
++,paddr
))
161 Port::writeBlob(paddr
, &c
, 1);
168 TranslatingPort::writeString(Addr addr
, const char *str
)
170 if (!tryWriteString(addr
, str
))
171 fatal("writeString(0x%x, ...) failed", addr
);
175 TranslatingPort::tryReadString(std::string
&str
, Addr addr
)
183 if (!pTable
->translate(vaddr
++,paddr
))
186 Port::readBlob(paddr
, &c
, 1);
194 TranslatingPort::readString(std::string
&str
, Addr addr
)
196 if (!tryReadString(str
, addr
))
197 fatal("readString(0x%x, ...) failed", addr
);