1/* |
2 * Copyright (c) 2017 ARM Limited 3 * All rights reserved. 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software 9 * licensed hereunder. You may use the software subject to the license 10 * terms below provided that you ensure that this notice is replicated 11 * unmodified and in its entirety in all distributions of the software, 12 * modified or unmodified, in source code or in binary form. 13 * |
14 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 15 * Copyright (c) 2017 Google Inc. 16 * All rights reserved. 17 * 18 * Redistribution and use in source and binary forms, with or without 19 * modification, are permitted provided that the following conditions are 20 * met: redistributions of source code must retain the above copyright 21 * notice, this list of conditions and the following disclaimer; --- 16 unchanged lines hidden (view full) --- 38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 40 * 41 * Authors: Lena Olson 42 */ 43 44#include "mem/ruby/structures/DirectoryMemory.hh" 45 |
46#include "base/addr_range.hh" |
47#include "base/intmath.hh" 48#include "debug/RubyCache.hh" 49#include "debug/RubyStats.hh" 50#include "mem/ruby/slicc_interface/RubySlicc_Util.hh" 51#include "mem/ruby/system/RubySystem.hh" 52#include "sim/system.hh" 53 54using namespace std; 55 |
56DirectoryMemory::DirectoryMemory(const Params *p) |
57 : SimObject(p), addrRanges(p->addr_ranges.begin(), p->addr_ranges.end()) |
58{ |
59 m_size_bytes = 0; 60 for (const auto &r: addrRanges) { 61 m_size_bytes += r.size(); |
62 } |
63 m_size_bits = floorLog2(m_size_bytes); 64 m_num_entries = 0; |
65} 66 67void 68DirectoryMemory::init() 69{ 70 m_num_entries = m_size_bytes / RubySystem::getBlockSizeBytes(); 71 m_entries = new AbstractEntry*[m_num_entries]; 72 for (int i = 0; i < m_num_entries; i++) 73 m_entries[i] = NULL; |
74} 75 76DirectoryMemory::~DirectoryMemory() 77{ 78 // free up all the directory entries 79 for (uint64_t i = 0; i < m_num_entries; i++) { 80 if (m_entries[i] != NULL) { 81 delete m_entries[i]; 82 } 83 } 84 delete [] m_entries; 85} 86 |
87bool 88DirectoryMemory::isPresent(Addr address) 89{ |
90 for (const auto& r: addrRanges) { 91 if (r.contains(address)) { 92 return true; 93 } 94 } 95 return false; |
96} 97 98uint64_t 99DirectoryMemory::mapAddressToLocalIdx(Addr address) 100{ |
101 uint64_t ret = 0; 102 for (const auto& r: addrRanges) { 103 if (r.contains(address)) { 104 ret += r.getOffset(address); 105 break; 106 } 107 ret += r.size(); |
108 } |
109 return ret >> RubySystem::getBlockSizeBits(); |
110} 111 112AbstractEntry* 113DirectoryMemory::lookup(Addr address) 114{ 115 assert(isPresent(address)); 116 DPRINTF(RubyCache, "Looking up address: %#x\n", address); 117 --- 36 unchanged lines hidden --- |