se_translating_port_proxy.cc revision 2404
1/* 2 * Copyright (c) 2001-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include <string> 30#include "base/chunk_generator.hh" 31#include "mem/port.hh" 32#include "mem/translating_port.hh" 33#include "mem/page_table.hh" 34 35TranslatingPort::TranslatingPort(Port *_port, PageTable *p_table) 36 : port(_port), pTable(p_table) 37{ } 38 39TranslatingPort::~TranslatingPort() 40{ } 41 42Fault 43TranslatingPort::readBlobFunctional(Addr addr, uint8_t *p, int size) 44{ 45 Addr paddr; 46 int prevSize = 0; 47 48 for (ChunkGenerator gen(addr, size, VMPageSize); !gen.done(); gen.next()) { 49 50 if (!pTable->translate(gen.addr(),paddr)) 51 return Machine_Check_Fault; 52 53 port->readBlobFunctional(paddr, p + prevSize, gen.size()); 54 prevSize += gen.size(); 55 } 56 57 return No_Fault; 58} 59 60Fault 61TranslatingPort::writeBlobFunctional(Addr addr, uint8_t *p, int size) 62{ 63 Addr paddr; 64 int prevSize = 0; 65 66 for (ChunkGenerator gen(addr, size, VMPageSize); !gen.done(); gen.next()) { 67 68 if (!pTable->translate(gen.addr(),paddr)) 69 return Machine_Check_Fault; 70 71 port->writeBlobFunctional(paddr, p + prevSize, gen.size()); 72 prevSize += gen.size(); 73 } 74 75 return No_Fault; 76} 77 78Fault 79TranslatingPort::memsetBlobFunctional(Addr addr, uint8_t val, int size) 80{ 81 Addr paddr; 82 83 for (ChunkGenerator gen(addr, size, VMPageSize); !gen.done(); gen.next()) { 84 85 if (!pTable->translate(gen.addr(),paddr)) 86 return Machine_Check_Fault; 87 88 port->memsetBlobFunctional(paddr, val, gen.size()); 89 } 90 91 return No_Fault; 92} 93 94Fault 95TranslatingPort::writeStringFunctional(Addr addr, const char *str) 96{ 97 Addr paddr,vaddr; 98 uint8_t c; 99 100 vaddr = addr; 101 102 do { 103 c = *str++; 104 if (!pTable->translate(vaddr++,paddr)) 105 return Machine_Check_Fault; 106 107 port->writeBlobFunctional(paddr, &c, 1); 108 } while (c); 109 110 return No_Fault; 111} 112 113Fault 114TranslatingPort::readStringFunctional(std::string &str, Addr addr) 115{ 116 Addr paddr,vaddr; 117 uint8_t c; 118 119 vaddr = addr; 120 121 do { 122 if (!pTable->translate(vaddr++,paddr)) 123 return Machine_Check_Fault; 124 125 port->readBlobFunctional(paddr, &c, 1); 126 str += c; 127 } while (c); 128 129 return No_Fault; 130} 131 132