se_translating_port_proxy.cc revision 14008:e36048ba1c2c
11689SN/A/* 22329SN/A * Copyright (c) 2011 ARM Limited 31689SN/A * All rights reserved 41689SN/A * 51689SN/A * The license below extends only to copyright in the software and shall 61689SN/A * not be construed as granting a license to any other intellectual 71689SN/A * property including but not limited to intellectual property relating 81689SN/A * to a hardware implementation of the functionality of the software 91689SN/A * licensed hereunder. You may use the software subject to the license 101689SN/A * terms below provided that you ensure that this notice is replicated 111689SN/A * unmodified and in its entirety in all distributions of the software, 121689SN/A * modified or unmodified, in source code or in binary form. 131689SN/A * 141689SN/A * Copyright (c) 2001-2005 The Regents of The University of Michigan 151689SN/A * All rights reserved. 161689SN/A * 171689SN/A * Redistribution and use in source and binary forms, with or without 181689SN/A * modification, are permitted provided that the following conditions are 191689SN/A * met: redistributions of source code must retain the above copyright 201689SN/A * notice, this list of conditions and the following disclaimer; 211689SN/A * redistributions in binary form must reproduce the above copyright 221689SN/A * notice, this list of conditions and the following disclaimer in the 231689SN/A * documentation and/or other materials provided with the distribution; 241689SN/A * neither the name of the copyright holders nor the names of its 251689SN/A * contributors may be used to endorse or promote products derived from 261689SN/A * this software without specific prior written permission. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 292831Sksewell@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 301689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 311689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 326221Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 336221Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 341858SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 351717SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 361060SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 376221Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 382292SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 391061SN/A * 404329Sktlim@umich.edu * Authors: Ron Dreslinski 412980Sgblack@eecs.umich.edu * Steve Reinhardt 426221Snate@binkert.org * Andreas Hansson 434329Sktlim@umich.edu */ 444329Sktlim@umich.edu 451060SN/A#include "mem/se_translating_port_proxy.hh" 461060SN/A 472292SN/A#include <string> 481060SN/A 496221Snate@binkert.org#include "arch/isa_traits.hh" 502877Sksewell@umich.edu#include "base/chunk_generator.hh" 512292SN/A#include "config/the_isa.hh" 522292SN/A#include "mem/page_table.hh" 532292SN/A#include "sim/process.hh" 542292SN/A#include "sim/system.hh" 552980Sgblack@eecs.umich.edu 562292SN/Ausing namespace TheISA; 572292SN/A 582292SN/ASETranslatingPortProxy::SETranslatingPortProxy(MasterPort& port, Process *p, 592292SN/A AllocType alloc) 602292SN/A : PortProxy(port, p->system->cacheLineSize()), pTable(p->pTable), 612292SN/A process(p), allocating(alloc) 622292SN/A{ } 632292SN/A 642292SN/Abool 652292SN/ASETranslatingPortProxy::tryReadBlob(Addr addr, uint8_t *p, int size) const 666221Snate@binkert.org{ 676221Snate@binkert.org int prevSize = 0; 682292SN/A 692292SN/A for (ChunkGenerator gen(addr, size, PageBytes); !gen.done(); gen.next()) { 702292SN/A Addr paddr; 712292SN/A 724329Sktlim@umich.edu if (!pTable->translate(gen.addr(),paddr)) 732292SN/A return false; 742292SN/A 752292SN/A PortProxy::readBlobPhys(paddr, 0, p + prevSize, gen.size()); 762292SN/A prevSize += gen.size(); 772292SN/A } 786221Snate@binkert.org 796221Snate@binkert.org return true; 802292SN/A} 812292SN/A 822292SN/A 832292SN/Abool 844329Sktlim@umich.eduSETranslatingPortProxy::tryWriteBlob(Addr addr, const uint8_t *p, 852292SN/A int size) const 862292SN/A{ 872292SN/A int prevSize = 0; 882292SN/A 896221Snate@binkert.org for (ChunkGenerator gen(addr, size, PageBytes); !gen.done(); gen.next()) { 906221Snate@binkert.org Addr paddr; 912292SN/A 922292SN/A if (!pTable->translate(gen.addr(), paddr)) { 932292SN/A if (allocating == Always) { 942292SN/A process->allocateMem(roundDown(gen.addr(), PageBytes), 952292SN/A PageBytes); 961060SN/A } else if (allocating == NextPage) { 972292SN/A // check if we've accessed the next page on the stack 986221Snate@binkert.org if (!process->fixupStackFault(gen.addr())) 996221Snate@binkert.org panic("Page table fault when accessing virtual address %#x " 1002292SN/A "during functional write\n", gen.addr()); 1011060SN/A } else { 1022292SN/A return false; 1032292SN/A } 1042292SN/A pTable->translate(gen.addr(), paddr); 1052292SN/A } 1062292SN/A 1072292SN/A PortProxy::writeBlobPhys(paddr, 0, p + prevSize, gen.size()); 1082292SN/A prevSize += gen.size(); 1094329Sktlim@umich.edu } 1104329Sktlim@umich.edu 1114329Sktlim@umich.edu return true; 1124329Sktlim@umich.edu} 1134329Sktlim@umich.edu 1144329Sktlim@umich.edu 1154329Sktlim@umich.edubool 1162292SN/ASETranslatingPortProxy::tryMemsetBlob(Addr addr, uint8_t val, int size) const 1176221Snate@binkert.org{ 1182292SN/A for (ChunkGenerator gen(addr, size, PageBytes); !gen.done(); gen.next()) { 1192292SN/A Addr paddr; 1202292SN/A 1212292SN/A if (!pTable->translate(gen.addr(), paddr)) { 1222292SN/A if (allocating == Always) { 1232307SN/A process->allocateMem(roundDown(gen.addr(), PageBytes), 1242307SN/A PageBytes); 1252307SN/A pTable->translate(gen.addr(), paddr); 1262307SN/A } else { 1276221Snate@binkert.org return false; 1282307SN/A } 1292307SN/A } 1302307SN/A 1312307SN/A PortProxy::memsetBlobPhys(paddr, 0, val, gen.size()); 1322307SN/A } 1332307SN/A 1342307SN/A return true; 1352307SN/A} 1366221Snate@binkert.org