fs_translating_port_proxy.cc revision 9850
15081Sgblack@eecs.umich.edu/* 25081Sgblack@eecs.umich.edu * Copyright (c) 2011,2013 ARM Limited 35081Sgblack@eecs.umich.edu * All rights reserved 47087Snate@binkert.org * 57087Snate@binkert.org * The license below extends only to copyright in the software and shall 67087Snate@binkert.org * not be construed as granting a license to any other intellectual 77087Snate@binkert.org * property including but not limited to intellectual property relating 87087Snate@binkert.org * to a hardware implementation of the functionality of the software 97087Snate@binkert.org * licensed hereunder. You may use the software subject to the license 107087Snate@binkert.org * terms below provided that you ensure that this notice is replicated 117087Snate@binkert.org * unmodified and in its entirety in all distributions of the software, 125081Sgblack@eecs.umich.edu * modified or unmodified, in source code or in binary form. 137087Snate@binkert.org * 147087Snate@binkert.org * Copyright (c) 2006 The Regents of The University of Michigan 157087Snate@binkert.org * All rights reserved. 167087Snate@binkert.org * 177087Snate@binkert.org * Redistribution and use in source and binary forms, with or without 187087Snate@binkert.org * modification, are permitted provided that the following conditions are 197087Snate@binkert.org * met: redistributions of source code must retain the above copyright 207087Snate@binkert.org * notice, this list of conditions and the following disclaimer; 215081Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 227087Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 235081Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution; 245081Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its 255081Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 265081Sgblack@eecs.umich.edu * this software without specific prior written permission. 275081Sgblack@eecs.umich.edu * 285081Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 295081Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 305081Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 315081Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 325081Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 335081Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 345081Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 355081Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 365081Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 375081Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 385081Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 395081Sgblack@eecs.umich.edu * 405081Sgblack@eecs.umich.edu * Authors: Ali Saidi 415081Sgblack@eecs.umich.edu * Andreas Hansson 425081Sgblack@eecs.umich.edu */ 435081Sgblack@eecs.umich.edu 445081Sgblack@eecs.umich.edu/** 455081Sgblack@eecs.umich.edu * @file 465081Sgblack@eecs.umich.edu * Port object definitions. 475081Sgblack@eecs.umich.edu */ 485081Sgblack@eecs.umich.edu 49#include "arch/vtophys.hh" 50#include "base/chunk_generator.hh" 51#include "cpu/base.hh" 52#include "cpu/thread_context.hh" 53#include "mem/fs_translating_port_proxy.hh" 54#include "sim/system.hh" 55 56using namespace TheISA; 57 58FSTranslatingPortProxy::FSTranslatingPortProxy(ThreadContext *tc) 59 : PortProxy(tc->getCpuPtr()->getDataPort(), 60 tc->getSystemPtr()->cacheLineSize()), _tc(tc) 61{ 62} 63 64FSTranslatingPortProxy::FSTranslatingPortProxy(MasterPort &port, 65 unsigned int cacheLineSize) 66 : PortProxy(port, cacheLineSize), _tc(NULL) 67{ 68} 69 70FSTranslatingPortProxy::~FSTranslatingPortProxy() 71{ 72} 73 74void 75FSTranslatingPortProxy::readBlob(Addr addr, uint8_t *p, int size) const 76{ 77 Addr paddr; 78 for (ChunkGenerator gen(addr, size, TheISA::PageBytes); !gen.done(); 79 gen.next()) 80 { 81 if (_tc) 82 paddr = TheISA::vtophys(_tc,gen.addr()); 83 else 84 paddr = TheISA::vtophys(gen.addr()); 85 86 PortProxy::readBlob(paddr, p, gen.size()); 87 p += gen.size(); 88 } 89} 90 91void 92FSTranslatingPortProxy::writeBlob(Addr addr, uint8_t *p, int size) const 93{ 94 Addr paddr; 95 for (ChunkGenerator gen(addr, size, TheISA::PageBytes); !gen.done(); 96 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, 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, 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