Merge pull request #117 from riscv/multicore_debug
[riscv-isa-sim.git] / riscv / devices.cc
index 4e88a1df4328e02d9be83263304c6c6224071f83..15115c8a6ccd5ec13ece8c125c8625fad7cd55be 100644 (file)
@@ -7,12 +7,9 @@ void bus_t::add_device(reg_t addr, abstract_device_t* dev)
 
 bool bus_t::load(reg_t addr, size_t len, uint8_t* bytes)
 {
-  fprintf(stderr, "bus load(0x%lx, %ld)\n", addr, len);
   auto it = devices.lower_bound(-addr);
-  if (it == devices.end()) {
-      fprintf(stderr, "  -> false\n");
+  if (it == devices.end())
     return false;
-  }
   return it->second->load(addr - -it->first, len, bytes);
 }
 
@@ -23,3 +20,11 @@ bool bus_t::store(reg_t addr, size_t len, const uint8_t* bytes)
     return false;
   return it->second->store(addr - -it->first, len, bytes);
 }
+
+std::pair<reg_t, abstract_device_t*> bus_t::find_device(reg_t addr)
+{
+  auto it = devices.lower_bound(-addr);
+  if (it == devices.end() || addr < -it->first)
+    return std::make_pair((reg_t)0, (abstract_device_t*)NULL);
+  return std::make_pair(-it->first, it->second);
+}