xref: /netbsd-src/external/bsd/elftosb/dist/common/GHSSecInfo.h (revision 993229b6fea628ff8b1fa09146c80b0cfb2768eb)
1 /*
2  * File:    GHSSecInfo.h
3  *
4  * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5  * See included license file for license details.
6  */
7 #if !defined(_GHSSecInfo_h_)
8 #define _GHSSecInfo_h_
9 
10 #include "StELFFile.h"
11 #include "smart_ptr.h"
12 
13 namespace elftosb
14 {
15 
16 /*!
17  * \brief Wrapper around the GHS-specific .secinfo ELF section.
18  *
19  * ELF files produced by the Green Hills MULTI toolset will have a
20  * special .secinfo section. For the most part, this section contains
21  * a list of address
22  * ranges that should be filled by the C runtime startup code. The
23  * address ranges correspond to those of ELF sections whose type is
24  * #SHT_NOBITS. The GHS runtime uses this table instead of just filling
25  * all #SHT_NOBITS sections because the linker command file can
26  * be used to optionally not fill individual sections.
27  *
28  * The isSectionFilled() methods let calling code determine if an ELF
29  * section is found in the .secinfo table. If the section is found,
30  * then it should be filled.
31  */
32 class GHSSecInfo
33 {
34 public:
35 	//! \brief Default constructor.
36 	GHSSecInfo(StELFFile * elf);
37 
38 	//! \brief Returns true if there is a .secinfo section present in the ELF file.
hasSecinfo()39 	bool hasSecinfo() const { return m_hasInfo; }
40 
41 	//! \brief Determines if a section should be filled.
42 	bool isSectionFilled(uint32_t addr, uint32_t length);
43 
44 	//! \brief Determines if \a section should be filled.
45 	bool isSectionFilled(const Elf32_Shdr & section);
46 
47 protected:
48 
49 #pragma pack(1)
50 
51 	/*!
52 	 * \brief The structure of one .secinfo entry.
53 	 */
54 	struct ghs_secinfo_t
55 	{
56 		uint32_t m_clearAddr;	//!< Address to start filling from.
57 		uint32_t m_clearValue;	//!< Value to fill with.
58 		uint32_t m_numBytesToClear;	//!< Number of bytes to fill.
59 	};
60 
61 #pragma pack()
62 
63 protected:
64 	StELFFile * m_elf;	//!< The parser object for our ELF file.
65 	bool m_hasInfo;		//!< Whether .secinfo is present in the ELF file.
66 	smart_array_ptr<ghs_secinfo_t> m_info;	//!< Pointer to the .secinfo entries. Will be NULL if there is no .secinfo section in the file.
67 	unsigned m_entryCount;	//!< Number of entries in #m_info.
68 };
69 
70 }; // namespace elftosb
71 
72 #endif // _GHSSecInfo_h_
73