diff options
author | Andrew Waterman <waterman@cs.berkeley.edu> | 2015-11-12 17:51:46 -0800 |
---|---|---|
committer | Andrew Waterman <waterman@cs.berkeley.edu> | 2015-11-12 17:52:56 -0800 |
commit | 0c3af3d73a28c0fc57eac535b2a28f45134b556b (patch) | |
tree | a9ad7bab1842bde77d6755d96b22a45a510e7a41 /riscv/devices.cc | |
parent | a7bde15c2b79de12484748b462e511e0d1c2eca5 (diff) | |
download | spike-0c3af3d73a28c0fc57eac535b2a28f45134b556b.zip spike-0c3af3d73a28c0fc57eac535b2a28f45134b556b.tar.gz spike-0c3af3d73a28c0fc57eac535b2a28f45134b556b.tar.bz2 |
Generate device tree for target machine
Diffstat (limited to 'riscv/devices.cc')
-rw-r--r-- | riscv/devices.cc | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/riscv/devices.cc b/riscv/devices.cc new file mode 100644 index 0000000..25e39e0 --- /dev/null +++ b/riscv/devices.cc @@ -0,0 +1,40 @@ +#include "devices.h" + +void bus_t::add_device(reg_t addr, abstract_device_t* dev) +{ + devices[-addr] = dev; +} + +bool bus_t::load(reg_t addr, size_t len, uint8_t* bytes) +{ + auto it = devices.lower_bound(-addr); + if (it == devices.end()) + return false; + return it->second->load(addr - -it->first, len, bytes); +} + +bool bus_t::store(reg_t addr, size_t len, const uint8_t* bytes) +{ + auto it = devices.lower_bound(-addr); + if (it == devices.end()) + return false; + return it->second->store(addr - -it->first, len, bytes); +} + +rom_device_t::rom_device_t(std::vector<char> data) + : data(data) +{ +} + +bool rom_device_t::load(reg_t addr, size_t len, uint8_t* bytes) +{ + if (addr + len > data.size()) + return false; + memcpy(bytes, &data[addr], len); + return true; +} + +bool rom_device_t::store(reg_t addr, size_t len, const uint8_t* bytes) +{ + return false; +} |