• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*!
2  * \file       trc_mem_acc_base.cpp
3  * \brief      OpenCSD : Trace memory accessor base class.
4  *
5  * \copyright  Copyright (c) 2015, ARM Limited. All Rights Reserved.
6  */
7 
8 
9 /*
10  * Redistribution and use in source and binary forms, with or without modification,
11  * are permitted provided that the following conditions are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright notice,
14  * this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright notice,
17  * this list of conditions and the following disclaimer in the documentation
18  * and/or other materials provided with the distribution.
19  *
20  * 3. Neither the name of the copyright holder nor the names of its contributors
21  * may be used to endorse or promote products derived from this software without
22  * specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27  * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #include "mem_acc/trc_mem_acc_base.h"
37 #include "mem_acc/trc_mem_acc_file.h"
38 #include "mem_acc/trc_mem_acc_cb.h"
39 #include "mem_acc/trc_mem_acc_bufptr.h"
40 
41 #include <sstream>
42 #include <iomanip>
43 
44  /** Accessor Creation */
CreateBufferAccessor(TrcMemAccessorBase ** pAccessor,const ocsd_vaddr_t s_address,const uint8_t * p_buffer,const uint32_t size)45 ocsd_err_t TrcMemAccFactory::CreateBufferAccessor(TrcMemAccessorBase **pAccessor, const ocsd_vaddr_t s_address, const uint8_t *p_buffer, const uint32_t size)
46 {
47     ocsd_err_t err = OCSD_OK;
48     TrcMemAccessorBase *pAcc = 0;
49     pAcc = new (std::nothrow) TrcMemAccBufPtr(s_address,p_buffer,size);
50     if(pAcc == 0)
51         err = OCSD_ERR_MEM;
52     *pAccessor = pAcc;
53     return err;
54 }
55 
CreateFileAccessor(TrcMemAccessorBase ** pAccessor,const std::string & pathToFile,ocsd_vaddr_t startAddr,size_t offset,size_t size)56 ocsd_err_t TrcMemAccFactory::CreateFileAccessor(TrcMemAccessorBase **pAccessor, const std::string &pathToFile, ocsd_vaddr_t startAddr, size_t offset /*= 0*/, size_t size /*= 0*/)
57 {
58     ocsd_err_t err = OCSD_OK;
59     TrcMemAccessorFile *pFileAccessor = 0;
60     err = TrcMemAccessorFile::createFileAccessor(&pFileAccessor, pathToFile, startAddr, offset,size);
61     *pAccessor = pFileAccessor;
62     return err;
63 }
64 
CreateCBAccessor(TrcMemAccessorBase ** pAccessor,const ocsd_vaddr_t s_address,const ocsd_vaddr_t e_address,const ocsd_mem_space_acc_t mem_space)65 ocsd_err_t TrcMemAccFactory::CreateCBAccessor(TrcMemAccessorBase **pAccessor, const ocsd_vaddr_t s_address, const ocsd_vaddr_t e_address, const ocsd_mem_space_acc_t mem_space)
66 {
67     ocsd_err_t err = OCSD_OK;
68     TrcMemAccessorBase *pAcc = 0;
69     pAcc = new (std::nothrow)  TrcMemAccCB(s_address,e_address,mem_space);
70     if(pAcc == 0)
71         err = OCSD_ERR_MEM;
72     *pAccessor = pAcc;
73     return err;
74 }
75 
76 /** Accessor Destruction */
DestroyAccessor(TrcMemAccessorBase * pAccessor)77 void TrcMemAccFactory::DestroyAccessor(TrcMemAccessorBase *pAccessor)
78 {
79     switch(pAccessor->getType())
80     {
81     case TrcMemAccessorBase::MEMACC_FILE:
82         TrcMemAccessorFile::destroyFileAccessor(dynamic_cast<TrcMemAccessorFile *>(pAccessor));
83         break;
84 
85     case TrcMemAccessorBase::MEMACC_CB_IF:
86     case TrcMemAccessorBase::MEMACC_BUFPTR:
87     delete pAccessor;
88         break;
89 
90     default:
91         break;
92     }
93 }
94 
95 
96 /* memory access info logging */
getMemAccString(std::string & accStr) const97 void TrcMemAccessorBase::getMemAccString(std::string &accStr) const
98 {
99     std::ostringstream oss;
100 
101     switch(m_type)
102     {
103     case MEMACC_FILE:
104         oss << "FileAcc; Range::0x";
105         break;
106 
107     case MEMACC_BUFPTR:
108         oss << "BuffAcc; Range::0x";
109         break;
110 
111     case MEMACC_CB_IF:
112         oss << "CB  Acc; Range::0x";
113         break;
114 
115     default:
116         oss << "UnknAcc; Range::0x";
117         break;
118     }
119     oss << std::hex << std::setw(2) << std::setfill('0') << m_startAddress << ":" << m_endAddress;
120     oss << "; Mem Space::";
121     switch(m_mem_space)
122     {
123     case OCSD_MEM_SPACE_EL1S: oss << "EL1S"; break;
124     case OCSD_MEM_SPACE_EL1N: oss << "EL1N"; break;
125     case OCSD_MEM_SPACE_EL2: oss << "EL2"; break;
126     case OCSD_MEM_SPACE_EL3: oss << "EL3"; break;
127     case OCSD_MEM_SPACE_S: oss << "Any S"; break;
128     case OCSD_MEM_SPACE_N: oss << "Any NS"; break;
129     case OCSD_MEM_SPACE_ANY: oss << "Any"; break;
130 
131     default:
132         {
133             uint8_t MSBits = (uint8_t)m_mem_space;
134             if(MSBits & (uint8_t)OCSD_MEM_SPACE_EL1S)
135                 oss << "EL1S,";
136             if(MSBits & (uint8_t)OCSD_MEM_SPACE_EL1N)
137                 oss << "EL1N,";
138             if(MSBits & (uint8_t)OCSD_MEM_SPACE_EL2)
139                 oss << "EL2,";
140             if(MSBits & (uint8_t)OCSD_MEM_SPACE_EL3)
141                 oss << "EL3,";
142         }
143         break;
144     }
145     accStr = oss.str();
146 }
147 
148 /* End of File trc_mem_acc_base.cpp */
149