Support more flexible main memory allocation
[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 bus_t::descriptor bus_t::find_device(reg_t addr)
25 {
26 auto it = devices.lower_bound(-addr);
27 if (it == devices.end()) {
28 bus_t::descriptor desc = {0, 0};
29 return desc;
30 }
31 bus_t::descriptor desc = {-it->first, it->second};
32 return desc;
33 }