2009-07-09 08:02:20 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2009 The Regents of The University of Michigan
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met: redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer;
|
|
|
|
* redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution;
|
|
|
|
* neither the name of the copyright holders nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* Authors: Gabe Black
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "arch/mips/isa.hh"
|
2009-07-10 05:28:39 +02:00
|
|
|
#include "arch/mips/mt.hh"
|
2011-04-15 19:44:06 +02:00
|
|
|
#include "arch/mips/mt_constants.hh"
|
2009-07-10 05:28:39 +02:00
|
|
|
#include "arch/mips/pra_constants.hh"
|
|
|
|
#include "base/bitfield.hh"
|
|
|
|
#include "cpu/base.hh"
|
2009-07-09 08:02:20 +02:00
|
|
|
#include "cpu/thread_context.hh"
|
|
|
|
|
|
|
|
namespace MipsISA
|
|
|
|
{
|
|
|
|
|
2009-07-10 05:28:39 +02:00
|
|
|
std::string
|
|
|
|
ISA::miscRegNames[NumMiscRegs] =
|
|
|
|
{
|
|
|
|
"Index", "MVPControl", "MVPConf0", "MVPConf1", "", "", "", "",
|
|
|
|
"Random", "VPEControl", "VPEConf0", "VPEConf1",
|
|
|
|
"YQMask", "VPESchedule", "VPEScheFBack", "VPEOpt",
|
|
|
|
"EntryLo0", "TCStatus", "TCBind", "TCRestart",
|
|
|
|
"TCHalt", "TCContext", "TCSchedule", "TCScheFBack",
|
|
|
|
"EntryLo1", "", "", "", "", "", "", "",
|
|
|
|
"Context", "ContextConfig", "", "", "", "", "", "",
|
|
|
|
"PageMask", "PageGrain", "", "", "", "", "", "",
|
|
|
|
"Wired", "SRSConf0", "SRCConf1", "SRSConf2",
|
|
|
|
"SRSConf3", "SRSConf4", "", "",
|
|
|
|
"HWREna", "", "", "", "", "", "", "",
|
|
|
|
"BadVAddr", "", "", "", "", "", "", "",
|
|
|
|
"Count", "", "", "", "", "", "", "",
|
|
|
|
"EntryHi", "", "", "", "", "", "", "",
|
|
|
|
"Compare", "", "", "", "", "", "", "",
|
|
|
|
"Status", "IntCtl", "SRSCtl", "SRSMap", "", "", "", "",
|
|
|
|
"Cause", "", "", "", "", "", "", "",
|
|
|
|
"EPC", "", "", "", "", "", "", "",
|
|
|
|
"PRId", "EBase", "", "", "", "", "", "",
|
|
|
|
"Config", "Config1", "Config2", "Config3", "", "", "", "",
|
|
|
|
"LLAddr", "", "", "", "", "", "", "",
|
|
|
|
"WatchLo0", "WatchLo1", "WatchLo2", "WatchLo3",
|
|
|
|
"WatchLo4", "WatchLo5", "WatchLo6", "WatchLo7",
|
|
|
|
"WatchHi0", "WatchHi1", "WatchHi2", "WatchHi3",
|
|
|
|
"WatchHi4", "WatchHi5", "WatchHi6", "WatchHi7",
|
|
|
|
"XCContext64", "", "", "", "", "", "", "",
|
|
|
|
"", "", "", "", "", "", "", "",
|
|
|
|
"", "", "", "", "", "", "", "",
|
|
|
|
"Debug", "TraceControl1", "TraceControl2", "UserTraceData",
|
|
|
|
"TraceBPC", "", "", "",
|
|
|
|
"DEPC", "", "", "", "", "", "", "",
|
|
|
|
"PerfCnt0", "PerfCnt1", "PerfCnt2", "PerfCnt3",
|
|
|
|
"PerfCnt4", "PerfCnt5", "PerfCnt6", "PerfCnt7",
|
|
|
|
"ErrCtl", "", "", "", "", "", "", "",
|
|
|
|
"CacheErr0", "CacheErr1", "CacheErr2", "CacheErr3", "", "", "", "",
|
|
|
|
"TagLo0", "DataLo1", "TagLo2", "DataLo3",
|
|
|
|
"TagLo4", "DataLo5", "TagLo6", "DataLo7",
|
|
|
|
"TagHi0", "DataHi1", "TagHi2", "DataHi3",
|
|
|
|
"TagHi4", "DataHi5", "TagHi6", "DataHi7",
|
|
|
|
"ErrorEPC", "", "", "", "", "", "", "",
|
|
|
|
"DESAVE", "", "", "", "", "", "", "",
|
|
|
|
"LLFlag"
|
|
|
|
};
|
|
|
|
|
2011-03-26 14:23:52 +01:00
|
|
|
ISA::ISA(uint8_t num_threads, uint8_t num_vpes)
|
2009-07-10 05:28:39 +02:00
|
|
|
{
|
2011-03-26 14:23:52 +01:00
|
|
|
numThreads = num_threads;
|
|
|
|
numVpes = num_vpes;
|
2009-07-10 05:28:39 +02:00
|
|
|
|
|
|
|
miscRegFile.resize(NumMiscRegs);
|
|
|
|
bankType.resize(NumMiscRegs);
|
|
|
|
|
|
|
|
for (int i=0; i < NumMiscRegs; i++) {
|
|
|
|
miscRegFile[i].resize(1);
|
|
|
|
bankType[i] = perProcessor;
|
|
|
|
}
|
|
|
|
|
|
|
|
miscRegFile_WriteMask.resize(NumMiscRegs);
|
|
|
|
|
2009-07-21 05:14:15 +02:00
|
|
|
for (int i = 0; i < NumMiscRegs; i++) {
|
|
|
|
miscRegFile_WriteMask[i].push_back(0);
|
2009-07-10 05:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize all Per-VPE regs
|
2009-07-22 08:38:26 +02:00
|
|
|
uint32_t per_vpe_regs[] = { MISCREG_VPE_CONTROL,
|
|
|
|
MISCREG_VPE_CONF0, MISCREG_VPE_CONF1,
|
|
|
|
MISCREG_YQMASK,
|
|
|
|
MISCREG_VPE_SCHEDULE, MISCREG_VPE_SCHEFBACK,
|
|
|
|
MISCREG_VPE_OPT, MISCREG_SRS_CONF0,
|
|
|
|
MISCREG_SRS_CONF1, MISCREG_SRS_CONF2,
|
|
|
|
MISCREG_SRS_CONF3, MISCREG_SRS_CONF4,
|
|
|
|
MISCREG_EBASE
|
2009-07-10 05:28:39 +02:00
|
|
|
};
|
|
|
|
uint32_t num_vpe_regs = sizeof(per_vpe_regs) / 4;
|
|
|
|
for (int i = 0; i < num_vpe_regs; i++) {
|
2011-03-26 14:23:52 +01:00
|
|
|
if (numVpes > 1) {
|
|
|
|
miscRegFile[per_vpe_regs[i]].resize(numVpes);
|
2009-07-10 05:28:39 +02:00
|
|
|
}
|
|
|
|
bankType[per_vpe_regs[i]] = perVirtProcessor;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize all Per-TC regs
|
2009-07-22 08:38:26 +02:00
|
|
|
uint32_t per_tc_regs[] = { MISCREG_STATUS,
|
|
|
|
MISCREG_TC_STATUS, MISCREG_TC_BIND,
|
|
|
|
MISCREG_TC_RESTART, MISCREG_TC_HALT,
|
|
|
|
MISCREG_TC_CONTEXT, MISCREG_TC_SCHEDULE,
|
|
|
|
MISCREG_TC_SCHEFBACK,
|
|
|
|
MISCREG_DEBUG, MISCREG_LLADDR
|
2009-07-10 05:28:39 +02:00
|
|
|
};
|
|
|
|
uint32_t num_tc_regs = sizeof(per_tc_regs) / 4;
|
|
|
|
|
|
|
|
for (int i = 0; i < num_tc_regs; i++) {
|
2011-03-26 14:23:52 +01:00
|
|
|
miscRegFile[per_tc_regs[i]].resize(numThreads);
|
2009-07-10 05:28:39 +02:00
|
|
|
bankType[per_tc_regs[i]] = perThreadContext;
|
|
|
|
}
|
|
|
|
|
2011-03-26 14:23:52 +01:00
|
|
|
clear();
|
|
|
|
}
|
2009-07-10 05:28:39 +02:00
|
|
|
|
2011-03-26 14:23:52 +01:00
|
|
|
void
|
|
|
|
ISA::clear()
|
|
|
|
{
|
|
|
|
for(int i = 0; i < NumMiscRegs; i++) {
|
|
|
|
for (int j = 0; j < miscRegFile[i].size(); j++)
|
|
|
|
miscRegFile[i][j] = 0;
|
2009-07-10 05:28:39 +02:00
|
|
|
|
2011-03-26 14:23:52 +01:00
|
|
|
for (int k = 0; k < miscRegFile_WriteMask[i].size(); k++)
|
|
|
|
miscRegFile_WriteMask[i][k] = (long unsigned int)(-1);
|
|
|
|
}
|
2009-07-10 05:28:39 +02:00
|
|
|
}
|
|
|
|
|
2011-03-26 14:23:52 +01:00
|
|
|
|
2009-07-09 08:02:20 +02:00
|
|
|
void
|
2011-03-26 14:23:52 +01:00
|
|
|
ISA::configCP()
|
2009-07-10 05:28:39 +02:00
|
|
|
{
|
|
|
|
DPRINTF(MipsPRA, "Resetting CP0 State with %i TCs and %i VPEs\n",
|
2011-03-26 14:23:52 +01:00
|
|
|
numThreads, numVpes);
|
2009-07-10 05:28:39 +02:00
|
|
|
|
2011-03-26 14:23:52 +01:00
|
|
|
CoreSpecific cp;
|
|
|
|
panic("CP state must be set before the following code is used");
|
2009-07-10 05:28:39 +02:00
|
|
|
|
|
|
|
// Do Default CP0 initialization HERE
|
|
|
|
|
|
|
|
// Do Initialization for MT cores here (eventually use
|
|
|
|
// core_name parameter to toggle this initialization)
|
|
|
|
// ===================================================
|
|
|
|
DPRINTF(MipsPRA, "Initializing CP0 State.... ");
|
|
|
|
|
2009-07-22 08:38:26 +02:00
|
|
|
PRIdReg procId = readMiscRegNoEffect(MISCREG_PRID);
|
2009-07-21 05:14:15 +02:00
|
|
|
procId.coOp = cp.CP0_PRId_CompanyOptions;
|
|
|
|
procId.coId = cp.CP0_PRId_CompanyID;
|
|
|
|
procId.procId = cp.CP0_PRId_ProcessorID;
|
|
|
|
procId.rev = cp.CP0_PRId_Revision;
|
2009-07-22 08:38:26 +02:00
|
|
|
setMiscRegNoEffect(MISCREG_PRID, procId);
|
2009-07-21 05:14:15 +02:00
|
|
|
|
2009-07-10 05:28:39 +02:00
|
|
|
// Now, create Write Mask for ProcID register
|
2009-07-22 08:38:26 +02:00
|
|
|
MiscReg procIDMask = 0; // Read-Only register
|
|
|
|
replaceBits(procIDMask, 0, 32, 0);
|
|
|
|
setRegMask(MISCREG_PRID, procIDMask);
|
2009-07-10 05:28:39 +02:00
|
|
|
|
|
|
|
// Config
|
2009-07-22 08:38:26 +02:00
|
|
|
ConfigReg cfg = readMiscRegNoEffect(MISCREG_CONFIG);
|
2009-07-21 05:14:15 +02:00
|
|
|
cfg.be = cp.CP0_Config_BE;
|
|
|
|
cfg.at = cp.CP0_Config_AT;
|
|
|
|
cfg.ar = cp.CP0_Config_AR;
|
|
|
|
cfg.mt = cp.CP0_Config_MT;
|
|
|
|
cfg.vi = cp.CP0_Config_VI;
|
|
|
|
cfg.m = 1;
|
2009-07-22 08:38:26 +02:00
|
|
|
setMiscRegNoEffect(MISCREG_CONFIG, cfg);
|
2009-07-10 05:28:39 +02:00
|
|
|
// Now, create Write Mask for Config register
|
|
|
|
MiscReg cfg_Mask = 0x7FFF0007;
|
2009-07-21 05:14:15 +02:00
|
|
|
replaceBits(cfg_Mask, 0, 32, 0);
|
2009-07-22 08:38:26 +02:00
|
|
|
setRegMask(MISCREG_CONFIG, cfg_Mask);
|
2009-07-10 05:28:39 +02:00
|
|
|
|
|
|
|
// Config1
|
2009-07-22 08:38:26 +02:00
|
|
|
Config1Reg cfg1 = readMiscRegNoEffect(MISCREG_CONFIG1);
|
2009-07-21 05:14:15 +02:00
|
|
|
cfg1.mmuSize = cp.CP0_Config1_MMU;
|
|
|
|
cfg1.is = cp.CP0_Config1_IS;
|
|
|
|
cfg1.il = cp.CP0_Config1_IL;
|
|
|
|
cfg1.ia = cp.CP0_Config1_IA;
|
|
|
|
cfg1.ds = cp.CP0_Config1_DS;
|
|
|
|
cfg1.dl = cp.CP0_Config1_DL;
|
|
|
|
cfg1.da = cp.CP0_Config1_DA;
|
|
|
|
cfg1.fp = cp.CP0_Config1_FP;
|
|
|
|
cfg1.ep = cp.CP0_Config1_EP;
|
|
|
|
cfg1.wr = cp.CP0_Config1_WR;
|
|
|
|
cfg1.md = cp.CP0_Config1_MD;
|
|
|
|
cfg1.c2 = cp.CP0_Config1_C2;
|
|
|
|
cfg1.pc = cp.CP0_Config1_PC;
|
|
|
|
cfg1.m = cp.CP0_Config1_M;
|
2009-07-22 08:38:26 +02:00
|
|
|
setMiscRegNoEffect(MISCREG_CONFIG1, cfg1);
|
2009-07-10 05:28:39 +02:00
|
|
|
// Now, create Write Mask for Config register
|
|
|
|
MiscReg cfg1_Mask = 0; // Read Only Register
|
2009-07-21 05:14:15 +02:00
|
|
|
replaceBits(cfg1_Mask, 0, 32, 0);
|
2009-07-22 08:38:26 +02:00
|
|
|
setRegMask(MISCREG_CONFIG1, cfg1_Mask);
|
2009-07-10 05:28:39 +02:00
|
|
|
|
|
|
|
// Config2
|
2009-07-22 08:38:26 +02:00
|
|
|
Config2Reg cfg2 = readMiscRegNoEffect(MISCREG_CONFIG2);
|
2009-07-21 05:14:15 +02:00
|
|
|
cfg2.tu = cp.CP0_Config2_TU;
|
|
|
|
cfg2.ts = cp.CP0_Config2_TS;
|
|
|
|
cfg2.tl = cp.CP0_Config2_TL;
|
|
|
|
cfg2.ta = cp.CP0_Config2_TA;
|
|
|
|
cfg2.su = cp.CP0_Config2_SU;
|
|
|
|
cfg2.ss = cp.CP0_Config2_SS;
|
|
|
|
cfg2.sl = cp.CP0_Config2_SL;
|
|
|
|
cfg2.sa = cp.CP0_Config2_SA;
|
|
|
|
cfg2.m = cp.CP0_Config2_M;
|
2009-07-22 08:38:26 +02:00
|
|
|
setMiscRegNoEffect(MISCREG_CONFIG2, cfg2);
|
2009-07-10 05:28:39 +02:00
|
|
|
// Now, create Write Mask for Config register
|
|
|
|
MiscReg cfg2_Mask = 0x7000F000; // Read Only Register
|
2009-07-21 05:14:15 +02:00
|
|
|
replaceBits(cfg2_Mask, 0, 32, 0);
|
2009-07-22 08:38:26 +02:00
|
|
|
setRegMask(MISCREG_CONFIG2, cfg2_Mask);
|
2009-07-10 05:28:39 +02:00
|
|
|
|
|
|
|
// Config3
|
2009-07-22 08:38:26 +02:00
|
|
|
Config3Reg cfg3 = readMiscRegNoEffect(MISCREG_CONFIG3);
|
2009-07-21 05:14:15 +02:00
|
|
|
cfg3.dspp = cp.CP0_Config3_DSPP;
|
|
|
|
cfg3.lpa = cp.CP0_Config3_LPA;
|
|
|
|
cfg3.veic = cp.CP0_Config3_VEIC;
|
|
|
|
cfg3.vint = cp.CP0_Config3_VInt;
|
|
|
|
cfg3.sp = cp.CP0_Config3_SP;
|
|
|
|
cfg3.mt = cp.CP0_Config3_MT;
|
|
|
|
cfg3.sm = cp.CP0_Config3_SM;
|
|
|
|
cfg3.tl = cp.CP0_Config3_TL;
|
2009-07-22 08:38:26 +02:00
|
|
|
setMiscRegNoEffect(MISCREG_CONFIG3, cfg3);
|
2009-07-10 05:28:39 +02:00
|
|
|
// Now, create Write Mask for Config register
|
|
|
|
MiscReg cfg3_Mask = 0; // Read Only Register
|
2009-07-21 05:14:15 +02:00
|
|
|
replaceBits(cfg3_Mask, 0, 32, 0);
|
2009-07-22 08:38:26 +02:00
|
|
|
setRegMask(MISCREG_CONFIG3, cfg3_Mask);
|
2009-07-10 05:28:39 +02:00
|
|
|
|
|
|
|
// EBase - CPUNum
|
2009-07-22 08:38:26 +02:00
|
|
|
EBaseReg eBase = readMiscRegNoEffect(MISCREG_EBASE);
|
2009-07-21 05:14:15 +02:00
|
|
|
eBase.cpuNum = cp.CP0_EBase_CPUNum;
|
|
|
|
replaceBits(eBase, 31, 31, 1);
|
2009-07-22 08:38:26 +02:00
|
|
|
setMiscRegNoEffect(MISCREG_EBASE, eBase);
|
2009-07-10 05:28:39 +02:00
|
|
|
// Now, create Write Mask for Config register
|
|
|
|
MiscReg EB_Mask = 0x3FFFF000;// Except Exception Base, the
|
|
|
|
// entire register is read only
|
2009-07-21 05:14:15 +02:00
|
|
|
replaceBits(EB_Mask, 0, 32, 0);
|
2009-07-22 08:38:26 +02:00
|
|
|
setRegMask(MISCREG_EBASE, EB_Mask);
|
2009-07-10 05:28:39 +02:00
|
|
|
|
|
|
|
// SRS Control - HSS (Highest Shadow Set)
|
2009-07-22 08:38:26 +02:00
|
|
|
SRSCtlReg scsCtl = readMiscRegNoEffect(MISCREG_SRSCTL);
|
2009-07-21 05:14:15 +02:00
|
|
|
scsCtl.hss = cp.CP0_SrsCtl_HSS;
|
2009-07-22 08:38:26 +02:00
|
|
|
setMiscRegNoEffect(MISCREG_SRSCTL, scsCtl);
|
2009-07-10 05:28:39 +02:00
|
|
|
// Now, create Write Mask for the SRS Ctl register
|
|
|
|
MiscReg SC_Mask = 0x0000F3C0;
|
2009-07-21 05:14:15 +02:00
|
|
|
replaceBits(SC_Mask, 0, 32, 0);
|
2009-07-22 08:38:26 +02:00
|
|
|
setRegMask(MISCREG_SRSCTL, SC_Mask);
|
2009-07-10 05:28:39 +02:00
|
|
|
|
|
|
|
// IntCtl - IPTI, IPPCI
|
2009-07-22 08:38:26 +02:00
|
|
|
IntCtlReg intCtl = readMiscRegNoEffect(MISCREG_INTCTL);
|
2009-07-21 05:14:15 +02:00
|
|
|
intCtl.ipti = cp.CP0_IntCtl_IPTI;
|
|
|
|
intCtl.ippci = cp.CP0_IntCtl_IPPCI;
|
2009-07-22 08:38:26 +02:00
|
|
|
setMiscRegNoEffect(MISCREG_INTCTL, intCtl);
|
2009-07-10 05:28:39 +02:00
|
|
|
// Now, create Write Mask for the IntCtl register
|
|
|
|
MiscReg IC_Mask = 0x000003E0;
|
2009-07-21 05:14:15 +02:00
|
|
|
replaceBits(IC_Mask, 0, 32, 0);
|
2009-07-22 08:38:26 +02:00
|
|
|
setRegMask(MISCREG_INTCTL, IC_Mask);
|
2009-07-10 05:28:39 +02:00
|
|
|
|
|
|
|
// Watch Hi - M - FIXME (More than 1 Watch register)
|
2009-07-22 08:38:26 +02:00
|
|
|
WatchHiReg watchHi = readMiscRegNoEffect(MISCREG_WATCHHI0);
|
2009-07-21 05:14:15 +02:00
|
|
|
watchHi.m = cp.CP0_WatchHi_M;
|
2009-07-22 08:38:26 +02:00
|
|
|
setMiscRegNoEffect(MISCREG_WATCHHI0, watchHi);
|
2009-07-10 05:28:39 +02:00
|
|
|
// Now, create Write Mask for the IntCtl register
|
|
|
|
MiscReg wh_Mask = 0x7FFF0FFF;
|
2009-07-21 05:14:15 +02:00
|
|
|
replaceBits(wh_Mask, 0, 32, 0);
|
2009-07-22 08:38:26 +02:00
|
|
|
setRegMask(MISCREG_WATCHHI0, wh_Mask);
|
2009-07-10 05:28:39 +02:00
|
|
|
|
|
|
|
// Perf Ctr - M - FIXME (More than 1 PerfCnt Pair)
|
2009-07-22 08:38:26 +02:00
|
|
|
PerfCntCtlReg perfCntCtl = readMiscRegNoEffect(MISCREG_PERFCNT0);
|
2009-07-21 05:14:15 +02:00
|
|
|
perfCntCtl.m = cp.CP0_PerfCtr_M;
|
|
|
|
perfCntCtl.w = cp.CP0_PerfCtr_W;
|
2009-07-22 08:38:26 +02:00
|
|
|
setMiscRegNoEffect(MISCREG_PERFCNT0, perfCntCtl);
|
2009-07-10 05:28:39 +02:00
|
|
|
// Now, create Write Mask for the IntCtl register
|
|
|
|
MiscReg pc_Mask = 0x00007FF;
|
2009-07-21 05:14:15 +02:00
|
|
|
replaceBits(pc_Mask, 0, 32, 0);
|
2009-07-22 08:38:26 +02:00
|
|
|
setRegMask(MISCREG_PERFCNT0, pc_Mask);
|
2009-07-10 05:28:39 +02:00
|
|
|
|
|
|
|
// Random
|
2009-07-22 08:38:26 +02:00
|
|
|
setMiscRegNoEffect(MISCREG_CP0_RANDOM, 63);
|
2009-07-10 05:28:39 +02:00
|
|
|
// Now, create Write Mask for the IntCtl register
|
|
|
|
MiscReg random_Mask = 0;
|
2009-07-21 05:14:15 +02:00
|
|
|
replaceBits(random_Mask, 0, 32, 0);
|
2009-07-22 08:38:26 +02:00
|
|
|
setRegMask(MISCREG_CP0_RANDOM, random_Mask);
|
2009-07-10 05:28:39 +02:00
|
|
|
|
|
|
|
// PageGrain
|
2009-07-22 08:38:26 +02:00
|
|
|
PageGrainReg pageGrain = readMiscRegNoEffect(MISCREG_PAGEGRAIN);
|
2009-07-21 05:14:15 +02:00
|
|
|
pageGrain.esp = cp.CP0_Config3_SP;
|
2009-07-22 08:38:26 +02:00
|
|
|
setMiscRegNoEffect(MISCREG_PAGEGRAIN, pageGrain);
|
2009-07-10 05:28:39 +02:00
|
|
|
// Now, create Write Mask for the IntCtl register
|
|
|
|
MiscReg pg_Mask = 0x10000000;
|
2009-07-21 05:14:15 +02:00
|
|
|
replaceBits(pg_Mask, 0, 32, 0);
|
2009-07-22 08:38:26 +02:00
|
|
|
setRegMask(MISCREG_PAGEGRAIN, pg_Mask);
|
2009-07-10 05:28:39 +02:00
|
|
|
|
|
|
|
// Status
|
2009-07-22 08:38:26 +02:00
|
|
|
StatusReg status = readMiscRegNoEffect(MISCREG_STATUS);
|
2009-07-10 05:28:39 +02:00
|
|
|
// Only CU0 and IE are modified on a reset - everything else needs
|
|
|
|
// to be controlled on a per CPU model basis
|
|
|
|
|
|
|
|
// Enable CP0 on reset
|
2009-07-21 05:14:15 +02:00
|
|
|
// status.cu0 = 1;
|
2009-07-10 05:28:39 +02:00
|
|
|
|
|
|
|
// Enable ERL bit on a reset
|
2009-07-21 05:14:15 +02:00
|
|
|
status.erl = 1;
|
2009-07-10 05:28:39 +02:00
|
|
|
// Enable BEV bit on a reset
|
2009-07-21 05:14:15 +02:00
|
|
|
status.bev = 1;
|
2009-07-10 05:28:39 +02:00
|
|
|
|
2009-07-22 08:38:26 +02:00
|
|
|
setMiscRegNoEffect(MISCREG_STATUS, status);
|
2009-07-10 05:28:39 +02:00
|
|
|
// Now, create Write Mask for the Status register
|
|
|
|
MiscReg stat_Mask = 0xFF78FF17;
|
2009-07-21 05:14:15 +02:00
|
|
|
replaceBits(stat_Mask, 0, 32, 0);
|
2009-07-22 08:38:26 +02:00
|
|
|
setRegMask(MISCREG_STATUS, stat_Mask);
|
2009-07-10 05:28:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
// MVPConf0
|
2009-07-22 08:38:26 +02:00
|
|
|
MVPConf0Reg mvpConf0 = readMiscRegNoEffect(MISCREG_MVP_CONF0);
|
2009-07-21 05:14:15 +02:00
|
|
|
mvpConf0.tca = 1;
|
2011-03-26 14:23:52 +01:00
|
|
|
mvpConf0.pvpe = numVpes - 1;
|
|
|
|
mvpConf0.ptc = numThreads - 1;
|
2009-07-22 08:38:26 +02:00
|
|
|
setMiscRegNoEffect(MISCREG_MVP_CONF0, mvpConf0);
|
2009-07-10 05:28:39 +02:00
|
|
|
|
|
|
|
// VPEConf0
|
2009-07-22 08:38:26 +02:00
|
|
|
VPEConf0Reg vpeConf0 = readMiscRegNoEffect(MISCREG_VPE_CONF0);
|
2009-07-21 05:14:15 +02:00
|
|
|
vpeConf0.mvp = 1;
|
2009-07-22 08:38:26 +02:00
|
|
|
setMiscRegNoEffect(MISCREG_VPE_CONF0, vpeConf0);
|
2009-07-10 05:28:39 +02:00
|
|
|
|
|
|
|
// TCBind
|
2011-03-26 14:23:52 +01:00
|
|
|
for (ThreadID tid = 0; tid < numThreads; tid++) {
|
2009-07-22 08:38:26 +02:00
|
|
|
TCBindReg tcBind = readMiscRegNoEffect(MISCREG_TC_BIND, tid);
|
2009-07-21 05:14:15 +02:00
|
|
|
tcBind.curTC = tid;
|
2009-07-22 08:38:26 +02:00
|
|
|
setMiscRegNoEffect(MISCREG_TC_BIND, tcBind, tid);
|
2009-07-10 05:28:39 +02:00
|
|
|
}
|
|
|
|
// TCHalt
|
2009-07-22 08:38:26 +02:00
|
|
|
TCHaltReg tcHalt = readMiscRegNoEffect(MISCREG_TC_HALT);
|
2009-07-21 05:14:15 +02:00
|
|
|
tcHalt.h = 0;
|
2009-07-22 08:38:26 +02:00
|
|
|
setMiscRegNoEffect(MISCREG_TC_HALT, tcHalt);
|
2009-07-10 05:28:39 +02:00
|
|
|
|
|
|
|
// TCStatus
|
|
|
|
// Set TCStatus Activated to 1 for the initial thread that is running
|
2009-07-22 08:38:26 +02:00
|
|
|
TCStatusReg tcStatus = readMiscRegNoEffect(MISCREG_TC_STATUS);
|
2009-07-21 05:14:15 +02:00
|
|
|
tcStatus.a = 1;
|
2009-07-22 08:38:26 +02:00
|
|
|
setMiscRegNoEffect(MISCREG_TC_STATUS, tcStatus);
|
2009-07-10 05:28:39 +02:00
|
|
|
|
|
|
|
// Set Dynamically Allocatable bit to 1 for all other threads
|
2011-03-26 14:23:52 +01:00
|
|
|
for (ThreadID tid = 1; tid < numThreads; tid++) {
|
2009-07-22 08:38:26 +02:00
|
|
|
tcStatus = readMiscRegNoEffect(MISCREG_TC_STATUS, tid);
|
2009-07-21 05:14:15 +02:00
|
|
|
tcStatus.da = 1;
|
2009-07-22 08:38:26 +02:00
|
|
|
setMiscRegNoEffect(MISCREG_TC_STATUS, tcStatus, tid);
|
2009-07-10 05:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-22 08:38:26 +02:00
|
|
|
MiscReg mask = 0x7FFFFFFF;
|
2009-07-10 05:28:39 +02:00
|
|
|
|
|
|
|
// Now, create Write Mask for the Index register
|
2009-07-22 08:38:26 +02:00
|
|
|
replaceBits(mask, 0, 32, 0);
|
|
|
|
setRegMask(MISCREG_INDEX, mask);
|
2009-07-10 05:28:39 +02:00
|
|
|
|
2009-07-22 08:38:26 +02:00
|
|
|
mask = 0x3FFFFFFF;
|
|
|
|
replaceBits(mask, 0, 32, 0);
|
|
|
|
setRegMask(MISCREG_ENTRYLO0, mask);
|
|
|
|
setRegMask(MISCREG_ENTRYLO1, mask);
|
2009-07-10 05:28:39 +02:00
|
|
|
|
2009-07-22 08:38:26 +02:00
|
|
|
mask = 0xFF800000;
|
|
|
|
replaceBits(mask, 0, 32, 0);
|
|
|
|
setRegMask(MISCREG_CONTEXT, mask);
|
2009-07-10 05:28:39 +02:00
|
|
|
|
2009-07-22 08:38:26 +02:00
|
|
|
mask = 0x1FFFF800;
|
|
|
|
replaceBits(mask, 0, 32, 0);
|
|
|
|
setRegMask(MISCREG_PAGEMASK, mask);
|
2009-07-10 05:28:39 +02:00
|
|
|
|
2009-07-22 08:38:26 +02:00
|
|
|
mask = 0x0;
|
|
|
|
replaceBits(mask, 0, 32, 0);
|
|
|
|
setRegMask(MISCREG_BADVADDR, mask);
|
|
|
|
setRegMask(MISCREG_LLADDR, mask);
|
2009-07-10 05:28:39 +02:00
|
|
|
|
2009-07-22 08:38:26 +02:00
|
|
|
mask = 0x08C00300;
|
|
|
|
replaceBits(mask, 0, 32, 0);
|
|
|
|
setRegMask(MISCREG_CAUSE, mask);
|
2009-07-10 05:28:39 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
inline unsigned
|
|
|
|
ISA::getVPENum(ThreadID tid)
|
2009-07-09 08:02:20 +02:00
|
|
|
{
|
2009-07-22 08:38:26 +02:00
|
|
|
TCBindReg tcBind = miscRegFile[MISCREG_TC_BIND][tid];
|
2009-07-21 05:14:15 +02:00
|
|
|
return tcBind.curVPE;
|
2009-07-09 08:02:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MiscReg
|
2009-07-22 08:38:26 +02:00
|
|
|
ISA::readMiscRegNoEffect(int misc_reg, ThreadID tid)
|
2009-07-10 05:28:39 +02:00
|
|
|
{
|
|
|
|
unsigned reg_sel = (bankType[misc_reg] == perThreadContext)
|
|
|
|
? tid : getVPENum(tid);
|
|
|
|
DPRINTF(MipsPRA, "Reading CP0 Register:%u Select:%u (%s) (%lx).\n",
|
|
|
|
misc_reg / 8, misc_reg % 8, miscRegNames[misc_reg],
|
|
|
|
miscRegFile[misc_reg][reg_sel]);
|
|
|
|
return miscRegFile[misc_reg][reg_sel];
|
|
|
|
}
|
|
|
|
|
|
|
|
//@TODO: MIPS MT's register view automatically connects
|
|
|
|
// Status to TCStatus depending on current thread
|
|
|
|
//template <class TC>
|
|
|
|
MiscReg
|
2009-07-22 08:38:26 +02:00
|
|
|
ISA::readMiscReg(int misc_reg, ThreadContext *tc, ThreadID tid)
|
2009-07-10 05:28:39 +02:00
|
|
|
{
|
|
|
|
unsigned reg_sel = (bankType[misc_reg] == perThreadContext)
|
|
|
|
? tid : getVPENum(tid);
|
|
|
|
DPRINTF(MipsPRA,
|
|
|
|
"Reading CP0 Register:%u Select:%u (%s) with effect (%lx).\n",
|
|
|
|
misc_reg / 8, misc_reg % 8, miscRegNames[misc_reg],
|
|
|
|
miscRegFile[misc_reg][reg_sel]);
|
|
|
|
|
2009-07-21 10:08:53 +02:00
|
|
|
return miscRegFile[misc_reg][reg_sel];
|
2009-07-10 05:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-07-22 08:38:26 +02:00
|
|
|
ISA::setMiscRegNoEffect(int misc_reg, const MiscReg &val, ThreadID tid)
|
2009-07-10 05:28:39 +02:00
|
|
|
{
|
|
|
|
unsigned reg_sel = (bankType[misc_reg] == perThreadContext)
|
|
|
|
? tid : getVPENum(tid);
|
|
|
|
DPRINTF(MipsPRA,
|
|
|
|
"[tid:%i]: Setting (direct set) CP0 Register:%u "
|
|
|
|
"Select:%u (%s) to %#x.\n",
|
|
|
|
tid, misc_reg / 8, misc_reg % 8, miscRegNames[misc_reg], val);
|
|
|
|
|
|
|
|
miscRegFile[misc_reg][reg_sel] = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-07-22 08:38:26 +02:00
|
|
|
ISA::setRegMask(int misc_reg, const MiscReg &val, ThreadID tid)
|
2009-07-09 08:02:20 +02:00
|
|
|
{
|
2009-07-10 05:28:39 +02:00
|
|
|
unsigned reg_sel = (bankType[misc_reg] == perThreadContext)
|
|
|
|
? tid : getVPENum(tid);
|
|
|
|
DPRINTF(MipsPRA,
|
|
|
|
"[tid:%i]: Setting CP0 Register: %u Select: %u (%s) to %#x\n",
|
|
|
|
tid, misc_reg / 8, misc_reg % 8, miscRegNames[misc_reg], val);
|
|
|
|
miscRegFile_WriteMask[misc_reg][reg_sel] = val;
|
2009-07-09 08:02:20 +02:00
|
|
|
}
|
|
|
|
|
2009-07-10 05:28:39 +02:00
|
|
|
// PROGRAMMER'S NOTES:
|
|
|
|
// (1) Some CP0 Registers have fields that cannot
|
|
|
|
// be overwritten. Make sure to handle those particular registers
|
|
|
|
// with care!
|
|
|
|
void
|
2009-07-22 08:38:26 +02:00
|
|
|
ISA::setMiscReg(int misc_reg, const MiscReg &val,
|
2009-07-10 05:28:39 +02:00
|
|
|
ThreadContext *tc, ThreadID tid)
|
|
|
|
{
|
|
|
|
int reg_sel = (bankType[misc_reg] == perThreadContext)
|
|
|
|
? tid : getVPENum(tid);
|
|
|
|
|
|
|
|
DPRINTF(MipsPRA,
|
|
|
|
"[tid:%i]: Setting CP0 Register:%u "
|
|
|
|
"Select:%u (%s) to %#x, with effect.\n",
|
|
|
|
tid, misc_reg / 8, misc_reg % 8, miscRegNames[misc_reg], val);
|
|
|
|
|
|
|
|
MiscReg cp0_val = filterCP0Write(misc_reg, reg_sel, val);
|
|
|
|
|
|
|
|
miscRegFile[misc_reg][reg_sel] = cp0_val;
|
|
|
|
|
2009-12-31 21:30:50 +01:00
|
|
|
scheduleCP0Update(tc->getCpuPtr(), 1);
|
2009-07-10 05:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method doesn't need to adjust the Control Register Offset
|
|
|
|
* since it has already been done in the calling method
|
|
|
|
* (setRegWithEffect)
|
|
|
|
*/
|
2009-07-09 08:02:20 +02:00
|
|
|
MiscReg
|
2009-07-10 05:28:39 +02:00
|
|
|
ISA::filterCP0Write(int misc_reg, int reg_sel, const MiscReg &val)
|
|
|
|
{
|
2009-07-21 10:08:53 +02:00
|
|
|
MiscReg retVal = val;
|
|
|
|
|
|
|
|
// Mask off read-only regions
|
|
|
|
retVal &= miscRegFile_WriteMask[misc_reg][reg_sel];
|
|
|
|
MiscReg curVal = miscRegFile[misc_reg][reg_sel];
|
|
|
|
// Mask off current alue with inverse mask (clear writeable bits)
|
|
|
|
curVal &= (~miscRegFile_WriteMask[misc_reg][reg_sel]);
|
|
|
|
retVal |= curVal; // Combine the two
|
|
|
|
DPRINTF(MipsPRA,
|
|
|
|
"filterCP0Write: Mask: %lx, Inverse Mask: %lx, write Val: %x, "
|
|
|
|
"current val: %lx, written val: %x\n",
|
|
|
|
miscRegFile_WriteMask[misc_reg][reg_sel],
|
|
|
|
~miscRegFile_WriteMask[misc_reg][reg_sel],
|
|
|
|
val, miscRegFile[misc_reg][reg_sel], retVal);
|
|
|
|
return retVal;
|
2009-07-10 05:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-12-31 21:30:50 +01:00
|
|
|
ISA::scheduleCP0Update(BaseCPU *cpu, int delay)
|
2009-07-09 08:02:20 +02:00
|
|
|
{
|
2009-07-10 05:28:39 +02:00
|
|
|
if (!cp0Updated) {
|
|
|
|
cp0Updated = true;
|
|
|
|
|
|
|
|
//schedule UPDATE
|
|
|
|
CP0Event *cp0_event = new CP0Event(this, cpu, UpdateCP0);
|
2011-01-08 06:50:29 +01:00
|
|
|
cpu->schedule(cp0_event, curTick() + cpu->ticks(delay));
|
2009-07-10 05:28:39 +02:00
|
|
|
}
|
2009-07-09 08:02:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-12-31 21:30:50 +01:00
|
|
|
ISA::updateCPU(BaseCPU *cpu)
|
2009-07-09 08:02:20 +02:00
|
|
|
{
|
2009-07-10 05:28:39 +02:00
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// EVALUATE CP0 STATE FOR MIPS MT
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////
|
2009-07-22 08:38:26 +02:00
|
|
|
MVPConf0Reg mvpConf0 = readMiscRegNoEffect(MISCREG_MVP_CONF0);
|
2009-07-21 05:14:15 +02:00
|
|
|
ThreadID num_threads = mvpConf0.ptc + 1;
|
2009-07-10 05:28:39 +02:00
|
|
|
|
|
|
|
for (ThreadID tid = 0; tid < num_threads; tid++) {
|
2009-07-22 08:38:26 +02:00
|
|
|
TCStatusReg tcStatus = readMiscRegNoEffect(MISCREG_TC_STATUS, tid);
|
|
|
|
TCHaltReg tcHalt = readMiscRegNoEffect(MISCREG_TC_HALT, tid);
|
2009-07-10 05:28:39 +02:00
|
|
|
|
|
|
|
//@todo: add vpe/mt check here thru mvpcontrol & vpecontrol regs
|
2009-07-21 05:14:15 +02:00
|
|
|
if (tcHalt.h == 1 || tcStatus.a == 0) {
|
2009-07-10 05:28:39 +02:00
|
|
|
haltThread(cpu->getContext(tid));
|
2009-07-21 05:14:15 +02:00
|
|
|
} else if (tcHalt.h == 0 && tcStatus.a == 1) {
|
2009-07-10 05:28:39 +02:00
|
|
|
restoreThread(cpu->getContext(tid));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-21 05:14:15 +02:00
|
|
|
num_threads = mvpConf0.ptc + 1;
|
2009-07-10 05:28:39 +02:00
|
|
|
|
|
|
|
// Toggle update flag after we finished updating
|
|
|
|
cp0Updated = false;
|
2009-07-09 08:02:20 +02:00
|
|
|
}
|
|
|
|
|
2009-07-10 05:28:39 +02:00
|
|
|
ISA::CP0Event::CP0Event(CP0 *_cp0, BaseCPU *_cpu, CP0EventType e_type)
|
|
|
|
: Event(CPU_Tick_Pri), cp0(_cp0), cpu(_cpu), cp0EventType(e_type)
|
|
|
|
{ }
|
|
|
|
|
2009-07-09 08:02:20 +02:00
|
|
|
void
|
2009-07-10 05:28:39 +02:00
|
|
|
ISA::CP0Event::process()
|
|
|
|
{
|
|
|
|
switch (cp0EventType)
|
|
|
|
{
|
|
|
|
case UpdateCP0:
|
2009-12-31 21:30:50 +01:00
|
|
|
cp0->updateCPU(cpu);
|
2009-07-10 05:28:39 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
ISA::CP0Event::description() const
|
2009-07-09 08:02:20 +02:00
|
|
|
{
|
2009-07-10 05:28:39 +02:00
|
|
|
return "Coprocessor-0 event";
|
2009-07-09 08:02:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-07-10 05:28:39 +02:00
|
|
|
ISA::CP0Event::scheduleEvent(int delay)
|
2009-07-09 08:02:20 +02:00
|
|
|
{
|
2011-01-08 06:50:29 +01:00
|
|
|
cpu->reschedule(this, curTick() + cpu->ticks(delay), true);
|
2009-07-09 08:02:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-07-10 05:28:39 +02:00
|
|
|
ISA::CP0Event::unscheduleEvent()
|
2009-07-09 08:02:20 +02:00
|
|
|
{
|
2009-07-10 05:28:39 +02:00
|
|
|
if (scheduled())
|
|
|
|
squash();
|
2009-07-09 08:02:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|