punk@33: /// The MIT License punk@33: punk@33: // Copyright (c) 2009 Massachusetts Institute of Technology punk@33: punk@33: // Permission is hereby granted, free of charge, to any person obtaining a copy punk@33: // of this software and associated documentation files (the "Software"), to deal punk@33: // in the Software without restriction, including without limitation the rights punk@33: // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell punk@33: // copies of the Software, and to permit persons to whom the Software is punk@33: // furnished to do so, subject to the following conditions: punk@33: punk@33: // The above copyright notice and this permission notice shall be included in punk@33: // all copies or substantial portions of the Software. punk@33: punk@33: // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR punk@33: // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, punk@33: // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE punk@33: // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER punk@33: // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, punk@33: // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN punk@33: // THE SOFTWARE. punk@33: punk@33: import Connectable::*; punk@33: import GetPut::*; punk@33: import ClientServer::*; punk@33: import RegFile::*; punk@33: punk@33: import FIFO::*; punk@33: import FIFOF::*; punk@33: import SFIFO::*; punk@33: import RWire::*; punk@33: punk@33: import BFIFO::*; punk@33: import MemTypes::*; punk@33: import ProcTypes::*; punk@33: import BRegFile::*; punk@33: import BranchPred::*; punk@33: //import PathTypes::*; This is only there to force the debugging punk@33: punk@33: import Trace::*; punk@33: punk@33: //AWB includes punk@33: `include "asim/provides/low_level_platform_interface.bsh" punk@33: `include "asim/provides/soft_connections.bsh" punk@33: `include "asim/provides/common_services.bsh" punk@33: punk@33: // Local includes punk@33: `include "asim/provides/processor_library.bsh" punk@33: `include "asim/rrr/remote_server_stub_PROCESSORSYSTEMRRR.bsh" punk@33: `include "asim/provides/common_services.bsh" punk@33: `include "asim/dict/STATS_PROCESSOR.bsh" punk@33: punk@33: interface ProcStats; punk@33: interface Get#(Stat) num_cycles; punk@33: interface Get#(Stat) num_inst; punk@33: endinterface punk@33: punk@33: interface CPUToHost; punk@33: method Bit#(32) cpuToHost(int req); punk@33: endinterface punk@33: punk@33: interface Proc; punk@33: punk@33: // Interface from processor to caches punk@33: interface Client#(DataReq,DataResp) dmem_client; punk@33: interface Client#(InstReq,InstResp) imem_client; punk@33: punk@33: // Interface for enabling/disabling statistics on the rest of the core punk@33: interface Get#(Bool) statsEn_get; punk@33: punk@33: // Interface for collecting statistics. punk@33: interface ProcStats stats; punk@33: punk@33: // Interface to host punk@33: interface CPUToHost tohost; punk@33: punk@33: endinterface punk@33: punk@33: punk@33: typedef enum { PCgen, Exec, Writeback } Stage deriving(Eq,Bits); punk@33: punk@33: //----------------------------------------------------------- punk@33: // Register file module punk@33: //----------------------------------------------------------- punk@33: punk@33: interface BRFile; punk@33: method Action wr( Rindx rindx, Bit#(32) data ); punk@33: method Bit#(32) rd1( Rindx rindx ); punk@33: method Bit#(32) rd2( Rindx rindx ); punk@33: endinterface punk@33: punk@33: module mkBRFile( BRFile ); punk@33: punk@33: RegFile#(Rindx,Bit#(32)) rfile <- mkBRegFile(); punk@33: punk@33: method Action wr( Rindx rindx, Bit#(32) data ); punk@33: rfile.upd( rindx, data ); punk@33: endmethod punk@33: punk@33: method Bit#(32) rd1( Rindx rindx ); punk@33: return ( rindx == 0 ) ? 0 : rfile.sub(rindx); punk@33: endmethod punk@33: punk@33: method Bit#(32) rd2( Rindx rindx ); punk@33: return ( rindx == 0 ) ? 0 : rfile.sub(rindx); punk@33: endmethod punk@33: punk@33: endmodule punk@33: punk@33: //----------------------------------------------------------- punk@33: // Helper functions punk@33: //----------------------------------------------------------- punk@33: punk@33: function Bit#(32) slt( Bit#(32) val1, Bit#(32) val2 ); punk@33: return zeroExtend( pack( signedLT(val1,val2) ) ); punk@33: endfunction punk@33: punk@33: function Bit#(32) sltu( Bit#(32) val1, Bit#(32) val2 ); punk@33: return zeroExtend( pack( val1 < val2 ) ); punk@33: endfunction punk@33: punk@33: function Bit#(32) rshft( Bit#(32) val ); punk@33: return zeroExtend(val[4:0]); punk@33: endfunction punk@33: punk@33: punk@33: //----------------------------------------------------------- punk@33: // Find funct for wbQ punk@33: //----------------------------------------------------------- punk@33: function Bool findwbf(Rindx fVal, WBResult cmpVal); punk@33: case (cmpVal) matches punk@33: tagged WB_ALU {data:.res, dest:.rd} : punk@33: return (fVal == rd); punk@33: tagged WB_Load .rd : punk@33: return (fVal == rd); punk@33: tagged WB_Store .st : punk@33: return False; punk@33: tagged WB_Host .x : punk@33: return False; punk@33: endcase punk@33: endfunction punk@33: punk@33: punk@33: //----------------------------------------------------------- punk@33: // Stall funct for wbQ punk@33: //----------------------------------------------------------- punk@33: function Bool stall(Instr inst, SFIFO#(WBResult, Rindx) f); punk@33: case (inst) matches punk@33: // -- Memory Ops ------------------------------------------------ punk@33: tagged LW .it : punk@33: return f.find(it.rbase); punk@33: tagged SW {rsrc:.dreg, rbase:.addr, offset:.o} : punk@33: return (f.find(addr) || f.find2(dreg)); punk@33: punk@33: // -- Simple Ops ------------------------------------------------ punk@33: tagged ADDIU .it : return f.find(it.rsrc); punk@33: tagged SLTI .it : return f.find(it.rsrc); punk@33: tagged SLTIU .it : return f.find(it.rsrc); punk@33: tagged ANDI .it : return f.find(it.rsrc); punk@33: tagged ORI .it : return f.find(it.rsrc); punk@33: tagged XORI .it : return f.find(it.rsrc); punk@33: punk@33: tagged LUI .it : return f.find(it.rdst); //this rds/wrs itself punk@33: tagged SLL .it : return f.find(it.rsrc); punk@33: tagged SRL .it : return f.find(it.rsrc); punk@33: tagged SRA .it : return f.find(it.rsrc); punk@33: tagged SLLV .it : return (f.find(it.rsrc) || f.find(it.rshamt)); punk@33: tagged SRLV .it : return (f.find(it.rsrc) || f.find(it.rshamt)); punk@33: tagged SRAV .it : return (f.find(it.rsrc) || f.find(it.rshamt)); punk@33: tagged ADDU .it : return (f.find(it.rsrc1) || f.find2(it.rsrc2)); punk@33: tagged SUBU .it : return (f.find(it.rsrc1) || f.find2(it.rsrc2)); punk@33: tagged AND .it : return (f.find(it.rsrc1) || f.find2(it.rsrc2)); punk@33: tagged OR .it : return (f.find(it.rsrc1) || f.find2(it.rsrc2)); punk@33: tagged XOR .it : return (f.find(it.rsrc1) || f.find2(it.rsrc2)); punk@33: tagged NOR .it : return (f.find(it.rsrc1) || f.find2(it.rsrc2)); punk@33: tagged SLT .it : return (f.find(it.rsrc1) || f.find2(it.rsrc2)); punk@33: tagged SLTU .it : return (f.find(it.rsrc1) || f.find2(it.rsrc2)); punk@33: punk@33: punk@33: // -- Branches -------------------------------------------------- punk@33: punk@33: tagged BLEZ .it : return (f.find(it.rsrc)); punk@33: tagged BGTZ .it : return (f.find(it.rsrc)); punk@33: tagged BLTZ .it : return (f.find(it.rsrc)); punk@33: tagged BGEZ .it : return (f.find(it.rsrc)); punk@33: tagged BEQ .it : return (f.find(it.rsrc1) || f.find2(it.rsrc2)); punk@33: tagged BNE .it : return (f.find(it.rsrc1) || f.find2(it.rsrc2)); punk@33: punk@33: // -- Jumps ----------------------------------------------------- punk@33: punk@33: tagged J .it : return False; punk@33: tagged JR .it : return f.find(it.rsrc); punk@33: tagged JALR .it : return f.find(it.rsrc); punk@33: tagged JAL .it : return False; punk@33: punk@33: // -- Cop0 ------------------------------------------------------ punk@33: punk@33: tagged MTC0 .it : return f.find(it.rsrc); punk@33: tagged MFC0 .it : return False; punk@33: punk@33: // -- Illegal --------------------------------------------------- punk@33: punk@33: default : return False; punk@33: punk@33: endcase punk@33: endfunction punk@33: //----------------------------------------------------------- punk@33: // Reference processor punk@33: //----------------------------------------------------------- punk@33: punk@33: punk@33: //(* doc = "synthesis attribute ram_style mkProc distributed;" *) punk@33: //(* synthesize *) punk@33: punk@33: module [CONNECTED_MODULE] mkProc( Proc ); punk@33: punk@33: //----------------------------------------------------------- punk@33: // Debug port punk@33: punk@33: ServerStub_PROCESSORSYSTEMRRR server_stub <- mkServerStub_PROCESSORSYSTEMRRR(); punk@33: punk@33: punk@33: //----------------------------------------------------------- punk@33: // State punk@33: punk@33: // Standard processor state punk@33: punk@33: Reg#(Addr) pc <- mkReg(32'h00001000); punk@33: Reg#(Epoch) epoch <- mkReg(0); punk@33: Reg#(Stage) stage <- mkReg(PCgen); punk@33: BRFile rf <- mkBRFile; punk@33: punk@33: // Branch Prediction punk@33: BranchPred bp <- mkBranchPred(); punk@33: FIFO#(PCStat) execpc <- mkLFIFO(); punk@33: punk@33: // Pipelines punk@33: FIFO#(PCStat) pcQ <-mkSizedFIFO(3); punk@33: SFIFO#(WBResult, Rindx) wbQ <-mkSFIFO(findwbf); punk@33: punk@33: Reg#(Bit#(32)) cp0_tohost <- mkReg(0); punk@33: Reg#(Bit#(32)) cp0_fromhost <- mkReg(0); punk@33: Reg#(Bool) cp0_statsEn <- mkReg(False); punk@33: punk@33: // Memory request/response state punk@33: punk@33: FIFO#(InstReq) instReqQ <- mkBFIFO1(); punk@33: FIFO#(InstResp) instRespQ <- mkFIFO(); punk@33: punk@33: FIFO#(DataReq) dataReqQ <- mkBFIFO1(); punk@33: FIFO#(DataResp) dataRespQ <- mkFIFO(); punk@33: punk@33: // Statistics state punk@33: Reg#(Stat) num_cycles <- mkReg(0); punk@33: Reg#(Stat) num_inst <- mkReg(0); punk@33: punk@33: //Or: punk@33: // Statistics state punk@33: //STAT num_cycles <- mkStatCounter(`STATS_PROCESSOR_CYCLE_COUNT); punk@33: //STAT num_inst <- mkStatCounter(`STATS_PROCESSOR_INST_COUNT); punk@33: punk@33: //----------------------------------------------------------- punk@33: // Rules punk@33: punk@33: (* descending_urgency = "exec, pcgen" *) punk@33: rule pcgen; //( stage == PCgen ); punk@33: let pc_plus4 = pc + 4; punk@33: punk@33: traceTiny("mkProc", "pc",pc); punk@33: traceTiny("mkProc", "pcgen","P"); punk@33: instReqQ.enq( LoadReq{ addr:pc, tag:epoch} ); punk@33: punk@33: let next_pc = bp.get(pc); punk@33: if (next_pc matches tagged Valid .npc) punk@33: begin punk@33: pcQ.enq(PCStat {qpc:pc, qnxtpc:npc, qepoch:epoch}); punk@33: pc <= npc; punk@33: end punk@33: else punk@33: begin punk@33: pcQ.enq(PCStat {qpc:pc, qnxtpc:pc_plus4, qepoch:epoch}); punk@33: pc <= pc_plus4; punk@33: end punk@33: punk@33: endrule punk@33: punk@33: rule discard (instRespQ.first() matches tagged LoadResp .ld punk@33: &&& ld.tag != epoch); punk@33: traceTiny("mkProc", "stage", "D"); punk@33: instRespQ.deq(); punk@33: endrule punk@33: punk@33: (* conflict_free = "exec, writeback" *) punk@33: rule exec (instRespQ.first() matches tagged LoadResp.ld punk@33: &&& (ld.tag == epoch) punk@33: &&& unpack(ld.data) matches .inst punk@33: &&& !stall(inst, wbQ)); punk@33: punk@33: // Some abbreviations punk@33: let sext = signExtend; punk@33: let zext = zeroExtend; punk@33: let sra = signedShiftRight; punk@33: punk@33: // Get the instruction punk@33: punk@33: instRespQ.deq(); punk@33: Instr inst punk@33: = case ( instRespQ.first() ) matches punk@33: tagged LoadResp .ld : return unpack(ld.data); punk@33: tagged StoreResp .st : return ?; punk@33: endcase; punk@33: punk@33: // Get the PC info punk@33: let instrpc = pcQ.first().qpc; punk@33: let pc_plus4 = instrpc + 4; punk@33: punk@33: Bool branchTaken = False; punk@33: Addr newPC = pc_plus4; punk@33: punk@33: // Tracing punk@33: traceTiny("mkProc", "exec","X"); punk@33: traceTiny("mkProc", "exInstTiny",inst); punk@33: traceFull("mkProc", "exInstFull",inst); punk@33: punk@33: case ( inst ) matches punk@33: punk@33: // -- Memory Ops ------------------------------------------------ punk@33: punk@33: tagged LW .it : punk@33: begin punk@33: Addr addr = rf.rd1(it.rbase) + sext(it.offset); punk@33: dataReqQ.enq( LoadReq{ addr:addr, tag:zeroExtend(it.rdst) } ); punk@33: wbQ.enq(tagged WB_Load it.rdst); punk@33: end punk@33: punk@33: tagged SW .it : punk@33: begin punk@33: Addr addr = rf.rd1(it.rbase) + sext(it.offset); punk@33: dataReqQ.enq( StoreReq{ tag:0, addr:addr, data:rf.rd2(it.rsrc) } ); punk@33: wbQ.enq(tagged WB_Store); punk@33: end punk@33: punk@33: // -- Simple Ops ------------------------------------------------ punk@33: punk@33: tagged ADDIU .it : punk@33: begin punk@33: Bit#(32) result = rf.rd1(it.rsrc) + sext(it.imm); punk@33: wbQ.enq(tagged WB_ALU {data:result, dest:it.rdst}); punk@33: end punk@33: tagged SLTI .it : wbQ.enq(tagged WB_ALU {dest:it.rdst, data:slt( rf.rd1(it.rsrc), sext(it.imm) )}); punk@33: tagged SLTIU .it : wbQ.enq(tagged WB_ALU {dest:it.rdst, data:sltu( rf.rd1(it.rsrc), sext(it.imm) ) }); punk@33: tagged ANDI .it : punk@33: begin punk@33: Bit#(32) zext_it_imm = zext(it.imm); punk@33: wbQ.enq(tagged WB_ALU {dest:it.rdst, data:(rf.rd1(it.rsrc) & zext_it_imm)} ); punk@33: end punk@33: tagged ORI .it : punk@33: begin punk@33: Bit#(32) zext_it_imm = zext(it.imm); punk@33: wbQ.enq(tagged WB_ALU {dest:it.rdst, data:(rf.rd1(it.rsrc) | zext_it_imm)} ); punk@33: end punk@33: tagged XORI .it : punk@33: begin punk@33: Bit#(32) zext_it_imm = zext(it.imm); punk@33: wbQ.enq(tagged WB_ALU {dest: it.rdst, data:(rf.rd1(it.rsrc) ^ zext_it_imm )}); punk@33: end punk@33: tagged LUI .it : punk@33: begin punk@33: Bit#(32) zext_it_imm = zext(it.imm); punk@33: wbQ.enq(tagged WB_ALU {dest: it.rdst, data:(zext_it_imm << 32'd16) }); punk@33: end punk@33: punk@33: tagged SLL .it : punk@33: begin punk@33: Bit#(32) zext_it_shamt = zext(it.shamt); punk@33: wbQ.enq(tagged WB_ALU {dest: it.rdst, data:(rf.rd1(it.rsrc) << zext_it_shamt )} ); punk@33: end punk@33: tagged SRL .it : punk@33: begin punk@33: Bit#(32) zext_it_shamt = zext(it.shamt); punk@33: wbQ.enq(tagged WB_ALU {dest: it.rdst, data:(rf.rd1(it.rsrc) >> zext_it_shamt )}); punk@33: end punk@33: tagged SRA .it : punk@33: begin punk@33: Bit#(32) zext_it_shamt = zext(it.shamt); punk@33: wbQ.enq(tagged WB_ALU {dest: it.rdst, data:sra( rf.rd1(it.rsrc), zext_it_shamt )}); punk@33: end punk@33: tagged SLLV .it : wbQ.enq(tagged WB_ALU {dest: it.rdst, data:(rf.rd1(it.rsrc) << rshft(rf.rd2(it.rshamt)) )}); punk@33: tagged SRLV .it : wbQ.enq(tagged WB_ALU {dest: it.rdst, data:(rf.rd1(it.rsrc) >> rshft(rf.rd2(it.rshamt)) )} ); punk@33: tagged SRAV .it : wbQ.enq(tagged WB_ALU {dest: it.rdst, data:sra( rf.rd1(it.rsrc), rshft(rf.rd2(it.rshamt)) ) }); punk@33: tagged ADDU .it : wbQ.enq(tagged WB_ALU {dest: it.rdst, data:(rf.rd1(it.rsrc1) + rf.rd2(it.rsrc2) )} ); punk@33: tagged SUBU .it : wbQ.enq(tagged WB_ALU {dest: it.rdst, data:(rf.rd1(it.rsrc1) - rf.rd2(it.rsrc2) )} ); punk@33: tagged AND .it : wbQ.enq(tagged WB_ALU {dest: it.rdst, data:(rf.rd1(it.rsrc1) & rf.rd2(it.rsrc2) )} ); punk@33: tagged OR .it : wbQ.enq(tagged WB_ALU {dest: it.rdst, data:(rf.rd1(it.rsrc1) | rf.rd2(it.rsrc2) )} ); punk@33: tagged XOR .it : wbQ.enq(tagged WB_ALU {dest: it.rdst, data:(rf.rd1(it.rsrc1) ^ rf.rd2(it.rsrc2) )} ); punk@33: tagged NOR .it : wbQ.enq(tagged WB_ALU {dest: it.rdst, data:(~(rf.rd1(it.rsrc1) | rf.rd2(it.rsrc2)) )} ); punk@33: tagged SLT .it : wbQ.enq(tagged WB_ALU {dest: it.rdst, data:slt( rf.rd1(it.rsrc1), rf.rd2(it.rsrc2) ) }); punk@33: tagged SLTU .it : wbQ.enq(tagged WB_ALU {dest: it.rdst, data:sltu( rf.rd1(it.rsrc1), rf.rd2(it.rsrc2) ) }); punk@33: punk@33: // -- Branches -------------------------------------------------- punk@33: punk@33: tagged BLEZ .it : punk@33: if ( signedLE( rf.rd1(it.rsrc), 0 ) ) punk@33: begin punk@33: newPC = pc_plus4 + (sext(it.offset) << 2); punk@33: branchTaken = True; punk@33: end punk@33: punk@33: tagged BGTZ .it : punk@33: if ( signedGT( rf.rd1(it.rsrc), 0 ) ) punk@33: begin punk@33: newPC = pc_plus4 + (sext(it.offset) << 2); punk@33: branchTaken = True; punk@33: end punk@33: punk@33: tagged BLTZ .it : punk@33: if ( signedLT( rf.rd1(it.rsrc), 0 ) ) punk@33: begin punk@33: newPC = pc_plus4 + (sext(it.offset) << 2); punk@33: branchTaken = True; punk@33: end punk@33: punk@33: tagged BGEZ .it : punk@33: if ( signedGE( rf.rd1(it.rsrc), 0 ) ) punk@33: begin punk@33: newPC = pc_plus4 + (sext(it.offset) << 2); punk@33: branchTaken = True; punk@33: end punk@33: punk@33: tagged BEQ .it : punk@33: if ( rf.rd1(it.rsrc1) == rf.rd2(it.rsrc2) ) punk@33: begin punk@33: newPC = pc_plus4 + (sext(it.offset) << 2); punk@33: branchTaken = True; punk@33: end punk@33: punk@33: tagged BNE .it : punk@33: if ( rf.rd1(it.rsrc1) != rf.rd2(it.rsrc2) ) punk@33: begin punk@33: newPC = pc_plus4 + (sext(it.offset) << 2); punk@33: branchTaken = True; punk@33: end punk@33: punk@33: // -- Jumps ----------------------------------------------------- punk@33: punk@33: tagged J .it : punk@33: begin punk@33: newPC = { pc_plus4[31:28], it.target, 2'b0 }; punk@33: branchTaken = True; punk@33: end punk@33: punk@33: tagged JR .it : punk@33: begin punk@33: newPC = rf.rd1(it.rsrc); punk@33: branchTaken = True; punk@33: end punk@33: punk@33: tagged JAL .it : punk@33: begin punk@33: wbQ.enq(tagged WB_ALU {dest:31, data:pc_plus4 }); punk@33: newPC = { pc_plus4[31:28], it.target, 2'b0 }; punk@33: branchTaken = True; punk@33: end punk@33: punk@33: tagged JALR .it : punk@33: begin punk@33: wbQ.enq(tagged WB_ALU {dest:it.rdst, data:pc_plus4 }); punk@33: newPC = rf.rd1(it.rsrc); punk@33: branchTaken = True; punk@33: end punk@33: punk@33: // -- Cop0 ------------------------------------------------------ punk@33: punk@33: tagged MTC0 .it : punk@33: begin punk@33: case ( it.cop0dst ) punk@33: 5'd10 : cp0_statsEn <= unpack(truncate(rf.rd1(it.rsrc))); punk@33: 5'd21 : cp0_tohost <= truncate(rf.rd1(it.rsrc)); punk@33: default : punk@33: $display( " RTL-ERROR : %m : Illegal MTC0 cop0dst register!" ); punk@33: endcase punk@33: wbQ.enq(tagged WB_Host 0); //no idea wwhat this actually should be. punk@33: end punk@33: punk@33: //this is host stuff? punk@33: tagged MFC0 .it : punk@33: begin punk@33: case ( it.cop0src ) punk@33: // not actually an ALU instruction but don't have the format otherwise punk@33: 5'd10 : wbQ.enq(tagged WB_ALU {dest:it.rdst, data:zext(pack(cp0_statsEn)) }); punk@33: 5'd20 : wbQ.enq(tagged WB_ALU {dest:it.rdst, data:cp0_fromhost }); punk@33: 5'd21 : wbQ.enq(tagged WB_ALU {dest:it.rdst, data:cp0_tohost }); punk@33: default : punk@33: $display( " RTL-ERROR : %m : Illegal MFC0 cop0src register!" ); punk@33: endcase punk@33: end punk@33: punk@33: // -- Illegal --------------------------------------------------- punk@33: punk@33: default : punk@33: $display( " RTL-ERROR : %m : Illegal instruction !" ); punk@33: punk@33: endcase punk@33: punk@33: //evaluate branch prediction punk@33: Addr ppc = pcQ.first().qnxtpc; //predicted branch punk@33: if (ppc != newPC) //prediction wrong punk@33: begin punk@33: epoch <= pcQ.first().qepoch + 1; punk@33: bp.upd(instrpc, newPC); //update branch predictor punk@33: pcQ.clear(); punk@33: pc <= newPC; punk@33: end punk@33: else punk@33: pcQ.deq(); punk@33: punk@33: if ( cp0_statsEn ) punk@33: num_inst <= num_inst+1; punk@33: punk@33: endrule punk@33: punk@33: rule writeback; // ( stage == Writeback ); punk@33: traceTiny("mkProc", "writeback","W"); punk@33: punk@33: punk@33: // get what to do off the writeback queue punk@33: wbQ.deq(); punk@33: case (wbQ.first()) matches punk@33: tagged WB_ALU {data:.res, dest:.rdst} : rf.wr(rdst, res); punk@33: tagged WB_Load .regWr : punk@33: begin punk@33: dataRespQ.deq(); punk@33: if (dataRespQ.first() matches tagged LoadResp .ld) punk@33: rf.wr(truncate(ld.tag), ld.data); // no need to use Rindx from queue? Duplicate? punk@33: end punk@33: tagged WB_Store : dataRespQ.deq(); punk@33: tagged WB_Host .dat : noAction; punk@33: endcase punk@33: punk@33: endrule punk@33: punk@33: rule inc_num_cycles; punk@33: if ( cp0_statsEn ) punk@33: num_cycles <= num_cycles+1; punk@33: endrule punk@33: punk@33: // THis rule breaks things punk@33: // rule handleCPUToHost; punk@33: // let req <- server_stub.acceptRequest_ReadCPUToHost(); punk@33: // case (req) punk@33: // 0: server_stub.sendResponse_ReadCPUToHost(cp0_tohost); punk@33: // 1: server_stub.sendResponse_ReadCPUToHost(pc); punk@33: // 2: server_stub.sendResponse_ReadCPUToHost(zeroExtend(pack(stage))); punk@33: // endcase punk@33: // endrule punk@33: //----------------------------------------------------------- punk@33: // My Adds punk@33: //----------------------------------------------------------- punk@33: punk@33: //----------------------------------------------------------- punk@33: // Methods punk@33: punk@33: interface Client imem_client; punk@33: interface Get request = toGet(instReqQ); punk@33: interface Put response = toPut(instRespQ); punk@33: endinterface punk@33: punk@33: interface Client dmem_client; punk@33: interface Get request = toGet(dataReqQ); punk@33: interface Put response = toPut(dataRespQ); punk@33: endinterface punk@33: punk@33: interface Get statsEn_get = toGet(asReg(cp0_statsEn)); punk@33: punk@33: interface ProcStats stats; punk@33: interface Get num_cycles = toGet(asReg(num_cycles)); punk@33: interface Get num_inst = toGet(asReg(num_inst)); punk@33: endinterface punk@33: punk@33: interface CPUToHost tohost; punk@33: method Bit#(32) cpuToHost(int req); punk@33: return (case (req) punk@33: 0: cp0_tohost; punk@33: 1: pc; punk@33: 2: zeroExtend(pack(stage)); punk@33: endcase); punk@33: endmethod punk@33: endinterface punk@33: punk@33: endmodule punk@33: