1 #pragma once 2 3 #include "internal/sys.hpp" 4 #include "io_interface.hpp" 5 6 #include <cstdint> 7 #include <string> 8 9 namespace host_tool 10 { 11 12 class DevMemDevice : public HostIoInterface 13 { 14 public: DevMemDevice(const internal::Sys * sys=& internal::sys_impl)15 explicit DevMemDevice(const internal::Sys* sys = &internal::sys_impl) : 16 sys(sys) 17 {} 18 19 ~DevMemDevice() = default; 20 21 /* Don't allow copying, assignment or move assignment, only moving. */ 22 DevMemDevice(const DevMemDevice&) = delete; 23 DevMemDevice& operator=(const DevMemDevice&) = delete; 24 DevMemDevice(DevMemDevice&&) = default; 25 DevMemDevice& operator=(DevMemDevice&&) = delete; 26 27 bool read(const std::size_t offset, const std::size_t length, 28 void* const destination) override; 29 30 bool write(const std::size_t offset, const std::size_t length, 31 const void* const source) override; 32 33 private: 34 static const std::string devMemPath; 35 int devMemFd = -1; 36 void* devMemMapped = nullptr; 37 const internal::Sys* sys; 38 }; 39 40 class PpcMemDevice : public HostIoInterface 41 { 42 public: PpcMemDevice(const std::string & ppcMemPath,const internal::Sys * sys=& internal::sys_impl)43 explicit PpcMemDevice(const std::string& ppcMemPath, 44 const internal::Sys* sys = &internal::sys_impl) : 45 ppcMemPath(ppcMemPath), sys(sys) 46 {} 47 48 ~PpcMemDevice() override; 49 50 /* Don't allow copying or assignment, only moving. */ 51 PpcMemDevice(const PpcMemDevice&) = delete; 52 PpcMemDevice& operator=(const PpcMemDevice&) = delete; 53 PpcMemDevice(PpcMemDevice&&) = default; 54 PpcMemDevice& operator=(PpcMemDevice&&) = default; 55 56 bool read(const std::size_t offset, const std::size_t length, 57 void* const destination) override; 58 59 bool write(const std::size_t offset, const std::size_t length, 60 const void* const source) override; 61 62 private: 63 void close(); 64 65 int ppcMemFd = -1; 66 const std::string ppcMemPath; 67 const internal::Sys* sys; 68 }; 69 70 } // namespace host_tool 71