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