fs_translating_port_proxy.cc revision 10564:a8c16e2d466a
14019Sstever@eecs.umich.edu/* 23187Srdreslin@umich.edu * Copyright (c) 2011,2013 ARM Limited 33187Srdreslin@umich.edu * All rights reserved 43187Srdreslin@umich.edu * 53187Srdreslin@umich.edu * The license below extends only to copyright in the software and shall 63187Srdreslin@umich.edu * not be construed as granting a license to any other intellectual 73187Srdreslin@umich.edu * property including but not limited to intellectual property relating 83187Srdreslin@umich.edu * to a hardware implementation of the functionality of the software 93187Srdreslin@umich.edu * licensed hereunder. You may use the software subject to the license 103187Srdreslin@umich.edu * terms below provided that you ensure that this notice is replicated 113187Srdreslin@umich.edu * unmodified and in its entirety in all distributions of the software, 123187Srdreslin@umich.edu * modified or unmodified, in source code or in binary form. 133187Srdreslin@umich.edu * 143187Srdreslin@umich.edu * Copyright (c) 2006 The Regents of The University of Michigan 153187Srdreslin@umich.edu * All rights reserved. 163187Srdreslin@umich.edu * 173187Srdreslin@umich.edu * Redistribution and use in source and binary forms, with or without 183187Srdreslin@umich.edu * modification, are permitted provided that the following conditions are 193187Srdreslin@umich.edu * met: redistributions of source code must retain the above copyright 203187Srdreslin@umich.edu * notice, this list of conditions and the following disclaimer; 213187Srdreslin@umich.edu * redistributions in binary form must reproduce the above copyright 223187Srdreslin@umich.edu * notice, this list of conditions and the following disclaimer in the 233187Srdreslin@umich.edu * documentation and/or other materials provided with the distribution; 243187Srdreslin@umich.edu * neither the name of the copyright holders nor the names of its 253187Srdreslin@umich.edu * contributors may be used to endorse or promote products derived from 263187Srdreslin@umich.edu * this software without specific prior written permission. 273187Srdreslin@umich.edu * 283187Srdreslin@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 293187Srdreslin@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 303187Srdreslin@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 313187Srdreslin@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 323187Srdreslin@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 333187Srdreslin@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 343187Srdreslin@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 353187Srdreslin@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 363187Srdreslin@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 374444Ssaidi@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 383187Srdreslin@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 393208Srdreslin@umich.edu * 403187Srdreslin@umich.edu * Authors: Ali Saidi 418134SAli.Saidi@ARM.com * Andreas Hansson 423187Srdreslin@umich.edu */ 433187Srdreslin@umich.edu 443187Srdreslin@umich.edu/** 453187Srdreslin@umich.edu * @file 463187Srdreslin@umich.edu * Port object definitions. 473187Srdreslin@umich.edu */ 483187Srdreslin@umich.edu 494444Ssaidi@eecs.umich.edu#include "arch/vtophys.hh" 503187Srdreslin@umich.edu#include "base/chunk_generator.hh" 513187Srdreslin@umich.edu#include "cpu/base.hh" 523187Srdreslin@umich.edu#include "cpu/thread_context.hh" 533187Srdreslin@umich.edu#include "mem/fs_translating_port_proxy.hh" 543196Srdreslin@umich.edu#include "sim/system.hh" 553196Srdreslin@umich.edu 564019Sstever@eecs.umich.eduusing namespace TheISA; 573187Srdreslin@umich.edu 583187Srdreslin@umich.eduFSTranslatingPortProxy::FSTranslatingPortProxy(ThreadContext *tc) 598931Sandreas.hansson@arm.com : PortProxy(tc->getCpuPtr()->getDataPort(), 609120Sandreas.hansson@arm.com tc->getSystemPtr()->cacheLineSize()), _tc(tc) 618931Sandreas.hansson@arm.com{ 629036Sandreas.hansson@arm.com} 633187Srdreslin@umich.edu 643187Srdreslin@umich.eduFSTranslatingPortProxy::FSTranslatingPortProxy(MasterPort &port, 659036Sandreas.hansson@arm.com unsigned int cacheLineSize) 663208Srdreslin@umich.edu : PortProxy(port, cacheLineSize), _tc(NULL) 678839Sandreas.hansson@arm.com{ 683187Srdreslin@umich.edu} 693187Srdreslin@umich.edu 708839Sandreas.hansson@arm.comFSTranslatingPortProxy::~FSTranslatingPortProxy() 713187Srdreslin@umich.edu{ 723187Srdreslin@umich.edu} 733187Srdreslin@umich.edu 743187Srdreslin@umich.eduvoid 753187Srdreslin@umich.eduFSTranslatingPortProxy::readBlob(Addr addr, uint8_t *p, int size) const 768839Sandreas.hansson@arm.com{ 779120Sandreas.hansson@arm.com Addr paddr; 783187Srdreslin@umich.edu for (ChunkGenerator gen(addr, size, TheISA::PageBytes); !gen.done(); 798839Sandreas.hansson@arm.com gen.next()) 808706Sandreas.hansson@arm.com { 819120Sandreas.hansson@arm.com if (_tc) 829120Sandreas.hansson@arm.com paddr = TheISA::vtophys(_tc,gen.addr()); 839120Sandreas.hansson@arm.com else 843187Srdreslin@umich.edu paddr = TheISA::vtophys(gen.addr()); 858839Sandreas.hansson@arm.com 863187Srdreslin@umich.edu PortProxy::readBlob(paddr, p, gen.size()); 873187Srdreslin@umich.edu p += gen.size(); 883187Srdreslin@umich.edu } 893187Srdreslin@umich.edu} 903187Srdreslin@umich.edu 913187Srdreslin@umich.eduvoid 928801Sgblack@eecs.umich.eduFSTranslatingPortProxy::writeBlob(Addr addr, const uint8_t *p, int size) const 933187Srdreslin@umich.edu{ 943341Srdreslin@umich.edu Addr paddr; 953341Srdreslin@umich.edu for (ChunkGenerator gen(addr, size, TheISA::PageBytes); !gen.done(); 963257Srdreslin@umich.edu gen.next()) 97 { 98 if (_tc) 99 paddr = TheISA::vtophys(_tc,gen.addr()); 100 else 101 paddr = TheISA::vtophys(gen.addr()); 102 103 PortProxy::writeBlob(paddr, p, gen.size()); 104 p += gen.size(); 105 } 106} 107 108void 109FSTranslatingPortProxy::memsetBlob(Addr address, uint8_t v, int size) const 110{ 111 Addr paddr; 112 for (ChunkGenerator gen(address, size, TheISA::PageBytes); !gen.done(); 113 gen.next()) 114 { 115 if (_tc) 116 paddr = TheISA::vtophys(_tc,gen.addr()); 117 else 118 paddr = TheISA::vtophys(gen.addr()); 119 120 PortProxy::memsetBlob(paddr, v, gen.size()); 121 } 122} 123 124void 125CopyOut(ThreadContext *tc, void *dest, Addr src, size_t cplen) 126{ 127 uint8_t *dst = (uint8_t *)dest; 128 tc->getVirtProxy().readBlob(src, dst, cplen); 129} 130 131void 132CopyIn(ThreadContext *tc, Addr dest, const void *source, size_t cplen) 133{ 134 uint8_t *src = (uint8_t *)source; 135 tc->getVirtProxy().writeBlob(dest, src, cplen); 136} 137 138void 139CopyStringOut(ThreadContext *tc, char *dst, Addr vaddr, size_t maxlen) 140{ 141 char *start = dst; 142 FSTranslatingPortProxy &vp = tc->getVirtProxy(); 143 144 bool foundNull = false; 145 while ((dst - start + 1) < maxlen && !foundNull) { 146 vp.readBlob(vaddr++, (uint8_t*)dst, 1); 147 if (*dst == '\0') 148 foundNull = true; 149 dst++; 150 } 151 152 if (!foundNull) 153 *dst = '\0'; 154} 155 156void 157CopyStringIn(ThreadContext *tc, const char *src, Addr vaddr) 158{ 159 FSTranslatingPortProxy &vp = tc->getVirtProxy(); 160 for (ChunkGenerator gen(vaddr, strlen(src), TheISA::PageBytes); !gen.done(); 161 gen.next()) 162 { 163 vp.writeBlob(gen.addr(), (uint8_t*)src, gen.size()); 164 src += gen.size(); 165 } 166} 167