aboutsummaryrefslogtreecommitdiff
path: root/riscv/devices.h
diff options
context:
space:
mode:
Diffstat (limited to 'riscv/devices.h')
-rw-r--r--riscv/devices.h35
1 files changed, 30 insertions, 5 deletions
diff --git a/riscv/devices.h b/riscv/devices.h
index 64ab79b..e4df6c9 100644
--- a/riscv/devices.h
+++ b/riscv/devices.h
@@ -22,6 +22,8 @@ class bus_t : public abstract_device_t {
bool store(reg_t addr, size_t len, const uint8_t* bytes);
void add_device(reg_t addr, abstract_device_t* dev);
+ std::pair<reg_t, abstract_device_t*> find_device(reg_t addr);
+
private:
std::map<reg_t, abstract_device_t*> devices;
};
@@ -36,17 +38,40 @@ class rom_device_t : public abstract_device_t {
std::vector<char> data;
};
-class rtc_t : public abstract_device_t {
+class mem_t : public abstract_device_t {
+ public:
+ mem_t(size_t size) : len(size) {
+ data = (char*)calloc(1, size);
+ if (!data)
+ throw std::runtime_error("couldn't allocate " + std::to_string(size) + " bytes of target memory");
+ }
+ mem_t(const mem_t& that) = delete;
+ ~mem_t() { free(data); }
+
+ bool load(reg_t addr, size_t len, uint8_t* bytes) { return false; }
+ bool store(reg_t addr, size_t len, const uint8_t* bytes) { return false; }
+ char* contents() { return data; }
+ size_t size() { return len; }
+
+ private:
+ char* data;
+ size_t len;
+};
+
+class clint_t : public abstract_device_t {
public:
- rtc_t(std::vector<processor_t*>&);
+ clint_t(std::vector<processor_t*>&);
bool load(reg_t addr, size_t len, uint8_t* bytes);
bool store(reg_t addr, size_t len, const uint8_t* bytes);
- size_t size() { return regs.size() * sizeof(regs[0]); }
+ size_t size() { return CLINT_SIZE; }
void increment(reg_t inc);
private:
+ typedef uint64_t mtime_t;
+ typedef uint64_t mtimecmp_t;
+ typedef uint32_t msip_t;
std::vector<processor_t*>& procs;
- std::vector<uint64_t> regs;
- uint64_t time() { return regs[0]; }
+ mtime_t mtime;
+ std::vector<mtimecmp_t> mtimecmp;
};
#endif