port_proxy.hh revision 8861
18706Sandreas.hansson@arm.com/* 28853Sandreas.hansson@arm.com * Copyright (c) 2011-2012 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 * 148706Sandreas.hansson@arm.com * Redistribution and use in source and binary forms, with or without 158706Sandreas.hansson@arm.com * modification, are permitted provided that the following conditions are 168706Sandreas.hansson@arm.com * met: redistributions of source code must retain the above copyright 178706Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer; 188706Sandreas.hansson@arm.com * redistributions in binary form must reproduce the above copyright 198706Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer in the 208706Sandreas.hansson@arm.com * documentation and/or other materials provided with the distribution; 218706Sandreas.hansson@arm.com * neither the name of the copyright holders nor the names of its 228706Sandreas.hansson@arm.com * contributors may be used to endorse or promote products derived from 238706Sandreas.hansson@arm.com * this software without specific prior written permission. 248706Sandreas.hansson@arm.com * 258706Sandreas.hansson@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 268706Sandreas.hansson@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 278706Sandreas.hansson@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 288706Sandreas.hansson@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 298706Sandreas.hansson@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 308706Sandreas.hansson@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 318706Sandreas.hansson@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 328706Sandreas.hansson@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 338706Sandreas.hansson@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 348706Sandreas.hansson@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 358706Sandreas.hansson@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 368706Sandreas.hansson@arm.com * 378706Sandreas.hansson@arm.com * Authors: Andreas Hansson 388706Sandreas.hansson@arm.com */ 398706Sandreas.hansson@arm.com 408706Sandreas.hansson@arm.com/** 418706Sandreas.hansson@arm.com * @file 428706Sandreas.hansson@arm.com * PortProxy Object Declaration. 438706Sandreas.hansson@arm.com * 448853Sandreas.hansson@arm.com * Port proxies are used when non-structural entities need access to 458853Sandreas.hansson@arm.com * the memory system (or structural entities that want to peak into 468853Sandreas.hansson@arm.com * the memory system without making a real memory access). 478853Sandreas.hansson@arm.com * 488853Sandreas.hansson@arm.com * Proxy objects replace the previous FunctionalPort, TranslatingPort 498853Sandreas.hansson@arm.com * and VirtualPort objects, which provided the same functionality as 508853Sandreas.hansson@arm.com * the proxies, but were instances of ports not corresponding to real 518853Sandreas.hansson@arm.com * structural ports of the simulated system. Via the port proxies all 528853Sandreas.hansson@arm.com * the accesses go through an actual port (either the system port, 538853Sandreas.hansson@arm.com * e.g. for processes or initialisation, or a the data port of the 548853Sandreas.hansson@arm.com * CPU, e.g. for threads) and thus are transparent to a potentially 558706Sandreas.hansson@arm.com * distributed memory and automatically adhere to the memory map of 568706Sandreas.hansson@arm.com * the system. 578706Sandreas.hansson@arm.com */ 588706Sandreas.hansson@arm.com 598706Sandreas.hansson@arm.com#ifndef __MEM_PORT_PROXY_HH__ 608706Sandreas.hansson@arm.com#define __MEM_PORT_PROXY_HH__ 618706Sandreas.hansson@arm.com 628706Sandreas.hansson@arm.com#include "config/the_isa.hh" 638706Sandreas.hansson@arm.com#if THE_ISA != NO_ISA 648706Sandreas.hansson@arm.com #include "arch/isa_traits.hh" 658706Sandreas.hansson@arm.com#endif 668706Sandreas.hansson@arm.com 678706Sandreas.hansson@arm.com#include "mem/port.hh" 688706Sandreas.hansson@arm.com#include "sim/byteswap.hh" 698706Sandreas.hansson@arm.com 708706Sandreas.hansson@arm.com/** 718853Sandreas.hansson@arm.com * This object is a proxy for a structural port, to be used for debug 728853Sandreas.hansson@arm.com * accesses. 738706Sandreas.hansson@arm.com * 748706Sandreas.hansson@arm.com * This proxy object is used when non structural entities 758706Sandreas.hansson@arm.com * (e.g. thread contexts, object file loaders) need access to the 768706Sandreas.hansson@arm.com * memory system. It calls the corresponding functions on the underlying 778706Sandreas.hansson@arm.com * structural port, and provides templatized convenience access functions. 788706Sandreas.hansson@arm.com * 798706Sandreas.hansson@arm.com * The addresses are interpreted as physical addresses. 808706Sandreas.hansson@arm.com * 818706Sandreas.hansson@arm.com * @sa SETranslatingProxy 828706Sandreas.hansson@arm.com * @sa FSTranslatingProxy 838706Sandreas.hansson@arm.com */ 848706Sandreas.hansson@arm.comclass PortProxy 858706Sandreas.hansson@arm.com{ 868853Sandreas.hansson@arm.com private: 878853Sandreas.hansson@arm.com 888853Sandreas.hansson@arm.com /** The actual physical port used by this proxy. */ 898706Sandreas.hansson@arm.com Port &_port; 908706Sandreas.hansson@arm.com 918861Sandreas.hansson@arm.com void blobHelper(Addr addr, uint8_t *p, int size, MemCmd cmd) const; 928853Sandreas.hansson@arm.com 938706Sandreas.hansson@arm.com public: 948706Sandreas.hansson@arm.com PortProxy(Port &port) : _port(port) { } 958706Sandreas.hansson@arm.com virtual ~PortProxy() { } 968706Sandreas.hansson@arm.com 978706Sandreas.hansson@arm.com /** 988706Sandreas.hansson@arm.com * Read size bytes memory at address and store in p. 998706Sandreas.hansson@arm.com */ 1008861Sandreas.hansson@arm.com virtual void readBlob(Addr addr, uint8_t* p, int size) const 1018853Sandreas.hansson@arm.com { blobHelper(addr, p, size, MemCmd::ReadReq); } 1028706Sandreas.hansson@arm.com 1038706Sandreas.hansson@arm.com /** 1048706Sandreas.hansson@arm.com * Write size bytes from p to address. 1058706Sandreas.hansson@arm.com */ 1068861Sandreas.hansson@arm.com virtual void writeBlob(Addr addr, uint8_t* p, int size) const 1078853Sandreas.hansson@arm.com { blobHelper(addr, p, size, MemCmd::WriteReq); } 1088706Sandreas.hansson@arm.com 1098706Sandreas.hansson@arm.com /** 1108706Sandreas.hansson@arm.com * Fill size bytes starting at addr with byte value val. 1118706Sandreas.hansson@arm.com */ 1128861Sandreas.hansson@arm.com virtual void memsetBlob(Addr addr, uint8_t v, int size) const; 1138706Sandreas.hansson@arm.com 1148706Sandreas.hansson@arm.com /** 1158706Sandreas.hansson@arm.com * Read sizeof(T) bytes from address and return as object T. 1168706Sandreas.hansson@arm.com */ 1178706Sandreas.hansson@arm.com template <typename T> 1188861Sandreas.hansson@arm.com T read(Addr address) const; 1198706Sandreas.hansson@arm.com 1208706Sandreas.hansson@arm.com /** 1218706Sandreas.hansson@arm.com * Write object T to address. Writes sizeof(T) bytes. 1228706Sandreas.hansson@arm.com */ 1238706Sandreas.hansson@arm.com template <typename T> 1248861Sandreas.hansson@arm.com void write(Addr address, T data) const; 1258706Sandreas.hansson@arm.com 1268706Sandreas.hansson@arm.com#if THE_ISA != NO_ISA 1278706Sandreas.hansson@arm.com /** 1288706Sandreas.hansson@arm.com * Read sizeof(T) bytes from address and return as object T. 1298706Sandreas.hansson@arm.com * Performs Guest to Host endianness transform. 1308706Sandreas.hansson@arm.com */ 1318706Sandreas.hansson@arm.com template <typename T> 1328861Sandreas.hansson@arm.com T readGtoH(Addr address) const; 1338706Sandreas.hansson@arm.com 1348706Sandreas.hansson@arm.com /** 1358706Sandreas.hansson@arm.com * Write object T to address. Writes sizeof(T) bytes. 1368706Sandreas.hansson@arm.com * Performs Host to Guest endianness transform. 1378706Sandreas.hansson@arm.com */ 1388706Sandreas.hansson@arm.com template <typename T> 1398861Sandreas.hansson@arm.com void writeHtoG(Addr address, T data) const; 1408706Sandreas.hansson@arm.com#endif 1418706Sandreas.hansson@arm.com}; 1428706Sandreas.hansson@arm.com 1438706Sandreas.hansson@arm.com 1448706Sandreas.hansson@arm.comtemplate <typename T> 1458706Sandreas.hansson@arm.comT 1468861Sandreas.hansson@arm.comPortProxy::read(Addr address) const 1478706Sandreas.hansson@arm.com{ 1488706Sandreas.hansson@arm.com T data; 1498706Sandreas.hansson@arm.com readBlob(address, (uint8_t*)&data, sizeof(T)); 1508706Sandreas.hansson@arm.com return data; 1518706Sandreas.hansson@arm.com} 1528706Sandreas.hansson@arm.com 1538706Sandreas.hansson@arm.comtemplate <typename T> 1548706Sandreas.hansson@arm.comvoid 1558861Sandreas.hansson@arm.comPortProxy::write(Addr address, T data) const 1568706Sandreas.hansson@arm.com{ 1578706Sandreas.hansson@arm.com writeBlob(address, (uint8_t*)&data, sizeof(T)); 1588706Sandreas.hansson@arm.com} 1598706Sandreas.hansson@arm.com 1608706Sandreas.hansson@arm.com#if THE_ISA != NO_ISA 1618706Sandreas.hansson@arm.comtemplate <typename T> 1628706Sandreas.hansson@arm.comT 1638861Sandreas.hansson@arm.comPortProxy::readGtoH(Addr address) const 1648706Sandreas.hansson@arm.com{ 1658706Sandreas.hansson@arm.com T data; 1668706Sandreas.hansson@arm.com readBlob(address, (uint8_t*)&data, sizeof(T)); 1678706Sandreas.hansson@arm.com return TheISA::gtoh(data); 1688706Sandreas.hansson@arm.com} 1698706Sandreas.hansson@arm.com 1708706Sandreas.hansson@arm.comtemplate <typename T> 1718706Sandreas.hansson@arm.comvoid 1728861Sandreas.hansson@arm.comPortProxy::writeHtoG(Addr address, T data) const 1738706Sandreas.hansson@arm.com{ 1748706Sandreas.hansson@arm.com data = TheISA::htog(data); 1758706Sandreas.hansson@arm.com writeBlob(address, (uint8_t*)&data, sizeof(T)); 1768706Sandreas.hansson@arm.com} 1778706Sandreas.hansson@arm.com#endif 1788706Sandreas.hansson@arm.com 1798706Sandreas.hansson@arm.com#endif // __MEM_PORT_PROXY_HH__ 180