AddrRange: Transition from Range<T> to AddrRange

This patch takes the final plunge and transitions from the templated
Range class to the more specific AddrRange. In doing so it changes the
obvious Range<Addr> to AddrRange, and also bumps the range_map to be
AddrRangeMap.

In addition to the obvious changes, including the removal of redundant
includes, this patch also does some house keeping in preparing for the
introduction of address interleaving support in the ranges. The Range
class is also stripped of all the functionality that is never used.

--HG--
rename : src/base/range.hh => src/base/addr_range.hh
rename : src/base/range_map.hh => src/base/addr_range_map.hh
This commit is contained in:
Andreas Hansson 2012-09-19 06:15:44 -04:00
parent c34df76272
commit ffb6aec603
48 changed files with 213 additions and 454 deletions

View file

@ -371,9 +371,9 @@ AddrRangeList
X86ISA::Interrupts::getAddrRanges() const
{
AddrRangeList ranges;
Range<Addr> range = RangeEx(x86LocalAPICAddress(initialApicId, 0),
x86LocalAPICAddress(initialApicId, 0) +
PageBytes);
AddrRange range = RangeEx(x86LocalAPICAddress(initialApicId, 0),
x86LocalAPICAddress(initialApicId, 0) +
PageBytes);
ranges.push_back(range);
return ranges;
}

126
src/base/addr_range.hh Normal file
View file

@ -0,0 +1,126 @@
/*
* Copyright (c) 2012 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
* not be construed as granting a license to any other intellectual
* property including but not limited to intellectual property relating
* to a hardware implementation of the functionality of the software
* licensed hereunder. You may use the software subject to the license
* terms below provided that you ensure that this notice is replicated
* unmodified and in its entirety in all distributions of the software,
* modified or unmodified, in source code or in binary form.
*
* Copyright (c) 2002-2005 The Regents of The University of Michigan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: Nathan Binkert
* Steve Reinhardt
* Andreas Hansson
*/
#ifndef __BASE_ADDR_RANGE_HH__
#define __BASE_ADDR_RANGE_HH__
#include "base/types.hh"
class AddrRange
{
public:
Addr start;
Addr end;
AddrRange()
: start(1), end(0)
{}
AddrRange(Addr _start, Addr _end)
: start(_start), end(_end)
{}
AddrRange(const std::pair<Addr, Addr> &r)
: start(r.first), end(r.second)
{}
Addr size() const { return end - start + 1; }
bool valid() const { return start < end; }
};
/**
* Keep the operators away from SWIG.
*/
#ifndef SWIG
/**
* @param range1 is a range.
* @param range2 is a range.
* @return if range1 is less than range2 and does not overlap range1.
*/
inline bool
operator<(const AddrRange& range1, const AddrRange& range2)
{
return range1.start < range2.start;
}
/**
* @param addr address in the range
* @param range range compared against.
* @return indicates that the address is not within the range.
*/
inline bool
operator!=(const Addr& addr, const AddrRange& range)
{
return addr < range.start || addr > range.end;
}
/**
* @param range range compared against.
* @param pos position compared to the range.
* @return indicates that position pos is within the range.
*/
inline bool
operator==(const AddrRange& range, const Addr& addr)
{
return addr >= range.start && addr <= range.end;
}
inline AddrRange
RangeEx(Addr start, Addr end)
{ return std::make_pair(start, end - 1); }
inline AddrRange
RangeIn(Addr start, Addr end)
{ return std::make_pair(start, end); }
inline AddrRange
RangeSize(Addr start, Addr size)
{ return std::make_pair(start, start + size - 1); }
#endif // SWIG
#endif // __BASE_ADDR_RANGE_HH__

View file

