summaryrefslogtreecommitdiffstats
path: root/common/GHSSecInfo.h
blob: 9042d391c811e47971bdeefc07cb2c8e245834e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
 * File:    GHSSecInfo.h
 *
 * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
 * See included license file for license details.
 */
#if !defined(_GHSSecInfo_h_)
#define _GHSSecInfo_h_

#include "StELFFile.h"
#include "smart_ptr.h"

namespace elftosb
{

/*!
 * \brief Wrapper around the GHS-specific .secinfo ELF section.
 *
 * ELF files produced by the Green Hills MULTI toolset will have a
 * special .secinfo section. For the most part, this section contains
 * a list of address
 * ranges that should be filled by the C runtime startup code. The
 * address ranges correspond to those of ELF sections whose type is
 * #SHT_NOBITS. The GHS runtime uses this table instead of just filling
 * all #SHT_NOBITS sections because the linker command file can
 * be used to optionally not fill individual sections.
 *
 * The isSectionFilled() methods let calling code determine if an ELF
 * section is found in the .secinfo table. If the section is found,
 * then it should be filled.
 */
class GHSSecInfo
{
public:
	//! \brief Default constructor.
	GHSSecInfo(StELFFile * elf);

	//! \brief Returns true if there is a .secinfo section present in the ELF file.
	bool hasSecinfo() const { return m_hasInfo; }
	
	//! \brief Determines if a section should be filled.
	bool isSectionFilled(uint32_t addr, uint32_t length);
	
	//! \brief Determines if \a section should be filled.
	bool isSectionFilled(const Elf32_Shdr & section);
	
protected:

#pragma pack(1)

	/*!
	 * \brief The structure of one .secinfo entry.
	 */
	struct ghs_secinfo_t
	{
		uint32_t m_clearAddr;	//!< Address to start filling from.
		uint32_t m_clearValue;	//!< Value to fill with.
		uint32_t m_numBytesToClear;	//!< Number of bytes to fill.
	};

#pragma pack()

protected:
	StELFFile * m_elf;	//!< The parser object for our ELF file.
	bool m_hasInfo;		//!< Whether .secinfo is present in the ELF file.
	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.
	unsigned m_entryCount;	//!< Number of entries in #m_info.
};

}; // namespace elftosb

#endif // _GHSSecInfo_h_