Loading...
Searching...
No Matches
trc_mem_acc_base.h
Go to the documentation of this file.
/*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ARM_TRC_MEM_ACC_BASE_H_INCLUDED
#define ARM_TRC_MEM_ACC_BASE_H_INCLUDED
#include "opencsd/ocsd_if_types.h"
#include <string>
class TrcMemAccessorBase
{
public:
enum MemAccTypes {
MEMACC_UNKNOWN,
MEMACC_FILE, //<! Binary data file accessor
MEMACC_BUFPTR, //<! memory buffer accessor
MEMACC_CB_IF, //<! callback interface accessor - use for live memory access
};
TrcMemAccessorBase(MemAccTypes type);
TrcMemAccessorBase(MemAccTypes type, ocsd_vaddr_t startAddr, ocsd_vaddr_t endAddr);
virtual ~TrcMemAccessorBase() {};
void setRange(ocsd_vaddr_t startAddr, ocsd_vaddr_t endAddr);
virtual const bool addrInRange(const ocsd_vaddr_t s_address) const;
virtual const bool addrStartOfRange(const ocsd_vaddr_t s_address) const;
virtual const uint32_t bytesInRange(const ocsd_vaddr_t s_address, const uint32_t reqBytes) const;
virtual const bool overLapRange(const TrcMemAccessorBase *p_test_acc) const;
virtual const uint32_t readBytes(const ocsd_vaddr_t s_address, const ocsd_mem_space_acc_t memSpace, const uint8_t trcID, const uint32_t reqBytes, uint8_t *byteBuffer) = 0;
virtual const bool validateRange();
const enum MemAccTypes getType() const { return m_type; };
/* handle memory spaces */
void setMemSpace(ocsd_mem_space_acc_t memSpace) { m_mem_space = memSpace; };
const ocsd_mem_space_acc_t getMemSpace() const { return m_mem_space; };
const bool inMemSpace(const ocsd_mem_space_acc_t mem_space) const { return (bool)(((uint8_t)m_mem_space & (uint8_t)mem_space) != 0); };
/* memory access info logging */
virtual void getMemAccString(std::string &accStr) const;
protected:
ocsd_vaddr_t m_startAddress;
ocsd_vaddr_t m_endAddress;
const MemAccTypes m_type;
ocsd_mem_space_acc_t m_mem_space;
};
inline TrcMemAccessorBase::TrcMemAccessorBase(MemAccTypes accType, ocsd_vaddr_t startAddr, ocsd_vaddr_t endAddr) :
m_startAddress(startAddr),
m_endAddress(endAddr),
m_type(accType),
m_mem_space(OCSD_MEM_SPACE_ANY)
{
}
inline TrcMemAccessorBase::TrcMemAccessorBase(MemAccTypes accType) :
m_startAddress(0),
m_endAddress(0),
m_type(accType),
m_mem_space(OCSD_MEM_SPACE_ANY)
{
}
inline void TrcMemAccessorBase::setRange(ocsd_vaddr_t startAddr, ocsd_vaddr_t endAddr)
{
m_startAddress = startAddr;
m_endAddress = endAddr;
}
inline const bool TrcMemAccessorBase::addrInRange(const ocsd_vaddr_t s_address) const
{
return (s_address >= m_startAddress) && (s_address <= m_endAddress);
}
inline const bool TrcMemAccessorBase::addrStartOfRange(const ocsd_vaddr_t s_address) const
{
return (s_address == m_startAddress);
}
inline const uint32_t TrcMemAccessorBase::bytesInRange(const ocsd_vaddr_t s_address, const uint32_t reqBytes) const
{
ocsd_vaddr_t bytesInRange = 0;
if(addrInRange(s_address)) // start not in range, return 0.
{
// bytes available till end address.
bytesInRange = m_endAddress - s_address + 1;
if(bytesInRange > reqBytes)
bytesInRange = reqBytes;
}
return (uint32_t)bytesInRange;
}
inline const bool TrcMemAccessorBase::overLapRange(const TrcMemAccessorBase *p_test_acc) const
{
if( addrInRange(p_test_acc->m_startAddress) ||
addrInRange(p_test_acc->m_endAddress)
)
return true;
return false;
}
inline const bool TrcMemAccessorBase::validateRange()
{
if(m_startAddress & 0x1) // at least hword aligned for thumb
return false;
if((m_endAddress + 1) & 0x1)
return false;
if(m_startAddress == m_endAddress) // zero length range.
return false;
if(m_startAddress > m_endAddress) // values bakcwards / invalid
return false;
return true;
}
class TrcMemAccFactory
{
public:
static ocsd_err_t CreateBufferAccessor(TrcMemAccessorBase **pAccessor, const ocsd_vaddr_t s_address, const uint8_t *p_buffer, const uint32_t size);
static ocsd_err_t CreateFileAccessor(TrcMemAccessorBase **pAccessor, const std::string &pathToFile, ocsd_vaddr_t startAddr, size_t offset = 0, size_t size = 0);
static ocsd_err_t CreateCBAccessor(TrcMemAccessorBase **pAccessor, const ocsd_vaddr_t s_address, const ocsd_vaddr_t e_address, const ocsd_mem_space_acc_t mem_space);
static void DestroyAccessor(TrcMemAccessorBase *pAccessor);
private:
TrcMemAccFactory() {};
~TrcMemAccFactory() {};
};
#endif // ARM_TRC_MEM_ACC_BASE_H_INCLUDED
/* End of File trc_mem_acc_base.h */
TrcMemAccFactory
Definition trc_mem_acc_base.h:229
TrcMemAccFactory::DestroyAccessor
static void DestroyAccessor(TrcMemAccessorBase *pAccessor)
TrcMemAccFactory::CreateCBAccessor
static ocsd_err_t CreateCBAccessor(TrcMemAccessorBase **pAccessor, const ocsd_vaddr_t s_address, const ocsd_vaddr_t e_address, const ocsd_mem_space_acc_t mem_space)
TrcMemAccFactory::CreateFileAccessor
static ocsd_err_t CreateFileAccessor(TrcMemAccessorBase **pAccessor, const std::string &pathToFile, ocsd_vaddr_t startAddr, size_t offset=0, size_t size=0)
TrcMemAccFactory::CreateBufferAccessor
static ocsd_err_t CreateBufferAccessor(TrcMemAccessorBase **pAccessor, const ocsd_vaddr_t s_address, const uint8_t *p_buffer, const uint32_t size)
TrcMemAccessorBase
Memory range to access by trace decoder.
Definition trc_mem_acc_base.h:53
TrcMemAccessorBase::m_type
const MemAccTypes m_type
Definition trc_mem_acc_base.h:155
TrcMemAccessorBase::overLapRange
virtual const bool overLapRange(const TrcMemAccessorBase *p_test_acc) const
Definition trc_mem_acc_base.h:205
TrcMemAccessorBase::setMemSpace
void setMemSpace(ocsd_mem_space_acc_t memSpace)
Definition trc_mem_acc_base.h:145
TrcMemAccessorBase::setRange
void setRange(ocsd_vaddr_t startAddr, ocsd_vaddr_t endAddr)
Definition trc_mem_acc_base.h:175
TrcMemAccessorBase::readBytes
virtual const uint32_t readBytes(const ocsd_vaddr_t s_address, const ocsd_mem_space_acc_t memSpace, const uint8_t trcID, const uint32_t reqBytes, uint8_t *byteBuffer)=0
TrcMemAccessorBase::getMemSpace
const ocsd_mem_space_acc_t getMemSpace() const
Definition trc_mem_acc_base.h:146
TrcMemAccessorBase::addrInRange
virtual const bool addrInRange(const ocsd_vaddr_t s_address) const
Definition trc_mem_acc_base.h:181
TrcMemAccessorBase::TrcMemAccessorBase
TrcMemAccessorBase(MemAccTypes type)
Definition trc_mem_acc_base.h:167
TrcMemAccessorBase::MemAccTypes
MemAccTypes
Definition trc_mem_acc_base.h:57
TrcMemAccessorBase::MEMACC_FILE
@ MEMACC_FILE
Definition trc_mem_acc_base.h:59
TrcMemAccessorBase::MEMACC_BUFPTR
@ MEMACC_BUFPTR
Definition trc_mem_acc_base.h:60
TrcMemAccessorBase::MEMACC_UNKNOWN
@ MEMACC_UNKNOWN
Definition trc_mem_acc_base.h:58
TrcMemAccessorBase::MEMACC_CB_IF
@ MEMACC_CB_IF
Definition trc_mem_acc_base.h:61
TrcMemAccessorBase::m_mem_space
ocsd_mem_space_acc_t m_mem_space
Definition trc_mem_acc_base.h:156
TrcMemAccessorBase::getType
enum MemAccTypes getType() const
Definition trc_mem_acc_base.h:142
TrcMemAccessorBase::bytesInRange
virtual const uint32_t bytesInRange(const ocsd_vaddr_t s_address, const uint32_t reqBytes) const
Definition trc_mem_acc_base.h:192
TrcMemAccessorBase::validateRange
virtual const bool validateRange()
Definition trc_mem_acc_base.h:214
TrcMemAccessorBase::m_endAddress
ocsd_vaddr_t m_endAddress
Definition trc_mem_acc_base.h:154
TrcMemAccessorBase::getMemAccString
virtual void getMemAccString(std::string &accStr) const
TrcMemAccessorBase::addrStartOfRange
virtual const bool addrStartOfRange(const ocsd_vaddr_t s_address) const
Definition trc_mem_acc_base.h:186
TrcMemAccessorBase::~TrcMemAccessorBase
virtual ~TrcMemAccessorBase()
Definition trc_mem_acc_base.h:71
TrcMemAccessorBase::inMemSpace
const bool inMemSpace(const ocsd_mem_space_acc_t mem_space) const
Definition trc_mem_acc_base.h:147
TrcMemAccessorBase::m_startAddress
ocsd_vaddr_t m_startAddress
Definition trc_mem_acc_base.h:153
ocsd_mem_space_acc_t
enum _ocsd_mem_space_acc_t ocsd_mem_space_acc_t
ocsd_err_t
enum _ocsd_err_t ocsd_err_t
ocsd_vaddr_t
uint64_t ocsd_vaddr_t
Definition ocsd_if_types.h:310
OCSD_MEM_SPACE_ANY
@ OCSD_MEM_SPACE_ANY
Definition ocsd_if_types.h:441
ocsd_if_types.h
OpenCSD : Standard Types used in the library interfaces.