@ -1,4 +1,16 @@
/*
* Copyright (c) 2012 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
* not be construed as granting a license to any other intellectual
* property including but not limited to intellectual property relating
* to a hardware implementation of the functionality of the software
* licensed hereunder. You may use the software subject to the license
* terms below provided that you ensure that this notice is replicated
* unmodified and in its entirety in all distributions of the software,
* modified or unmodified, in source code or in binary form.
*
* Copyright (c) 2006 The Regents of The University of Michigan
* All rights reserved.
*
@ -26,36 +38,35 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: Ali Saidi
* Andreas Hansson
*/
#ifndef __BASE_RANGE_MAP_HH__
#define __BASE_RANGE_MAP_HH__
#ifndef __BASE_ADDR_RANGE_MAP_HH__
#define __BASE_ADDR_RANGE_MAP_HH__
#include <map>
#include <utility>
#include "base/range.hh"
#include "base/addr_range.hh"
/**
* The range_map uses an STL map to implement an interval tree. The
* type of both the key (range) and the value are template
* parameters. It can, for example, be used for address decoding,
* using a range of addresses to map to ports.
* The AddrRangeMap uses an STL map to implement an interval tree for
* address decoding. The value stored is a template type and can be
* e.g. a port identifier, or a pointer.
*/
template <class T,class V>
class range_map
template <typename V>
class AddrRangeMap
{
private:
typedef std::map<Range<T>,V> RangeMap;
typedef std::map<AddrRange, V> RangeMap;
RangeMap tree;
public:
typedef typename RangeMap::iterator iterator;
typedef typename RangeMap::const_iterator const_iterator;
template <class U>
const_iterator
find(const Range<U> &r) const
find(const AddrRange &r) const
{
const_iterator i;
@ -77,9 +88,8 @@ class range_map
return tree.end();
}
template <class U>
iterator
find(const Range<U> &r)
find(const AddrRange &r)
{
iterator i;
@ -101,23 +111,20 @@ class range_map
return tree.end();
}
template <class U>
const_iterator
find(const U &r) const
find(const Addr &r) const
{
return find(RangeSize(r, 1));
}
template <class U>
iterator
find(const U &r)
find(const Addr &r)
{
return find(RangeSize(r, 1));
}
template <class U>
bool
intersect(const Range<U> &r)
intersect(const AddrRange &r)
{
iterator i;
i = find(r);
@ -126,9 +133,8 @@ class range_map
return false;
}
template <class U,class W>
iterator
insert(const Range<U> &r, const W d)
insert(const AddrRange &r, const V& d)
{
if (intersect(r))
return tree.end();
@ -136,8 +142,8 @@ class range_map
return tree.insert(std::make_pair(r, d)).first;
}
size_t
erase(T k)
std::size_t
erase(Addr k)
{
return tree.erase(k);
}
@ -184,7 +190,7 @@ class range_map
return tree.end();
}
size_t
std::size_t
size() const
{
return tree.size();
@ -197,4 +203,4 @@ class range_map
}
};
#endif //__BASE_RANGE_MAP_HH__
#endif //__BASE_ADDR_RANGE_MAP_HH__

View file

@ -39,7 +39,6 @@
#include <utility>
#include <vector>
#include "base/range.hh"
#include "base/types.hh"
#include "dev/etherpkt.hh"
#include "dnet/os.h"

View file

@ -42,7 +42,6 @@
#include <ios>
#include <string>
#include "base/range.hh"
#include "base/types.hh"
class Checkpoint;
@ -210,13 +209,6 @@ class Random
return _random(min, max);
}
template <typename T>
T
random(const Range<T> &range)
{
return _random(range.start, range.end);
}
// [0,1]
double
gen_real1()

View file

