558ecc7f59e0ddaf9890b5cdf096baa5fddfaa32
[riscv-isa-sim.git] / riscv / devices.h
1 #ifndef _RISCV_DEVICES_H
2 #define _RISCV_DEVICES_H
3
4 #include "decode.h"
5 #include <map>
6 #include <vector>
7
8 class abstract_device_t {
9 public:
10 virtual bool load(reg_t addr, size_t len, uint8_t* bytes) = 0;
11 virtual bool store(reg_t addr, size_t len, const uint8_t* bytes) = 0;
12 virtual ~abstract_device_t() {}
13 };
14
15 class bus_t : public abstract_device_t {
16 public:
17 bool load(reg_t addr, size_t len, uint8_t* bytes);
18 bool store(reg_t addr, size_t len, const uint8_t* bytes);
19 void add_device(reg_t addr, abstract_device_t* dev);
20
21 private:
22 std::map<reg_t, abstract_device_t*> devices;
23 };
24
25 class rom_device_t : public abstract_device_t {
26 public:
27 rom_device_t(std::vector<char> data);
28 bool load(reg_t addr, size_t len, uint8_t* bytes);
29 bool store(reg_t addr, size_t len, const uint8_t* bytes);
30 private:
31 std::vector<char> data;
32 };
33
34 #endif