Internal change PiperOrigin-RevId: 549108726
diff --git a/sim/kelvin_top.cc b/sim/kelvin_top.cc index 39b1724..8cdaf64 100644 --- a/sim/kelvin_top.cc +++ b/sim/kelvin_top.cc
@@ -115,28 +115,29 @@ semihost_ = new mpact::sim::riscv::RiscVArmSemihost( mpact::sim::riscv::RiscVArmSemihost::BitWidth::kWord32, memory_, memory_); // Set the software breakpoint callback. - state_->AddEbreakHandler([this](const mpact::sim::generic::Instruction *inst) - -> bool { - if (inst != nullptr) { - if (absl::GetFlag(FLAGS_use_semihost) && - semihost_->IsSemihostingCall(inst)) { - semihost_->OnEBreak(inst); - } else if (absl::GetFlag(FLAGS_use_semihost)) { // Software breakpoint. - RequestHalt(HaltReason::kSoftwareBreakpoint, inst); - } else { // The default Kelvin simulation mode. - std::cout << "Hit breakpoint or program exits with fault" << std::endl; - RequestHalt(HaltReason::kSoftwareBreakpoint, inst); - } - return true; - } - return false; - }); + state_->AddEbreakHandler( + [this](const mpact::sim::generic::Instruction *inst) -> bool { + if (inst != nullptr) { + if (absl::GetFlag(FLAGS_use_semihost) && + semihost_->IsSemihostingCall(inst)) { + semihost_->OnEBreak(inst); + } else if (rv_bp_manager_->HasBreakpoint( + inst->address())) { // Software breakpoint. + RequestHalt(HaltReason::kSoftwareBreakpoint, inst); + } else { // The default Kelvin simulation mode. + std::cout << "Program exits with fault" << std::endl; + RequestHalt(HaltReason::kUserRequest, inst); + } + return true; + } + return false; + }); state_->AddMpauseHandler( [this](const mpact::sim::generic::Instruction *inst) -> bool { - if (inst != nullptr) { // Software breakpoint + if (inst != nullptr) { std::cout << "Program exits properly" << std::endl; - RequestHalt(HaltReason::kSoftwareBreakpoint, inst); + RequestHalt(HaltReason::kUserRequest, inst); return true; } return false;
diff --git a/sim/test/kelvin_top_test.cc b/sim/test/kelvin_top_test.cc index d8f1546..807b6b5 100644 --- a/sim/test/kelvin_top_test.cc +++ b/sim/test/kelvin_top_test.cc
@@ -71,9 +71,9 @@ auto halt_result = kelvin_top_->GetLastHaltReason(); CHECK_OK(halt_result); EXPECT_EQ(static_cast<int>(halt_result.value()), - static_cast<int>(HaltReason::kSoftwareBreakpoint)); + static_cast<int>(HaltReason::kUserRequest)); const std::string stdout_str = testing::internal::GetCapturedStdout(); - EXPECT_EQ("Hit breakpoint or program exits with fault\n", stdout_str); + EXPECT_EQ("Program exits with fault\n", stdout_str); } // Runs the program from beginning to end. Enable arm semihosting. @@ -103,7 +103,7 @@ auto halt_result = kelvin_top_->GetLastHaltReason(); CHECK_OK(halt_result); EXPECT_EQ(static_cast<int>(halt_result.value()), - static_cast<int>(HaltReason::kSoftwareBreakpoint)); + static_cast<int>(HaltReason::kUserRequest)); const std::string stdout_str = testing::internal::GetCapturedStdout(); EXPECT_EQ("Program exits properly\n", stdout_str); } @@ -171,9 +171,9 @@ auto halt_result = kelvin_top_->GetLastHaltReason(); CHECK_OK(halt_result); EXPECT_EQ(static_cast<int>(halt_result.value()), - static_cast<int>(HaltReason::kSoftwareBreakpoint)); + static_cast<int>(HaltReason::kUserRequest)); - EXPECT_EQ("Hit breakpoint or program exits with fault\n", + EXPECT_EQ("Program exits with fault\n", testing::internal::GetCapturedStdout()); }