@ -1,328 +0,0 @@
/*
* Copyright (c) 2002-2005 The Regents of The University of Michigan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: Nathan Binkert
* Steve Reinhardt
*/
#ifndef __BASE_RANGE_HH__
#define __BASE_RANGE_HH__
template <class T>
struct Range
{
T start;
T end;
Range() { invalidate(); }
template <class U>
Range(const std::pair<U, U> &r)
: start(r.first), end(r.second)
{}
template <class U>
Range(const Range<U> &r)
: start(r.start), end(r.end)
{}
template <class U>
const Range<T> &operator=(const Range<U> &r)
{
start = r.start;
end = r.end;
return *this;
}
template <class U>
const Range<T> &operator=(const std::pair<U, U> &r)
{
start = r.first;
end = r.second;
return *this;
}
void invalidate() { start = 1; end = 0; }
T size() const { return end - start + 1; }
bool valid() const { return start < end; }
};
template <class T>
inline Range<T>
RangeEx(T start, T end)
{ return std::make_pair(start, end - 1); }
template <class T>
inline Range<T>
RangeIn(T start, T end)
{ return std::make_pair(start, end); }
template <class T, class U>
inline Range<T>
RangeSize(T start, U size)
{ return std::make_pair(start, start + size - 1); }
////////////////////////////////////////////////////////////////////////
//
// Range to Range Comparisons
//
/**
* @param range1 is a range.
* @param range2 is a range.
* @return if range1 and range2 are identical.
*/
template <class T, class U>
inline bool
operator==(const Range<T> &range1, const Range<U> &range2)
{
return range1.start == range2.start && range1.end == range2.end;
}
/**
* @param range1 is a range.
* @param range2 is a range.
* @return if range1 and range2 are not identical.
*/
template <class T, class U>
inline bool
operator!=(const Range<T> &range1, const Range<U> &range2)
{
return range1.start != range2.start || range1.end != range2.end;
}
/**
* @param range1 is a range.
* @param range2 is a range.
* @return if range1 is less than range2 and does not overlap range1.
*/
template <class T, class U>
inline bool
operator<(const Range<T> &range1, const Range<U> &range2)
{
return range1.start < range2.start;
}
/**
* @param range1 is a range.
* @param range2 is a range.
* @return if range1 is less than range2. range1 may overlap range2,
* but not extend beyond the end of range2.
*/
template <class T, class U>
inline bool
operator<=(const Range<T> &range1, const Range<U> &range2)
{
return range1.start <= range2.start;
}
/**
* @param range1 is a range.
* @param range2 is a range.
* @return if range1 is greater than range2 and does not overlap range2.
*/
template <class T, class U>
inline bool
operator>(const Range<T> &range1, const Range<U> &range2)
{
return range1.start > range2.start;
}
/**
* @param range1 is a range.
* @param range2 is a range.
* @return if range1 is greater than range2. range1 may overlap range2,
* but not extend beyond the beginning of range2.
*/
template <class T, class U>
inline bool
operator>=(const Range<T> &range1, const Range<U> &range2)
{
return range1.start >= range2.start;
}
////////////////////////////////////////////////////////////////////////
//
// Position to Range Comparisons
//
/**
* @param pos position compared to the range.
* @param range range compared against.
* @return indicates that position pos is within the range.
*/
template <class T, class U>
inline bool
operator==(const T &pos, const Range<U> &range)
{
return pos >= range.start && pos <= range.end;
}
/**
* @param pos position compared to the range.
* @param range range compared against.
* @return indicates that position pos is not within the range.
*/
template <class T, class U>
inline bool
operator!=(const T &pos, const Range<U> &range)
{
return pos < range.start || pos > range.end;
}
/**
* @param pos position compared to the range.
* @param range range compared against.
* @return indicates that position pos is below the range.
*/
template <class T, class U>
inline bool
operator<(const T &pos, const Range<U> &range)
{
return pos < range.start;
}
/**
* @param pos position compared to the range.
* @param range range compared against.
* @return indicates that position pos is below or in the range.
*/
template <class T, class U>
inline bool
operator<=(const T &pos, const Range<U> &range)
{
return pos <= range.end;
}
/**
* @param pos position compared to the range.
* @param range range compared against.
* @return indicates that position pos is above the range.
*/
template <class T, class U>
inline bool
operator>(const T &pos, const Range<U> &range)
{
return pos > range.end;
}
/**
* @param pos position compared to the range.
* @param range range compared against.
* @return indicates that position pos is above or in the range.
*/
template <class T, class U>
inline bool
operator>=(const T &pos, const Range<U> &range)
{
return pos >= range.start;
}
////////////////////////////////////////////////////////////////////////
//
// Range to Position Comparisons (for symmetry)
//
/**
* @param range range compared against.
* @param pos position compared to the range.
* @return indicates that position pos is within the range.
*/
template <class T, class U>
inline bool
operator==(const Range<T> &range, const U &pos)
{
return pos >= range.start && pos <= range.end;
}
/**
* @param range range compared against.
* @param pos position compared to the range.
* @return indicates that position pos is not within the range.
*/
template <class T, class U>
inline bool
operator!=(const Range<T> &range, const U &pos)
{
return pos < range.start || pos > range.end;
}
/**
* @param range range compared against.
* @param pos position compared to the range.
* @return indicates that position pos is above the range.
*/
template <class T, class U>
inline bool
operator<(const Range<T> &range, const U &pos)
{
// with -std=gnu++0x, gcc and clang get confused when range.end is
// compared to pos using the operator "<", and the parser expects it
// to be the opening bracket for a template parameter,
// i.e. range.end<pos>(...);, the reason seems to be the range-type
// iteration introduced in c++11 where begin and end are members
// that return iterators
return operator<(range.end, pos);
}
/**
* @param range range compared against.
* @param pos position compared to the range.
* @return indicates that position pos is above or in the range.
*/
template <class T, class U>
inline bool
operator<=(const Range<T> &range, const U &pos)
{
return range.start <= pos;
}
/**
* @param range range compared against.
* @param pos position compared to the range.
* 'range > pos' indicates that position pos is below the range.
*/
template <class T, class U>
inline bool
operator>(const Range<T> &range, const U &pos)
{
return range.start > pos;
}
/**
* @param range range compared against.
* @param pos position compared to the range.
* 'range >= pos' indicates that position pos is below or in the range.
*/
template <class T, class U>
inline bool
operator>=(const Range<T> &range, const U &pos)
{
return range.end >= pos;
}
#endif // __BASE_RANGE_HH__

