• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * \file       ss_to_dcdtree.cpp
3  * \brief      OpenCSD :
4  *
5  * \copyright  Copyright (c) 2015, ARM Limited. All Rights Reserved.
6  */
7 
8 /*
9  * Redistribution and use in source and binary forms, with or without modification,
10  * are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * 3. Neither the name of the copyright holder nor the names of its contributors
20  * may be used to endorse or promote products derived from this software without
21  * specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #include "ss_to_dcdtree.h"
36 #include "ss_key_value_names.h"
37 
38 
CreateDcdTreeFromSnapShot()39 CreateDcdTreeFromSnapShot::CreateDcdTreeFromSnapShot() :
40     m_bInit(false),
41     m_pDecodeTree(0),
42     m_pReader(0),
43     m_pErrLogInterface(0),
44     m_bPacketProcOnly(false),
45     m_BufferFileName("")
46 {
47     m_errlog_handle = 0;
48     m_add_create_flags = 0;
49 }
50 
~CreateDcdTreeFromSnapShot()51 CreateDcdTreeFromSnapShot::~CreateDcdTreeFromSnapShot()
52 {
53     destroyDecodeTree();
54 }
55 
initialise(SnapShotReader * pReader,ITraceErrorLog * pErrLogInterface)56 void CreateDcdTreeFromSnapShot::initialise(SnapShotReader *pReader, ITraceErrorLog *pErrLogInterface)
57 {
58     if((pErrLogInterface != 0) && (pReader != 0))
59     {
60         m_pReader = pReader;
61         m_pErrLogInterface = pErrLogInterface;
62         m_errlog_handle = m_pErrLogInterface->RegisterErrorSource("ss2_dcdtree");
63         m_bInit = true;
64     }
65 }
66 
getBufferFileNameFromBuffName(const std::string & buff_name)67 std::string CreateDcdTreeFromSnapShot::getBufferFileNameFromBuffName(const std::string& buff_name)
68 {
69     Parser::TraceBufferSourceTree tree;
70     std::string buffFileName = "";
71 
72     if (m_pReader->getTraceBufferSourceTree(buff_name, tree))
73     {
74         buffFileName = m_pReader->getSnapShotDir() + tree.buffer_info.dataFileName;
75     }
76     return buffFileName;
77 }
78 
79 
createDecodeTree(const std::string & SourceName,bool bPacketProcOnly,uint32_t add_create_flags)80 bool CreateDcdTreeFromSnapShot::createDecodeTree(const std::string &SourceName, bool bPacketProcOnly, uint32_t add_create_flags)
81 {
82     m_add_create_flags = add_create_flags;
83     if(m_bInit)
84     {
85         if(!m_pReader->snapshotReadOK())
86         {
87             LogError("Supplied snapshot reader has not correctly read the snapshot.\n");
88             return false;
89         }
90 
91         m_bPacketProcOnly = bPacketProcOnly;
92         Parser::TraceBufferSourceTree tree;
93 
94         if(m_pReader->getTraceBufferSourceTree(SourceName, tree))
95         {
96             int numDecodersCreated = 0; // count how many we create - if none then give up.
97             uint32_t formatter_flags = OCSD_DFRMTR_FRAME_MEM_ALIGN;
98 
99             /* make a note of the trace binary file name + path to ss directory */
100             m_BufferFileName = m_pReader->getSnapShotDir() + tree.buffer_info.dataFileName;
101 
102             ocsd_dcd_tree_src_t src_format = tree.buffer_info.dataFormat == "source_data" ? OCSD_TRC_SRC_SINGLE : OCSD_TRC_SRC_FRAME_FORMATTED;
103 
104             if (tree.buffer_info.dataFormat == "dstream_coresight")
105                 formatter_flags = OCSD_DFRMTR_HAS_FSYNCS;
106 
107             /* create the initial device tree */
108             // TBD:     handle syncs / hsyncs data from TPIU
109             m_pDecodeTree = DecodeTree::CreateDecodeTree(src_format, formatter_flags);
110             if(m_pDecodeTree == 0)
111             {
112                 LogError("Failed to create decode tree object\n");
113                 return false;
114             }
115 
116             // use our error logger - don't use the tree default.
117             m_pDecodeTree->setAlternateErrorLogger(m_pErrLogInterface);
118 
119             if(!bPacketProcOnly)
120             {
121                 m_pDecodeTree->createMemAccMapper();
122             }
123 
124             /* run through each protocol source to this buffer... */
125             std::map<std::string, std::string>::iterator it = tree.source_core_assoc.begin();
126 
127             while(it != tree.source_core_assoc.end())
128             {
129                 Parser::Parsed *etm_dev, *core_dev;
130                 if(m_pReader->getDeviceData(it->first,&etm_dev))
131                 {
132                     // found the device data for this device.
133 
134                     // see if we have a core name (STM / ITM not associated with a core);
135                     std::string coreDevName = it->second;
136                     if(coreDevName.size() > 0)
137                     {
138                         if(m_pReader->getDeviceData(coreDevName,&core_dev))
139                         {
140                             if(createPEDecoder(core_dev->deviceTypeName,etm_dev))
141                             {
142                                 numDecodersCreated++;
143                                 if(!bPacketProcOnly &&(core_dev->dumpDefs.size() > 0))
144                                 {
145                                     processDumpfiles(core_dev->dumpDefs);
146                                 }
147                             }
148                             else
149                             {
150                                 std::ostringstream oss;
151                                 oss << "Failed to create decoder for source " << it->first << ".\n";
152                                 LogError(oss.str());
153                             }
154                         }
155                         else
156                         {
157                             // Could not find the device data for the core.
158                             // unexpected - since we created the associations.
159                             std::ostringstream oss;
160                             oss << "Failed to get device data for source " << it->first << ".\n";
161                             LogError(oss.str());
162                         }
163                     }
164                     else
165                     {
166                         // none-core source
167                         if(createSTDecoder(etm_dev))
168                         {
169                              numDecodersCreated++;
170                         }
171                         else
172                         {
173                             std::ostringstream oss;
174                             oss << "Failed to create decoder for none core source " << it->first << ".\n";
175                             LogError(oss.str());
176                         }
177                     }
178                 }
179                 else
180                 {
181                     // TBD: could not find the device data for the source.
182                     // again unexpected - suggests ss format error.
183                     std::ostringstream oss;
184                     oss << "Failed to find device data for source " << it->first << ".\n";
185                     LogError(oss.str());
186                 }
187                 if(src_format == OCSD_TRC_SRC_SINGLE)
188                     it = tree.source_core_assoc.end();
189                 else
190                     it++;
191             }
192 
193             if(numDecodersCreated == 0)
194             {
195                 // nothing useful found
196                 destroyDecodeTree();
197             }
198         }
199         else
200         {
201             std::ostringstream oss;
202             oss << "Failed to get parsed source tree for buffer " << SourceName << ".\n";
203             LogError(oss.str());
204         }
205     }
206     return (bool)(m_pDecodeTree != 0);
207 }
208 
destroyDecodeTree()209 void CreateDcdTreeFromSnapShot::destroyDecodeTree()
210 {
211     if(m_pDecodeTree)
212         DecodeTree::DestroyDecodeTree(m_pDecodeTree);
213     m_pDecodeTree = 0;
214     m_pReader = 0;
215     m_pErrLogInterface = 0;
216     m_errlog_handle = 0;
217     m_BufferFileName = "";
218 }
219 
LogError(const std::string & msg)220 void  CreateDcdTreeFromSnapShot::LogError(const std::string &msg)
221 {
222     ocsdError err(OCSD_ERR_SEV_ERROR,OCSD_ERR_TEST_SS_TO_DECODER,msg);
223     m_pErrLogInterface->LogError(m_errlog_handle,&err);
224 }
225 
LogError(const ocsdError & err)226 void CreateDcdTreeFromSnapShot::LogError(const ocsdError &err)
227 {
228     m_pErrLogInterface->LogError(m_errlog_handle,&err);
229 }
230 
createPEDecoder(const std::string & coreName,Parser::Parsed * devSrc)231 bool CreateDcdTreeFromSnapShot::createPEDecoder(const std::string &coreName, Parser::Parsed *devSrc)
232 {
233     bool bCreatedDecoder = false;
234     std::string devTypeName = devSrc->deviceTypeName;
235 
236     // split off .x from type name.
237     std::string::size_type pos = devTypeName.find_first_of('.');
238     if(pos != std::string::npos)
239         devTypeName = devTypeName.substr(0,pos);
240 
241     // split according to protocol
242     if(devTypeName == ETMv4Protocol)
243     {
244         bCreatedDecoder = createETMv4Decoder(coreName,devSrc);
245     }
246     else if(devTypeName == ETMv3Protocol)
247     {
248         bCreatedDecoder = createETMv3Decoder(coreName,devSrc);
249     }
250     else if(devTypeName == PTMProtocol || devTypeName == PFTProtocol)
251     {
252         bCreatedDecoder = createPTMDecoder(coreName,devSrc);
253     }
254     else if (devTypeName == ETEProtocol)
255     {
256         bCreatedDecoder = createETEDecoder(coreName, devSrc);
257     }
258 
259     return bCreatedDecoder;
260 }
261 
262 // create an ETMv4 decoder based on the deviceN.ini file.
createETMv4Decoder(const std::string & coreName,Parser::Parsed * devSrc,const bool bDataChannel)263 bool CreateDcdTreeFromSnapShot::createETMv4Decoder(const std::string &coreName, Parser::Parsed *devSrc, const bool bDataChannel /* = false*/)
264 {
265     bool createdDecoder = false;
266     bool configOK = true;
267 
268     // generate the config data from the device data.
269     ocsd_etmv4_cfg config;
270 
271     regs_to_access_t regs_to_access[] = {
272         { ETMv4RegCfg, true, &config.reg_configr, 0 },
273         { ETMv4RegIDR, true, &config.reg_traceidr, 0 },
274         { ETMv4RegIDR0, true, &config.reg_idr0, 0 },
275         { ETMv4RegIDR1, false, &config.reg_idr1, 0x4100F403 },
276         { ETMv4RegIDR2, true, &config.reg_idr2, 0 },
277         { ETMv4RegIDR8, false, &config.reg_idr8, 0 },
278         { ETMv4RegIDR9, false, &config.reg_idr9, 0 },
279         { ETMv4RegIDR10, false, &config.reg_idr10, 0 },
280         { ETMv4RegIDR11, false, &config.reg_idr11, 0 },
281         { ETMv4RegIDR12, false, &config.reg_idr12, 0 },
282         { ETMv4RegIDR13,false, &config.reg_idr13, 0 },
283     };
284 
285     // extract registers
286     configOK = getRegisters(devSrc->regDefs,sizeof(regs_to_access)/sizeof(regs_to_access_t), regs_to_access);
287 
288     // extract core profile
289     if(configOK)
290         configOK = getCoreProfile(coreName,config.arch_ver,config.core_prof);
291 
292     // good config - generate the decoder on the tree.
293     if(configOK)
294     {
295         ocsd_err_t err = OCSD_OK;
296         EtmV4Config configObj(&config);
297         const char *decoderName = bDataChannel ? OCSD_BUILTIN_DCD_ETMV4D : OCSD_BUILTIN_DCD_ETMV4I;
298 
299         err = m_pDecodeTree->createDecoder(decoderName, m_add_create_flags | (m_bPacketProcOnly ? OCSD_CREATE_FLG_PACKET_PROC : OCSD_CREATE_FLG_FULL_DECODER),&configObj);
300 
301         if(err ==  OCSD_OK)
302             createdDecoder = true;
303         else
304         {
305             std::string msg = "Snapshot processor : failed to create " +  (std::string)decoderName + " decoder on decode tree.";
306             LogError(ocsdError(OCSD_ERR_SEV_ERROR,err,msg));
307         }
308     }
309 
310     return createdDecoder;
311 }
312 
createETEDecoder(const std::string & coreName,Parser::Parsed * devSrc)313 bool CreateDcdTreeFromSnapShot::createETEDecoder(const std::string &coreName, Parser::Parsed *devSrc)
314 {
315     bool createdDecoder = false;
316     bool configOK = true;
317 
318     // generate the config data from the device data.
319     ocsd_ete_cfg config;
320 
321     // ete regs are same names Etmv4 in places...
322     regs_to_access_t regs_to_access[] = {
323         { ETMv4RegCfg, true, &config.reg_configr, 0 },
324         { ETMv4RegIDR, true, &config.reg_traceidr, 0 },
325         { ETMv4RegIDR0, true, &config.reg_idr0, 0 },
326         { ETMv4RegIDR1, false, &config.reg_idr1, 0x4100F403 },
327         { ETMv4RegIDR2, true, &config.reg_idr2, 0 },
328         { ETMv4RegIDR8, false, &config.reg_idr8, 0 },
329         { ETERegDevArch, false, &config.reg_devarch, 0x47705A13 },
330     };
331 
332     // extract registers
333     configOK = getRegisters(devSrc->regDefs, sizeof(regs_to_access) / sizeof(regs_to_access_t), regs_to_access);
334 
335     // extract core profile
336     if (configOK)
337         configOK = getCoreProfile(coreName, config.arch_ver, config.core_prof);
338 
339     // good config - generate the decoder on the tree.
340     if (configOK)
341     {
342         ocsd_err_t err = OCSD_OK;
343         ETEConfig configObj(&config);
344         const char *decoderName = OCSD_BUILTIN_DCD_ETE;
345 
346         err = m_pDecodeTree->createDecoder(decoderName, m_add_create_flags | (m_bPacketProcOnly ? OCSD_CREATE_FLG_PACKET_PROC : OCSD_CREATE_FLG_FULL_DECODER), &configObj);
347 
348         if (err == OCSD_OK)
349             createdDecoder = true;
350         else
351         {
352             std::string msg = "Snapshot processor : failed to create " + (std::string)decoderName + " decoder on decode tree.";
353             LogError(ocsdError(OCSD_ERR_SEV_ERROR, err, msg));
354         }
355     }
356 
357     return createdDecoder;
358 }
359 
360 // create an ETMv3 decoder based on the register values in the deviceN.ini file.
createETMv3Decoder(const std::string & coreName,Parser::Parsed * devSrc)361 bool CreateDcdTreeFromSnapShot::createETMv3Decoder(const std::string &coreName, Parser::Parsed *devSrc)
362 {
363     bool createdDecoder = false;
364     bool configOK = true;
365 
366     // generate the config data from the device data.
367     ocsd_etmv3_cfg cfg_regs;
368 
369     regs_to_access_t regs_to_access[] = {
370         { ETMv3PTMRegIDR, true, &cfg_regs.reg_idr, 0 },
371         { ETMv3PTMRegCR, true, &cfg_regs.reg_ctrl, 0 },
372         { ETMv3PTMRegCCER, true, &cfg_regs.reg_ccer, 0 },
373         { ETMv3PTMRegTraceIDR, true, &cfg_regs.reg_trc_id, 0}
374     };
375 
376     // extract registers
377     configOK = getRegisters(devSrc->regDefs,sizeof(regs_to_access)/sizeof(regs_to_access_t), regs_to_access);
378 
379     // extract core profile
380     if(configOK)
381         configOK = getCoreProfile(coreName,cfg_regs.arch_ver,cfg_regs.core_prof);
382 
383     // good config - generate the decoder on the tree.
384     if(configOK)
385     {
386         EtmV3Config config(&cfg_regs);
387         ocsd_err_t err = OCSD_OK;
388         err = m_pDecodeTree->createDecoder(OCSD_BUILTIN_DCD_ETMV3, m_bPacketProcOnly ? OCSD_CREATE_FLG_PACKET_PROC : OCSD_CREATE_FLG_FULL_DECODER,&config);
389 
390         if(err ==  OCSD_OK)
391             createdDecoder = true;
392         else
393             LogError(ocsdError(OCSD_ERR_SEV_ERROR,err,"Snapshot processor : failed to create ETMV3 decoder on decode tree."));
394     }
395     return createdDecoder;
396 }
397 
createPTMDecoder(const std::string & coreName,Parser::Parsed * devSrc)398 bool CreateDcdTreeFromSnapShot::createPTMDecoder(const std::string &coreName, Parser::Parsed *devSrc)
399 {
400     bool createdDecoder = false;
401     bool configOK = true;
402 
403     // generate the config data from the device data.
404 
405     ocsd_ptm_cfg config;
406 
407     regs_to_access_t regs_to_access[] = {
408         { ETMv3PTMRegIDR, true, &config.reg_idr, 0 },
409         { ETMv3PTMRegCR, true, &config.reg_ctrl, 0 },
410         { ETMv3PTMRegCCER, true, &config.reg_ccer, 0 },
411         { ETMv3PTMRegTraceIDR, true, &config.reg_trc_id, 0}
412     };
413 
414     // extract registers
415     configOK = getRegisters(devSrc->regDefs,sizeof(regs_to_access)/sizeof(regs_to_access_t), regs_to_access);
416 
417     // extract core profile
418     if(configOK)
419         configOK = getCoreProfile(coreName,config.arch_ver,config.core_prof);
420 
421     // good config - generate the decoder on the tree.
422     if(configOK)
423     {
424         PtmConfig configObj(&config);
425         ocsd_err_t err = OCSD_OK;
426         err = m_pDecodeTree->createDecoder(OCSD_BUILTIN_DCD_PTM, m_bPacketProcOnly ? OCSD_CREATE_FLG_PACKET_PROC : OCSD_CREATE_FLG_FULL_DECODER,&configObj);
427 
428         if(err ==  OCSD_OK)
429             createdDecoder = true;
430         else
431             LogError(ocsdError(OCSD_ERR_SEV_ERROR,err,"Snapshot processor : failed to create PTM decoder on decode tree."));
432     }
433     return createdDecoder;
434 }
435 
createSTDecoder(Parser::Parsed * devSrc)436 bool CreateDcdTreeFromSnapShot::createSTDecoder(Parser::Parsed *devSrc)
437 {
438     bool bCreatedDecoder = false;
439     std::string devTypeName = devSrc->deviceTypeName;
440 
441     // split off .x from type name.
442     std::string::size_type pos = devTypeName.find_first_of('.');
443     if(pos != std::string::npos)
444         devTypeName = devTypeName.substr(0,pos);
445 
446     if(devTypeName == STMProtocol)
447     {
448         bCreatedDecoder = createSTMDecoder(devSrc);
449     }
450 
451     return bCreatedDecoder;
452 }
453 
createSTMDecoder(Parser::Parsed * devSrc)454 bool CreateDcdTreeFromSnapShot::createSTMDecoder(Parser::Parsed *devSrc)
455 {
456     bool createdDecoder = false;
457     bool configOK = true;
458 
459     // generate the config data from the device data.
460 
461     ocsd_stm_cfg config;
462 
463     regs_to_access_t regs_to_access[] = {
464         { STMRegTCSR, true, &config.reg_tcsr, 0 }
465     };
466 
467     configOK = getRegisters(devSrc->regDefs,sizeof(regs_to_access)/sizeof(regs_to_access_t), regs_to_access);
468     if(configOK)
469     {
470         ocsd_err_t err = OCSD_OK;
471         STMConfig configObj(&config);
472 
473         err = m_pDecodeTree->createDecoder(OCSD_BUILTIN_DCD_STM, m_bPacketProcOnly ? OCSD_CREATE_FLG_PACKET_PROC : OCSD_CREATE_FLG_FULL_DECODER,&configObj);
474 
475         if(err ==  OCSD_OK)
476             createdDecoder = true;
477         else
478             LogError(ocsdError(OCSD_ERR_SEV_ERROR,err,"Snapshot processor : failed to create STM decoder on decode tree."));
479     }
480 
481     return createdDecoder;
482 }
483 
484 
485 
486 // get a set of register values.
getRegisters(std::map<std::string,std::string,Util::CaseInsensitiveLess> & regDefs,int numRegs,regs_to_access_t * reg_access_array)487 bool CreateDcdTreeFromSnapShot::getRegisters(std::map<std::string, std::string, Util::CaseInsensitiveLess> &regDefs, int numRegs, regs_to_access_t *reg_access_array)
488 {
489     bool regsOK = true;
490 
491     for(int rv = 0; rv < numRegs; rv++)
492     {
493         if(!getRegByPrefix( regDefs,reg_access_array[rv]))
494             regsOK = false;
495     }
496     return regsOK;
497 }
498 
499 // strip out any parts with brackets
getRegByPrefix(std::map<std::string,std::string,Util::CaseInsensitiveLess> & regDefs,regs_to_access_t & reg_accessor)500 bool CreateDcdTreeFromSnapShot::getRegByPrefix(std::map<std::string, std::string, Util::CaseInsensitiveLess> &regDefs,
501     regs_to_access_t &reg_accessor)
502 {
503     std::ostringstream oss;
504     bool bFound = false;
505     std::map<std::string, std::string, Util::CaseInsensitiveLess>::iterator it;
506     std::string prefix_cmp;
507     std::string::size_type pos;
508     std::string strval;
509 
510     *reg_accessor.value = 0;
511 
512     it = regDefs.begin();
513     while((it != regDefs.end()) && !bFound)
514     {
515         prefix_cmp = it->first;
516         pos = prefix_cmp.find_first_of('(');
517         if(pos != std::string::npos)
518         {
519             prefix_cmp = prefix_cmp.substr(0, pos);
520         }
521         if(prefix_cmp == reg_accessor.pszName)
522         {
523             strval = it->second;
524             bFound = true;
525         }
526         it++;
527     }
528 
529     if(bFound)
530         *reg_accessor.value = strtoul(strval.c_str(),0,0);
531     else
532     {
533         ocsd_err_severity_t sev = OCSD_ERR_SEV_ERROR;
534         if(reg_accessor.failIfMissing)
535         {
536             oss << "Error:";
537         }
538         else
539         {
540             // no fail if missing - set any default and just warn.
541             bFound = true;
542             oss << "Warning: Default set for register. ";
543             sev = OCSD_ERR_SEV_WARN;
544             *reg_accessor.value = reg_accessor.val_default;
545         }
546         oss << "Missing " << reg_accessor.pszName << "\n";
547         m_pErrLogInterface->LogMessage(m_errlog_handle, sev, oss.str());
548     }
549     return bFound;
550 }
551 
getCoreProfile(const std::string & coreName,ocsd_arch_version_t & arch_ver,ocsd_core_profile_t & core_prof)552 bool CreateDcdTreeFromSnapShot::getCoreProfile(const std::string &coreName, ocsd_arch_version_t &arch_ver, ocsd_core_profile_t &core_prof)
553 {
554     bool profileOK = true;
555     ocsd_arch_profile_t ap = m_arch_profiles.getArchProfile(coreName);
556     if(ap.arch != ARCH_UNKNOWN)
557     {
558         arch_ver = ap.arch;
559         core_prof = ap.profile;
560     }
561     else
562     {
563         std::ostringstream oss;
564         oss << "Unrecognized Core name " << coreName << ". Cannot evaluate profile or architecture.";
565         LogError(oss.str());
566         profileOK = false;
567     }
568     return profileOK;
569 }
570 
571 typedef struct mem_space_keys {
572     const char* key_name;
573     ocsd_mem_space_acc_t memspace;
574 } mem_space_keys_t;
575 
576 static mem_space_keys_t space_map[] = {
577     /* single spaces */
578     { "EL1S", OCSD_MEM_SPACE_EL1S },
579     { "EL1N", OCSD_MEM_SPACE_EL1N },
580     { "EL1R", OCSD_MEM_SPACE_EL1R },
581     { "EL2S", OCSD_MEM_SPACE_EL2S },
582     { "EL2" , OCSD_MEM_SPACE_EL2 }, /* old EL2 NS name - prior to EL2S existing */
583     { "EL2N", OCSD_MEM_SPACE_EL2 },
584     { "EL2R", OCSD_MEM_SPACE_EL2R },
585     { "EL3" , OCSD_MEM_SPACE_EL3  },
586     { "ROOT", OCSD_MEM_SPACE_ROOT },
587     /* multiple memory spaces */
588     { "S"   , OCSD_MEM_SPACE_S},
589     { "N"   , OCSD_MEM_SPACE_N},
590     { "R"   , OCSD_MEM_SPACE_R},
591     { "ANY" , OCSD_MEM_SPACE_ANY},
592     /* older names - from spec but not expected to be used in future. */
593     { "H"   , OCSD_MEM_SPACE_EL2 }, /* hypervisor - EL2 NS */
594     { "P"   , OCSD_MEM_SPACE_EL1N }, /* privileged - EL1 NS */
595     { "NP"   , OCSD_MEM_SPACE_EL1N }, /* non secure privileged - EL1 NS */
596     { "SP"   , OCSD_MEM_SPACE_EL1S }, /* secure privileged - EL1 S */
597     /* table terminator */
598     { "", OCSD_MEM_SPACE_NONE},
599 };
600 
601 /* get mem space from input string */
getMemSpaceFromString(const std::string & memspace)602 ocsd_mem_space_acc_t CreateDcdTreeFromSnapShot::getMemSpaceFromString(const std::string& memspace)
603 {
604 
605 
606     ocsd_mem_space_acc_t mem_space = OCSD_MEM_SPACE_ANY;
607     if (memspace.length() > 0) {
608         int i = 0;
609 
610         while (space_map[i].memspace != OCSD_MEM_SPACE_NONE) {
611             if (space_map[i].key_name == memspace) {
612                 mem_space = space_map[i].memspace;
613                 break;
614             }
615             i++;
616         }
617     }
618     return mem_space;
619 }
620 
processDumpfiles(std::vector<Parser::DumpDef> & dumps)621 void CreateDcdTreeFromSnapShot::processDumpfiles(std::vector<Parser::DumpDef> &dumps)
622 {
623     std::string dumpFilePathName;
624     std::vector<Parser::DumpDef>::const_iterator it;
625     ocsd_mem_space_acc_t mem_space;
626 
627     it = dumps.begin();
628     while(it != dumps.end())
629     {
630         dumpFilePathName = m_pReader->getSnapShotDir() + it->path;
631         ocsd_file_mem_region_t region;
632         ocsd_err_t err = OCSD_OK;
633 
634         region.start_address = it->address;
635         region.file_offset = it->offset;
636         region.region_size = it->length;
637         mem_space = getMemSpaceFromString(it->space);
638 
639         // ensure we respect optional length and offset parameter and
640         // allow multiple dump entries with same file name to define regions
641         if (!TrcMemAccessorFile::isExistingFileAccessor(dumpFilePathName))
642             err = m_pDecodeTree->addBinFileRegionMemAcc(&region, 1, mem_space, dumpFilePathName);
643         else
644             err = m_pDecodeTree->updateBinFileRegionMemAcc(&region, 1, mem_space, dumpFilePathName);
645         if(err != OCSD_OK)
646         {
647             std::ostringstream oss;
648             oss << "Failed to create memory accessor for file " << dumpFilePathName << ".";
649             LogError(ocsdError(OCSD_ERR_SEV_ERROR,err,oss.str()));
650         }
651         it++;
652     }
653 }
654 
655 /* End of File ss_to_dcdtree.cpp */
656