diff options
author | Mike Leach <mike.leach@linaro.org> | 2023-11-15 11:36:54 +0000 |
---|---|---|
committer | Mike Leach <mike.leach@linaro.org> | 2023-12-18 14:57:54 +0000 |
commit | 12eb668a24fb36233db62c4fd114504193635abe (patch) | |
tree | 4148cc18052d0a6159e70d436b1bb0ed839873c9 | |
parent | 1d44e99cded93bb97dc5febbf660e1723eee56ec (diff) | |
download | OpenCSD-12eb668a24fb36233db62c4fd114504193635abe.tar.gz |
opencsd: memacc: Updates to memory accessors and mapper
Add default constructor and initialise function to mem-acc-buf
and mem-acc-cb to allow declaration as local stack objects.
Fix memory issue in mapper - do not destroy accessors on clear, code that
adds then must delete them after removal from mapper.
Signed-off-by: Mike Leach <mike.leach@linaro.org>
-rw-r--r-- | decoder/include/mem_acc/trc_mem_acc_bufptr.h | 17 | ||||
-rw-r--r-- | decoder/include/mem_acc/trc_mem_acc_cb.h | 4 | ||||
-rw-r--r-- | decoder/include/mem_acc/trc_mem_acc_mapper.h | 2 | ||||
-rw-r--r-- | decoder/source/mem_acc/trc_mem_acc_bufptr.cpp | 17 | ||||
-rw-r--r-- | decoder/source/mem_acc/trc_mem_acc_cb.cpp | 13 | ||||
-rw-r--r-- | decoder/source/mem_acc/trc_mem_acc_mapper.cpp | 30 |
6 files changed, 67 insertions, 16 deletions
diff --git a/decoder/include/mem_acc/trc_mem_acc_bufptr.h b/decoder/include/mem_acc/trc_mem_acc_bufptr.h index b6208a7..e36f165 100644 --- a/decoder/include/mem_acc/trc_mem_acc_bufptr.h +++ b/decoder/include/mem_acc/trc_mem_acc_bufptr.h @@ -61,6 +61,23 @@ public: */ TrcMemAccBufPtr(const ocsd_vaddr_t s_address, const uint8_t *p_buffer, const uint32_t size); + /*! + * Default constructor - init later + * + */ + TrcMemAccBufPtr(); + + /* + *uses the start address as the start of rangeand calculates the end address + * according to the buffer size + * + * @param s_address : Start address in memory map represented by the data in the buffer. + * @param* p_buffer : pointer to a buffer of binary data. + * @param size : size of the buffer. + */ + void initAccessor(const ocsd_vaddr_t s_address, const uint8_t* p_buffer, const uint32_t size); + + virtual ~TrcMemAccBufPtr() {}; /**< default destructor */ /** Memory access override - allow decoder to read bytes from the buffer. */ diff --git a/decoder/include/mem_acc/trc_mem_acc_cb.h b/decoder/include/mem_acc/trc_mem_acc_cb.h index e58c616..a1785b3 100644 --- a/decoder/include/mem_acc/trc_mem_acc_cb.h +++ b/decoder/include/mem_acc/trc_mem_acc_cb.h @@ -45,6 +45,10 @@ public: const ocsd_vaddr_t e_address, const ocsd_mem_space_acc_t mem_space); + // default constructor + TrcMemAccCB(); + + void initAccessor(const ocsd_vaddr_t s_address, const ocsd_vaddr_t e_address, const ocsd_mem_space_acc_t mem_space); virtual ~TrcMemAccCB() {}; diff --git a/decoder/include/mem_acc/trc_mem_acc_mapper.h b/decoder/include/mem_acc/trc_mem_acc_mapper.h index 4a08498..f4523c7 100644 --- a/decoder/include/mem_acc/trc_mem_acc_mapper.h +++ b/decoder/include/mem_acc/trc_mem_acc_mapper.h @@ -103,7 +103,7 @@ protected: // address spaces common to all sources using this mapper. -// trace id unused. +// trace id unused when differentiating accessors - may be used by underlying read operations. class TrcMemAccMapGlobalSpace : public TrcMemAccMapper { public: diff --git a/decoder/source/mem_acc/trc_mem_acc_bufptr.cpp b/decoder/source/mem_acc/trc_mem_acc_bufptr.cpp index 7ecd3b0..3f5c2df 100644 --- a/decoder/source/mem_acc/trc_mem_acc_bufptr.cpp +++ b/decoder/source/mem_acc/trc_mem_acc_bufptr.cpp @@ -41,9 +41,24 @@ TrcMemAccBufPtr::TrcMemAccBufPtr(const ocsd_vaddr_t s_address, const uint8_t *p_ { } +TrcMemAccBufPtr::TrcMemAccBufPtr() : + TrcMemAccessorBase(MEMACC_BUFPTR), m_p_buffer(0) +{ +} + +void TrcMemAccBufPtr::initAccessor(const ocsd_vaddr_t s_address, const uint8_t* p_buffer, const uint32_t size) +{ + m_p_buffer = p_buffer; + setRange(s_address, s_address + size - 1); +} + const uint32_t TrcMemAccBufPtr::readBytes(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, const uint8_t trcID, const uint32_t reqBytes, uint8_t *byteBuffer) { - // mapper wlll filter memory spaces. + // no buffer - nothing to read. + if (!m_p_buffer) + return 0; + + // mapper will filter memory spaces. uint32_t bytesRead = bytesInRange(address,reqBytes); // check bytes available if(bytesRead) memcpy(byteBuffer,m_p_buffer+address-m_startAddress,bytesRead); diff --git a/decoder/source/mem_acc/trc_mem_acc_cb.cpp b/decoder/source/mem_acc/trc_mem_acc_cb.cpp index 1a1565b..6435415 100644 --- a/decoder/source/mem_acc/trc_mem_acc_cb.cpp +++ b/decoder/source/mem_acc/trc_mem_acc_cb.cpp @@ -18,6 +18,19 @@ TrcMemAccCB::TrcMemAccCB(const ocsd_vaddr_t s_address, setMemSpace(mem_space); } +TrcMemAccCB::TrcMemAccCB() : + TrcMemAccessorBase(MEMACC_CB_IF), + m_p_CBclass(0), + m_p_CBfn(0), + m_p_cbfn_context(0) +{}; + +void TrcMemAccCB::initAccessor(const ocsd_vaddr_t s_address, const ocsd_vaddr_t e_address, const ocsd_mem_space_acc_t mem_space) +{ + setRange(s_address, e_address); + setMemSpace(mem_space); +} + /** Memory access override - allow decoder to read bytes from the buffer. */ const uint32_t TrcMemAccCB::readBytes(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t memSpace, const uint8_t trcID, const uint32_t reqBytes, uint8_t *byteBuffer) { diff --git a/decoder/source/mem_acc/trc_mem_acc_mapper.cpp b/decoder/source/mem_acc/trc_mem_acc_mapper.cpp index dc07a1e..72efe77 100644 --- a/decoder/source/mem_acc/trc_mem_acc_mapper.cpp +++ b/decoder/source/mem_acc/trc_mem_acc_mapper.cpp @@ -129,18 +129,12 @@ void TrcMemAccMapper::InvalidateMemAccCache(const uint8_t /* cs_trace_id */) void TrcMemAccMapper::RemoveAllAccessors() { - TrcMemAccessorBase *pAcc = 0; - pAcc = getFirstAccessor(); - while(pAcc != 0) - { - TrcMemAccFactory::DestroyAccessor(pAcc); - pAcc = getNextAccessor(); - if (m_cache.enabled()) - m_cache.invalidateAll(); - } clearAccessorList(); - if (m_cache.enabled()) + if (m_cache.enabled()) + { + m_cache.invalidateAll(); m_cache.logAndClearCounts(); + } } ocsd_err_t TrcMemAccMapper::RemoveAccessorByAddress(const ocsd_vaddr_t st_address, const ocsd_mem_space_acc_t mem_space, const uint8_t cs_trace_id /* = 0 */) @@ -151,12 +145,13 @@ ocsd_err_t TrcMemAccMapper::RemoveAccessorByAddress(const ocsd_vaddr_t st_addres err = RemoveAccessor(m_acc_curr); m_acc_curr = 0; if (m_cache.enabled()) + { m_cache.invalidateAll(); + m_cache.logAndClearCounts(); + } } else - err = OCSD_ERR_INVALID_PARAM_VAL; - if (m_cache.enabled()) - m_cache.logAndClearCounts(); + err = OCSD_ERR_INVALID_PARAM_VAL; return err; } @@ -267,6 +262,7 @@ TrcMemAccessorBase *TrcMemAccMapGlobalSpace::getNextAccessor() void TrcMemAccMapGlobalSpace::clearAccessorList() { m_acc_global.clear(); + m_acc_curr = 0; } ocsd_err_t TrcMemAccMapGlobalSpace::RemoveAccessor(const TrcMemAccessorBase *p_accessor) @@ -278,9 +274,15 @@ ocsd_err_t TrcMemAccMapGlobalSpace::RemoveAccessor(const TrcMemAccessorBase *p_a if(p_acc == p_accessor) { m_acc_global.erase(m_acc_it); - TrcMemAccFactory::DestroyAccessor(p_acc); p_acc = 0; bFound = true; + if (m_cache.enabled()) + { + m_cache.invalidateAll(); + m_cache.logAndClearCounts(); + } + if (m_acc_curr == p_accessor) + m_acc_curr = 0; } else p_acc = getNextAccessor(); |