View file

@ -51,7 +51,6 @@
#include "base/inifile.hh"
#include "base/misc.hh"
#include "base/pollevent.hh"
#include "base/range.hh"
#include "base/trace.hh"
#include "base/types.hh"
#include "config/the_isa.hh"

View file

@ -35,7 +35,6 @@
#ifndef __DEV_ALPHA_BACKDOOR_HH__
#define __DEV_ALPHA_BACKDOOR_HH__
#include "base/range.hh"
#include "base/types.hh"
#include "dev/alpha/access.h"
#include "dev/io_device.hh"

View file

@ -35,7 +35,6 @@
#ifndef __TSUNAMI_CCHIP_HH__
#define __TSUNAMI_CCHIP_HH__
#include "base/range.hh"
#include "dev/alpha/tsunami.hh"
#include "dev/io_device.hh"
#include "params/TsunamiCChip.hh"

View file

@ -37,7 +37,6 @@
#ifndef __DEV_TSUNAMI_IO_HH__
#define __DEV_TSUNAMI_IO_HH__
#include "base/range.hh"
#include "dev/alpha/tsunami.hh"
#include "dev/intel_8254_timer.hh"
#include "dev/io_device.hh"

View file

@ -35,7 +35,6 @@
#ifndef __TSUNAMI_PCHIP_HH__
#define __TSUNAMI_PCHIP_HH__
#include "base/range.hh"
#include "dev/alpha/tsunami.hh"
#include "dev/io_device.hh"
#include "params/TsunamiPChip.hh"

View file

@ -40,7 +40,6 @@
#ifndef __DEV_ARM_A9SCU_HH__
#define __DEV_ARM_A9SCU_HH__
#include "base/range.hh"
#include "dev/io_device.hh"
#include "params/A9SCU.hh"

View file

@ -49,7 +49,6 @@
#ifndef __DEV_ARM_AMBA_DEVICE_HH__
#define __DEV_ARM_AMBA_DEVICE_HH__
#include "base/range.hh"
#include "dev/arm/gic.hh"
#include "dev/dma_device.hh"
#include "dev/io_device.hh"

