fs_translating_port_proxy.cc revision 14009
12521SN/A/* 29814Sandreas.hansson@arm.com * Copyright (c) 2011,2013 ARM Limited 38706Sandreas.hansson@arm.com * All rights reserved 48706Sandreas.hansson@arm.com * 58706Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall 68706Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual 78706Sandreas.hansson@arm.com * property including but not limited to intellectual property relating 88706Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software 98706Sandreas.hansson@arm.com * licensed hereunder. You may use the software subject to the license 108706Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated 118706Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software, 128706Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form. 138706Sandreas.hansson@arm.com * 142521SN/A * Copyright (c) 2006 The Regents of The University of Michigan 152521SN/A * All rights reserved. 162521SN/A * 172521SN/A * Redistribution and use in source and binary forms, with or without 182521SN/A * modification, are permitted provided that the following conditions are 192521SN/A * met: redistributions of source code must retain the above copyright 202521SN/A * notice, this list of conditions and the following disclaimer; 212521SN/A * redistributions in binary form must reproduce the above copyright 222521SN/A * notice, this list of conditions and the following disclaimer in the 232521SN/A * documentation and/or other materials provided with the distribution; 242521SN/A * neither the name of the copyright holders nor the names of its 252521SN/A * contributors may be used to endorse or promote products derived from 262521SN/A * this software without specific prior written permission. 272521SN/A * 282521SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 292521SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 302521SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 312521SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 322521SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 332521SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 342521SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 352521SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 362521SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 372521SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 382521SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392665SN/A * 402665SN/A * Authors: Ali Saidi 418706Sandreas.hansson@arm.com * Andreas Hansson 422521SN/A */ 432521SN/A 442521SN/A/** 452982SN/A * @file 462982SN/A * Port object definitions. 472521SN/A */ 482521SN/A 4911793Sbrandon.potter@amd.com#include "mem/fs_translating_port_proxy.hh" 5011793Sbrandon.potter@amd.com 519850Sandreas.hansson@arm.com#include "arch/vtophys.hh" 522521SN/A#include "base/chunk_generator.hh" 538706Sandreas.hansson@arm.com#include "cpu/base.hh" 544070SN/A#include "cpu/thread_context.hh" 559814Sandreas.hansson@arm.com#include "sim/system.hh" 568706Sandreas.hansson@arm.com 578706Sandreas.hansson@arm.comFSTranslatingPortProxy::FSTranslatingPortProxy(ThreadContext *tc) 589814Sandreas.hansson@arm.com : PortProxy(tc->getCpuPtr()->getDataPort(), 599814Sandreas.hansson@arm.com tc->getSystemPtr()->cacheLineSize()), _tc(tc) 608706Sandreas.hansson@arm.com{ 618706Sandreas.hansson@arm.com} 628706Sandreas.hansson@arm.com 639814Sandreas.hansson@arm.comFSTranslatingPortProxy::FSTranslatingPortProxy(MasterPort &port, 649814Sandreas.hansson@arm.com unsigned int cacheLineSize) 659814Sandreas.hansson@arm.com : PortProxy(port, cacheLineSize), _tc(NULL) 668706Sandreas.hansson@arm.com{ 678706Sandreas.hansson@arm.com} 688706Sandreas.hansson@arm.com 6914008Sgabeblack@google.combool 7014009Sgabeblack@google.comFSTranslatingPortProxy::tryReadBlob(Addr addr, void *p, int size) const 712521SN/A{ 722521SN/A Addr paddr; 732521SN/A for (ChunkGenerator gen(addr, size, TheISA::PageBytes); !gen.done(); 748706Sandreas.hansson@arm.com gen.next()) 752521SN/A { 768706Sandreas.hansson@arm.com if (_tc) 778706Sandreas.hansson@arm.com paddr = TheISA::vtophys(_tc,gen.addr()); 782521SN/A else 792521SN/A paddr = TheISA::vtophys(gen.addr()); 802521SN/A 8112532Sandreas.sandberg@arm.com PortProxy::readBlobPhys(paddr, 0, p, gen.size()); 8214009Sgabeblack@google.com p = static_cast<uint8_t *>(p) + gen.size(); 832521SN/A } 8414008Sgabeblack@google.com return true; 852521SN/A} 862521SN/A 8714008Sgabeblack@google.combool 8814008Sgabeblack@google.comFSTranslatingPortProxy::tryWriteBlob( 8914009Sgabeblack@google.com Addr addr, const void *p, int size) const 902521SN/A{ 912521SN/A Addr paddr; 922521SN/A for (ChunkGenerator gen(addr, size, TheISA::PageBytes); !gen.done(); 938706Sandreas.hansson@arm.com gen.next()) 942521SN/A { 958706Sandreas.hansson@arm.com if (_tc) 968706Sandreas.hansson@arm.com paddr = TheISA::vtophys(_tc,gen.addr()); 972521SN/A else 982521SN/A paddr = TheISA::vtophys(gen.addr()); 992521SN/A 10012532Sandreas.sandberg@arm.com PortProxy::writeBlobPhys(paddr, 0, p, gen.size()); 10114009Sgabeblack@google.com p = static_cast<const uint8_t *>(p) + gen.size(); 1022521SN/A } 10314008Sgabeblack@google.com return true; 1042521SN/A} 1052521SN/A 10614008Sgabeblack@google.combool 10714008Sgabeblack@google.comFSTranslatingPortProxy::tryMemsetBlob(Addr address, uint8_t v, int size) const 1088706Sandreas.hansson@arm.com{ 1098706Sandreas.hansson@arm.com Addr paddr; 1108706Sandreas.hansson@arm.com for (ChunkGenerator gen(address, size, TheISA::PageBytes); !gen.done(); 1118706Sandreas.hansson@arm.com gen.next()) 1128706Sandreas.hansson@arm.com { 1138706Sandreas.hansson@arm.com if (_tc) 1148706Sandreas.hansson@arm.com paddr = TheISA::vtophys(_tc,gen.addr()); 1158706Sandreas.hansson@arm.com else 1168706Sandreas.hansson@arm.com paddr = TheISA::vtophys(gen.addr()); 1178706Sandreas.hansson@arm.com 11812532Sandreas.sandberg@arm.com PortProxy::memsetBlobPhys(paddr, 0, v, gen.size()); 1198706Sandreas.hansson@arm.com } 12014008Sgabeblack@google.com return true; 1218706Sandreas.hansson@arm.com} 1228706Sandreas.hansson@arm.com 1238706Sandreas.hansson@arm.comvoid 1244070SN/ACopyOut(ThreadContext *tc, void *dest, Addr src, size_t cplen) 1254070SN/A{ 1264070SN/A uint8_t *dst = (uint8_t *)dest; 1278852Sandreas.hansson@arm.com tc->getVirtProxy().readBlob(src, dst, cplen); 1284070SN/A} 1294070SN/A 1304070SN/Avoid 13110564Sandreas.hansson@arm.comCopyIn(ThreadContext *tc, Addr dest, const void *source, size_t cplen) 1324070SN/A{ 1334070SN/A uint8_t *src = (uint8_t *)source; 1348852Sandreas.hansson@arm.com tc->getVirtProxy().writeBlob(dest, src, cplen); 1354070SN/A} 1364070SN/A 1374070SN/Avoid 1384070SN/ACopyStringOut(ThreadContext *tc, char *dst, Addr vaddr, size_t maxlen) 1394070SN/A{ 1404070SN/A char *start = dst; 1418852Sandreas.hansson@arm.com FSTranslatingPortProxy &vp = tc->getVirtProxy(); 1424070SN/A 1438722SMitchell.Hayenga@ARM.com bool foundNull = false; 1448722SMitchell.Hayenga@ARM.com while ((dst - start + 1) < maxlen && !foundNull) { 1458852Sandreas.hansson@arm.com vp.readBlob(vaddr++, (uint8_t*)dst, 1); 1468996SAli.Saidi@ARM.com if (*dst == '\0') 1478722SMitchell.Hayenga@ARM.com foundNull = true; 1488722SMitchell.Hayenga@ARM.com dst++; 1498722SMitchell.Hayenga@ARM.com } 1504070SN/A 1518722SMitchell.Hayenga@ARM.com if (!foundNull) 1528722SMitchell.Hayenga@ARM.com *dst = '\0'; 1534070SN/A} 1544070SN/A 1554070SN/Avoid 15610564Sandreas.hansson@arm.comCopyStringIn(ThreadContext *tc, const char *src, Addr vaddr) 1574070SN/A{ 1588852Sandreas.hansson@arm.com FSTranslatingPortProxy &vp = tc->getVirtProxy(); 1594070SN/A for (ChunkGenerator gen(vaddr, strlen(src), TheISA::PageBytes); !gen.done(); 1608852Sandreas.hansson@arm.com gen.next()) 1614070SN/A { 1628852Sandreas.hansson@arm.com vp.writeBlob(gen.addr(), (uint8_t*)src, gen.size()); 1634070SN/A src += gen.size(); 1644070SN/A } 1654070SN/A} 166