📄 decode.cpp
字号:
/***************************************************************************** The following code is derived, directly or indirectly, from the SystemC source code Copyright (c) 1996-2006 by all Contributors. All Rights reserved. The contents of this file are subject to the restrictions and limitations set forth in the SystemC Open Source License Version 2.4 (the "License"); You may not use this file except in compliance with such restrictions and limitations. You may obtain instructions on how to receive a copy of the License at http://www.systemc.org/. Software distributed by Contributors under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. *****************************************************************************//***************************************************************************** decode.cpp -- Instruction Decode Unit. Original Author: Martin Wang, Synopsys, Inc. *****************************************************************************/ /***************************************************************************** MODIFICATION LOG - modifiers, enter your name, affiliation, date and changes you are making here. Name, Affiliation, Date: Description of Modification: *****************************************************************************/ #include <climits> // for definition on value 's MAX#include "systemc.h"#include "decode.h"#include "directive.h"void decode::entry(){ unsigned int instr_tmp = 0; unsigned int opcode_tmp = 0; unsigned int regA_tmp = 0; unsigned int regB_tmp = 0; unsigned int regC_tmp = 0; unsigned int imm_tmp = 0; unsigned int offset_tmp = 0; signed int label_tmp = 0; unsigned int longlabel_tmp = 0; unsigned int lastreg_tmp = 0; signed int srcA_tmp = 0; signed int srcB_tmp = 0; signed int srcC_tmp = 0; int i; bool branch_direction_tmp = 0; branch_valid.write(false); decode_valid.write(false); float_valid.write(false); mmx_valid.write(false); wait(2); while (true) { if (destreg_write.read() == true) { cpu_reg[destreg_write_src.read()] = alu_dataout.read(); cout << "\t\t\t-------------------------------" << endl; printf("\t\t\tID: R%d=0x%x(%d) fr ALU", destreg_write_src.read(), alu_dataout.read(),alu_dataout.read()); cout.setf(ios::dec,ios::basefield); cout << " at CSIM " << sc_time_stamp() << endl; cout << "\t\t\t-------------------------------" << endl; } if (dram_rd_valid.read() == true) { cpu_reg[dram_write_src.read()] = dram_dataout.read(); cout << "\t\t\t-------------------------------" << endl; printf("\t\t\tID: R%d=0x%x(%d) fr MemLd", dram_write_src.read(), dram_dataout.read(), dram_dataout.read()); cout.setf(ios::dec,ios::basefield); cout << " at CSIM " << sc_time_stamp() << endl; cout << "\t\t\t-------------------------------" << endl; } if (fpu_valid.read() == true) { cpu_reg[fpu_destout.read()] = fpu_dout.read(); cout << "\t\t\t-------------------------------" << endl; printf("\t\t\tID: R%d=0x%x fr MMX", fpu_destout.read(), fpu_dout.read()); cout.setf(ios::dec,ios::basefield); cout << " at CSIM " << sc_time_stamp() << endl; cout << "\t\t\t-------------------------------" << endl; } if ((instruction_valid.read() == true)) { pc_reg = pc.read(); if (clear_branch.read() == true) { cout << "\t\t\t-------------------------------" << endl; printf("\t\t\tID: clear branch"); cout.setf(ios::dec,ios::basefield); cout << " at CSIM " << sc_time_stamp() << endl; cout << "\t\t\t-------------------------------" << endl; branch_valid.write(false); } instr_tmp = instruction.read(); opcode_tmp = (instr_tmp & 0xff000000) >> 24; regC_tmp = (instr_tmp & 0x00f00000) >> 20; regA_tmp = (instr_tmp & 0x000f0000) >> 16; regB_tmp = (instr_tmp & 0x0000f000) >> 12; imm_tmp = (instr_tmp & 0x0000ffff); offset_tmp = (instr_tmp & 0x00000fff); label_tmp = (instr_tmp & 0x0000ffff); longlabel_tmp = (instr_tmp & 0x00ffffff); branch_direction_tmp = (instr_tmp & 0x00008000) >> 15; if (branch_direction_tmp) { // handle backward branch label_tmp = - (0xffff - label_tmp + 1) ; } //printf("opcode = %d regC = %d regA = %d regB = %d\n",opcode_tmp, regC_tmp, regA_tmp, regB_tmp); srcA_tmp = cpu_reg[regA_tmp]; srcB_tmp = cpu_reg[regB_tmp]; srcC_tmp = cpu_reg[regC_tmp]; wait(); lastreg_tmp = regC_tmp; cout << "\t\t\t-------------------------------" << endl;/****************************************************************************** if (regA_tmp == lastreg_tmp){ forward_A.write(true); forward_B.write(false); } else if (regB_tmp == lastreg_tmp){ forward_A.write(false); forward_B.write(true); } else { forward_A.write(false); forward_B.write(false); }*********************************************************************************/ switch(opcode_tmp) { case 0x0: // halt printf("\n\n\t\t\t*******************************\n"); printf("\t\t\tID: REGISTERS DUMP"); cout << " at CSIM " << sc_time_stamp() << endl; printf("\t\t\t*******************************\n"); printf("REG :==================================================================\n"); for(i =0; i<32; i++){ printf(" R%2d(%08x) ",i, cpu_reg[i]); if ((i==3) || (i== 11) || (i==19) || (i== 27) ||(i==7) || (i==15) || (i==23) || (i==31)){ printf("\n"); } } printf("=======================================================================\n\n"); wait(); wait(); break; case 0x01: // add R1, R2, R3 printf("\t\t\tID: R%d= R%d(=%d)+R%d(=%d)", regC_tmp, regA_tmp, srcA_tmp, regB_tmp, srcB_tmp); cout << " \n\t\t\t : at CSIM " << sc_time_stamp() << endl; cout << "\t\t\t-------------------------------" << endl; src_A.write(srcA_tmp); src_B.write(srcB_tmp); alu_src.write(regC_tmp); alu_op.write(3); decode_valid.write(true); wait(); decode_valid.write(false); wait(); break; case 0x02: // addi R1, R2, #value printf("\t\t\tID: R%d= R%d(=%d)+%d", regC_tmp, regA_tmp, srcA_tmp, imm_tmp); cout << " \n\t\t\t : at CSIM " << sc_time_stamp() << endl; cout << "\t\t\t-------------------------------" << endl; src_A.write(srcA_tmp); src_B.write(imm_tmp); alu_src.write(regC_tmp); alu_op.write(3); decode_valid.write(true); wait(); decode_valid.write(false); wait(); break; case 0x03: // addc R1, R2, R3 + Carrybit printf("\t\t\tID: R%d= R%d(=%d)+R%d(=%d)+C", regC_tmp, regA_tmp, srcA_tmp, regB_tmp, srcB_tmp); cout << " \n\t\t\t : at CSIM " << sc_time_stamp() << endl; cout << "\t\t\t-------------------------------" << endl; src_A.write(srcA_tmp); src_B.write(srcB_tmp); alu_src.write(regC_tmp); alu_op.write(1); decode_valid.write(true); wait(); decode_valid.write(false); wait(); break; case 0x04: // sub R1, R2, R3 printf("\t\t\tID: R%d=R%d(=%d)-R%d(=%d)", regC_tmp, regA_tmp, srcA_tmp, regB_tmp, srcB_tmp); cout << " \n\t\t\t : at CSIM " << sc_time_stamp() << endl; cout << "\t\t\t-------------------------------" << endl; src_A.write(srcA_tmp); src_B.write(srcB_tmp); alu_src.write(regC_tmp); alu_op.write(4); decode_valid.write(true); wait(); decode_valid.write(false); wait(); break; case 0x05: // subi R1, R2, #value printf("\t\t\tID: R%d=R%d(=%d)-%d", regC_tmp, regA_tmp, srcA_tmp, imm_tmp); cout << " \n\t\t\t : at CSIM " << sc_time_stamp() << endl; cout << "\t\t\t-------------------------------" << endl; src_A.write(srcA_tmp); src_B.write(imm_tmp); alu_src.write(regC_tmp); alu_op.write(4); decode_valid.write(true); wait(); decode_valid.write(false); wait(); break; case 0x06: // subc R1, R2, R3 - Carrybit printf("\t\t\tID: R%d=R%d(=%d)-R%d(=%d)-C", regC_tmp, regA_tmp, srcA_tmp, regB_tmp, srcB_tmp); cout << " \n\t\t\t : at CSIM " << sc_time_stamp() << endl; cout << "\t\t\t-------------------------------" << endl; src_A.write(srcA_tmp); src_B.write(srcB_tmp); alu_src.write(regC_tmp); alu_op.write(2); decode_valid.write(true); wait(); decode_valid.write(false); wait(); break; case 0x07: // mul R1, R2, R3 printf("\t\t\tID: R%d=R%d(=%d)*R%d(=%d)", regC_tmp, regA_tmp, srcA_tmp, regB_tmp, srcB_tmp); cout << " \n\t\t\t : at CSIM " << sc_time_stamp() << endl; cout << "\t\t\t-------------------------------" << endl; src_A.write(srcA_tmp); src_B.write(srcB_tmp); alu_src.write(regC_tmp); alu_op.write(5); decode_valid.write(true); wait(); decode_valid.write(false); wait(); break; case 0x08: // div R1, R2, R3 printf("\t\t\tID: R%d=R%d(=%d)/R%d(=%d)", regC_tmp, regA_tmp, srcA_tmp, regB_tmp, srcB_tmp); cout << " \n\t\t\t : at CSIM " << sc_time_stamp() << endl; cout << "\t\t\t-------------------------------" << endl; src_A.write(srcA_tmp); src_B.write(srcB_tmp); alu_src.write(regC_tmp); alu_op.write(6); decode_valid.write(true); wait(); decode_valid.write(false); wait(); break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -