port_proxy.hh revision 8853
112334Sgabeblack@google.com/*
212334Sgabeblack@google.com * Copyright (c) 2011-2012 ARM Limited
312334Sgabeblack@google.com * All rights reserved
412334Sgabeblack@google.com *
512334Sgabeblack@google.com * The license below extends only to copyright in the software and shall
612334Sgabeblack@google.com * not be construed as granting a license to any other intellectual
712334Sgabeblack@google.com * property including but not limited to intellectual property relating
812334Sgabeblack@google.com * to a hardware implementation of the functionality of the software
912334Sgabeblack@google.com * licensed hereunder.  You may use the software subject to the license
1012334Sgabeblack@google.com * terms below provided that you ensure that this notice is replicated
1112334Sgabeblack@google.com * unmodified and in its entirety in all distributions of the software,
1212334Sgabeblack@google.com * modified or unmodified, in source code or in binary form.
1312334Sgabeblack@google.com *
1412334Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
1512334Sgabeblack@google.com * modification, are permitted provided that the following conditions are
1612334Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
1712334Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
1812334Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
1912334Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
2012334Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
2112334Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
2212334Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
2312334Sgabeblack@google.com * this software without specific prior written permission.
2412334Sgabeblack@google.com *
2512334Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2612334Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2712334Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2812334Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2912334Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3012334Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3112334Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3212334Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3312334Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3412334Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3512334Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3612334Sgabeblack@google.com *
3712334Sgabeblack@google.com * Authors: Andreas Hansson
3812334Sgabeblack@google.com */
3912334Sgabeblack@google.com
4012334Sgabeblack@google.com/**
4112334Sgabeblack@google.com * @file
4212334Sgabeblack@google.com * PortProxy Object Declaration.
4312334Sgabeblack@google.com *
4412334Sgabeblack@google.com * Port proxies are used when non-structural entities need access to
4512334Sgabeblack@google.com * the memory system (or structural entities that want to peak into
4612334Sgabeblack@google.com * the memory system without making a real memory access).
4712334Sgabeblack@google.com *
4812334Sgabeblack@google.com * Proxy objects replace the previous FunctionalPort, TranslatingPort
4912334Sgabeblack@google.com * and VirtualPort objects, which provided the same functionality as
5012334Sgabeblack@google.com * the proxies, but were instances of ports not corresponding to real
5112334Sgabeblack@google.com * structural ports of the simulated system. Via the port proxies all
5212334Sgabeblack@google.com * the accesses go through an actual port (either the system port,
5312334Sgabeblack@google.com * e.g. for processes or initialisation, or a the data port of the
5412334Sgabeblack@google.com * CPU, e.g. for threads) and thus are transparent to a potentially
5512334Sgabeblack@google.com * distributed memory and automatically adhere to the memory map of
5612334Sgabeblack@google.com * the system.
5712334Sgabeblack@google.com */
5812334Sgabeblack@google.com
5912334Sgabeblack@google.com#ifndef __MEM_PORT_PROXY_HH__
6012334Sgabeblack@google.com#define __MEM_PORT_PROXY_HH__
6112334Sgabeblack@google.com
6212334Sgabeblack@google.com#include "config/the_isa.hh"
6312334Sgabeblack@google.com#if THE_ISA != NO_ISA
6412334Sgabeblack@google.com    #include "arch/isa_traits.hh"
6512334Sgabeblack@google.com#endif
6612334Sgabeblack@google.com
6712334Sgabeblack@google.com#include "mem/port.hh"
6812334Sgabeblack@google.com#include "sim/byteswap.hh"
6912334Sgabeblack@google.com
7012334Sgabeblack@google.com/**
7112334Sgabeblack@google.com * This object is a proxy for a structural port, to be used for debug
7212334Sgabeblack@google.com * accesses.
7312334Sgabeblack@google.com *
7412334Sgabeblack@google.com * This proxy object is used when non structural entities
7512334Sgabeblack@google.com * (e.g. thread contexts, object file loaders) need access to the
7612334Sgabeblack@google.com * memory system. It calls the corresponding functions on the underlying
7712334Sgabeblack@google.com * structural port, and provides templatized convenience access functions.
7812334Sgabeblack@google.com *
7912334Sgabeblack@google.com * The addresses are interpreted as physical addresses.
8012334Sgabeblack@google.com *
8112334Sgabeblack@google.com * @sa SETranslatingProxy
8212334Sgabeblack@google.com * @sa FSTranslatingProxy
8312334Sgabeblack@google.com */
8412334Sgabeblack@google.comclass PortProxy
8512334Sgabeblack@google.com{
8612334Sgabeblack@google.com  private:
8712334Sgabeblack@google.com
8812334Sgabeblack@google.com    /** The actual physical port used by this proxy. */
8912334Sgabeblack@google.com    Port &_port;
9012334Sgabeblack@google.com
9112334Sgabeblack@google.com    void blobHelper(Addr addr, uint8_t *p, int size, MemCmd cmd);
9212334Sgabeblack@google.com
9312334Sgabeblack@google.com  public:
9412334Sgabeblack@google.com    PortProxy(Port &port) : _port(port) { }
9512334Sgabeblack@google.com    virtual ~PortProxy() { }
9612334Sgabeblack@google.com
9712334Sgabeblack@google.com    /**
9812334Sgabeblack@google.com     * Read size bytes memory at address and store in p.
9912334Sgabeblack@google.com     */
10012334Sgabeblack@google.com    virtual void readBlob(Addr addr, uint8_t* p, int size)
10112334Sgabeblack@google.com    { blobHelper(addr, p, size, MemCmd::ReadReq); }
10212334Sgabeblack@google.com
10312334Sgabeblack@google.com    /**
10412334Sgabeblack@google.com     * Write size bytes from p to address.
10512334Sgabeblack@google.com     */
10612334Sgabeblack@google.com    virtual void writeBlob(Addr addr, uint8_t* p, int size)
10712334Sgabeblack@google.com    { blobHelper(addr, p, size, MemCmd::WriteReq); }
10812334Sgabeblack@google.com
10912334Sgabeblack@google.com    /**
11012334Sgabeblack@google.com     * Fill size bytes starting at addr with byte value val.
11112334Sgabeblack@google.com     */
11212334Sgabeblack@google.com    virtual void memsetBlob(Addr addr, uint8_t v, int size);
11312334Sgabeblack@google.com
11412334Sgabeblack@google.com    /**
11512334Sgabeblack@google.com     * Read sizeof(T) bytes from address and return as object T.
11612334Sgabeblack@google.com     */
11712334Sgabeblack@google.com    template <typename T>
11812334Sgabeblack@google.com    T read(Addr address);
11912334Sgabeblack@google.com
12012334Sgabeblack@google.com    /**
12112334Sgabeblack@google.com     * Write object T to address. Writes sizeof(T) bytes.
12212334Sgabeblack@google.com     */
12312334Sgabeblack@google.com    template <typename T>
12412334Sgabeblack@google.com    void write(Addr address, T data);
12512334Sgabeblack@google.com
12612334Sgabeblack@google.com#if THE_ISA != NO_ISA
12712334Sgabeblack@google.com    /**
12812334Sgabeblack@google.com     * Read sizeof(T) bytes from address and return as object T.
12912334Sgabeblack@google.com     * Performs Guest to Host endianness transform.
13012334Sgabeblack@google.com     */
13112334Sgabeblack@google.com    template <typename T>
13212334Sgabeblack@google.com    T readGtoH(Addr address);
13312334Sgabeblack@google.com
13412334Sgabeblack@google.com    /**
13512334Sgabeblack@google.com     * Write object T to address. Writes sizeof(T) bytes.
13612334Sgabeblack@google.com     * Performs Host to Guest endianness transform.
13712334Sgabeblack@google.com     */
13812334Sgabeblack@google.com    template <typename T>
13912334Sgabeblack@google.com    void writeHtoG(Addr address, T data);
14012334Sgabeblack@google.com#endif
14112334Sgabeblack@google.com};
14212334Sgabeblack@google.com
14312334Sgabeblack@google.com
14412334Sgabeblack@google.comtemplate <typename T>
14512334Sgabeblack@google.comT
14612334Sgabeblack@google.comPortProxy::read(Addr address)
14712334Sgabeblack@google.com{
14812334Sgabeblack@google.com    T data;
14912334Sgabeblack@google.com    readBlob(address, (uint8_t*)&data, sizeof(T));
15012334Sgabeblack@google.com    return data;
15112334Sgabeblack@google.com}
15212334Sgabeblack@google.com
15312334Sgabeblack@google.comtemplate <typename T>
15412334Sgabeblack@google.comvoid
15512334Sgabeblack@google.comPortProxy::write(Addr address, T data)
15612334Sgabeblack@google.com{
15712334Sgabeblack@google.com    writeBlob(address, (uint8_t*)&data, sizeof(T));
15812334Sgabeblack@google.com}
15912334Sgabeblack@google.com
16012334Sgabeblack@google.com#if THE_ISA != NO_ISA
16112334Sgabeblack@google.comtemplate <typename T>
16212334Sgabeblack@google.comT
16312334Sgabeblack@google.comPortProxy::readGtoH(Addr address)
16412334Sgabeblack@google.com{
16512334Sgabeblack@google.com    T data;
16612334Sgabeblack@google.com    readBlob(address, (uint8_t*)&data, sizeof(T));
16712334Sgabeblack@google.com    return TheISA::gtoh(data);
16812334Sgabeblack@google.com}
16912334Sgabeblack@google.com
17012334Sgabeblack@google.comtemplate <typename T>
17112334Sgabeblack@google.comvoid
17212334Sgabeblack@google.comPortProxy::writeHtoG(Addr address, T data)
17312334Sgabeblack@google.com{
17412334Sgabeblack@google.com    data = TheISA::htog(data);
17512334Sgabeblack@google.com    writeBlob(address, (uint8_t*)&data, sizeof(T));
17612334Sgabeblack@google.com}
17712334Sgabeblack@google.com#endif
17812334Sgabeblack@google.com
17912334Sgabeblack@google.com#endif // __MEM_PORT_PROXY_HH__
18012334Sgabeblack@google.com