Home | History | Annotate | Line # | Download | only in common
      1 /*
      2  * File:	SRecordSourceFile.h
      3  *
      4  * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
      5  * See included license file for license details.
      6  */
      7 #if !defined(_SRecordSourceFile_h_)
      8 #define _SRecordSourceFile_h_
      9 
     10 #include "SourceFile.h"
     11 #include "StSRecordFile.h"
     12 #include "StExecutableImage.h"
     13 
     14 namespace elftosb
     15 {
     16 
     17 /*!
     18  * \brief Executable file in the Motorola S-record format.
     19  *
     20  * Instead of presenting each S-record in the file separately, this class
     21  * builds up a memory image of all of the records. Records next to each other
     22  * in memory are coalesced into a single memory region. The data source that
     23  * is returned from createDataSource() exposes these regions as its segments.
     24  *
     25  * Because the S-record format does not support the concepts, no support is
     26  * provided for named sections or symbols.
     27  */
     28 class SRecordSourceFile : public SourceFile
     29 {
     30 public:
     31 	//! \brief Default constructor.
     32 	SRecordSourceFile(const std::string & path);
     33 
     34 	//! \brief Destructor.
     35 	virtual ~SRecordSourceFile() {}
     36 
     37 	//! \brief Test whether the \a stream contains a valid S-record file.
     38 	static bool isSRecordFile(std::istream & stream);
     39 
     40 	//! \name Opening and closing
     41 	//@{
     42 	//! \brief Opens the file.
     43 	virtual void open();
     44 
     45 	//! \brief Closes the file.
     46 	virtual void close();
     47 	//@}
     48 
     49 	//! \name Format capabilities
     50 	//@{
     51 	virtual bool supportsNamedSections() const { return false; }
     52 	virtual bool supportsNamedSymbols() const { return false; }
     53 	//@}
     54 
     55 	//! \name Data sources
     56 	//@{
     57 	//! \brief Returns data source for the entire file.
     58 	virtual DataSource * createDataSource();
     59 	//@}
     60 
     61 	//! \name Entry point
     62 	//@{
     63 	//! \brief Returns true if an entry point was set in the file.
     64 	virtual bool hasEntryPoint();
     65 
     66 	//! \brief Returns the entry point address.
     67 	virtual uint32_t getEntryPointAddress();
     68 	//@}
     69 
     70 protected:
     71 	StSRecordFile * m_file;	//!< S-record parser instance.
     72 	StExecutableImage * m_image;	//!< Memory image of the S-record file.
     73 	bool m_hasEntryRecord;	//!< Whether an S7,8,9 record was found.
     74 	StSRecordFile::SRecord m_entryRecord;	//!< Record for the entry point.
     75 
     76 protected:
     77 	//! \brief Build memory image of the S-record file.
     78 	void buildMemoryImage();
     79 };
     80 
     81 }; // namespace elftosb
     82 
     83 #endif // _SRecordSourceFile_h_
     84