src/Sim/Register/RegisterFile.cpp

説明を見る。
00001 // 
00002 // Copyright (c) 2005-2008 Kenichi Watanabe.
00003 // Copyright (c) 2005-2008 Yasuhiro Watari.
00004 // Copyright (c) 2005-2008 Hironori Ichibayashi.
00005 // Copyright (c) 2008-2009 Kazuo Horio.
00006 // Copyright (c) 2009-2013 Naruki Kurata.
00007 // Copyright (c) 2005-2013 Ryota Shioya.
00008 // Copyright (c) 2005-2013 Masahiro Goshima.
00009 // 
00010 // This software is provided 'as-is', without any express or implied
00011 // warranty. In no event will the authors be held liable for any damages
00012 // arising from the use of this software.
00013 // 
00014 // Permission is granted to anyone to use this software for any purpose,
00015 // including commercial applications, and to alter it and redistribute it
00016 // freely, subject to the following restrictions:
00017 // 
00018 // 1. The origin of this software must not be misrepresented; you must not
00019 // claim that you wrote the original software. If you use this software
00020 // in a product, an acknowledgment in the product documentation would be
00021 // appreciated but is not required.
00022 // 
00023 // 2. Altered source versions must be plainly marked as such, and must not be
00024 // misrepresented as being the original software.
00025 // 
00026 // 3. This notice may not be removed or altered from any source
00027 // distribution.
00028 // 
00029 // 
00030 
00031 
00032 #include <pch.h>
00033 
00034 #include "Sim/Register/RegisterFile.h"
00035 #include "Utility/RuntimeError.h"
00036 #include "Sim/Core/Core.h"
00037 
00038 // <FIXME> PhyReg 
00039 #include "Sim/Dependency/PhyReg/PhyReg.h"
00040 
00041 using namespace Onikiri;
00042 
00043 RegisterFile::RegisterFile() :
00044     m_totalCapacity(0),
00045     m_core(0),
00046     m_emulator(0)
00047 {
00048 }
00049 
00050 RegisterFile::~RegisterFile()
00051 {
00052     for (int i = 0; i < m_totalCapacity; i++) {
00053         delete m_register[i];
00054     }
00055     ReleaseParam();
00056 }
00057 
00058 void RegisterFile::Initialize(InitPhase phase)
00059 {
00060     if(phase == INIT_PRE_CONNECTION){
00061         LoadParam();
00062     }
00063     else if(phase == INIT_POST_CONNECTION){
00064         // member `FbN
00065         CheckNodeInitialized( "core", m_core );
00066         CheckNodeInitialized( "emulator", m_emulator );
00067 
00068         // Check the physical register configuration.
00069         ISAInfoIF* isaInfo = m_emulator->GetISAInfo();
00070         if( (size_t)isaInfo->GetRegisterSegmentCount() != m_capacity.size() ){
00071             THROW_RUNTIME_ERROR(
00072                 "The specified number of the physical register segments (%d) "
00073                 "and that of the logical register segments defined by the ISA (%d) "
00074                 "do not match in the configuration XML. Check the configuration "
00075                 "of the physical registers and the ISA.",
00076                 m_capacity.size(),
00077                 isaInfo->GetRegisterSegmentCount()
00078             );
00079         }
00080 
00081         // SWX^KvvZ
00082         m_totalCapacity = 0;
00083         for(int i = 0; i < static_cast<int>(m_capacity.size()); ++i) {
00084             m_totalCapacity += m_capacity[i];
00085         }
00086         
00087         // WX^m
00088         int schedulerCount = m_core->GetNumScheduler();
00089         m_register.resize(m_totalCapacity, 0);
00090         for (int i = 0; i < m_totalCapacity; i++) {
00091             PhyReg* reg = new PhyReg(schedulerCount, i);
00092             reg->Clear();
00093             m_register[i] = reg;
00094         }
00095     }
00096 }
00097 
00098 PhyReg* RegisterFile::GetPhyReg(int phyRegNo) const
00099 {
00100     ASSERT(phyRegNo >= 0 && phyRegNo < m_totalCapacity,
00101         "illegal phyRegNo %d.", phyRegNo);
00102     return m_register[phyRegNo];
00103 }
00104 
00105 PhyReg* RegisterFile::operator[](int phyRegNo) const
00106 {
00107     return GetPhyReg(phyRegNo);
00108 }
00109 
00110 void RegisterFile::SetPhyReg(int phyRegNo, PhyReg* phyReg)
00111 {
00112     ASSERT(phyRegNo >= 0 && phyRegNo < m_totalCapacity,
00113         "illegal phyRegNo %d.", phyRegNo);
00114     m_register[phyRegNo] = phyReg;
00115 }
00116 
00117 size_t RegisterFile::GetSegmentCount() const
00118 {
00119     return m_capacity.size();
00120 }
00121 
00122 int RegisterFile::GetCapacity(int segment) const
00123 {
00124     ASSERT(segment >= 0 && segment < static_cast<int>(m_capacity.size()),
00125         "unknown segment %d", segment);     
00126     return m_capacity[segment];
00127 }
00128 
00129 int RegisterFile::GetTotalCapacity() const
00130 {
00131     return m_totalCapacity; 
00132 }

Onikiri2に対してTue Jun 18 14:34:25 2013に生成されました。  doxygen 1.4.7