Merge pull request #117 from riscv/multicore_debug
[riscv-isa-sim.git] / riscv / devices.cc
1 #include "devices.h"
2
3 void bus_t::add_device(reg_t addr, abstract_device_t* dev)
4 {
5 devices[-addr] = dev;
6 }
7
8 bool bus_t::load(reg_t addr, size_t len, uint8_t* bytes)
9 {
10 auto it = devices.lower_bound(-addr);
11 if (it == devices.end())
12 return false;
13 return it->second->load(addr - -it->first, len, bytes);
14 }
15
16 bool bus_t::store(reg_t addr, size_t len, const uint8_t* bytes)
17 {
18 auto it = devices.lower_bound(-addr);
19 if (it == devices.end())
20 return false;
21 return it->second->store(addr - -it->first, len, bytes);
22 }
23
24 std::pair<reg_t, abstract_device_t*> bus_t::find_device(reg_t addr)
25 {
26 auto it = devices.lower_bound(-addr);
27 if (it == devices.end() || addr < -it->first)
28 return std::make_pair((reg_t)0, (abstract_device_t*)NULL);
29 return std::make_pair(-it->first, it->second);
30 }