diff --git a/include/alu.h b/include/alu.h index 5e6d57d..a628292 100644 --- a/include/alu.h +++ b/include/alu.h @@ -145,6 +145,8 @@ struct ALU : public dark::Module { alu_status <= 0b10; result_ROB_index <= request_ROB_index; result <= static_cast(operand1) + imm; + std::cerr << "\taddi: operand1=" << std::hex << static_cast(operand1) << " imm=" << std::hex + << static_cast(imm) << " result=" << std::hex << result.peek() << std::endl; completed_alu_resulting_PC <= static_cast(request_PC) + 4; return; } diff --git a/include/csu.h b/include/csu.h index fdd6dbd..6398dde 100644 --- a/include/csu.h +++ b/include/csu.h @@ -255,6 +255,8 @@ struct CentralScheduleUnit commit_has_resulting_register <= record.has_resulting_register; commit_reg_index <= record.resulting_register_idx; commit_reg_value <= record.resulting_register_value; + std::cerr << "commit_reg_index=" << std::dec << commit_reg_index.peek() << " commit_reg_value=" << std::hex + << std::setw(8) << std::setfill('0') << std::uppercase << commit_reg_value.peek() << std::endl; commit_ins_ROB_index <= i; actual_PC <= static_cast(record.resulting_PC); if (static_cast(record.PC_mismatch_mark) == 1) { @@ -266,6 +268,10 @@ struct CentralScheduleUnit halt_signal <= (0b100000000 | static_cast(a0)); std::cerr << "halting with code " << std::dec << int(halt_signal.peek()) << std::endl; } + if (record.instruction == 0x1B07A503) { + std::cerr << "judgeResult loaded from memory is " << std::dec + << static_cast(record.resulting_register_value) << std::endl; + } } } if (!has_committed) is_committing <= 0; @@ -331,7 +337,8 @@ struct CentralScheduleUnit // can issue std::cerr << "csu is issuing mem instruct " << std::hex << std::setw(8) << std::setfill('0') << std::uppercase << instruction << " full_ins_id= " << std::hex << std::setw(8) << std::setfill('0') - << std::uppercase << full_ins_id << std::endl; + << std::uppercase << full_ins_id << " with ROB_index=" << std::dec + << static_cast(ROB_tail) << std::endl; is_issuing <= 1; has_instruction_issued_last_cycle <= 1; uint32_t tail = static_cast(ROB_tail); @@ -370,7 +377,8 @@ struct CentralScheduleUnit // can issue std::cerr << "csu is issuing alu instruct " << std::hex << std::setw(8) << std::setfill('0') << std::uppercase << instruction << " full_ins_id= " << std::hex << std::setw(8) << std::setfill('0') - << std::uppercase << full_ins_id << std::endl; + << std::uppercase << full_ins_id << " with ROB_index=" << std::dec + << static_cast(ROB_tail) << std::endl; is_issuing <= 1; has_instruction_issued_last_cycle <= 1; uint32_t tail = static_cast(ROB_tail); diff --git a/include/loadstorequeue.h b/include/loadstorequeue.h index 5bef6fb..3d60bd5 100644 --- a/include/loadstorequeue.h +++ b/include/loadstorequeue.h @@ -1,5 +1,6 @@ #pragma once #include +#include #include "concept.h" #ifndef LOADSTOREQUEUE_H #include @@ -134,6 +135,8 @@ struct LoadStoreQueue : public dark::Module(has_decoded_rs1) << std::endl; std::cerr << "\thas_decoded_rs2: " << std::hex << std::setw(8) << std::setfill('0') << static_cast(has_decoded_rs2) << std::endl; + std::cerr << "\tstored in positon " << std::dec << static_cast(cur_queue_tail) << " of LSQ" + << std::endl; // LSQ_queue[cur_queue_tail].Q1 <= decoded_rs1; // temporarily, no use // LSQ_queue[cur_queue_tail].Q2 <= decoded_rs2; // temporarily, no use } else @@ -156,6 +159,8 @@ struct LoadStoreQueue : public dark::Module void { + std::cerr << "res_ROB_index=" << std::dec << res_ROB_index << std::endl; + std::cerr << "res_value=" << std::hex << std::setw(8) << std::setfill('0') << res_value << std::endl; + std::cerr << "rs1_deps=" << std::dec << static_cast(rs1_deps) << std::endl; + std::cerr << "rs2_deps=" << std::dec << static_cast(rs2_deps) << std::endl; uint32_t ptr = static_cast(LSQ_head); while (ptr != static_cast(LSQ_tail)) { + std::cerr << "\tptr=" << std::dec << ptr << std::endl; if ((!bool(has_accepted_ins_last_cycle)) || ptr != last_idx) { + std::cerr << "\tnormal" << std::endl; dark::debug::assert(LSQ_queue[ptr].state == 2, "LSQ_queue[ptr].state != 2"); - if (static_cast(LSQ_queue[ptr].Q1) == res_ROB_index) { + if ((!bool(LSQ_queue[ptr].D1)) && static_cast(LSQ_queue[ptr].Q1) == res_ROB_index) { LSQ_queue[ptr].V1 <= res_value; LSQ_queue[ptr].D1 <= 1; } - if (static_cast(LSQ_queue[ptr].Q2) == res_ROB_index) { + if ((!bool(LSQ_queue[ptr].D2)) && static_cast(LSQ_queue[ptr].Q2) == res_ROB_index) { LSQ_queue[ptr].V2 <= res_value; LSQ_queue[ptr].D2 <= 1; } } else { + std::cerr << "\timmediately listend data" << std::endl; + std::cerr << "should_monitor_V1=" << should_monitor_V1 << std::endl; + std::cerr << "should_monitor_V2=" << should_monitor_V2 << std::endl; if (should_monitor_V1 && static_cast(rs1_deps) == res_ROB_index) { + std::cerr << "load rs1" << std::endl; LSQ_queue[last_idx].V1 <= res_value; LSQ_queue[last_idx].D1 <= 1; should_monitor_V1 = false; } if (should_monitor_V2 && static_cast(rs2_deps) == res_ROB_index) { + std::cerr << "load rs2" << std::endl; LSQ_queue[last_idx].V2 <= res_value; LSQ_queue[last_idx].D2 <= 1; should_monitor_V2 = false; @@ -206,11 +224,13 @@ struct LoadStoreQueue : public dark::Module(alu_status_receiver) == 0b10) { + std::cerr << "potentially have sth from alu" << std::endl; process_listend_data(static_cast(completed_aluins_ROB_index), static_cast(completed_aluins_result)); } std::cerr << "Load Store Queue is listening data from memory" << std::endl; if (static_cast(mem_data_sign) == 0b10) { + std::cerr << "potentially have sth from memory" << std::endl; process_listend_data(static_cast(completed_memins_ROB_index), static_cast(completed_memins_read_data)); } @@ -237,7 +257,7 @@ struct LoadStoreQueue : public dark::Module(LSQ_queue[head].full_ins_id); @@ -299,6 +319,14 @@ struct LoadStoreQueue : public dark::Module(LSQ_queue[head].ins_ROB_index); request_address_output <= (static_cast(LSQ_queue[head].V1) + static_cast(LSQ_queue[head].ins_imm)); + std::cerr << "\trequest_address_output=" << std::hex << std::setfill('0') << std::setw(8) + << request_address_output.peek() << std::endl; + std::cerr << "\toperand1=" << std::hex << std::setfill('0') << std::setw(8) + << static_cast(LSQ_queue[head].V1) << std::endl; + std::cerr << "\timm=" << std::hex << std::setfill('0') << std::setw(8) + << static_cast(LSQ_queue[head].ins_imm) << std::endl; + std::cerr << "\tROB_index=" << std::dec << static_cast(LSQ_queue[head].ins_ROB_index) + << std::endl; request_data_output <= static_cast(LSQ_queue[head].V2); } else { throw std::runtime_error("Invalid instruction"); @@ -310,6 +338,8 @@ struct LoadStoreQueue : public dark::Module(LSQ_queue[16].V1) << std::endl; } }; } // namespace ZYM diff --git a/include/registerfile.h b/include/registerfile.h index 59c1c90..57cbb43 100644 --- a/include/registerfile.h +++ b/include/registerfile.h @@ -9,7 +9,7 @@ const static size_t kTotalRegisters = 32; struct RegisterFile_Input { // receive control signal from CSU dark::Wire<1> reset; - // dark::Wire<1> force_clear_receiver; + dark::Wire<1> force_clear_receiver; dark::Wire<1> is_issuing; dark::Wire<1> issue_type; dark::Wire<5> issue_ROB_index; @@ -70,11 +70,22 @@ struct RegisterFile : public dark::Module(commit_reg_index)] <= commit_reg_value; if (register_deps[static_cast(commit_reg_index)] == commit_ins_ROB_index) { std::cerr << "The dependency is cleared" << std::endl; - register_nodep[static_cast(commit_reg_index)] <= 1; + if (!(bool(is_issuing) && bool(has_decoded_rd) && + (static_cast(decoded_rd) == static_cast(commit_reg_index)))) + register_nodep[static_cast(commit_reg_index)] <= 1; dependency_cleared = true; } } } + if (bool(force_clear_receiver)) { + for (auto ® : register_deps) { + reg <= 0; + } + for (auto ® : register_nodep) { + reg <= 1; + } + return; + } if (bool(is_issuing)) { std::cerr << "Register File Found CSU is issuing" << std::endl; if (bool(has_decoded_rs1)) { diff --git a/include/reservestation.h b/include/reservestation.h index f39bf3f..a88b912 100644 --- a/include/reservestation.h +++ b/include/reservestation.h @@ -1,4 +1,5 @@ #pragma once +#include #include "concept.h" #ifndef RESERVATIONSTATION_H #include @@ -88,6 +89,7 @@ struct ReserveStation : public dark::Module(RS_remaining_space); @@ -127,6 +130,9 @@ struct ReserveStation : public dark::Module(RS_records[ptr].Q1) == res_ROB_index) { + if ((!bool(RS_records[ptr].D1)) && static_cast(RS_records[ptr].Q1) == res_ROB_index) { RS_records[ptr].V1 <= res_value; RS_records[ptr].D1 <= 1; } - if (static_cast(RS_records[ptr].Q2) == res_ROB_index) { + if ((!bool(RS_records[ptr].D2)) && static_cast(RS_records[ptr].Q2) == res_ROB_index) { RS_records[ptr].V2 <= res_value; RS_records[ptr].D2 <= 1; } @@ -191,13 +198,14 @@ struct ReserveStation : public dark::Module(alu_status_receiver) == 0b10) { process_listend_data(static_cast(completed_aluins_ROB_index), static_cast(completed_aluins_result)); } + std::cerr << "Reservestation is listening data from Memory" << std::endl; if (static_cast(mem_status_receiver) == 0b10) { process_listend_data(static_cast(completed_memins_ROB_index), static_cast(completed_memins_read_data)); @@ -237,6 +245,16 @@ struct ReserveStation : public dark::Module(RS_remaining_space) << std::endl; + if (tot != static_cast(RS_remaining_space)) { + throw std::runtime_error("Reservestation: RS_remaining_space is not consistent with RS_records"); + } } }; } // namespace ZYM diff --git a/src/main.cpp b/src/main.cpp index 2b7980b..24e2f8f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -78,7 +78,7 @@ int main(int argc, char **argv) { RWConnect(alu.result, csu.completed_aluins_result); RWConnect(alu.completed_alu_resulting_PC, csu.completed_alu_resulting_PC); // csu <-> register file - // RWConnect(csu.force_clear_announcer, rf.force_clear_receiver); + RWConnect(csu.force_clear_announcer, rf.force_clear_receiver); RWConnect(csu.is_issuing, rf.is_issuing); RWConnect(csu.issue_type, rf.issue_type); RWConnect(csu.issue_ROB_index, rf.issue_ROB_index); diff --git a/src/rv32iinterpreter.cpp b/src/rv32iinterpreter.cpp index a09ff0b..d7eb783 100644 --- a/src/rv32iinterpreter.cpp +++ b/src/rv32iinterpreter.cpp @@ -12,7 +12,8 @@ #ifdef DEBUG #define DEBUG_CERR std::cerr #else -#define DEBUG_CERR if(0) std::cerr +#define DEBUG_CERR \ + if (0) std::cerr #endif inline uint8_t ReadBit(uint32_t data, int pos) { return (data >> pos) & 1; } inline void WriteBit(uint32_t &data, int pos, uint8_t bit) { @@ -81,7 +82,7 @@ ExecuteFunc Decode(uint32_t instr) { } uint8_t second_key = funct3 | (funct7 << 3); DEBUG_CERR << "Decoding, opcode=" << std::hex << (int)opcode << " second_key=" << std::dec << (int)second_key - << std::endl; + << std::endl; if (ExecuteFuncMap.find({opcode, second_key}) == ExecuteFuncMap.end()) { throw std::runtime_error("Unsupported instruction"); } @@ -136,7 +137,7 @@ class RV32IInterpreter { void PrintRegisters() { for (int i = 0; i < 32; i++) { DEBUG_CERR << "x" << i << "=" << std::hex << std::uppercase << std::setw(8) << std::setfill('0') << reg[i] - << std::endl; + << std::endl; } } @@ -173,7 +174,7 @@ class RV32IInterpreter { memset(reg, 0, sizeof(reg)); } bool Fetch() { - DEBUG_CERR<<"Fetching PC: "<(&dat[PC]); if (IR == 0x0FF00513) { // DEBUG_CERR<<"ready to exit"<