DirectoryMemory.cc revision 6145
1
2/*
3 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/*
31 * DirectoryMemory.C
32 *
33 * Description: See DirectoryMemory.h
34 *
35 * $Id$
36 *
37 */
38
39#include "System.hh"
40#include "Driver.hh"
41#include "DirectoryMemory.hh"
42#include "RubySlicc_Util.hh"
43#include "RubyConfig.hh"
44#include "Chip.hh"
45#include "interface.hh"
46
47DirectoryMemory::DirectoryMemory(Chip* chip_ptr, int version)
48{
49  m_chip_ptr = chip_ptr;
50  m_version = version;
51  // THIS DOESN'T SEEM TO WORK -- MRM
52  // m_size = RubyConfig::memoryModuleBlocks()/RubyConfig::numberOfDirectory();
53  m_size = RubyConfig::memoryModuleBlocks();
54  assert(m_size > 0);
55  // allocates an array of directory entry pointers & sets them to NULL
56  m_entries = new Directory_Entry*[m_size];
57  if (m_entries == NULL) {
58    ERROR_MSG("Directory Memory: unable to allocate memory.");
59  }
60
61  for (int i=0; i < m_size; i++) {
62    m_entries[i] = NULL;
63  }
64}
65
66DirectoryMemory::~DirectoryMemory()
67{
68  // free up all the directory entries
69  for (int i=0; i < m_size; i++) {
70    if (m_entries[i] != NULL) {
71      delete m_entries[i];
72      m_entries[i] = NULL;
73    }
74  }
75
76  // free up the array of directory entries
77  delete[] m_entries;
78}
79
80// Static method
81void DirectoryMemory::printConfig(ostream& out)
82{
83  out << "Memory config:" << endl;
84  out << "  memory_bits: " << RubyConfig::memorySizeBits() << endl;
85  out << "  memory_size_bytes: " << RubyConfig::memorySizeBytes() << endl;
86  out << "  memory_size_Kbytes: " << double(RubyConfig::memorySizeBytes()) / (1<<10) << endl;
87  out << "  memory_size_Mbytes: " << double(RubyConfig::memorySizeBytes()) / (1<<20) << endl;
88  out << "  memory_size_Gbytes: " << double(RubyConfig::memorySizeBytes()) / (1<<30) << endl;
89
90  out << "  module_bits: " << RubyConfig::memoryModuleBits() << endl;
91  out << "  module_size_lines: " << RubyConfig::memoryModuleBlocks() << endl;
92  out << "  module_size_bytes: " << RubyConfig::memoryModuleBlocks() * RubyConfig::dataBlockBytes() << endl;
93  out << "  module_size_Kbytes: " << double(RubyConfig::memoryModuleBlocks() * RubyConfig::dataBlockBytes()) / (1<<10) << endl;
94  out << "  module_size_Mbytes: " << double(RubyConfig::memoryModuleBlocks() * RubyConfig::dataBlockBytes()) / (1<<20) << endl;
95}
96
97// Public method
98bool DirectoryMemory::isPresent(PhysAddress address)
99{
100  return (map_Address_to_DirectoryNode(address) == m_chip_ptr->getID()*RubyConfig::numberOfDirectoryPerChip()+m_version);
101}
102
103Directory_Entry& DirectoryMemory::lookup(PhysAddress address)
104{
105  assert(isPresent(address));
106  Index index = address.memoryModuleIndex();
107
108  if (index < 0 || index > m_size) {
109    WARN_EXPR(m_chip_ptr->getID());
110    WARN_EXPR(address.getAddress());
111    WARN_EXPR(index);
112    WARN_EXPR(m_size);
113    ERROR_MSG("Directory Memory Assertion: accessing memory out of range.");
114  }
115  Directory_Entry* entry = m_entries[index];
116
117  // allocate the directory entry on demand.
118  if (entry == NULL) {
119    entry = new Directory_Entry;
120
121    //    entry->getProcOwner() = m_chip_ptr->getID(); // FIXME - This should not be hard coded
122    //    entry->getDirOwner() = true;        // FIXME - This should not be hard-coded
123
124    // load the data from SimICS when first initalizing
125    if (g_SIMICS) {
126      if (DATA_BLOCK) {
127        physical_address_t physAddr = address.getAddress();
128
129        for(int j=0; j < RubyConfig::dataBlockBytes(); j++) {
130          int8 data_byte = (int8) SIMICS_read_physical_memory( m_chip_ptr->getID(),
131                                                               physAddr + j, 1 );
132          //printf("SimICS, byte %d: %lld\n", j, data_byte );
133          entry->getDataBlk().setByte(j, data_byte);
134        }
135        DEBUG_EXPR(NODE_COMP, MedPrio,entry->getDataBlk());
136      }
137    }
138
139    // store entry to the table
140    m_entries[index] = entry;
141  }
142
143  return (*entry);
144}
145
146/*
147void DirectoryMemory::invalidateBlock(PhysAddress address)
148{
149  assert(isPresent(address));
150
151  Index index = address.memoryModuleIndex();
152
153  if (index < 0 || index > m_size) {
154    ERROR_MSG("Directory Memory Assertion: accessing memory out of range.");
155  }
156
157  if(m_entries[index] != NULL){
158    delete m_entries[index];
159    m_entries[index] = NULL;
160  }
161
162}
163*/
164
165void DirectoryMemory::print(ostream& out) const
166{
167  out << "Directory dump: " << endl;
168  for (int i=0; i < m_size; i++) {
169    if (m_entries[i] != NULL) {
170      out << i << ": ";
171      out << *m_entries[i] << endl;
172    }
173  }
174}
175
176