fs_translating_port_proxy.cc revision 14008
112855Sgabeblack@google.com/*
212855Sgabeblack@google.com * Copyright (c) 2011,2013 ARM Limited
312855Sgabeblack@google.com * All rights reserved
412855Sgabeblack@google.com *
512855Sgabeblack@google.com * The license below extends only to copyright in the software and shall
612855Sgabeblack@google.com * not be construed as granting a license to any other intellectual
712855Sgabeblack@google.com * property including but not limited to intellectual property relating
812855Sgabeblack@google.com * to a hardware implementation of the functionality of the software
912855Sgabeblack@google.com * licensed hereunder.  You may use the software subject to the license
1012855Sgabeblack@google.com * terms below provided that you ensure that this notice is replicated
1112855Sgabeblack@google.com * unmodified and in its entirety in all distributions of the software,
1212855Sgabeblack@google.com * modified or unmodified, in source code or in binary form.
1312855Sgabeblack@google.com *
1412855Sgabeblack@google.com * Copyright (c) 2006 The Regents of The University of Michigan
1512855Sgabeblack@google.com * All rights reserved.
1612855Sgabeblack@google.com *
1712855Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
1812855Sgabeblack@google.com * modification, are permitted provided that the following conditions are
1912855Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
2012855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
2112855Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
2212855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
2312855Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
2412855Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
2512855Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
2612855Sgabeblack@google.com * this software without specific prior written permission.
2712855Sgabeblack@google.com *
2812855Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2912855Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3012855Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3112855Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3212855Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3312855Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3412855Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3512855Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3612855Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3712855Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3812855Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3912855Sgabeblack@google.com *
4012855Sgabeblack@google.com * Authors: Ali Saidi
4112855Sgabeblack@google.com *          Andreas Hansson
4212855Sgabeblack@google.com */
4312855Sgabeblack@google.com
4412855Sgabeblack@google.com/**
4512855Sgabeblack@google.com * @file
4612855Sgabeblack@google.com * Port object definitions.
4712855Sgabeblack@google.com */
4812855Sgabeblack@google.com
4912855Sgabeblack@google.com#include "mem/fs_translating_port_proxy.hh"
5012855Sgabeblack@google.com
5112855Sgabeblack@google.com#include "arch/vtophys.hh"
5212855Sgabeblack@google.com#include "base/chunk_generator.hh"
5312855Sgabeblack@google.com#include "cpu/base.hh"
5412855Sgabeblack@google.com#include "cpu/thread_context.hh"
5512855Sgabeblack@google.com#include "sim/system.hh"
5612855Sgabeblack@google.com
5712855Sgabeblack@google.comFSTranslatingPortProxy::FSTranslatingPortProxy(ThreadContext *tc)
5812855Sgabeblack@google.com    : PortProxy(tc->getCpuPtr()->getDataPort(),
5912855Sgabeblack@google.com                tc->getSystemPtr()->cacheLineSize()), _tc(tc)
6012855Sgabeblack@google.com{
6112855Sgabeblack@google.com}
6212855Sgabeblack@google.com
6312855Sgabeblack@google.comFSTranslatingPortProxy::FSTranslatingPortProxy(MasterPort &port,
6412855Sgabeblack@google.com                                               unsigned int cacheLineSize)
6512855Sgabeblack@google.com    : PortProxy(port, cacheLineSize), _tc(NULL)
6612855Sgabeblack@google.com{
6712855Sgabeblack@google.com}
6812855Sgabeblack@google.com
6912855Sgabeblack@google.combool
7012855Sgabeblack@google.comFSTranslatingPortProxy::tryReadBlob(Addr addr, uint8_t *p, int size) const
7112855Sgabeblack@google.com{
7212855Sgabeblack@google.com    Addr paddr;
7312855Sgabeblack@google.com    for (ChunkGenerator gen(addr, size, TheISA::PageBytes); !gen.done();
7412855Sgabeblack@google.com         gen.next())
7512855Sgabeblack@google.com    {
7612855Sgabeblack@google.com        if (_tc)
7712855Sgabeblack@google.com            paddr = TheISA::vtophys(_tc,gen.addr());
7812855Sgabeblack@google.com        else
7912855Sgabeblack@google.com            paddr = TheISA::vtophys(gen.addr());
8012855Sgabeblack@google.com
8112855Sgabeblack@google.com        PortProxy::readBlobPhys(paddr, 0, p, gen.size());
8212855Sgabeblack@google.com        p += gen.size();
8312855Sgabeblack@google.com    }
8412855Sgabeblack@google.com    return true;
8512855Sgabeblack@google.com}
8612855Sgabeblack@google.com
8712855Sgabeblack@google.combool
8812855Sgabeblack@google.comFSTranslatingPortProxy::tryWriteBlob(
8912855Sgabeblack@google.com        Addr addr, const uint8_t *p, int size) const
9012855Sgabeblack@google.com{
9112855Sgabeblack@google.com    Addr paddr;
9212855Sgabeblack@google.com    for (ChunkGenerator gen(addr, size, TheISA::PageBytes); !gen.done();
9312855Sgabeblack@google.com         gen.next())
9412855Sgabeblack@google.com    {
9512855Sgabeblack@google.com        if (_tc)
9612855Sgabeblack@google.com            paddr = TheISA::vtophys(_tc,gen.addr());
9712855Sgabeblack@google.com        else
9812855Sgabeblack@google.com            paddr = TheISA::vtophys(gen.addr());
9912855Sgabeblack@google.com
10012855Sgabeblack@google.com        PortProxy::writeBlobPhys(paddr, 0, p, gen.size());
10112855Sgabeblack@google.com        p += gen.size();
10212855Sgabeblack@google.com    }
10312855Sgabeblack@google.com    return true;
10412855Sgabeblack@google.com}
10512855Sgabeblack@google.com
10612855Sgabeblack@google.combool
10712855Sgabeblack@google.comFSTranslatingPortProxy::tryMemsetBlob(Addr address, uint8_t v, int size) const
10812855Sgabeblack@google.com{
10912855Sgabeblack@google.com    Addr paddr;
11012855Sgabeblack@google.com    for (ChunkGenerator gen(address, size, TheISA::PageBytes); !gen.done();
11112855Sgabeblack@google.com         gen.next())
11212855Sgabeblack@google.com    {
11312855Sgabeblack@google.com        if (_tc)
11412855Sgabeblack@google.com            paddr = TheISA::vtophys(_tc,gen.addr());
11512855Sgabeblack@google.com        else
11612855Sgabeblack@google.com            paddr = TheISA::vtophys(gen.addr());
11712855Sgabeblack@google.com
11812855Sgabeblack@google.com        PortProxy::memsetBlobPhys(paddr, 0, v, gen.size());
11912855Sgabeblack@google.com    }
12012855Sgabeblack@google.com    return true;
12112855Sgabeblack@google.com}
12212855Sgabeblack@google.com
12312855Sgabeblack@google.comvoid
12412855Sgabeblack@google.comCopyOut(ThreadContext *tc, void *dest, Addr src, size_t cplen)
12512855Sgabeblack@google.com{
12612855Sgabeblack@google.com    uint8_t *dst = (uint8_t *)dest;
12712855Sgabeblack@google.com    tc->getVirtProxy().readBlob(src, dst, cplen);
12812855Sgabeblack@google.com}
12912855Sgabeblack@google.com
13012855Sgabeblack@google.comvoid
13112855Sgabeblack@google.comCopyIn(ThreadContext *tc, Addr dest, const void *source, size_t cplen)
13212855Sgabeblack@google.com{
13312855Sgabeblack@google.com    uint8_t *src = (uint8_t *)source;
13412855Sgabeblack@google.com    tc->getVirtProxy().writeBlob(dest, src, cplen);
13512855Sgabeblack@google.com}
13612855Sgabeblack@google.com
13712855Sgabeblack@google.comvoid
13812855Sgabeblack@google.comCopyStringOut(ThreadContext *tc, char *dst, Addr vaddr, size_t maxlen)
13912855Sgabeblack@google.com{
14012855Sgabeblack@google.com    char *start = dst;
14112855Sgabeblack@google.com    FSTranslatingPortProxy &vp = tc->getVirtProxy();
14212855Sgabeblack@google.com
14312855Sgabeblack@google.com    bool foundNull = false;
14412855Sgabeblack@google.com    while ((dst - start + 1) < maxlen && !foundNull) {
14512855Sgabeblack@google.com        vp.readBlob(vaddr++, (uint8_t*)dst, 1);
14612855Sgabeblack@google.com        if (*dst == '\0')
14712855Sgabeblack@google.com            foundNull = true;
14812855Sgabeblack@google.com        dst++;
14912855Sgabeblack@google.com    }
15012855Sgabeblack@google.com
15112855Sgabeblack@google.com    if (!foundNull)
15212855Sgabeblack@google.com        *dst = '\0';
15312855Sgabeblack@google.com}
15412855Sgabeblack@google.com
15512855Sgabeblack@google.comvoid
15612855Sgabeblack@google.comCopyStringIn(ThreadContext *tc, const char *src, Addr vaddr)
15712855Sgabeblack@google.com{
15812855Sgabeblack@google.com    FSTranslatingPortProxy &vp = tc->getVirtProxy();
15912855Sgabeblack@google.com    for (ChunkGenerator gen(vaddr, strlen(src), TheISA::PageBytes); !gen.done();
16012855Sgabeblack@google.com         gen.next())
16112855Sgabeblack@google.com    {
16212855Sgabeblack@google.com        vp.writeBlob(gen.addr(), (uint8_t*)src, gen.size());
16312855Sgabeblack@google.com        src += gen.size();
16412855Sgabeblack@google.com    }
16512855Sgabeblack@google.com}
16612855Sgabeblack@google.com