diff --git a/src/core/sal/gem5/Gem5Controller.hpp b/src/core/sal/gem5/Gem5Controller.hpp index a38b29a8..f405900f 100644 --- a/src/core/sal/gem5/Gem5Controller.hpp +++ b/src/core/sal/gem5/Gem5Controller.hpp @@ -2,6 +2,9 @@ #define __GEM5_CONTROLLER_HPP__ #include "../SimulatorController.hpp" +#include "Gem5Memory.hpp" + +#include "sim/system.hh" namespace fail { @@ -11,6 +14,13 @@ namespace fail { */ class Gem5Controller : public SimulatorController { public: + void startup() + { + SimulatorController::startup(); + + m_Mem = new Gem5MemoryManager(System::systemList.front()); + } + void onBreakpoint(address_t instrPtr, address_t address_space); bool save(const std::string &path); diff --git a/src/core/sal/gem5/Gem5Memory.hpp b/src/core/sal/gem5/Gem5Memory.hpp new file mode 100644 index 00000000..6cf10f55 --- /dev/null +++ b/src/core/sal/gem5/Gem5Memory.hpp @@ -0,0 +1,75 @@ +#ifndef __GEM5_MEMORY_HPP__ + #define __GEM5_MEMORY_HPP__ + +#include "../Memory.hpp" + +#include "sim/system.hh" +#include "mem/packet.hh" +#include "mem/physical.hh" + +//class System; + +namespace fail { + +/** + * \class Gem5MemoryManager + * Represents a concrete implemenation of the abstract + * MemoryManager to provide access to gem5's memory pool. + */ +class Gem5MemoryManager : public MemoryManager { +public: + Gem5MemoryManager(System* system) : m_System(system), m_Mem(&system->getPhysMem()) {} + + size_t getPoolSize() const { return m_Mem->totalSize(); } + host_address_t getStartAddr() const { return 0; } + + byte_t getByte(guest_address_t addr) + { + Request req(addr, 1, Request::PHYSICAL, 0); + + Packet pkt(&req, MemCmd::ReadReq); + byte_t data; + pkt.dataStatic(&data); + + m_Mem->functionalAccess(&pkt); + return data; + } + + void getBytes(guest_address_t addr, size_t cnt, void *dest) + { + Request req(addr, cnt, Request::PHYSICAL, 0); + + Packet pkt(&req, MemCmd::ReadReq); + pkt.dataStatic(dest); + + m_Mem->functionalAccess(&pkt); + } + + void setByte(guest_address_t addr, byte_t data) + { + Request req(addr, 1, Request::PHYSICAL, 0); + + Packet pkt(&req, MemCmd::WriteReq); + pkt.dataStatic(&data); + + m_Mem->functionalAccess(&pkt); + } + + void setBytes(guest_address_t addr, size_t cnt, void const *src) + { + Request req(addr, cnt, Request::PHYSICAL, 0); + + Packet pkt(&req, MemCmd::WriteReq); + pkt.dataStatic(src); + + m_Mem->functionalAccess(&pkt); + } + +private: + System* m_System; + PhysicalMemory* m_Mem; +}; + +} // end-of-namespace: fail + +#endif // __GEM5_MEMORY_HPP__