View file

@ -51,7 +51,6 @@
#ifndef __DEV_ARM_AMBA_FAKE_H__
#define __DEV_ARM_AMBA_FAKE_H__
#include "base/range.hh"
#include "dev/arm/amba_device.hh"
#include "params/AmbaFake.hh"

View file

@ -49,7 +49,6 @@
#define __DEV_ARM_GIC_H__
#include "base/bitunion.hh"
#include "base/range.hh"
#include "dev/io_device.hh"
#include "dev/platform.hh"
#include "cpu/intr_control.hh"

View file

@ -51,7 +51,6 @@
#include <list>
#include "base/vnc/vncserver.hh"
#include "base/range.hh"
#include "dev/arm/amba_device.hh"
#include "params/Pl050.hh"

View file

@ -48,7 +48,6 @@
#ifndef __DEV_ARM_PL011_H__
#define __DEV_ARM_PL011_H__
#include "base/range.hh"
#include "dev/io_device.hh"
#include "dev/uart.hh"
#include "params/Pl011.hh"

View file

@ -48,7 +48,6 @@
#include <fstream>
#include "base/range.hh"
#include "dev/arm/amba_device.hh"
#include "params/Pl111.hh"
#include "sim/serialize.hh"

View file

@ -40,7 +40,6 @@
#ifndef __DEV_ARM_RTC_PL310_HH__
#define __DEV_ARM_RTC_PL310_HH__
#include "base/range.hh"
#include "dev/arm/amba_device.hh"
#include "params/PL031.hh"

View file

@ -41,7 +41,6 @@
#define __DEV_ARM_RV_HH__
#include "base/bitunion.hh"
#include "base/range.hh"
#include "dev/io_device.hh"
#include "params/RealViewCtrl.hh"

View file

@ -41,7 +41,6 @@
#ifndef __DEV_ARM_LOCALTIMER_HH__
#define __DEV_ARM_LOCALTIMER_HH__
#include "base/range.hh"
#include "dev/io_device.hh"
#include "params/CpuLocalTimer.hh"

View file

@ -40,7 +40,6 @@
#ifndef __DEV_ARM_SP804_HH__
#define __DEV_ARM_SP804_HH__
#include "base/range.hh"
#include "dev/arm/amba_device.hh"
#include "params/Sp804.hh"

View file

@ -36,7 +36,6 @@
#ifndef __DEV_BADDEV_HH__
#define __DEV_BADDEV_HH__
#include "base/range.hh"
#include "dev/io_device.hh"
#include "params/BadDevice.hh"

View file

@ -37,7 +37,6 @@
#include <string>
#include "base/range.hh"
#include "dev/io_device.hh"
// #include "dev/alpha/tsunami.hh"
#include "mem/packet.hh"

View file

@ -33,7 +33,6 @@
#ifndef __DEV_MC146818_HH__
#define __DEV_MC146818_HH__
#include "base/range.hh"
#include "sim/eventq.hh"
/** Real-Time Clock (MC146818) */

View file

@ -36,7 +36,6 @@
#ifndef __MALTA_CCHIP_HH__
#define __MALTA_CCHIP_HH__
#include "base/range.hh"
#include "dev/mips/malta.hh"
#include "dev/io_device.hh"
#include "params/MaltaCChip.hh"

View file

@ -37,7 +37,6 @@
#ifndef __DEV_MALTA_IO_HH__
#define __DEV_MALTA_IO_HH__
#include "base/range.hh"
#include "dev/mips/malta.hh"
#include "dev/intel_8254_timer.hh"
#include "dev/io_device.hh"

View file

@ -35,7 +35,6 @@
#ifndef __MALTA_PCHIP_HH__
#define __MALTA_PCHIP_HH__
#include "base/range.hh"
#include "dev/mips/malta.hh"
#include "dev/io_device.hh"
#include "params/MaltaPChip.hh"

View file

