fs_translating_port_proxy.cc revision 9850
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 499850Sandreas.hansson@arm.com#include "arch/vtophys.hh" 502521SN/A#include "base/chunk_generator.hh" 518706Sandreas.hansson@arm.com#include "cpu/base.hh" 524070SN/A#include "cpu/thread_context.hh" 538706Sandreas.hansson@arm.com#include "mem/fs_translating_port_proxy.hh" 549814Sandreas.hansson@arm.com#include "sim/system.hh" 558706Sandreas.hansson@arm.com 568706Sandreas.hansson@arm.comusing namespace TheISA; 578706Sandreas.hansson@arm.com 588706Sandreas.hansson@arm.comFSTranslatingPortProxy::FSTranslatingPortProxy(ThreadContext *tc) 599814Sandreas.hansson@arm.com : PortProxy(tc->getCpuPtr()->getDataPort(), 609814Sandreas.hansson@arm.com tc->getSystemPtr()->cacheLineSize()), _tc(tc) 618706Sandreas.hansson@arm.com{ 628706Sandreas.hansson@arm.com} 638706Sandreas.hansson@arm.com 649814Sandreas.hansson@arm.comFSTranslatingPortProxy::FSTranslatingPortProxy(MasterPort &port, 659814Sandreas.hansson@arm.com unsigned int cacheLineSize) 669814Sandreas.hansson@arm.com : PortProxy(port, cacheLineSize), _tc(NULL) 678706Sandreas.hansson@arm.com{ 688706Sandreas.hansson@arm.com} 698706Sandreas.hansson@arm.com 708706Sandreas.hansson@arm.comFSTranslatingPortProxy::~FSTranslatingPortProxy() 718706Sandreas.hansson@arm.com{ 728706Sandreas.hansson@arm.com} 732521SN/A 742521SN/Avoid 758861Sandreas.hansson@arm.comFSTranslatingPortProxy::readBlob(Addr addr, uint8_t *p, int size) const 762521SN/A{ 772521SN/A Addr paddr; 782521SN/A for (ChunkGenerator gen(addr, size, TheISA::PageBytes); !gen.done(); 798706Sandreas.hansson@arm.com gen.next()) 802521SN/A { 818706Sandreas.hansson@arm.com if (_tc) 828706Sandreas.hansson@arm.com paddr = TheISA::vtophys(_tc,gen.addr()); 832521SN/A else 842521SN/A paddr = TheISA::vtophys(gen.addr()); 852521SN/A 868706Sandreas.hansson@arm.com PortProxy::readBlob(paddr, p, gen.size()); 872521SN/A p += gen.size(); 882521SN/A } 892521SN/A} 902521SN/A 912521SN/Avoid 928861Sandreas.hansson@arm.comFSTranslatingPortProxy::writeBlob(Addr addr, uint8_t *p, int size) const 932521SN/A{ 942521SN/A Addr paddr; 952521SN/A for (ChunkGenerator gen(addr, size, TheISA::PageBytes); !gen.done(); 968706Sandreas.hansson@arm.com gen.next()) 972521SN/A { 988706Sandreas.hansson@arm.com if (_tc) 998706Sandreas.hansson@arm.com paddr = TheISA::vtophys(_tc,gen.addr()); 1002521SN/A else 1012521SN/A paddr = TheISA::vtophys(gen.addr()); 1022521SN/A 1038706Sandreas.hansson@arm.com PortProxy::writeBlob(paddr, p, gen.size()); 1042521SN/A p += gen.size(); 1052521SN/A } 1062521SN/A} 1072521SN/A 1084070SN/Avoid 1098861Sandreas.hansson@arm.comFSTranslatingPortProxy::memsetBlob(Addr address, uint8_t v, int size) const 1108706Sandreas.hansson@arm.com{ 1118706Sandreas.hansson@arm.com Addr paddr; 1128706Sandreas.hansson@arm.com for (ChunkGenerator gen(address, size, TheISA::PageBytes); !gen.done(); 1138706Sandreas.hansson@arm.com gen.next()) 1148706Sandreas.hansson@arm.com { 1158706Sandreas.hansson@arm.com if (_tc) 1168706Sandreas.hansson@arm.com paddr = TheISA::vtophys(_tc,gen.addr()); 1178706Sandreas.hansson@arm.com else 1188706Sandreas.hansson@arm.com paddr = TheISA::vtophys(gen.addr()); 1198706Sandreas.hansson@arm.com 1208706Sandreas.hansson@arm.com PortProxy::memsetBlob(paddr, v, gen.size()); 1218706Sandreas.hansson@arm.com } 1228706Sandreas.hansson@arm.com} 1238706Sandreas.hansson@arm.com 1248706Sandreas.hansson@arm.comvoid 1254070SN/ACopyOut(ThreadContext *tc, void *dest, Addr src, size_t cplen) 1264070SN/A{ 1274070SN/A uint8_t *dst = (uint8_t *)dest; 1288852Sandreas.hansson@arm.com tc->getVirtProxy().readBlob(src, dst, cplen); 1294070SN/A} 1304070SN/A 1314070SN/Avoid 1324070SN/ACopyIn(ThreadContext *tc, Addr dest, void *source, size_t cplen) 1334070SN/A{ 1344070SN/A uint8_t *src = (uint8_t *)source; 1358852Sandreas.hansson@arm.com tc->getVirtProxy().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; 1428852Sandreas.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) { 1468852Sandreas.hansson@arm.com vp.readBlob(vaddr++, (uint8_t*)dst, 1); 1478996SAli.Saidi@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{ 1598852Sandreas.hansson@arm.com FSTranslatingPortProxy &vp = tc->getVirtProxy(); 1604070SN/A for (ChunkGenerator gen(vaddr, strlen(src), TheISA::PageBytes); !gen.done(); 1618852Sandreas.hansson@arm.com gen.next()) 1624070SN/A { 1638852Sandreas.hansson@arm.com vp.writeBlob(gen.addr(), (uint8_t*)src, gen.size()); 1644070SN/A src += gen.size(); 1654070SN/A } 1664070SN/A} 167