se_translating_port_proxy.cc revision 14009
17584SN/A/*
28869SAli.Saidi@ARM.com * Copyright (c) 2011 ARM Limited
37584SN/A * All rights reserved
47584SN/A *
57584SN/A * The license below extends only to copyright in the software and shall
67584SN/A * not be construed as granting a license to any other intellectual
77584SN/A * property including but not limited to intellectual property relating
87584SN/A * to a hardware implementation of the functionality of the software
97584SN/A * licensed hereunder.  You may use the software subject to the license
107584SN/A * terms below provided that you ensure that this notice is replicated
117584SN/A * unmodified and in its entirety in all distributions of the software,
127584SN/A * modified or unmodified, in source code or in binary form.
137584SN/A *
147584SN/A * Copyright (c) 2001-2005 The Regents of The University of Michigan
157584SN/A * All rights reserved.
167584SN/A *
177584SN/A * Redistribution and use in source and binary forms, with or without
187584SN/A * modification, are permitted provided that the following conditions are
197584SN/A * met: redistributions of source code must retain the above copyright
207584SN/A * notice, this list of conditions and the following disclaimer;
217584SN/A * redistributions in binary form must reproduce the above copyright
227584SN/A * notice, this list of conditions and the following disclaimer in the
237584SN/A * documentation and/or other materials provided with the distribution;
247584SN/A * neither the name of the copyright holders nor the names of its
257584SN/A * contributors may be used to endorse or promote products derived from
267584SN/A * this software without specific prior written permission.
277584SN/A *
287584SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
297584SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
307584SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
317584SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
327584SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
337584SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
347584SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
357584SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
367584SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
377584SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
387584SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
397584SN/A *
407584SN/A * Authors: Ron Dreslinski
418869SAli.Saidi@ARM.com *          Steve Reinhardt
427584SN/A *          Andreas Hansson
438245SN/A */
448245SN/A
458869SAli.Saidi@ARM.com#include "mem/se_translating_port_proxy.hh"
468869SAli.Saidi@ARM.com
477584SN/A#include <string>
487584SN/A
497584SN/A#include "arch/isa_traits.hh"
508869SAli.Saidi@ARM.com#include "base/chunk_generator.hh"
519808Sstever@gmail.com#include "config/the_isa.hh"
529808Sstever@gmail.com#include "mem/page_table.hh"
539808Sstever@gmail.com#include "sim/process.hh"
547584SN/A#include "sim/system.hh"
557584SN/A
567584SN/Ausing namespace TheISA;
577584SN/A
587584SN/ASETranslatingPortProxy::SETranslatingPortProxy(MasterPort& port, Process *p,
598869SAli.Saidi@ARM.com                                           AllocType alloc)
607584SN/A    : PortProxy(port, p->system->cacheLineSize()), pTable(p->pTable),
617584SN/A      process(p), allocating(alloc)
627584SN/A{ }
637584SN/A
648869SAli.Saidi@ARM.combool
657584SN/ASETranslatingPortProxy::tryReadBlob(Addr addr, void *p, int size) const
668869SAli.Saidi@ARM.com{
678869SAli.Saidi@ARM.com    int prevSize = 0;
688869SAli.Saidi@ARM.com    auto *bytes = static_cast<uint8_t *>(p);
698869SAli.Saidi@ARM.com
708869SAli.Saidi@ARM.com    for (ChunkGenerator gen(addr, size, PageBytes); !gen.done(); gen.next()) {
718869SAli.Saidi@ARM.com        Addr paddr;
728869SAli.Saidi@ARM.com
738869SAli.Saidi@ARM.com        if (!pTable->translate(gen.addr(),paddr))
748869SAli.Saidi@ARM.com            return false;
758869SAli.Saidi@ARM.com
768869SAli.Saidi@ARM.com        PortProxy::readBlobPhys(paddr, 0, bytes + prevSize, gen.size());
778869SAli.Saidi@ARM.com        prevSize += gen.size();
788869SAli.Saidi@ARM.com    }
798869SAli.Saidi@ARM.com
808869SAli.Saidi@ARM.com    return true;
818869SAli.Saidi@ARM.com}
828869SAli.Saidi@ARM.com
838869SAli.Saidi@ARM.com
848869SAli.Saidi@ARM.combool
858869SAli.Saidi@ARM.comSETranslatingPortProxy::tryWriteBlob(Addr addr, const void *p, int size) const
868869SAli.Saidi@ARM.com{
878869SAli.Saidi@ARM.com    int prevSize = 0;
888869SAli.Saidi@ARM.com    auto *bytes = static_cast<const uint8_t *>(p);
898869SAli.Saidi@ARM.com
908869SAli.Saidi@ARM.com    for (ChunkGenerator gen(addr, size, PageBytes); !gen.done(); gen.next()) {
919806Sstever@gmail.com        Addr paddr;
928869SAli.Saidi@ARM.com
938869SAli.Saidi@ARM.com        if (!pTable->translate(gen.addr(), paddr)) {
948869SAli.Saidi@ARM.com            if (allocating == Always) {
958869SAli.Saidi@ARM.com                process->allocateMem(roundDown(gen.addr(), PageBytes),
968869SAli.Saidi@ARM.com                                     PageBytes);
978869SAli.Saidi@ARM.com            } else if (allocating == NextPage) {
988869SAli.Saidi@ARM.com                // check if we've accessed the next page on the stack
998869SAli.Saidi@ARM.com                if (!process->fixupStackFault(gen.addr()))
1008869SAli.Saidi@ARM.com                    panic("Page table fault when accessing virtual address %#x "
1018869SAli.Saidi@ARM.com                            "during functional write\n", gen.addr());
1028869SAli.Saidi@ARM.com            } else {
1038869SAli.Saidi@ARM.com                return false;
1048869SAli.Saidi@ARM.com            }
1058869SAli.Saidi@ARM.com            pTable->translate(gen.addr(), paddr);
1068869SAli.Saidi@ARM.com        }
1078869SAli.Saidi@ARM.com
1088869SAli.Saidi@ARM.com        PortProxy::writeBlobPhys(paddr, 0, bytes + prevSize, gen.size());
1098869SAli.Saidi@ARM.com        prevSize += gen.size();
1108869SAli.Saidi@ARM.com    }
1118869SAli.Saidi@ARM.com
1128869SAli.Saidi@ARM.com    return true;
1138869SAli.Saidi@ARM.com}
1148869SAli.Saidi@ARM.com
1158869SAli.Saidi@ARM.com
1167584SN/Abool
1177584SN/ASETranslatingPortProxy::tryMemsetBlob(Addr addr, uint8_t val, int size) const
1187584SN/A{
1197584SN/A    for (ChunkGenerator gen(addr, size, PageBytes); !gen.done(); gen.next()) {
1207584SN/A        Addr paddr;
1218869SAli.Saidi@ARM.com
1227584SN/A        if (!pTable->translate(gen.addr(), paddr)) {
1237584SN/A            if (allocating == Always) {
1247584SN/A                process->allocateMem(roundDown(gen.addr(), PageBytes),
1257584SN/A                                     PageBytes);
1268869SAli.Saidi@ARM.com                pTable->translate(gen.addr(), paddr);
1277584SN/A            } else {
1288869SAli.Saidi@ARM.com                return false;
1298869SAli.Saidi@ARM.com            }
1308869SAli.Saidi@ARM.com        }
1318869SAli.Saidi@ARM.com
1328869SAli.Saidi@ARM.com        PortProxy::memsetBlobPhys(paddr, 0, val, gen.size());
1338869SAli.Saidi@ARM.com    }
1348869SAli.Saidi@ARM.com
1358869SAli.Saidi@ARM.com    return true;
1368869SAli.Saidi@ARM.com}
1378869SAli.Saidi@ARM.com