@ -37,7 +37,6 @@
#ifndef __PCICONFIGALL_HH__
#define __PCICONFIGALL_HH__
#include "base/range.hh"
#include "dev/io_device.hh"
#include "dev/pcireg.h"
#include "params/PciConfigAll.hh"

View file

@ -38,7 +38,6 @@
#include <vector>
#include "base/range.hh"
#include "dev/io_device.hh"
#include "params/DumbTOD.hh"

View file

@ -36,7 +36,6 @@
#ifndef __DEV_SPARC_IOB_HH__
#define __DEV_SPARC_IOB_HH__
#include "base/range.hh"
#include "dev/disk_image.hh"
#include "dev/io_device.hh"
#include "params/Iob.hh"

View file

@ -36,7 +36,6 @@
#ifndef __DEV_SPARC_MM_DISK_HH__
#define __DEV_SPARC_MM_DISK_HH__
#include "base/range.hh"
#include "dev/disk_image.hh"
#include "dev/io_device.hh"
#include "params/MmDisk.hh"

View file

@ -35,7 +35,6 @@
#ifndef __UART_HH__
#define __UART_HH__
#include "base/range.hh"
#include "dev/io_device.hh"
#include "params/Uart.hh"

View file

@ -35,7 +35,6 @@
#ifndef __DEV_UART8250_HH__
#define __DEV_UART8250_HH__
#include "base/range.hh"
#include "dev/io_device.hh"
#include "dev/uart.hh"
#include "params/Uart8250.hh"

View file

@ -34,7 +34,6 @@
#include <map>
#include "base/bitunion.hh"
#include "base/range_map.hh"
#include "dev/x86/intdev.hh"
#include "dev/io_device.hh"
#include "params/I82094AA.hh"

View file

@ -85,9 +85,8 @@ AbstractMemory::AbstractMemory(const Params *p) :
int fd = open(params()->file.c_str(), O_RDONLY);
long _size = lseek(fd, 0, SEEK_END);
if (_size != range.size()) {
warn("Specified size %d does not match file %s %d\n", range.size(),
params()->file, _size);
range = RangeSize(range.start, _size);
fatal("Specified size %d does not match file %s %d\n",
range.size(), params()->file, _size);
}
lseek(fd, 0, SEEK_SET);
pmemAddr = (uint8_t *)mmap(NULL, roundUp(_size, sysconf(_SC_PAGESIZE)),
@ -222,7 +221,7 @@ AbstractMemory::regStats()
bwTotal = (bytesRead + bytesWritten) / simSeconds;
}
Range<Addr>
AddrRange
AbstractMemory::getAddrRange() const
{
return range;

View file

@ -68,7 +68,7 @@ class AbstractMemory : public MemObject
protected:
// Address range of this memory
Range<Addr> range;
AddrRange range;
// Pointer to host memory used to implement this memory
uint8_t* pmemAddr;
@ -209,7 +209,7 @@ class AbstractMemory : public MemObject
*
* @return a single contigous address range
*/
Range<Addr> getAddrRange() const;
AddrRange getAddrRange() const;
/**
* Get the memory size.

View file

@ -57,7 +57,7 @@ Bridge::BridgeSlavePort::BridgeSlavePort(const std::string& _name,
Bridge& _bridge,
BridgeMasterPort& _masterPort,
Cycles _delay, int _resp_limit,
std::vector<Range<Addr> > _ranges)
std::vector<AddrRange> _ranges)
: SlavePort(_name, &_bridge), bridge(_bridge), masterPort(_masterPort),
delay(_delay), ranges(_ranges.begin(), _ranges.end()),
outstandingResponses(0), retryReq(false),

View file

@ -193,7 +193,7 @@ class Bridge : public MemObject
*/
BridgeSlavePort(const std::string& _name, Bridge& _bridge,
BridgeMasterPort& _masterPort, Cycles _delay,
int _resp_limit, std::vector<Range<Addr> > _ranges);
int _resp_limit, std::vector<AddrRange> _ranges);
/**
* Queue a response packet to be sent out later and also schedule

View file

@ -355,7 +355,6 @@ BaseBus::findPort(Addr addr)
void
BaseBus::recvRangeChange(PortID master_port_id)
{
AddrRangeList ranges;
AddrRangeIter iter;
if (inRecvRangeChange.count(master_port_id))
@ -394,7 +393,7 @@ BaseBus::recvRangeChange(PortID master_port_id)
}
// get the address ranges of the connected slave port
ranges = port->getAddrRanges();
AddrRangeList ranges = port->getAddrRanges();
for (iter = ranges.begin(); iter != ranges.end(); iter++) {
DPRINTF(BusAddrRanges, "Adding range %#llx - %#llx for id %d\n",

View file

@ -54,8 +54,7 @@
#include <list>
#include <set>
#include "base/range.hh"
#include "base/range_map.hh"
#include "base/addr_range_map.hh"
#include "base/types.hh"
#include "mem/mem_object.hh"
#include "params/BaseBus.hh"
@ -233,9 +232,9 @@ class BaseBus : public MemObject
/** the width of the bus in bytes */
int width;
typedef range_map<Addr, PortID>::iterator PortMapIter;
typedef range_map<Addr, PortID>::const_iterator PortMapConstIter;
range_map<Addr, PortID> portMap;
typedef AddrRangeMap<PortID>::iterator PortMapIter;
typedef AddrRangeMap<PortID>::const_iterator PortMapConstIter;
AddrRangeMap<PortID> portMap;
AddrRangeList defaultRange;

