4 * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 * See included license file for license details.
8 #include "DataTarget.h"
9 #include "DataSource.h"
10 #include "ElftosbErrors.h"
12 using namespace elftosb;
14 //! \exception elftosb::semantic_error Thrown if the source has multiple segments.
15 DataTarget::AddressRange ConstantDataTarget::getRangeForSegment(DataSource & source, DataSource::Segment & segment)
17 // can't handle multi-segment data sources
18 if (source.getSegmentCount() > 1)
20 throw semantic_error("constant targets only support single-segment sources");
23 // always relocate the segment to our begin address
25 range.m_begin = m_begin;
29 // we have an end address. trim the result range to the segment size
30 // or let the end address crop the segment.
31 range.m_end = std::min<uint32_t>(m_end, m_begin + segment.getLength());
35 // we have no end address, so the segment size determines it.
36 range.m_end = m_begin + segment.getLength();
42 //! If the \a segment has a natural location, the returned address range extends
43 //! from the segment's base address to its base address plus its length.
45 //! \exception elftosb::semantic_error This exception is thrown if the \a segment
46 //! does not have a natural location associated with it.
47 DataTarget::AddressRange NaturalDataTarget::getRangeForSegment(DataSource & source, DataSource::Segment & segment)
49 if (!segment.hasNaturalLocation())
51 throw semantic_error("source has no natural location");
55 range.m_begin = segment.getBaseAddress();
56 range.m_end = segment.getBaseAddress() + segment.getLength();