2018-09-11 00:44:54 +08:00
|
|
|
#include "Instruction.h"
|
|
|
|
|
|
|
|
|
2018-10-10 18:08:53 +08:00
|
|
|
Instruction::Instruction(sc_uint<32> instr) {
|
2018-09-11 00:44:54 +08:00
|
|
|
m_instr = instr;
|
|
|
|
}
|
|
|
|
|
|
|
|
opCodes Instruction::decode() {
|
|
|
|
switch (opcode()) {
|
|
|
|
case LUI:
|
|
|
|
return OP_LUI;
|
|
|
|
case AUIPC:
|
|
|
|
return OP_AUIPC;
|
|
|
|
case JAL:
|
|
|
|
return OP_JAL;
|
|
|
|
case JALR:
|
|
|
|
return OP_JALR;
|
|
|
|
case BEQ:
|
2018-10-10 18:08:53 +08:00
|
|
|
switch(get_funct3()) {
|
2018-09-11 00:44:54 +08:00
|
|
|
case BEQ_F:
|
|
|
|
return OP_BEQ;
|
|
|
|
case BNE_F:
|
|
|
|
return OP_BNE;
|
|
|
|
case BLT_F:
|
|
|
|
return OP_BLT;
|
|
|
|
case BGE_F:
|
|
|
|
return OP_BGE;
|
|
|
|
case BLTU_F:
|
|
|
|
return OP_BLTU;
|
|
|
|
case BGEU_F:
|
|
|
|
return OP_BGEU;
|
|
|
|
}
|
|
|
|
return OP_ERROR;
|
|
|
|
case LB:
|
2018-10-10 18:08:53 +08:00
|
|
|
switch(get_funct3()) {
|
2018-09-11 00:44:54 +08:00
|
|
|
case LB_F:
|
|
|
|
return OP_LB;
|
|
|
|
case LH_F:
|
|
|
|
return OP_LH;
|
|
|
|
case LW_F:
|
|
|
|
return OP_LW;
|
|
|
|
case LBU_F:
|
|
|
|
return OP_LBU;
|
|
|
|
case LHU_F:
|
|
|
|
return OP_LHU;
|
|
|
|
}
|
|
|
|
return OP_ERROR;
|
|
|
|
case SB:
|
2018-10-10 18:08:53 +08:00
|
|
|
switch(get_funct3()) {
|
2018-09-11 00:44:54 +08:00
|
|
|
case SB_F:
|
|
|
|
return OP_SB;
|
|
|
|
case SH_F:
|
|
|
|
return OP_SH;
|
|
|
|
case SW_F:
|
|
|
|
return OP_SW;
|
|
|
|
}
|
|
|
|
return OP_ERROR;
|
|
|
|
case ADDI:
|
2018-10-10 18:08:53 +08:00
|
|
|
switch(get_funct3()) {
|
2018-09-11 00:44:54 +08:00
|
|
|
case ADDI_F:
|
|
|
|
return OP_ADDI;
|
|
|
|
case SLTI_F:
|
|
|
|
return OP_SLTI;
|
|
|
|
case SLTIU_F:
|
|
|
|
return OP_SLTIU;
|
|
|
|
case XORI_F:
|
|
|
|
return OP_XORI;
|
|
|
|
case ORI_F:
|
|
|
|
return OP_ORI;
|
|
|
|
case ANDI_F:
|
|
|
|
return OP_ANDI;
|
|
|
|
case SLLI_F:
|
|
|
|
return OP_SLLI;
|
|
|
|
case SRLI_F:
|
2018-10-10 18:08:53 +08:00
|
|
|
switch(get_funct7()) {
|
2018-09-11 00:44:54 +08:00
|
|
|
case SRLI_F7:
|
|
|
|
return OP_SRLI;
|
|
|
|
case SRAI_F7:
|
|
|
|
return OP_SRAI;
|
|
|
|
}
|
|
|
|
return OP_ERROR;
|
|
|
|
}
|
|
|
|
return OP_ERROR;
|
|
|
|
case ADD: {
|
2018-10-10 18:08:53 +08:00
|
|
|
switch(get_funct3()) {
|
2018-09-11 00:44:54 +08:00
|
|
|
case ADD_F:
|
2018-10-10 18:08:53 +08:00
|
|
|
switch (get_funct7()) {
|
2018-09-11 00:44:54 +08:00
|
|
|
case ADD_F7:
|
|
|
|
return OP_ADD;
|
|
|
|
case SUB_F7:
|
|
|
|
return OP_SUB;
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case SLL_F:
|
|
|
|
return OP_SLL;
|
|
|
|
case SLT_F:
|
|
|
|
return OP_SLT;
|
|
|
|
case SLTU_F:
|
|
|
|
return OP_SLTU;
|
|
|
|
case XOR_F:
|
|
|
|
return OP_XOR;
|
|
|
|
case SRL_F:
|
2018-10-10 18:08:53 +08:00
|
|
|
switch(get_funct7()) {
|
2018-09-11 00:44:54 +08:00
|
|
|
case SRL_F7:
|
|
|
|
return OP_SRL;
|
|
|
|
case SRA_F7:
|
|
|
|
return OP_SRA;
|
|
|
|
}
|
|
|
|
case OR_F:
|
|
|
|
return OP_OR;
|
|
|
|
case AND_F:
|
|
|
|
return OP_AND;
|
|
|
|
}
|
|
|
|
} /* ADD */
|
|
|
|
return OP_ERROR;
|
|
|
|
default:
|
|
|
|
return OP_ERROR;
|
|
|
|
}
|
|
|
|
}
|