00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
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
00065 CheckNodeInitialized( "core", m_core );
00066 CheckNodeInitialized( "emulator", m_emulator );
00067
00068
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
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
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 }