diff --git a/inc/Registers.h b/inc/Registers.h index 7b3c43b..5f0d8bb 100644 --- a/inc/Registers.h +++ b/inc/Registers.h @@ -197,7 +197,7 @@ public: * @param reg_num register number * @return register value */ - int32_t getValue(int reg_num); + uint32_t getValue(int reg_num); /** * Returns PC value @@ -245,7 +245,7 @@ private: /** * bank of registers (32 regs of 32bits each) */ - std::array register_bank = { {0} }; + std::array register_bank = { {0} }; /** * Program counter (32 bits width) diff --git a/src/BASE_ISA.cpp b/src/BASE_ISA.cpp index 0104a6d..85c645f 100644 --- a/src/BASE_ISA.cpp +++ b/src/BASE_ISA.cpp @@ -84,7 +84,7 @@ enum Codes { bool BASE_ISA::Exec_LUI() const { int rd; - uint32_t imm = 0; + uint32_t imm; rd = get_rd(); imm = get_imm_U() << 12; @@ -100,7 +100,7 @@ bool BASE_ISA::Exec_LUI() const { bool BASE_ISA::Exec_AUIPC() const { int rd; - uint32_t imm = 0; + uint32_t imm; int new_pc; rd = get_rd(); @@ -118,7 +118,7 @@ bool BASE_ISA::Exec_AUIPC() const { } bool BASE_ISA::Exec_JAL() const { - int32_t mem_addr = 0; + int32_t mem_addr; int rd; int new_pc, old_pc; @@ -142,7 +142,7 @@ bool BASE_ISA::Exec_JAL() const { } bool BASE_ISA::Exec_JALR() { - uint32_t mem_addr = 0; + uint32_t mem_addr; int rd, rs1; int new_pc, old_pc; @@ -174,7 +174,7 @@ bool BASE_ISA::Exec_JALR() { bool BASE_ISA::Exec_BEQ() const { int rs1, rs2; - int new_pc = 0; + int new_pc; rs1 = get_rs1(); rs2 = get_rs2(); @@ -199,7 +199,7 @@ bool BASE_ISA::Exec_BEQ() const { bool BASE_ISA::Exec_BNE() const { int rs1, rs2; - int new_pc = 0; + int new_pc; uint32_t val1, val2; rs1 = get_rs1(); @@ -278,7 +278,7 @@ bool BASE_ISA::Exec_BGE() const { bool BASE_ISA::Exec_BLTU() const { int rs1, rs2; - int new_pc = 0; + int new_pc; rs1 = get_rs1(); rs2 = get_rs2(); @@ -326,9 +326,9 @@ bool BASE_ISA::Exec_BGEU() const { } bool BASE_ISA::Exec_LB() const { - uint32_t mem_addr = 0; + uint32_t mem_addr ; int rd, rs1; - int32_t imm = 0; + int32_t imm; int8_t data; rd = get_rd(); @@ -349,9 +349,9 @@ bool BASE_ISA::Exec_LB() const { } bool BASE_ISA::Exec_LH() const { - uint32_t mem_addr = 0; + uint32_t mem_addr ; int rd, rs1; - int32_t imm = 0; + int32_t imm; int16_t data; rd = get_rd(); @@ -372,9 +372,9 @@ bool BASE_ISA::Exec_LH() const { } bool BASE_ISA::Exec_LW() const { - uint32_t mem_addr = 0; + uint32_t mem_addr; int rd, rs1; - int32_t imm = 0; + int32_t imm; uint32_t data; rd = get_rd(); @@ -396,9 +396,9 @@ bool BASE_ISA::Exec_LW() const { } bool BASE_ISA::Exec_LBU() const { - uint32_t mem_addr = 0; + uint32_t mem_addr; int rd, rs1; - int32_t imm = 0; + int32_t imm; uint8_t data; rd = get_rd(); @@ -418,9 +418,9 @@ bool BASE_ISA::Exec_LBU() const { } bool BASE_ISA::Exec_LHU() const { - uint32_t mem_addr = 0; + uint32_t mem_addr; int rd, rs1; - int32_t imm = 0; + int32_t imm; uint16_t data; rd = get_rd(); @@ -443,9 +443,9 @@ bool BASE_ISA::Exec_LHU() const { } bool BASE_ISA::Exec_SB() const { - uint32_t mem_addr = 0; + uint32_t mem_addr; int rs1, rs2; - int32_t imm = 0; + int32_t imm; uint32_t data; rs1 = get_rs1(); @@ -468,9 +468,9 @@ bool BASE_ISA::Exec_SB() const { } bool BASE_ISA::Exec_SH() const { - uint32_t mem_addr = 0; + uint32_t mem_addr; int rs1, rs2; - int32_t imm = 0; + int32_t imm; uint32_t data; rs1 = get_rs1(); @@ -493,9 +493,9 @@ bool BASE_ISA::Exec_SH() const { } bool BASE_ISA::Exec_SW() const { - uint32_t mem_addr = 0; + uint32_t mem_addr; int rs1, rs2; - int32_t imm = 0; + int32_t imm; uint32_t data; rs1 = get_rs1(); @@ -518,14 +518,14 @@ bool BASE_ISA::Exec_SW() const { bool BASE_ISA::Exec_ADDI() const { int rd, rs1; - int32_t imm = 0; + int32_t imm; int32_t calc; rd = get_rd(); rs1 = get_rs1(); imm = get_imm_I(); - calc = regs->getValue(rs1) + imm; + calc = static_cast(regs->getValue(rs1)) + imm; regs->setValue(rd, calc); if (log->getLogLevel() >= Log::INFO) { @@ -545,7 +545,7 @@ bool BASE_ISA::Exec_SLTI() const { rs1 = get_rs1(); imm = get_imm_I(); - if (regs->getValue(rs1) < imm) { + if (static_cast(regs->getValue(rs1)) < imm) { regs->setValue(rd, 1); log->SC_log(Log::INFO) << "SLTI: x" << rs1 << " < " << imm << " => " << "1 -> x" << rd << "\n"; @@ -704,7 +704,7 @@ bool BASE_ISA::Exec_SRAI() const { shift = rs2 & 0x1F; - calc = regs->getValue(rs1) >> shift; + calc = static_cast(regs->getValue(rs1)) >> shift; regs->setValue(rd, calc); if (log->getLogLevel() >= Log::INFO) { @@ -866,7 +866,7 @@ bool BASE_ISA::Exec_SRA() const { shift = regs->getValue(rs2) & 0x1F; - calc = regs->getValue(rs1) >> shift; + calc = static_cast(regs->getValue(rs1)) >> shift; regs->setValue(rd, calc); if (log->getLogLevel() >= Log::INFO) { diff --git a/src/C_extension.cpp b/src/C_extension.cpp index 932b342..cbd75bc 100644 --- a/src/C_extension.cpp +++ b/src/C_extension.cpp @@ -244,7 +244,7 @@ bool C_extension::Exec_C_ADDI4SPN() { return false; } - calc = regs->getValue(rs1) + imm; + calc = static_cast(regs->getValue(rs1)) + imm; regs->setValue(rd, calc); if (log->getLogLevel() >= Log::INFO) { @@ -269,7 +269,7 @@ bool C_extension::Exec_C_ADDI16SP() { rs1 = 2; imm = get_imm_ADDI16SP(); - calc = regs->getValue(rs1) + imm; + calc = static_cast(regs->getValue(rs1)) + imm; regs->setValue(rd, calc); log->SC_log(Log::INFO) << std::dec << "C.ADDI16SP: x" << rs1 << " + " @@ -372,7 +372,7 @@ bool C_extension::Exec_C_LI() { rs1 = 0; imm = get_imm_ADDI(); - calc = regs->getValue(rs1) + imm; + calc = static_cast(regs->getValue(rs1)) + imm; regs->setValue(rd, calc); if (log->getLogLevel() >= Log::INFO) { @@ -557,7 +557,7 @@ bool C_extension::Exec_C_ADDI() const { rs1 = rd; imm = get_imm_ADDI(); - calc = regs->getValue(rs1) + imm; + calc = static_cast(regs->getValue(rs1)) + imm; regs->setValue(rd, calc); if (log->getLogLevel() >= Log::INFO) { diff --git a/src/M_extension.cpp b/src/M_extension.cpp index 9635340..b8cd7ba 100644 --- a/src/M_extension.cpp +++ b/src/M_extension.cpp @@ -52,8 +52,8 @@ bool M_extension::Exec_M_MUL() const { rs1 = get_rs1(); rs2 = get_rs2(); - multiplier = regs->getValue(rs1); - multiplicand = regs->getValue(rs2); + multiplier = static_cast(regs->getValue(rs1)); + multiplicand = static_cast(regs->getValue(rs2)); result = (int64_t) multiplier * multiplicand; result = result & 0x00000000FFFFFFFF; @@ -75,8 +75,8 @@ bool M_extension::Exec_M_MULH() const { rs1 = get_rs1(); rs2 = get_rs2(); - multiplier = regs->getValue(rs1); - multiplicand = regs->getValue(rs2); + multiplier = static_cast(regs->getValue(rs1)); + multiplicand = static_cast(regs->getValue(rs2)); result = (int64_t) multiplier * (int64_t) multiplicand; @@ -99,7 +99,7 @@ bool M_extension::Exec_M_MULHSU() const { rs1 = get_rs1(); rs2 = get_rs2(); - multiplier = regs->getValue(rs1); + multiplier = static_cast(regs->getValue(rs1)); multiplicand = regs->getValue(rs2); result = static_cast(multiplier * (uint64_t) multiplicand); @@ -122,8 +122,8 @@ bool M_extension::Exec_M_MULHU() const { rs1 = get_rs1(); rs2 = get_rs2(); - multiplier = (uint32_t) regs->getValue(rs1); - multiplicand = (uint32_t) regs->getValue(rs2); + multiplier = static_cast(regs->getValue(rs1)); + multiplicand = static_cast(regs->getValue(rs2)); result = (uint64_t) multiplier * (uint64_t) multiplicand; ret_value = static_cast((result >> 32) & 0x00000000FFFFFFFF); @@ -144,8 +144,8 @@ bool M_extension::Exec_M_DIV() const { rs1 = get_rs1(); rs2 = get_rs2(); - dividend = regs->getValue(rs1); - divisor = regs->getValue(rs2); + dividend = static_cast(regs->getValue(rs1)); + divisor = static_cast(regs->getValue(rs2)); if (divisor == 0) { result = -1; @@ -200,8 +200,8 @@ bool M_extension::Exec_M_REM() const { rs1 = get_rs1(); rs2 = get_rs2(); - dividend = regs->getValue(rs1); - divisor = regs->getValue(rs2); + dividend = static_cast(regs->getValue(rs1)); + divisor = static_cast(regs->getValue(rs2)); if (divisor == 0) { result = dividend; @@ -228,8 +228,8 @@ bool M_extension::Exec_M_REMU() const { rs1 = get_rs1(); rs2 = get_rs2(); - dividend = regs->getValue(rs1); - divisor = regs->getValue(rs2); + dividend = static_cast(regs->getValue(rs1)); + divisor = static_cast(regs->getValue(rs2)); if (divisor == 0) { result = dividend; diff --git a/src/Registers.cpp b/src/Registers.cpp index 7e47854..94e9d77 100644 --- a/src/Registers.cpp +++ b/src/Registers.cpp @@ -108,7 +108,7 @@ void Registers::setValue(int reg_num, int32_t value) { } } -int32_t Registers::getValue(int reg_num) { +uint32_t Registers::getValue(int reg_num) { if ((reg_num >= 0) && (reg_num < 32)) { perf->registerRead(); return register_bank[reg_num];