3 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
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.
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.
33 * Description: See DirectoryMemory.h
41 #include "DirectoryMemory.hh"
42 #include "RubySlicc_Util.hh"
43 #include "RubyConfig.hh"
45 #include "interface.hh"
47 DirectoryMemory::DirectoryMemory(Chip
* chip_ptr
, int version
)
49 m_chip_ptr
= chip_ptr
;
51 // THIS DOESN'T SEEM TO WORK -- MRM
52 // m_size = RubyConfig::memoryModuleBlocks()/RubyConfig::numberOfDirectory();
53 m_size
= RubyConfig::memoryModuleBlocks();
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.");
61 for (int i
=0; i
< m_size
; i
++) {
66 DirectoryMemory::~DirectoryMemory()
68 // free up all the directory entries
69 for (int i
=0; i
< m_size
; i
++) {
70 if (m_entries
[i
] != NULL
) {
76 // free up the array of directory entries
81 void DirectoryMemory::printConfig(ostream
& out
)
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
;
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
;
98 bool DirectoryMemory::isPresent(PhysAddress address
)
100 return (map_Address_to_DirectoryNode(address
) == m_chip_ptr
->getID()*RubyConfig::numberOfDirectoryPerChip()+m_version
);
103 Directory_Entry
& DirectoryMemory::lookup(PhysAddress address
)
105 assert(isPresent(address
));
106 Index index
= address
.memoryModuleIndex();
108 if (index
< 0 || index
> m_size
) {
109 WARN_EXPR(m_chip_ptr
->getID());
110 WARN_EXPR(address
.getAddress());
113 ERROR_MSG("Directory Memory Assertion: accessing memory out of range.");
115 Directory_Entry
* entry
= m_entries
[index
];
117 // allocate the directory entry on demand.
119 entry
= new Directory_Entry
;
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
124 // load the data from SimICS when first initalizing
127 physical_address_t physAddr
= address
.getAddress();
129 for(int j
=0; j
< RubyConfig::dataBlockBytes(); j
++) {
130 int8 data_byte
= (int8
) SIMICS_read_physical_memory( m_chip_ptr
->getID(),
132 //printf("SimICS, byte %d: %lld\n", j, data_byte );
133 entry
->getDataBlk().setByte(j
, data_byte
);
135 DEBUG_EXPR(NODE_COMP
, MedPrio
,entry
->getDataBlk());
139 // store entry to the table
140 m_entries
[index
] = entry
;
147 void DirectoryMemory::invalidateBlock(PhysAddress address)
149 assert(isPresent(address));
151 Index index = address.memoryModuleIndex();
153 if (index < 0 || index > m_size) {
154 ERROR_MSG("Directory Memory Assertion: accessing memory out of range.");
157 if(m_entries[index] != NULL){
158 delete m_entries[index];
159 m_entries[index] = NULL;
165 void DirectoryMemory::print(ostream
& out
) const
167 out
<< "Directory dump: " << endl
;
168 for (int i
=0; i
< m_size
; i
++) {
169 if (m_entries
[i
] != NULL
) {
171 out
<< *m_entries
[i
] << endl
;