#ifndef _RISCV_DEVICES_H #define _RISCV_DEVICES_H #include "decode.h" #include #include class processor_t; class abstract_device_t { public: virtual bool load(reg_t addr, size_t len, uint8_t* bytes) = 0; virtual bool store(reg_t addr, size_t len, const uint8_t* bytes) = 0; virtual ~abstract_device_t() {} }; class bus_t : public abstract_device_t { public: bool load(reg_t addr, size_t len, uint8_t* bytes); bool store(reg_t addr, size_t len, const uint8_t* bytes); void add_device(reg_t addr, abstract_device_t* dev); private: std::map devices; }; class rom_device_t : public abstract_device_t { public: rom_device_t(std::vector data); bool load(reg_t addr, size_t len, uint8_t* bytes); bool store(reg_t addr, size_t len, const uint8_t* bytes); const std::vector& contents() { return data; } private: std::vector data; }; class clint_t : public abstract_device_t { public: clint_t(std::vector&); 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 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& procs; mtime_t mtime; std::vector mtimecmp; }; #endif