Home | History | Annotate | Line # | Download | only in common
      1  1.1  jkunz /*
      2  1.1  jkunz  * File:	DataTarget.cpp
      3  1.1  jkunz  *
      4  1.1  jkunz  * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
      5  1.1  jkunz  * See included license file for license details.
      6  1.1  jkunz  */
      7  1.1  jkunz 
      8  1.1  jkunz #include "DataTarget.h"
      9  1.1  jkunz #include "DataSource.h"
     10  1.1  jkunz #include "ElftosbErrors.h"
     11  1.1  jkunz 
     12  1.1  jkunz using namespace elftosb;
     13  1.1  jkunz 
     14  1.1  jkunz //! \exception elftosb::semantic_error Thrown if the source has multiple segments.
     15  1.1  jkunz DataTarget::AddressRange ConstantDataTarget::getRangeForSegment(DataSource & source, DataSource::Segment & segment)
     16  1.1  jkunz {
     17  1.1  jkunz 	// can't handle multi-segment data sources
     18  1.1  jkunz 	if (source.getSegmentCount() > 1)
     19  1.1  jkunz 	{
     20  1.1  jkunz 		throw semantic_error("constant targets only support single-segment sources");
     21  1.1  jkunz 	}
     22  1.1  jkunz 
     23  1.1  jkunz 	// always relocate the segment to our begin address
     24  1.1  jkunz 	AddressRange range;
     25  1.1  jkunz 	range.m_begin = m_begin;
     26  1.1  jkunz 
     27  1.1  jkunz 	if (isBounded())
     28  1.1  jkunz 	{
     29  1.1  jkunz 		// we have an end address. trim the result range to the segment size
     30  1.1  jkunz 		// or let the end address crop the segment.
     31  1.1  jkunz 		range.m_end = std::min<uint32_t>(m_end, m_begin + segment.getLength());
     32  1.1  jkunz 	}
     33  1.1  jkunz 	else
     34  1.1  jkunz 	{
     35  1.1  jkunz 		// we have no end address, so the segment size determines it.
     36  1.1  jkunz 		range.m_end = m_begin + segment.getLength();
     37  1.1  jkunz 	}
     38  1.1  jkunz 
     39  1.1  jkunz 	return range;
     40  1.1  jkunz }
     41  1.1  jkunz 
     42  1.1  jkunz //! If the \a segment has a natural location, the returned address range extends
     43  1.1  jkunz //! from the segment's base address to its base address plus its length.
     44  1.1  jkunz //!
     45  1.1  jkunz //! \exception elftosb::semantic_error This exception is thrown if the \a segment
     46  1.1  jkunz //!		does not have a natural location associated with it.
     47  1.1  jkunz DataTarget::AddressRange NaturalDataTarget::getRangeForSegment(DataSource & source, DataSource::Segment & segment)
     48  1.1  jkunz {
     49  1.1  jkunz 	if (!segment.hasNaturalLocation())
     50  1.1  jkunz 	{
     51  1.1  jkunz 		throw semantic_error("source has no natural location");
     52  1.1  jkunz 	}
     53  1.1  jkunz 
     54  1.1  jkunz 	AddressRange range;
     55  1.1  jkunz 	range.m_begin = segment.getBaseAddress();
     56  1.1  jkunz 	range.m_end = segment.getBaseAddress() + segment.getLength();
     57  1.1  jkunz 	return range;
     58  1.1  jkunz }
     59  1.1  jkunz 
     60