miscregfile.cc

来自「M5,一个功能强大的多处理器系统模拟器.很多针对处理器架构,性能的研究都使用它作」· CC 代码 · 共 744 行 · 第 1/2 页

CC
744
字号
/* * Copyright (c) 2003, 2004, 2005 * The Regents of The University of Michigan * All Rights Reserved * * This code is part of the M5 simulator. * * Permission is granted to use, copy, create derivative works and * redistribute this software and such derivative works for any * purpose, so long as the copyright notice above, this grant of * permission, and the disclaimer below appear in all copies made; and * so long as the name of The University of Michigan is not used in * any advertising or publicity pertaining to the use or distribution * of this software without specific, written prior authorization. * * THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION FROM THE * UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY PURPOSE, AND * WITHOUT WARRANTY BY THE UNIVERSITY OF MICHIGAN OF ANY KIND, EITHER * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE. THE REGENTS OF THE UNIVERSITY OF MICHIGAN SHALL NOT BE * LIABLE FOR ANY DAMAGES, INCLUDING DIRECT, SPECIAL, INDIRECT, * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WITH RESPECT TO ANY CLAIM * ARISING OUT OF OR IN CONNECTION WITH THE USE OF THE SOFTWARE, EVEN * IF IT HAS BEEN OR IS HEREAFTER ADVISED OF THE POSSIBILITY OF SUCH * DAMAGES. * * Authors: Gabe M. Black *          Ali G. Saidi */#include "arch/sparc/asi.hh"#include "arch/sparc/miscregfile.hh"#include "base/bitfield.hh"#include "base/trace.hh"#include "config/full_system.hh"#include "cpu/base.hh"#include "cpu/thread_context.hh"using namespace SparcISA;using namespace std;class Checkpoint;//These functions map register indices to namesstring SparcISA::getMiscRegName(RegIndex index){    static::string miscRegName[NumMiscRegs] =        {/*"y", "ccr",*/ "asi", "tick", "fprs", "pcr", "pic",         "gsr", "softint_set", "softint_clr", "softint", "tick_cmpr",         "stick", "stick_cmpr",         "tpc", "tnpc", "tstate", "tt", "privtick", "tba", "pstate", "tl",         "pil", "cwp", /*"cansave", "canrestore", "cleanwin", "otherwin",         "wstate",*/ "gl",         "hpstate", "htstate", "hintp", "htba", "hver", "strand_sts_reg",         "hstick_cmpr",         "fsr", "prictx", "secctx", "partId", "lsuCtrlReg",         "scratch0", "scratch1", "scratch2", "scratch3", "scratch4",         "scratch5", "scratch6", "scratch7", "cpuMondoHead", "cpuMondoTail",         "devMondoHead", "devMondoTail", "resErrorHead", "resErrorTail",         "nresErrorHead", "nresErrorTail", "TlbData" };    return miscRegName[index];}enum RegMask{        PSTATE_MASK = (((1 << 4) - 1) << 1) | (((1 << 4) - 1) << 6) | (1 << 12)};void MiscRegFile::clear(){    //y = 0;    //ccr = 0;    asi = 0;    tick = ULL(1) << 63;    fprs = 0;    gsr = 0;    softint = 0;    tick_cmpr = 0;    stick = 0;    stick_cmpr = 0;    memset(tpc, 0, sizeof(tpc));    memset(tnpc, 0, sizeof(tnpc));    memset(tstate, 0, sizeof(tstate));    memset(tt, 0, sizeof(tt));    pstate = 0;    tl = 0;    pil = 0;    cwp = 0;    //cansave = 0;    //canrestore = 0;    //cleanwin = 0;    //otherwin = 0;    //wstate = 0;    gl = 0;    //In a T1, bit 11 is apparently always 1    hpstate = (1 << 11);    memset(htstate, 0, sizeof(htstate));    hintp = 0;    htba = 0;    hstick_cmpr = 0;    //This is set this way in Legion for some reason    strandStatusReg = 0x50000;    fsr = 0;    priContext = 0;    secContext = 0;    partId = 0;    lsuCtrlReg = 0;    memset(scratchPad, 0, sizeof(scratchPad));#if FULL_SYSTEM    tickCompare = NULL;    sTickCompare = NULL;    hSTickCompare = NULL;#endif}MiscReg MiscRegFile::readRegNoEffect(int miscReg){  // The three miscRegs are moved up from the switch statement  // due to more frequent calls.  if (miscReg == MISCREG_GL)    return gl;  if (miscReg == MISCREG_CWP)    return cwp;  if (miscReg == MISCREG_TLB_DATA) {    /* Package up all the data for the tlb:     * 6666555555555544444444443333333333222222222211111111110000000000     * 3210987654321098765432109876543210987654321098765432109876543210     *   secContext   | priContext    |             |tl|partid|  |||||^hpriv     *                                                           ||||^red     *                                                           |||^priv     *                                                           ||^am     *                                                           |^lsuim     *                                                           ^lsudm     */    return bits((uint64_t)hpstate,2,2) |           bits((uint64_t)hpstate,5,5) << 1 |           bits((uint64_t)pstate,3,2) << 2 |           bits((uint64_t)lsuCtrlReg,3,2) << 4 |           bits((uint64_t)partId,7,0) << 8 |           bits((uint64_t)tl,2,0) << 16 |                (uint64_t)priContext << 32 |                (uint64_t)secContext << 48;  }    switch (miscReg) {      //case MISCREG_TLB_DATA:      //  [original contents see above]      //case MISCREG_Y:      //  return y;      //case MISCREG_CCR:      //  return ccr;      case MISCREG_ASI:        return asi;      case MISCREG_FPRS:        return fprs;      case MISCREG_TICK:        return tick;      case MISCREG_PCR:        panic("PCR not implemented\n");      case MISCREG_PIC:        panic("PIC not implemented\n");      case MISCREG_GSR:        return gsr;      case MISCREG_SOFTINT:        return softint;      case MISCREG_TICK_CMPR:        return tick_cmpr;      case MISCREG_STICK:        return stick;      case MISCREG_STICK_CMPR:        return stick_cmpr;        /** Privilged Registers */      case MISCREG_TPC:        return tpc[tl-1];      case MISCREG_TNPC:        return tnpc[tl-1];      case MISCREG_TSTATE:        return tstate[tl-1];      case MISCREG_TT:        return tt[tl-1];      case MISCREG_PRIVTICK:        panic("Priviliged access to tick registers not implemented\n");      case MISCREG_TBA:        return tba;      case MISCREG_PSTATE:        return pstate;      case MISCREG_TL:        return tl;      case MISCREG_PIL:        return pil;      //CWP, GL moved      //case MISCREG_CWP:      //  return cwp;      //case MISCREG_CANSAVE:      //  return cansave;      //case MISCREG_CANRESTORE:      //  return canrestore;      //case MISCREG_CLEANWIN:      //  return cleanwin;      //case MISCREG_OTHERWIN:      //  return otherwin;      //case MISCREG_WSTATE:      //  return wstate;      //case MISCREG_GL:      //  return gl;        /** Hyper privileged registers */      case MISCREG_HPSTATE:        return hpstate;      case MISCREG_HTSTATE:        return htstate[tl-1];      case MISCREG_HINTP:        return hintp;      case MISCREG_HTBA:        return htba;      case MISCREG_STRAND_STS_REG:        return strandStatusReg;      case MISCREG_HSTICK_CMPR:        return hstick_cmpr;        /** Floating Point Status Register */      case MISCREG_FSR:        DPRINTF(Sparc, "FSR read as: %#x\n", fsr);        return fsr;      case MISCREG_MMU_P_CONTEXT:        return priContext;      case MISCREG_MMU_S_CONTEXT:        return secContext;      case MISCREG_MMU_PART_ID:        return partId;      case MISCREG_MMU_LSU_CTRL:        return lsuCtrlReg;      case MISCREG_SCRATCHPAD_R0:        return scratchPad[0];      case MISCREG_SCRATCHPAD_R1:        return scratchPad[1];      case MISCREG_SCRATCHPAD_R2:        return scratchPad[2];      case MISCREG_SCRATCHPAD_R3:        return scratchPad[3];      case MISCREG_SCRATCHPAD_R4:        return scratchPad[4];      case MISCREG_SCRATCHPAD_R5:        return scratchPad[5];      case MISCREG_SCRATCHPAD_R6:        return scratchPad[6];      case MISCREG_SCRATCHPAD_R7:        return scratchPad[7];      case MISCREG_QUEUE_CPU_MONDO_HEAD:        return cpu_mondo_head;      case MISCREG_QUEUE_CPU_MONDO_TAIL:        return cpu_mondo_tail;      case MISCREG_QUEUE_DEV_MONDO_HEAD:        return dev_mondo_head;      case MISCREG_QUEUE_DEV_MONDO_TAIL:        return dev_mondo_tail;      case MISCREG_QUEUE_RES_ERROR_HEAD:        return res_error_head;      case MISCREG_QUEUE_RES_ERROR_TAIL:        return res_error_tail;      case MISCREG_QUEUE_NRES_ERROR_HEAD:        return nres_error_head;      case MISCREG_QUEUE_NRES_ERROR_TAIL:        return nres_error_tail;      default:        panic("Miscellaneous register %d not implemented\n", miscReg);    }}MiscReg MiscRegFile::readReg(int miscReg, ThreadContext * tc){    switch (miscReg) {        // tick and stick are aliased to each other in niagra        // well store the tick data in stick and the interrupt bit in tick      case MISCREG_STICK:      case MISCREG_TICK:      case MISCREG_PRIVTICK:        // I'm not sure why legion ignores the lowest two bits, but we'll go        // with it        // change from curCycle() to instCount() until we're done with legion        DPRINTF(Timer, "Instruction Count when TICK read: %#X stick=%#X\n",                tc->getCpuPtr()->instCount(), stick);        return mbits(tc->getCpuPtr()->instCount() + (int64_t)stick,62,2) |               mbits(tick,63,63);      case MISCREG_FPRS:        // in legion if fp is enabled du and dl are set        return fprs | 0x3;      case MISCREG_PCR:      case MISCREG_PIC:        panic("Performance Instrumentation not impl\n");      case MISCREG_SOFTINT_CLR:      case MISCREG_SOFTINT_SET:        panic("Can read from softint clr/set\n");      case MISCREG_SOFTINT:      case MISCREG_TICK_CMPR:      case MISCREG_STICK_CMPR:      case MISCREG_HINTP:      case MISCREG_HTSTATE:      case MISCREG_HTBA:      case MISCREG_HVER:      case MISCREG_STRAND_STS_REG:      case MISCREG_HSTICK_CMPR:      case MISCREG_QUEUE_CPU_MONDO_HEAD:      case MISCREG_QUEUE_CPU_MONDO_TAIL:      case MISCREG_QUEUE_DEV_MONDO_HEAD:      case MISCREG_QUEUE_DEV_MONDO_TAIL:      case MISCREG_QUEUE_RES_ERROR_HEAD:      case MISCREG_QUEUE_RES_ERROR_TAIL:      case MISCREG_QUEUE_NRES_ERROR_HEAD:      case MISCREG_QUEUE_NRES_ERROR_TAIL:#if FULL_SYSTEM      case MISCREG_HPSTATE:        return readFSReg(miscReg, tc);#else      case MISCREG_HPSTATE:        //HPSTATE is special because because sometimes in privilege checks for instructions        //it will read HPSTATE to make sure the priv. level is ok        //So, we'll just have to tell it it isn't, instead of panicing.        return 0;      panic("Accessing Fullsystem register %s in SE mode\n",getMiscRegName(miscReg));#endif    }    return readRegNoEffect(miscReg);}void MiscRegFile::setRegNoEffect(int miscReg, const MiscReg &val){    switch (miscReg) {//      case MISCREG_Y://        y = val;//        break;//      case MISCREG_CCR://        ccr = val;//        break;      case MISCREG_ASI:        asi = val;        break;      case MISCREG_FPRS:        fprs = val;        break;      case MISCREG_TICK:        tick = val;        break;      case MISCREG_PCR:        panic("PCR not implemented\n");      case MISCREG_PIC:        panic("PIC not implemented\n");      case MISCREG_GSR:        gsr = val;        break;      case MISCREG_SOFTINT:        softint = val;        break;      case MISCREG_TICK_CMPR:        tick_cmpr = val;        break;      case MISCREG_STICK:        stick = val;        break;      case MISCREG_STICK_CMPR:        stick_cmpr = val;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?