2 Copyright (c) 2002-2009 Tampere University.
4 This file is part of TTA-Based Codesign Environment (TCE).
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
27 * Inline definitions of Section and RawSection classes.
29 * @author Mikael Lepistö 2003 (tmlepist-no.spam-cs.tut.fi)
31 * @note rating: yellow
34 /////////////////////////////////////////////////////////////////////////////
36 /////////////////////////////////////////////////////////////////////////////
41 * Returns an element from index given in parameter.
43 * @param index Index of requested element.
44 * @return An element of requested index.
46 inline SectionElement*
47 Section::element(Word index) const {
48 return elements_[index];
52 * Returns number of elements in section.
54 * @return Number of elements in section.
57 Section::elementCount() const {
58 return elements_.size();
64 * If this is set, section data is not written to file.
65 * There should be undefined element in those sections
66 * that provides it, if this flag is set.
69 Section::setFlagNoBits() {
76 * If this is set, section data is not written to file.
77 * There should be undefined element in those sections
78 * that provides it, if this flag is set.
81 Section::unsetFlagNoBits() {
88 * If this is set, the section contains elements
89 * with variable length.
92 Section::setFlagVLen() {
100 Section::unsetFlagVLen() {
105 * Tests if NOBITS flag is set.
107 * If this is set, section data is not written to file.
108 * There should be undefined element in those sections
109 * that provides it, if this flag is set.
111 * @return True if NOBITS is on, otherwise false.
114 Section::noBits() const {
115 return flag(SF_NOBITS);
119 * Tests if VLEN flag is set.
121 * @return True if VLEN is on, otherwise false.
124 Section::vLen() const {
125 return flag(SF_VLEN);
129 * Returns whole flag byte.
134 Section::flags() const {
139 * Sets whole flag byte.
141 * @param flagByte Value that is set to section flags.
144 Section::setFlags(Byte flagByte) {
150 * Returns true if flag is set.
152 * @param aFlag Flag that is tested.
153 * @return True if flag is set.
156 Section::flag(SectionFlag aFlag) const {
157 return flags_ & aFlag;
163 * @param aFlag Flag that is set.
166 Section::setFlag(SectionFlag aFlag) {
167 flags_ = flags_ | aFlag;
173 * @param aFlag Flag that is unset.
176 Section::unsetFlag(SectionFlag aFlag) {
177 flags_ = flags_ & (~aFlag);
181 * Sets starting memory address.
183 * @param address Memory address to set.
186 Section::setStartingAddress(AddressImage address) {
187 startingAddress_ = address;
191 * Returns an address where from the section begins.
193 * @return An address where from the section begins.
196 Section::startingAddress() const {
197 return startingAddress_;
201 * Sets pointer to some other section that is connected to this one somehow.
203 * See Section header from TPEF format specification for more information.
205 * @param aLink Section which we want to set to link field.
208 Section::setLink(const ReferenceManager::SafePointer* aLink) {
213 * Sets pointer to some other section that is connected to this one somehow.
215 * See Section header from TPEF format specification for more information.
217 * @param aLink Section which we want to set to link field.
220 Section::setLink(Section* aLink) {
221 link_ = ReferenceManager::SafePointer::replaceReference(link_,aLink);
225 * Returns link section.
227 * Each section may contain link to another section. Link section for
228 * every section type is listed in TPEF format specification.
230 * @return Link section.
233 Section::link() const {
234 return dynamic_cast<Section*>(link_->pointer());
238 * Sets pointer to the address space entry or program section.
240 * See Section header from TPEF format specification for more information.
242 * @param addrSpace Address space entry or program section.
245 Section::setASpace(const ReferenceManager::SafePointer* addrSpace) {
250 * Sets pointer to the address space of a section.
252 * See Section header from TPEF format specification for more information.
254 * @param addrSpace Address space to set.
257 Section::setASpace(ASpaceElement* addrSpace) {
258 aSpace_ = ReferenceManager::SafePointer::replaceReference(aSpace_, addrSpace);
262 * Returns the address space of a section.
264 * @return the address space of a section.
266 inline ASpaceElement*
267 Section::aSpace() const {
268 return dynamic_cast<ASpaceElement*>(aSpace_->pointer());
272 * Sets name of the section.
274 * @param sectionName String table element of section name.
277 Section::setName(const ReferenceManager::SafePointer* sectionName) {
282 * Sets name of the section.
284 * @param sectionName String table element of section name.
287 Section::setName(Chunk* sectionName) {
289 ReferenceManager::SafePointer::replaceReference(name_, sectionName);
293 * Returns section's name.
295 * @return String table element of section name.
298 Section::name() const {
299 return dynamic_cast<Chunk*>(name_->pointer());
303 * Checks if section type is auxiliary section.
305 * Auxiliary section means, that the section does not contain
306 * instructions or data.
308 * @return True if section is auxiliary section otherwise false.
311 Section::isAuxSection() const {
312 return ((type() & PROGRAM_SECTION_MASK) == 0x00);
316 * Checks if section is program section.
318 * Program sections are those sections, which contain program or data.
320 * @return True if section is program section otherwise false.
323 Section::isProgramSection() const {
324 return isProgramSection(type());
328 * Checks if section type is program section type.
330 * Program sections are those sections, which contain program or data.
332 * @param type Section type to check.
333 * @return True if section is program section otherwise false.
336 Section::isProgramSection(SectionType type) {
337 return ((type & PROGRAM_SECTION_MASK) == PROGRAM_SECTION_MASK);
340 /////////////////////////////////////////////////////////////////////////////
342 /////////////////////////////////////////////////////////////////////////////
345 * Tells if section has data.
347 * @return True if raw section has no data.
350 RawSection::empty() const {
351 return length() == 0;