port_proxy.hh revision 14012
18706Sandreas.hansson@arm.com/* 212522Sandreas.sandberg@arm.com * Copyright (c) 2011-2013, 2018 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 6214012Sgabeblack@google.com#include <limits> 6314012Sgabeblack@google.com 648706Sandreas.hansson@arm.com#include "mem/port.hh" 658706Sandreas.hansson@arm.com#include "sim/byteswap.hh" 668706Sandreas.hansson@arm.com 678706Sandreas.hansson@arm.com/** 688853Sandreas.hansson@arm.com * This object is a proxy for a structural port, to be used for debug 698853Sandreas.hansson@arm.com * accesses. 708706Sandreas.hansson@arm.com * 718706Sandreas.hansson@arm.com * This proxy object is used when non structural entities 728706Sandreas.hansson@arm.com * (e.g. thread contexts, object file loaders) need access to the 738706Sandreas.hansson@arm.com * memory system. It calls the corresponding functions on the underlying 748706Sandreas.hansson@arm.com * structural port, and provides templatized convenience access functions. 758706Sandreas.hansson@arm.com * 768706Sandreas.hansson@arm.com * The addresses are interpreted as physical addresses. 778706Sandreas.hansson@arm.com * 788706Sandreas.hansson@arm.com * @sa SETranslatingProxy 798706Sandreas.hansson@arm.com * @sa FSTranslatingProxy 808706Sandreas.hansson@arm.com */ 818706Sandreas.hansson@arm.comclass PortProxy 828706Sandreas.hansson@arm.com{ 838853Sandreas.hansson@arm.com private: 848853Sandreas.hansson@arm.com 858853Sandreas.hansson@arm.com /** The actual physical port used by this proxy. */ 868922Swilliam.wang@arm.com MasterPort &_port; 878706Sandreas.hansson@arm.com 889814Sandreas.hansson@arm.com /** Granularity of any transactions issued through this proxy. */ 899814Sandreas.hansson@arm.com const unsigned int _cacheLineSize; 909814Sandreas.hansson@arm.com 918706Sandreas.hansson@arm.com public: 929814Sandreas.hansson@arm.com PortProxy(MasterPort &port, unsigned int cacheLineSize) : 9313893Sgabeblack@google.com _port(port), _cacheLineSize(cacheLineSize) 9413893Sgabeblack@google.com {} 958706Sandreas.hansson@arm.com virtual ~PortProxy() { } 968706Sandreas.hansson@arm.com 978706Sandreas.hansson@arm.com 988706Sandreas.hansson@arm.com 9914008Sgabeblack@google.com /** Fixed functionality for use in base classes. */ 10012532Sandreas.sandberg@arm.com 10112532Sandreas.sandberg@arm.com /** 10212532Sandreas.sandberg@arm.com * Read size bytes memory at physical address and store in p. 10312532Sandreas.sandberg@arm.com */ 10412532Sandreas.sandberg@arm.com void readBlobPhys(Addr addr, Request::Flags flags, 10514009Sgabeblack@google.com void *p, int size) const; 10612532Sandreas.sandberg@arm.com 10712532Sandreas.sandberg@arm.com /** 10812532Sandreas.sandberg@arm.com * Write size bytes from p to physical address. 10912532Sandreas.sandberg@arm.com */ 11012532Sandreas.sandberg@arm.com void writeBlobPhys(Addr addr, Request::Flags flags, 11114009Sgabeblack@google.com const void *p, int size) const; 11212532Sandreas.sandberg@arm.com 11312532Sandreas.sandberg@arm.com /** 11412532Sandreas.sandberg@arm.com * Fill size bytes starting at physical addr with byte value val. 11512532Sandreas.sandberg@arm.com */ 11612532Sandreas.sandberg@arm.com void memsetBlobPhys(Addr addr, Request::Flags flags, 11712532Sandreas.sandberg@arm.com uint8_t v, int size) const; 1188706Sandreas.hansson@arm.com 11914008Sgabeblack@google.com 12014008Sgabeblack@google.com 12114008Sgabeblack@google.com /** Methods to override in base classes */ 12214008Sgabeblack@google.com 12314008Sgabeblack@google.com /** 12414008Sgabeblack@google.com * Read size bytes memory at address and store in p. 12514008Sgabeblack@google.com * Returns true on success and false on failure. 12614008Sgabeblack@google.com */ 12714008Sgabeblack@google.com virtual bool 12814009Sgabeblack@google.com tryReadBlob(Addr addr, void *p, int size) const 12914008Sgabeblack@google.com { 13014008Sgabeblack@google.com readBlobPhys(addr, 0, p, size); 13114008Sgabeblack@google.com return true; 13214008Sgabeblack@google.com } 13314008Sgabeblack@google.com 13414008Sgabeblack@google.com /** 13514008Sgabeblack@google.com * Write size bytes from p to address. 13614008Sgabeblack@google.com * Returns true on success and false on failure. 13714008Sgabeblack@google.com */ 13814008Sgabeblack@google.com virtual bool 13914009Sgabeblack@google.com tryWriteBlob(Addr addr, const void *p, int size) const 14014008Sgabeblack@google.com { 14114008Sgabeblack@google.com writeBlobPhys(addr, 0, p, size); 14214008Sgabeblack@google.com return true; 14314008Sgabeblack@google.com } 14414008Sgabeblack@google.com 14514008Sgabeblack@google.com /** 14614008Sgabeblack@google.com * Fill size bytes starting at addr with byte value val. 14714008Sgabeblack@google.com * Returns true on success and false on failure. 14814008Sgabeblack@google.com */ 14914008Sgabeblack@google.com virtual bool 15014008Sgabeblack@google.com tryMemsetBlob(Addr addr, uint8_t val, int size) const 15114008Sgabeblack@google.com { 15214008Sgabeblack@google.com memsetBlobPhys(addr, 0, val, size); 15314008Sgabeblack@google.com return true; 15414008Sgabeblack@google.com } 15514008Sgabeblack@google.com 15614008Sgabeblack@google.com 15714008Sgabeblack@google.com 15814008Sgabeblack@google.com /** Higher level interfaces based on the above. */ 15914008Sgabeblack@google.com 16014008Sgabeblack@google.com /** 16114008Sgabeblack@google.com * Same as tryReadBlob, but insists on success. 16214008Sgabeblack@google.com */ 16314008Sgabeblack@google.com void 16414009Sgabeblack@google.com readBlob(Addr addr, void *p, int size) const 16514008Sgabeblack@google.com { 16614008Sgabeblack@google.com if (!tryReadBlob(addr, p, size)) 16714008Sgabeblack@google.com fatal("readBlob(%#x, ...) failed", addr); 16814008Sgabeblack@google.com } 16914008Sgabeblack@google.com 17014008Sgabeblack@google.com /** 17114008Sgabeblack@google.com * Same as tryWriteBlob, but insists on success. 17214008Sgabeblack@google.com */ 17314008Sgabeblack@google.com void 17414009Sgabeblack@google.com writeBlob(Addr addr, const void *p, int size) const 17514008Sgabeblack@google.com { 17614008Sgabeblack@google.com if (!tryWriteBlob(addr, p, size)) 17714008Sgabeblack@google.com fatal("writeBlob(%#x, ...) failed", addr); 17814008Sgabeblack@google.com } 17914008Sgabeblack@google.com 18014008Sgabeblack@google.com /** 18114008Sgabeblack@google.com * Same as tryMemsetBlob, but insists on success. 18214008Sgabeblack@google.com */ 18314008Sgabeblack@google.com void 18414008Sgabeblack@google.com memsetBlob(Addr addr, uint8_t v, int size) const 18514008Sgabeblack@google.com { 18614008Sgabeblack@google.com if (!tryMemsetBlob(addr, v, size)) 18714008Sgabeblack@google.com fatal("memsetBlob(%#x, ...) failed", addr); 18814008Sgabeblack@google.com } 18914008Sgabeblack@google.com 1908706Sandreas.hansson@arm.com /** 1918706Sandreas.hansson@arm.com * Read sizeof(T) bytes from address and return as object T. 1928706Sandreas.hansson@arm.com */ 1938706Sandreas.hansson@arm.com template <typename T> 1948861Sandreas.hansson@arm.com T read(Addr address) const; 1958706Sandreas.hansson@arm.com 1968706Sandreas.hansson@arm.com /** 1978706Sandreas.hansson@arm.com * Write object T to address. Writes sizeof(T) bytes. 1988706Sandreas.hansson@arm.com */ 1998706Sandreas.hansson@arm.com template <typename T> 20014011Sgabeblack@google.com void write(Addr address, const T &data) const; 2018706Sandreas.hansson@arm.com 20212522Sandreas.sandberg@arm.com /** 20312522Sandreas.sandberg@arm.com * Read sizeof(T) bytes from address and return as object T. 20413893Sgabeblack@google.com * Performs endianness conversion from the selected guest to host order. 20512522Sandreas.sandberg@arm.com */ 20612522Sandreas.sandberg@arm.com template <typename T> 20713893Sgabeblack@google.com T read(Addr address, ByteOrder guest_byte_order) const; 20812522Sandreas.sandberg@arm.com 20912522Sandreas.sandberg@arm.com /** 21012522Sandreas.sandberg@arm.com * Write object T to address. Writes sizeof(T) bytes. 21113893Sgabeblack@google.com * Performs endianness conversion from host to the selected guest order. 21212522Sandreas.sandberg@arm.com */ 21312522Sandreas.sandberg@arm.com template <typename T> 21413893Sgabeblack@google.com void write(Addr address, T data, ByteOrder guest_byte_order) const; 21514008Sgabeblack@google.com 21614008Sgabeblack@google.com /** 21714008Sgabeblack@google.com * Write the string str into guest memory at address addr. 21814008Sgabeblack@google.com * Returns true on success and false on failure. 21914008Sgabeblack@google.com */ 22014008Sgabeblack@google.com bool tryWriteString(Addr addr, const char *str) const; 22114008Sgabeblack@google.com 22214008Sgabeblack@google.com /** 22314008Sgabeblack@google.com * Same as tryWriteString, but insists on success. 22414008Sgabeblack@google.com */ 22514008Sgabeblack@google.com void 22614008Sgabeblack@google.com writeString(Addr addr, const char *str) const 22714008Sgabeblack@google.com { 22814008Sgabeblack@google.com if (!tryWriteString(addr, str)) 22914008Sgabeblack@google.com fatal("writeString(%#x, ...) failed", addr); 23014008Sgabeblack@google.com } 23114008Sgabeblack@google.com 23214008Sgabeblack@google.com /** 23314008Sgabeblack@google.com * Reads the string at guest address addr into the std::string str. 23414008Sgabeblack@google.com * Returns true on success and false on failure. 23514008Sgabeblack@google.com */ 23614008Sgabeblack@google.com bool tryReadString(std::string &str, Addr addr) const; 23714008Sgabeblack@google.com 23814008Sgabeblack@google.com /** 23914008Sgabeblack@google.com * Same as tryReadString, but insists on success. 24014008Sgabeblack@google.com */ 24114008Sgabeblack@google.com void 24214008Sgabeblack@google.com readString(std::string &str, Addr addr) const 24314008Sgabeblack@google.com { 24414008Sgabeblack@google.com if (!tryReadString(str, addr)) 24514008Sgabeblack@google.com fatal("readString(%#x, ...) failed", addr); 24614008Sgabeblack@google.com } 24714012Sgabeblack@google.com 24814012Sgabeblack@google.com /** 24914012Sgabeblack@google.com * Reads the string at guest address addr into the char * str, reading up 25014012Sgabeblack@google.com * to maxlen characters. The last character read is always a nul 25114012Sgabeblack@google.com * terminator. Returns true on success and false on failure. 25214012Sgabeblack@google.com */ 25314012Sgabeblack@google.com bool tryReadString(char *str, Addr addr, size_t maxlen) const; 25414012Sgabeblack@google.com 25514012Sgabeblack@google.com /** 25614012Sgabeblack@google.com * Same as tryReadString, but insists on success. 25714012Sgabeblack@google.com */ 25814012Sgabeblack@google.com void 25914012Sgabeblack@google.com readString(char *str, Addr addr, size_t maxlen) const 26014012Sgabeblack@google.com { 26114012Sgabeblack@google.com if (!tryReadString(str, addr, maxlen)) 26214012Sgabeblack@google.com fatal("readString(%#x, ...) failed", addr); 26314012Sgabeblack@google.com } 2648706Sandreas.hansson@arm.com}; 2658706Sandreas.hansson@arm.com 2668706Sandreas.hansson@arm.com 2678706Sandreas.hansson@arm.comtemplate <typename T> 2688706Sandreas.hansson@arm.comT 2698861Sandreas.hansson@arm.comPortProxy::read(Addr address) const 2708706Sandreas.hansson@arm.com{ 2718706Sandreas.hansson@arm.com T data; 27214009Sgabeblack@google.com readBlob(address, &data, sizeof(T)); 2738706Sandreas.hansson@arm.com return data; 2748706Sandreas.hansson@arm.com} 2758706Sandreas.hansson@arm.com 2768706Sandreas.hansson@arm.comtemplate <typename T> 2778706Sandreas.hansson@arm.comvoid 27814011Sgabeblack@google.comPortProxy::write(Addr address, const T &data) const 2798706Sandreas.hansson@arm.com{ 28014009Sgabeblack@google.com writeBlob(address, &data, sizeof(T)); 2818706Sandreas.hansson@arm.com} 2828706Sandreas.hansson@arm.com 28312522Sandreas.sandberg@arm.comtemplate <typename T> 28412522Sandreas.sandberg@arm.comT 28513893Sgabeblack@google.comPortProxy::read(Addr address, ByteOrder byte_order) const 28612522Sandreas.sandberg@arm.com{ 28712522Sandreas.sandberg@arm.com T data; 28814009Sgabeblack@google.com readBlob(address, &data, sizeof(T)); 28912522Sandreas.sandberg@arm.com return gtoh(data, byte_order); 29012522Sandreas.sandberg@arm.com} 29112522Sandreas.sandberg@arm.com 29212522Sandreas.sandberg@arm.comtemplate <typename T> 29312522Sandreas.sandberg@arm.comvoid 29413893Sgabeblack@google.comPortProxy::write(Addr address, T data, ByteOrder byte_order) const 29512522Sandreas.sandberg@arm.com{ 29612522Sandreas.sandberg@arm.com data = htog(data, byte_order); 29714009Sgabeblack@google.com writeBlob(address, &data, sizeof(T)); 29812522Sandreas.sandberg@arm.com} 29912522Sandreas.sandberg@arm.com 3008706Sandreas.hansson@arm.com#endif // __MEM_PORT_PROXY_HH__ 301