View file

@ -51,7 +51,6 @@
*/
#include "base/misc.hh"
#include "base/range.hh"
#include "base/types.hh"
#include "debug/Cache.hh"
#include "debug/CachePort.hh"

View file

@ -64,7 +64,6 @@ PhysicalMemory::PhysicalMemory(const vector<AbstractMemory*>& _memories) :
"Skipping memory %s that is not in global address map\n",
(*m)->name());
}
rangeCache.invalidate();
}
bool
@ -73,8 +72,7 @@ PhysicalMemory::isMemAddr(Addr addr) const
// see if the address is within the last matched range
if (addr != rangeCache) {
// lookup in the interval tree
range_map<Addr, AbstractMemory*>::const_iterator r =
addrMap.find(addr);
AddrRangeMap<AbstractMemory*>::const_iterator r = addrMap.find(addr);
if (r == addrMap.end()) {
// not in the cache, and not in the tree
return false;
@ -110,7 +108,7 @@ PhysicalMemory::access(PacketPtr pkt)
{
assert(pkt->isRequest());
Addr addr = pkt->getAddr();
range_map<Addr, AbstractMemory*>::const_iterator m = addrMap.find(addr);
AddrRangeMap<AbstractMemory*>::const_iterator m = addrMap.find(addr);
assert(m != addrMap.end());
m->second->access(pkt);
}
@ -120,7 +118,7 @@ PhysicalMemory::functionalAccess(PacketPtr pkt)
{
assert(pkt->isRequest());
Addr addr = pkt->getAddr();
range_map<Addr, AbstractMemory*>::const_iterator m = addrMap.find(addr);
AddrRangeMap<AbstractMemory*>::const_iterator m = addrMap.find(addr);
assert(m != addrMap.end());
m->second->functionalAccess(pkt);
}

View file

@ -40,7 +40,7 @@
#ifndef __PHYSICAL_MEMORY_HH__
#define __PHYSICAL_MEMORY_HH__
#include "base/range_map.hh"
#include "base/addr_range_map.hh"
#include "mem/abstract_mem.hh"
#include "mem/packet.hh"
@ -55,10 +55,10 @@ class PhysicalMemory
private:
// Global address map
range_map<Addr, AbstractMemory* > addrMap;
AddrRangeMap<AbstractMemory*> addrMap;
// a mutable cache for the last range that matched an address
mutable Range<Addr> rangeCache;
mutable AddrRange rangeCache;
// All address-mapped memories
std::vector<AbstractMemory*> memories;

View file

@ -52,7 +52,7 @@
#include <list>
#include "base/range.hh"
#include "base/addr_range.hh"
#include "mem/packet.hh"
/**
@ -62,9 +62,9 @@
* defined.
*/
typedef std::list<Range<Addr> > AddrRangeList;
typedef std::list<Range<Addr> >::iterator AddrRangeIter;
typedef std::list<Range<Addr> >::const_iterator AddrRangeConstIter;
typedef std::list<AddrRange> AddrRangeList;
typedef std::list<AddrRange>::iterator AddrRangeIter;
typedef std::list<AddrRange>::const_iterator AddrRangeConstIter;
class MemObject;

View file

@ -550,7 +550,7 @@ class Addr(CheckedInt):
return self.value + other
class AddrRange(ParamValue):
cxx_type = 'Range<Addr>'
cxx_type = 'AddrRange'
def __init__(self, *args, **kwargs):
def handle_kwargs(self, kwargs):
@ -594,20 +594,18 @@ class AddrRange(ParamValue):
@classmethod
def cxx_predecls(cls, code):
Addr.cxx_predecls(code)
code('#include "base/range.hh"')
code('#include "base/addr_range.hh"')
@classmethod
def swig_predecls(cls, code):
Addr.swig_predecls(code)
code('%import "python/swig/range.i"')
def getValue(self):
# Go from the Python class to the wrapped C++ class generated
# by swig
from m5.internal.range import AddrRange
value = AddrRange()
value.start = long(self.start)
value.end = long(self.end)
return value
return AddrRange(long(self.start), long(self.end))
# Boolean parameter type. Python doesn't let you subclass bool, since
# it doesn't want to let you create multiple instances of True and

View file

@ -31,15 +31,12 @@
%module(package="m5.internal") range
%{
#include "base/range.hh"
#include "base/types.hh"
#include "base/addr_range.hh"
%}
%include <stdint.i>
%rename(assign) *::operator=;
%include "base/range.hh"
%include "base/types.hh"
%template(AddrRange) Range<Addr>;
%template(TickRange) Range<Tick>;
%include "base/addr_range.hh"

View file

@ -1,4 +1,16 @@
/*
* Copyright (c) 2012 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
* not be construed as granting a license to any other intellectual
* property including but not limited to intellectual property relating
* to a hardware implementation of the functionality of the software
* licensed hereunder. You may use the software subject to the license
* terms below provided that you ensure that this notice is replicated
* unmodified and in its entirety in all distributions of the software,
* modified or unmodified, in source code or in binary form.
*
* Copyright (c) 2006 The Regents of The University of Michigan
* All rights reserved.
*
@ -31,46 +43,38 @@
#include <cassert>
#include <iostream>
#include "base/range_map.hh"
#include "base/types.hh"
#include "base/addr_range_map.hh"
using namespace std;
int
main()
{
range_map<Addr,int> r;
AddrRangeMap<int> r;
range_map<Addr,int>::iterator i;
AddrRangeMap<int>::iterator i;
i = r.insert(RangeIn<Addr>(10,40),5);
i = r.insert(RangeIn(10, 40), 5);
assert(i != r.end());
i = r.insert(RangeIn<Addr>(60,90),3);
i = r.insert(RangeIn(60, 90), 3);
assert(i != r.end());
i = r.find(RangeIn(20,30));
i = r.find(RangeIn(20, 30));
assert(i != r.end());
cout << i->first << " " << i->second << endl;
i = r.find(RangeIn(55,55));
i = r.find(RangeIn(55, 55));
assert(i == r.end());
i = r.insert(RangeIn<Addr>(0,12),1);
i = r.insert(RangeIn(0, 12), 1);
assert(i == r.end());
i = r.insert(RangeIn<Addr>(0,9),1);
i = r.insert(RangeIn(0, 9), 1);
assert(i != r.end());
i = r.find(RangeIn(20,30));
i = r.find(RangeIn(20, 30));
assert(i != r.end());
cout << i->first << " " << i->second << endl;
return 0;
}