From 402ca4ec45dcd5a22e1b85536ec028bf24a910a4 Mon Sep 17 00:00:00 2001 From: friemel Date: Fri, 7 Sep 2012 00:57:05 +0000 Subject: [PATCH] Added mechanism to specialize listener + basic BPSingleListener for gem5 git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@1603 8c4709b5-6ec9-48aa-a5cd-a96041d1645a --- src/core/sal/CMakeLists.txt | 2 ++ src/core/sal/Listener.cc | 2 +- src/core/sal/Listener.hpp | 16 +++++++++++--- src/core/sal/bochs/BochsListener.hpp | 10 ++++----- src/core/sal/gem5/Gem5Controller.cc | 15 +++++++++++++ src/core/sal/gem5/Gem5Listener.cc | 33 ++++++++++++++++++++++++++++ src/core/sal/gem5/Gem5Listener.hpp | 23 +++++++++++++++++++ src/core/sal/gem5/Gem5PCEvent.cc | 7 ++++++ src/core/sal/gem5/Gem5PCEvent.hh | 14 ++++++++++++ src/core/util/ElfReader.cc | 1 + 10 files changed, 114 insertions(+), 9 deletions(-) create mode 100644 src/core/sal/gem5/Gem5Listener.cc create mode 100644 src/core/sal/gem5/Gem5Listener.hpp create mode 100644 src/core/sal/gem5/Gem5PCEvent.cc create mode 100644 src/core/sal/gem5/Gem5PCEvent.hh diff --git a/src/core/sal/CMakeLists.txt b/src/core/sal/CMakeLists.txt index 79be3fcc..01428081 100644 --- a/src/core/sal/CMakeLists.txt +++ b/src/core/sal/CMakeLists.txt @@ -28,6 +28,8 @@ elseif(BUILD_GEM5) Register.cc SimulatorController.cc gem5/Gem5Controller.cc + gem5/Gem5Listener.cc + gem5/Gem5PCEvent.cc ) endif(BUILD_BOCHS) diff --git a/src/core/sal/Listener.cc b/src/core/sal/Listener.cc index 80d8de41..dfbba2e8 100644 --- a/src/core/sal/Listener.cc +++ b/src/core/sal/Listener.cc @@ -69,7 +69,7 @@ bool BPRangeListener::isMatching(address_t addr, address_t aspace) const return true; } -bool BPSingleListener::isMatching(address_t addr, address_t aspace) const +bool GenericBPSingleListener::isMatching(address_t addr, address_t aspace) const { if (aspaceIsMatching(aspace)) { if (m_WatchInstrPtr == ANY_ADDR || m_WatchInstrPtr == addr) diff --git a/src/core/sal/Listener.hpp b/src/core/sal/Listener.hpp index 06666109..1e6b56e4 100644 --- a/src/core/sal/Listener.hpp +++ b/src/core/sal/Listener.hpp @@ -156,8 +156,8 @@ public: * \class BPSingleListener * A Breakpoint listener to observe specific instruction pointers. */ -class BPSingleListener : public BPListener { -private: +class GenericBPSingleListener : public BPListener { +protected: address_t m_WatchInstrPtr; public: /** @@ -172,7 +172,7 @@ public: * Here, too, ANY_ADDR is a placeholder to allow debugging * in a random address space. */ - BPSingleListener(address_t ip = 0, address_t address_space = ANY_ADDR) + GenericBPSingleListener(address_t ip = 0, address_t address_space = ANY_ADDR) : BPListener(address_space), m_WatchInstrPtr(ip) { } /** * Returns the instruction pointer this listener waits for. @@ -595,4 +595,14 @@ public: } // end-of-namespace: fail +#if defined BUILD_BOCHS + #include "bochs/BochsListener.hpp" +#elif defined BUILD_OVP +// #include "ovp/OVPListener.hpp" +#elif defined BUILD_GEM5 + #include "gem5/Gem5Listener.hpp" +#else + #error SAL Config Target not defined +#endif + #endif // __LISTENER_HPP__ diff --git a/src/core/sal/bochs/BochsListener.hpp b/src/core/sal/bochs/BochsListener.hpp index 15943ffd..915a83ca 100644 --- a/src/core/sal/bochs/BochsListener.hpp +++ b/src/core/sal/bochs/BochsListener.hpp @@ -1,12 +1,12 @@ -#ifndef __BOCHS_EVENTS_HPP__ - #define __BOCHS_EVENTS_HPP__ +#ifndef __BOCHS_LISTENER_HPP__ + #define __BOCHS_LISTENER_HPP__ #include "../Listener.hpp" -#include "BochsController.hpp" - namespace fail { +typedef GenericBPSingleListener BPSingleListener; + /** * \class TimerListener * Concrete TimerListener implementation of GenericTimerListener for the Bochs @@ -75,4 +75,4 @@ public: } // end-of-namespace: fail -#endif // __BOCHS_EVENTS_HPP__ +#endif // __BOCHS_LISTENER_HPP__ diff --git a/src/core/sal/gem5/Gem5Controller.cc b/src/core/sal/gem5/Gem5Controller.cc index 159933fd..bb4b56fb 100644 --- a/src/core/sal/gem5/Gem5Controller.cc +++ b/src/core/sal/gem5/Gem5Controller.cc @@ -1,12 +1,27 @@ #include "Gem5Controller.hpp" +#include + +#include "sim/core.hh" +#include "sim/sim_exit.hh" +//#include "sim/root.hh" + namespace fail { int interrupt_to_fire = -1; void Gem5Controller::save(const std::string &path) { + // Takes a snapshot in the m5out dir + Tick when = curTick() + 1; + exitSimLoop("checkpoint", 0, when, 0); + + // This could be a version to take snapshots with a specified name + /*Root* root = Root::root(); + std::ofstream file(path.c_str()); + root->serialize(file); + file.close();*/ } void Gem5Controller::restore(const std::string &path) diff --git a/src/core/sal/gem5/Gem5Listener.cc b/src/core/sal/gem5/Gem5Listener.cc new file mode 100644 index 00000000..61868416 --- /dev/null +++ b/src/core/sal/gem5/Gem5Listener.cc @@ -0,0 +1,33 @@ +#include "Gem5Listener.hpp" +#include "../SALInst.hpp" + +#include "sim/system.hh" + +namespace fail { + +Gem5BPSingleListener::Gem5BPSingleListener(address_t ip) + : GenericBPSingleListener(ip) +{ + +} + +bool Gem5BPSingleListener::onAddition() +{ + if(!m_Breakpoint) + { + System* sys = *System::systemList.begin(); + m_Breakpoint = new Gem5PCEvent(&sys->pcEventQueue, this->m_WatchInstrPtr); + return true; + } + return false; +} + +Gem5BPSingleListener::~Gem5BPSingleListener() +{ + if(m_Breakpoint) + { + delete m_Breakpoint; + } +} + +} // end-of-namespace: fail diff --git a/src/core/sal/gem5/Gem5Listener.hpp b/src/core/sal/gem5/Gem5Listener.hpp new file mode 100644 index 00000000..fc692302 --- /dev/null +++ b/src/core/sal/gem5/Gem5Listener.hpp @@ -0,0 +1,23 @@ +#ifndef __GEM5_LISTENER_HPP__ + #define __GEM5_LISTENER_HPP__ + +#include "../Listener.hpp" +#include "Gem5PCEvent.hh" + +namespace fail { + +class Gem5BPSingleListener : public GenericBPSingleListener +{ +public: + Gem5BPSingleListener(address_t ip = 0); + virtual bool onAddition(); + ~Gem5BPSingleListener(); +private: + Gem5PCEvent* m_Breakpoint; +}; + +typedef Gem5BPSingleListener BPSingleListener; + +} // end-of-namespace: fail + +#endif // __GEM5_LISTENER_HPP__ diff --git a/src/core/sal/gem5/Gem5PCEvent.cc b/src/core/sal/gem5/Gem5PCEvent.cc new file mode 100644 index 00000000..84dc6ca3 --- /dev/null +++ b/src/core/sal/gem5/Gem5PCEvent.cc @@ -0,0 +1,7 @@ +#include "Gem5PCEvent.hh" +#include "../SALInst.hpp" + +void Gem5PCEvent::process(ThreadContext *tc) +{ + fail::simulator.onBreakpoint(this->evpc, fail::ANY_ADDR); +} diff --git a/src/core/sal/gem5/Gem5PCEvent.hh b/src/core/sal/gem5/Gem5PCEvent.hh new file mode 100644 index 00000000..54e89792 --- /dev/null +++ b/src/core/sal/gem5/Gem5PCEvent.hh @@ -0,0 +1,14 @@ +#ifndef __GEM5_PCEVENT_HPP__ + #define __GEM5_PCEVENT_HPP__ + +#include "cpu/pc_event.hh" + +class Gem5PCEvent : public PCEvent +{ +public: + Gem5PCEvent(PCEventQueue* queue, Addr ip) + : PCEvent(queue, "Fail Breakpoint", ip) {} + virtual void process(ThreadContext *tc); +}; + +#endif // __GEM5_PCEVENT_HPP__ diff --git a/src/core/util/ElfReader.cc b/src/core/util/ElfReader.cc index c4dafd8a..cfee08a6 100644 --- a/src/core/util/ElfReader.cc +++ b/src/core/util/ElfReader.cc @@ -1,6 +1,7 @@ #include "ElfReader.hpp" #include "elfinfo/elfinfo.h" #include +#include namespace fail {