fs_translating_port_proxy.cc revision 8722
12521SN/A/* 28706Sandreas.hansson@arm.com * Copyright (c) 2011 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 492521SN/A#include "base/chunk_generator.hh" 508706Sandreas.hansson@arm.com#include "cpu/base.hh" 514070SN/A#include "cpu/thread_context.hh" 528706Sandreas.hansson@arm.com#include "mem/fs_translating_port_proxy.hh" 538706Sandreas.hansson@arm.com 548706Sandreas.hansson@arm.comusing namespace TheISA; 558706Sandreas.hansson@arm.com 568706Sandreas.hansson@arm.comFSTranslatingPortProxy::FSTranslatingPortProxy(ThreadContext *tc) 578706Sandreas.hansson@arm.com : PortProxy(*(tc->getCpuPtr()->getPort("dcache_port"))), _tc(tc) 588706Sandreas.hansson@arm.com{ 598706Sandreas.hansson@arm.com} 608706Sandreas.hansson@arm.com 618706Sandreas.hansson@arm.comFSTranslatingPortProxy::FSTranslatingPortProxy(Port &port) 628706Sandreas.hansson@arm.com : PortProxy(port), _tc(NULL) 638706Sandreas.hansson@arm.com{ 648706Sandreas.hansson@arm.com} 658706Sandreas.hansson@arm.com 668706Sandreas.hansson@arm.comFSTranslatingPortProxy::~FSTranslatingPortProxy() 678706Sandreas.hansson@arm.com{ 688706Sandreas.hansson@arm.com} 692521SN/A 702521SN/Avoid 718706Sandreas.hansson@arm.comFSTranslatingPortProxy::readBlob(Addr addr, uint8_t *p, int size) 722521SN/A{ 732521SN/A Addr paddr; 742521SN/A for (ChunkGenerator gen(addr, size, TheISA::PageBytes); !gen.done(); 758706Sandreas.hansson@arm.com gen.next()) 762521SN/A { 778706Sandreas.hansson@arm.com if (_tc) 788706Sandreas.hansson@arm.com paddr = TheISA::vtophys(_tc,gen.addr()); 792521SN/A else 802521SN/A paddr = TheISA::vtophys(gen.addr()); 812521SN/A 828706Sandreas.hansson@arm.com PortProxy::readBlob(paddr, p, gen.size()); 832521SN/A p += gen.size(); 842521SN/A } 852521SN/A} 862521SN/A 872521SN/Avoid 888706Sandreas.hansson@arm.comFSTranslatingPortProxy::writeBlob(Addr addr, uint8_t *p, int size) 892521SN/A{ 902521SN/A Addr paddr; 912521SN/A for (ChunkGenerator gen(addr, size, TheISA::PageBytes); !gen.done(); 928706Sandreas.hansson@arm.com gen.next()) 932521SN/A { 948706Sandreas.hansson@arm.com if (_tc) 958706Sandreas.hansson@arm.com paddr = TheISA::vtophys(_tc,gen.addr()); 962521SN/A else 972521SN/A paddr = TheISA::vtophys(gen.addr()); 982521SN/A 998706Sandreas.hansson@arm.com PortProxy::writeBlob(paddr, p, gen.size()); 1002521SN/A p += gen.size(); 1012521SN/A } 1022521SN/A} 1032521SN/A 1044070SN/Avoid 1058706Sandreas.hansson@arm.comFSTranslatingPortProxy::memsetBlob(Addr address, uint8_t v, int size) 1068706Sandreas.hansson@arm.com{ 1078706Sandreas.hansson@arm.com Addr paddr; 1088706Sandreas.hansson@arm.com for (ChunkGenerator gen(address, size, TheISA::PageBytes); !gen.done(); 1098706Sandreas.hansson@arm.com gen.next()) 1108706Sandreas.hansson@arm.com { 1118706Sandreas.hansson@arm.com if (_tc) 1128706Sandreas.hansson@arm.com paddr = TheISA::vtophys(_tc,gen.addr()); 1138706Sandreas.hansson@arm.com else 1148706Sandreas.hansson@arm.com paddr = TheISA::vtophys(gen.addr()); 1158706Sandreas.hansson@arm.com 1168706Sandreas.hansson@arm.com PortProxy::memsetBlob(paddr, v, gen.size()); 1178706Sandreas.hansson@arm.com } 1188706Sandreas.hansson@arm.com} 1198706Sandreas.hansson@arm.com 1208706Sandreas.hansson@arm.comvoid 1214070SN/ACopyOut(ThreadContext *tc, void *dest, Addr src, size_t cplen) 1224070SN/A{ 1234070SN/A uint8_t *dst = (uint8_t *)dest; 1248706Sandreas.hansson@arm.com FSTranslatingPortProxy* vp = tc->getVirtProxy(); 1254070SN/A 1264070SN/A vp->readBlob(src, dst, cplen); 1274070SN/A} 1284070SN/A 1294070SN/Avoid 1304070SN/ACopyIn(ThreadContext *tc, Addr dest, void *source, size_t cplen) 1314070SN/A{ 1324070SN/A uint8_t *src = (uint8_t *)source; 1338706Sandreas.hansson@arm.com FSTranslatingPortProxy* vp = tc->getVirtProxy(); 1344070SN/A 1354070SN/A vp->writeBlob(dest, src, cplen); 1364070SN/A} 1374070SN/A 1384070SN/Avoid 1394070SN/ACopyStringOut(ThreadContext *tc, char *dst, Addr vaddr, size_t maxlen) 1404070SN/A{ 1414070SN/A char *start = dst; 1428706Sandreas.hansson@arm.com FSTranslatingPortProxy* vp = tc->getVirtProxy(); 1434070SN/A 1448722SMitchell.Hayenga@ARM.com bool foundNull = false; 1458722SMitchell.Hayenga@ARM.com while ((dst - start + 1) < maxlen && !foundNull) { 1468722SMitchell.Hayenga@ARM.com vp->readBlob(vaddr++, (uint8_t*)dst, 1); 1478722SMitchell.Hayenga@ARM.com if (dst == '\0') 1488722SMitchell.Hayenga@ARM.com foundNull = true; 1498722SMitchell.Hayenga@ARM.com dst++; 1508722SMitchell.Hayenga@ARM.com } 1514070SN/A 1528722SMitchell.Hayenga@ARM.com if (!foundNull) 1538722SMitchell.Hayenga@ARM.com *dst = '\0'; 1544070SN/A} 1554070SN/A 1564070SN/Avoid 1574070SN/ACopyStringIn(ThreadContext *tc, char *src, Addr vaddr) 1584070SN/A{ 1598706Sandreas.hansson@arm.com FSTranslatingPortProxy* vp = tc->getVirtProxy(); 1604070SN/A for (ChunkGenerator gen(vaddr, strlen(src), TheISA::PageBytes); !gen.done(); 1614070SN/A gen.next()) 1624070SN/A { 1634070SN/A vp->writeBlob(gen.addr(), (uint8_t*)src, gen.size()); 1644070SN/A src += gen.size(); 1654070SN/A } 1664070SN/A} 167