mt.hh revision 6376
14661Sksewell@umich.edu/* 25268Sksewell@umich.edu * Copyright (c) 2007 MIPS Technologies, Inc. 35268Sksewell@umich.edu * All rights reserved. 44661Sksewell@umich.edu * 55268Sksewell@umich.edu * Redistribution and use in source and binary forms, with or without 65268Sksewell@umich.edu * modification, are permitted provided that the following conditions are 75268Sksewell@umich.edu * met: redistributions of source code must retain the above copyright 85268Sksewell@umich.edu * notice, this list of conditions and the following disclaimer; 95268Sksewell@umich.edu * redistributions in binary form must reproduce the above copyright 105268Sksewell@umich.edu * notice, this list of conditions and the following disclaimer in the 115268Sksewell@umich.edu * documentation and/or other materials provided with the distribution; 125268Sksewell@umich.edu * neither the name of the copyright holders nor the names of its 135268Sksewell@umich.edu * contributors may be used to endorse or promote products derived from 145268Sksewell@umich.edu * this software without specific prior written permission. 154661Sksewell@umich.edu * 165268Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 175268Sksewell@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 185268Sksewell@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 195268Sksewell@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 205268Sksewell@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 215268Sksewell@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 225268Sksewell@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 235268Sksewell@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 245268Sksewell@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 255268Sksewell@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 265268Sksewell@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 275222Sksewell@umich.edu * 285254Sksewell@umich.edu * Authors: Korey Sewell 294661Sksewell@umich.edu */ 304661Sksewell@umich.edu 314661Sksewell@umich.edu#ifndef __ARCH_MIPS_MT_HH__ 324661Sksewell@umich.edu#define __ARCH_MIPS_MT_HH__ 334661Sksewell@umich.edu 344661Sksewell@umich.edu/** 354661Sksewell@umich.edu * @file 364661Sksewell@umich.edu * 374661Sksewell@umich.edu * ISA-specific helper functions for multithreaded execution. 384661Sksewell@umich.edu */ 394661Sksewell@umich.edu 404661Sksewell@umich.edu#include "arch/mips/faults.hh" 416329Sgblack@eecs.umich.edu#include "arch/mips/isa_traits.hh" 424661Sksewell@umich.edu#include "arch/mips/mt_constants.hh" 436376Sgblack@eecs.umich.edu#include "arch/mips/pra_constants.hh" 446329Sgblack@eecs.umich.edu#include "arch/mips/registers.hh" 454661Sksewell@umich.edu#include "base/bitfield.hh" 464661Sksewell@umich.edu#include "base/trace.hh" 474661Sksewell@umich.edu#include "base/misc.hh" 484661Sksewell@umich.edu 494661Sksewell@umich.edu#include <iostream> 504661Sksewell@umich.edu 514661Sksewell@umich.edunamespace MipsISA 524661Sksewell@umich.edu{ 534661Sksewell@umich.edu 544661Sksewell@umich.edu 554661Sksewell@umich.edutemplate <class TC> 564661Sksewell@umich.eduinline unsigned 574661Sksewell@umich.edugetVirtProcNum(TC *tc) 584661Sksewell@umich.edu{ 596376Sgblack@eecs.umich.edu TCBindReg tcbind = tc->readMiscRegNoEffect(TCBind); 606376Sgblack@eecs.umich.edu return tcbind.curVPE; 614661Sksewell@umich.edu} 624661Sksewell@umich.edu 634661Sksewell@umich.edutemplate <class TC> 644661Sksewell@umich.eduinline unsigned 654661Sksewell@umich.edugetTargetThread(TC *tc) 664661Sksewell@umich.edu{ 676376Sgblack@eecs.umich.edu VPEControlReg vpeCtrl = tc->readMiscRegNoEffect(VPEControl); 686376Sgblack@eecs.umich.edu return vpeCtrl.targTC; 694661Sksewell@umich.edu} 704661Sksewell@umich.edu 714661Sksewell@umich.edutemplate <class TC> 724661Sksewell@umich.eduinline void 734661Sksewell@umich.eduhaltThread(TC *tc) 744661Sksewell@umich.edu{ 754661Sksewell@umich.edu if (tc->status() == TC::Active) { 764661Sksewell@umich.edu tc->halt(); 774661Sksewell@umich.edu 784661Sksewell@umich.edu // Save last known PC in TCRestart 794661Sksewell@umich.edu // @TODO: Needs to check if this is a branch and if so, take previous instruction 804661Sksewell@umich.edu tc->setMiscReg(TCRestart, tc->readNextPC()); 814661Sksewell@umich.edu 825715Shsul@eecs.umich.edu warn("%i: Halting thread %i in %s @ PC %x, setting restart PC to %x", curTick, tc->threadId(), tc->getCpuPtr()->name(), 834661Sksewell@umich.edu tc->readPC(), tc->readNextPC()); 844661Sksewell@umich.edu } 854661Sksewell@umich.edu} 864661Sksewell@umich.edu 874661Sksewell@umich.edutemplate <class TC> 884661Sksewell@umich.eduinline void 894661Sksewell@umich.edurestoreThread(TC *tc) 904661Sksewell@umich.edu{ 914661Sksewell@umich.edu if (tc->status() != TC::Active) { 924661Sksewell@umich.edu // Restore PC from TCRestart 934661Sksewell@umich.edu IntReg pc = tc->readMiscRegNoEffect(TCRestart); 944661Sksewell@umich.edu 954661Sksewell@umich.edu // TODO: SET PC WITH AN EVENT INSTEAD OF INSTANTANEOUSLY 964661Sksewell@umich.edu // tc->setPCEvent(pc, pc + 4, pc + 8); 974661Sksewell@umich.edu tc->setPC(pc); 984661Sksewell@umich.edu tc->setNextPC(pc + 4); 994661Sksewell@umich.edu tc->setNextNPC(pc + 8); 1004661Sksewell@umich.edu tc->activate(0); 1014661Sksewell@umich.edu 1025715Shsul@eecs.umich.edu warn("%i: Restoring thread %i in %s @ PC %x", curTick, tc->threadId(), tc->getCpuPtr()->name(), 1034661Sksewell@umich.edu tc->readPC()); 1044661Sksewell@umich.edu } 1054661Sksewell@umich.edu} 1064661Sksewell@umich.edu 1074661Sksewell@umich.edutemplate <class TC> 1084661Sksewell@umich.eduvoid 1094661Sksewell@umich.eduforkThread(TC *tc, Fault &fault, int Rd_bits, int Rs, int Rt) 1104661Sksewell@umich.edu{ 1116376Sgblack@eecs.umich.edu MVPConf0Reg mvpConf = tc->readMiscRegNoEffect(MVPConf0); 1126376Sgblack@eecs.umich.edu int num_threads = mvpConf.ptc + 1; 1134661Sksewell@umich.edu 1144661Sksewell@umich.edu int success = 0; 1156221Snate@binkert.org for (ThreadID tid = 0; tid < num_threads && success == 0; tid++) { 1166376Sgblack@eecs.umich.edu TCBindReg tidTCBind = 1176376Sgblack@eecs.umich.edu tc->readRegOtherThread(TCBind + Ctrl_Base_DepTag, tid); 1186376Sgblack@eecs.umich.edu TCBindReg tcBind = tc->readMiscRegNoEffect(TCBind); 1194661Sksewell@umich.edu 1206376Sgblack@eecs.umich.edu if (tidTCBind.curVPE = tcBind.curVPE) { 1214661Sksewell@umich.edu 1226376Sgblack@eecs.umich.edu TCStatusReg tidTCStatus = 1236376Sgblack@eecs.umich.edu tc->readRegOtherThread(TCStatus + Ctrl_Base_DepTag,tid); 1244661Sksewell@umich.edu 1256376Sgblack@eecs.umich.edu TCHaltReg tidTCHalt = 1266376Sgblack@eecs.umich.edu tc->readRegOtherThread(TCHalt + Ctrl_Base_DepTag,tid); 1274661Sksewell@umich.edu 1286376Sgblack@eecs.umich.edu if (tidTCStatus.da == 1 && tidTCHalt.h == 0 && 1296376Sgblack@eecs.umich.edu tidTCStatus.a == 0 && success == 0) { 1304661Sksewell@umich.edu 1316376Sgblack@eecs.umich.edu tc->setRegOtherThread(TCRestart + Ctrl_Base_DepTag, Rs, tid); 1324661Sksewell@umich.edu tc->setRegOtherThread(Rd_bits, Rt, tid); 1334661Sksewell@umich.edu 1346376Sgblack@eecs.umich.edu StatusReg status = tc->readMiscReg(Status); 1356376Sgblack@eecs.umich.edu TCStatusReg tcStatus = tc->readMiscReg(TCStatus); 1364661Sksewell@umich.edu 1374661Sksewell@umich.edu // Set Run-State to Running 1386376Sgblack@eecs.umich.edu tidTCStatus.rnst = 0; 1394661Sksewell@umich.edu // Set Delay-Slot to 0 1406376Sgblack@eecs.umich.edu tidTCStatus.tds = 0; 1414661Sksewell@umich.edu // Set Dirty TC to 1 1426376Sgblack@eecs.umich.edu tidTCStatus.dt = 1; 1434661Sksewell@umich.edu // Set Activated to 1 1446376Sgblack@eecs.umich.edu tidTCStatus.a = 1; 1454661Sksewell@umich.edu // Set status to previous thread's status 1466376Sgblack@eecs.umich.edu tidTCStatus.tksu = status.ksu; 1474661Sksewell@umich.edu // Set ASID to previous thread's state 1486376Sgblack@eecs.umich.edu tidTCStatus.asid = tcStatus.asid; 1494661Sksewell@umich.edu 1504661Sksewell@umich.edu // Write Status Register 1516376Sgblack@eecs.umich.edu tc->setRegOtherThread(TCStatus + Ctrl_Base_DepTag, 1526376Sgblack@eecs.umich.edu tidTCStatus, tid); 1534661Sksewell@umich.edu 1544661Sksewell@umich.edu // Mark As Successful Fork 1554661Sksewell@umich.edu success = 1; 1564661Sksewell@umich.edu } 1574661Sksewell@umich.edu } else { 1585991Ssteve.reinhardt@amd.com std::cerr << "Bad VPEs" << std::endl; 1594661Sksewell@umich.edu } 1604661Sksewell@umich.edu } 1614661Sksewell@umich.edu 1624661Sksewell@umich.edu if (success == 0) { 1636376Sgblack@eecs.umich.edu VPEControlReg vpeControl = tc->readMiscRegNoEffect(VPEControl); 1646376Sgblack@eecs.umich.edu vpeControl.excpt = 1; 1656376Sgblack@eecs.umich.edu tc->setMiscReg(VPEControl, vpeControl); 1664661Sksewell@umich.edu fault = new ThreadFault(); 1674661Sksewell@umich.edu } 1684661Sksewell@umich.edu} 1694661Sksewell@umich.edu 1704661Sksewell@umich.edu 1714661Sksewell@umich.edutemplate <class TC> 1724661Sksewell@umich.eduint 1734661Sksewell@umich.eduyieldThread(TC *tc, Fault &fault, int src_reg, uint32_t yield_mask) 1744661Sksewell@umich.edu{ 1754661Sksewell@umich.edu if (src_reg == 0) { 1766376Sgblack@eecs.umich.edu MVPConf0Reg mvpConf0 = tc->readMiscRegNoEffect(MVPConf0); 1776376Sgblack@eecs.umich.edu ThreadID num_threads = mvpConf0.ptc + 1; 1784661Sksewell@umich.edu 1794661Sksewell@umich.edu int ok = 0; 1804661Sksewell@umich.edu 1814661Sksewell@umich.edu // Get Current VPE & TC numbers from calling thread 1826376Sgblack@eecs.umich.edu TCBindReg tcBind = tc->readMiscRegNoEffect(TCBind); 1834661Sksewell@umich.edu 1846221Snate@binkert.org for (ThreadID tid = 0; tid < num_threads; tid++) { 1856376Sgblack@eecs.umich.edu TCStatusReg tidTCStatus = 1866376Sgblack@eecs.umich.edu tc->readRegOtherThread(TCStatus + Ctrl_Base_DepTag, tid); 1876376Sgblack@eecs.umich.edu TCHaltReg tidTCHalt = 1886376Sgblack@eecs.umich.edu tc->readRegOtherThread(TCHalt + Ctrl_Base_DepTag, tid); 1896376Sgblack@eecs.umich.edu TCBindReg tidTCBind = 1906376Sgblack@eecs.umich.edu tc->readRegOtherThread(TCBind + Ctrl_Base_DepTag, tid); 1914661Sksewell@umich.edu 1926376Sgblack@eecs.umich.edu if (tidTCBind.curVPE == tcBind.curVPE && 1936376Sgblack@eecs.umich.edu tidTCBind.curTC == tcBind.curTC && 1946376Sgblack@eecs.umich.edu tidTCStatus.da == 1 && 1956376Sgblack@eecs.umich.edu tidTCHalt.h == 0 && 1966376Sgblack@eecs.umich.edu tidTCStatus.a == 1) { 1974661Sksewell@umich.edu ok = 1; 1984661Sksewell@umich.edu } 1994661Sksewell@umich.edu } 2004661Sksewell@umich.edu 2014661Sksewell@umich.edu if (ok == 1) { 2026376Sgblack@eecs.umich.edu TCStatusReg tcStatus = tc->readMiscRegNoEffect(TCStatus); 2036376Sgblack@eecs.umich.edu tcStatus.a = 0; 2046376Sgblack@eecs.umich.edu tc->setMiscReg(TCStatus, tcStatus); 2056376Sgblack@eecs.umich.edu warn("%i: Deactivating Hardware Thread Context #%i", 2066376Sgblack@eecs.umich.edu curTick, tc->threadId()); 2074661Sksewell@umich.edu } 2084661Sksewell@umich.edu } else if (src_reg > 0) { 2095561Snate@binkert.org if (src_reg && !yield_mask != 0) { 2106376Sgblack@eecs.umich.edu VPEControlReg vpeControl = tc->readMiscReg(VPEControl); 2116376Sgblack@eecs.umich.edu vpeControl.excpt = 2; 2126376Sgblack@eecs.umich.edu tc->setMiscReg(VPEControl, vpeControl); 2134661Sksewell@umich.edu fault = new ThreadFault(); 2144661Sksewell@umich.edu } else { 2154661Sksewell@umich.edu } 2164661Sksewell@umich.edu } else if (src_reg != -2) { 2176376Sgblack@eecs.umich.edu TCStatusReg tcStatus = tc->readMiscRegNoEffect(TCStatus); 2186376Sgblack@eecs.umich.edu VPEControlReg vpeControl = tc->readMiscRegNoEffect(VPEControl); 2194661Sksewell@umich.edu 2206376Sgblack@eecs.umich.edu if (vpeControl.ysi == 1 && tcStatus.dt == 1 ) { 2216376Sgblack@eecs.umich.edu vpeControl.excpt = 4; 2224661Sksewell@umich.edu fault = new ThreadFault(); 2234661Sksewell@umich.edu } else { 2244661Sksewell@umich.edu } 2254661Sksewell@umich.edu } 2264661Sksewell@umich.edu 2274661Sksewell@umich.edu return src_reg & yield_mask; 2284661Sksewell@umich.edu} 2294661Sksewell@umich.edu 2304661Sksewell@umich.edu 2314661Sksewell@umich.edu// TC will usually be a object derived from ThreadContext 2324661Sksewell@umich.edu// (src/cpu/thread_context.hh) 2334661Sksewell@umich.edutemplate <class TC> 2344661Sksewell@umich.eduinline void 2354661Sksewell@umich.eduupdateStatusView(TC *tc) 2364661Sksewell@umich.edu{ 2374661Sksewell@umich.edu // TCStatus' register view must be the same as 2384661Sksewell@umich.edu // Status register view for CU, MX, KSU bits 2396376Sgblack@eecs.umich.edu TCStatusReg tcStatus = tc->readMiscRegNoEffect(TCStatus); 2406376Sgblack@eecs.umich.edu StatusReg status = tc->readMiscRegNoEffect(Status); 2414661Sksewell@umich.edu 2426376Sgblack@eecs.umich.edu status.cu = tcStatus.tcu; 2436376Sgblack@eecs.umich.edu status.mx = tcStatus.tmx; 2446376Sgblack@eecs.umich.edu status.ksu = tcStatus.tksu; 2454661Sksewell@umich.edu 2464661Sksewell@umich.edu tc->setMiscRegNoEffect(Status, status); 2474661Sksewell@umich.edu} 2484661Sksewell@umich.edu 2494661Sksewell@umich.edu// TC will usually be a object derived from ThreadContext 2504661Sksewell@umich.edu// (src/cpu/thread_context.hh) 2514661Sksewell@umich.edutemplate <class TC> 2524661Sksewell@umich.eduinline void 2534661Sksewell@umich.eduupdateTCStatusView(TC *tc) 2544661Sksewell@umich.edu{ 2554661Sksewell@umich.edu // TCStatus' register view must be the same as 2564661Sksewell@umich.edu // Status register view for CU, MX, KSU bits 2576376Sgblack@eecs.umich.edu TCStatusReg tcStatus = tc->readMiscRegNoEffect(TCStatus); 2586376Sgblack@eecs.umich.edu StatusReg status = tc->readMiscRegNoEffect(Status); 2594661Sksewell@umich.edu 2606376Sgblack@eecs.umich.edu tcStatus.tcu = status.cu; 2616376Sgblack@eecs.umich.edu tcStatus.tmx = status.mx; 2626376Sgblack@eecs.umich.edu tcStatus.tksu = status.ksu; 2634661Sksewell@umich.edu 2646376Sgblack@eecs.umich.edu tc->setMiscRegNoEffect(TCStatus, tcStatus); 2654661Sksewell@umich.edu} 2664661Sksewell@umich.edu 2674661Sksewell@umich.edu} // namespace MipsISA 2684661Sksewell@umich.edu 2694661Sksewell@umich.edu 2704661Sksewell@umich.edu#endif 271