diff --git a/src/experiments/ezs-logger/CMakeLists.txt b/src/experiments/ezs-logger/CMakeLists.txt new file mode 100644 index 00000000..b66af55e --- /dev/null +++ b/src/experiments/ezs-logger/CMakeLists.txt @@ -0,0 +1,20 @@ +set(EXPERIMENT_NAME ezs-logger) +set(EXPERIMENT_TYPE EZSLogger) +configure_file(../instantiate-experiment.ah.in + ${CMAKE_CURRENT_BINARY_DIR}/instantiate-${EXPERIMENT_NAME}.ah @ONLY +) + +## Setup desired protobuf descriptions HERE ## +set(MY_PROTOS +) + +set(MY_CAMPAIGN_SRCS + experiment.hpp + experiment.cc +) + +## Build library +add_library(fail-${EXPERIMENT_NAME} ${MY_CAMPAIGN_SRCS}) +add_dependencies(fail-${EXPERIMENT_NAME} fail-comm) +target_link_libraries(fail-${EXPERIMENT_NAME}) + diff --git a/src/experiments/ezs-logger/experiment.cc b/src/experiments/ezs-logger/experiment.cc new file mode 100644 index 00000000..c7ba82ee --- /dev/null +++ b/src/experiments/ezs-logger/experiment.cc @@ -0,0 +1,99 @@ +#include +#include + +#include +#include "experiment.hpp" +#include "sal/SALConfig.hpp" +#include "sal/SALInst.hpp" +#include "sal/Memory.hpp" +#include "sal/Listener.hpp" + +#include "sal/bochs/BochsListener.hpp" +#include +#include +#include +#include +#include "../plugins/realtimelogger/RealtimeLogger.hpp" +#include "../plugins/signalgenerator/SignalGenerator.hpp" + +using namespace std; +using namespace fail; + +// Check if configuration dependencies are satisfied: +#if !defined(CONFIG_EVENT_MEMREAD) || !defined(CONFIG_EVENT_MEMWRITE) +#error This experiment needs: MemRead and MemWrite. Enable these in the configuration. +#endif + + +void EZSLogger::setupLog(const ElfSymbol & target, const string& prefix) +{ + + if( target.getAddress() == 0 ){ + m_log << target << " Memory address not found. " << std::endl; + simulator.terminate(1); + } + + char *u = getenv("USER"); + if (u == NULL){ + m_log << "Username not found :(" << std::endl; + simulator.terminate(1); + } + + /* Set output path to /tmp/'prefix'-.dac */ + std::string outputfile = "/tmp/" + prefix + "-" + std::string(u) + ".txt"; + + // TODO delete rl. object sometimes? + RealtimeLogger *rl = new RealtimeLogger(target, outputfile); + + simulator.addFlow(rl); +} + +bool EZSLogger::run() +{ + m_log << "STARTING EZS Logger" << endl; + + ElfReader m_elf; + + // Invalidate Hpet by setting COUNTER_CLK_PERIOD > 0x05f5E100 + // Segfaults... + // MemoryManager &mm = simulator.getMemoryManager(); + // uint64_t hpet_cap_reg = 0xffffffff00000000ULL; + // mm.setBytes(0xFED00000, sizeof(hpet_cap_reg), &hpet_cap_reg); + + //! Setup RealtimeLogger instances: + setupLog(m_elf.getSymbol("ezs_tracer_register"), "ezs-trace"); + setupLog(m_elf.getSymbol("ezs_dac_out_register"), "ezs-dac"); + + //! Setup Superimposed sine waves: @see Sine::SineParams_t + Sine::SineParamsList_t plist; + plist.push_back(Sine::SineParams_t(2,0.7)); + plist.push_back(Sine::SineParams_t(10,0.3)); + //! Initialize and install signal generator @see SignalGenerator + const ElfSymbol & s_adc = m_elf.getSymbol("ezs_adc_in_register"); + SignalGenerator siggen(s_adc, new Sine(plist)); + simulator.addFlow(&siggen); + + + //! Let the SUT know, we are in Bochs. + const ElfSymbol & s_bochsid = m_elf.getSymbol("FAILBOCHSID"); + m_log << "FAILBOCHSID @ " << s_bochsid << std::endl; + + MemAccessListener l_bochsid(s_bochsid); + MemoryManager & mm = simulator.getMemoryManager(); + uint32_t bochsid = 42; + + //! Simulate forever. + while(true) { + if(s_bochsid.getAddress() != 0){ + simulator.addListenerAndResume(&l_bochsid); + mm.setBytes(s_bochsid.getAddress(), sizeof(bochsid), &bochsid); + } else { + simulator.resume(); + } + } + + // Explicitly terminate, or the simulator will continue to run. + simulator.terminate(); + +} + diff --git a/src/experiments/ezs-logger/experiment.hpp b/src/experiments/ezs-logger/experiment.hpp new file mode 100644 index 00000000..1b4fa42f --- /dev/null +++ b/src/experiments/ezs-logger/experiment.hpp @@ -0,0 +1,38 @@ +#ifndef __EZS_LOGGER_EXPERIMENT_HPP__ +#define __EZS_LOGGER_EXPERIMENT_HPP__ + + +#include "sal/SALInst.hpp" +#include "efw/ExperimentFlow.hpp" +#include "util/Logger.hpp" +#include +#include +#include "util/ElfReader.hpp" + +/** + * @file + * @brief Base system for EZS realtime lecture + */ + +/** + * @class + * @brief Experiment implementation + */ +class EZSLogger : public fail::ExperimentFlow { +public: + +private: + fail::Logger m_log; //! debug output + + /** + * @brief Tiniy little helper to setup a RealtimeLogger instance + */ + void setupLog(const fail::ElfSymbol & target, const std::string& prefix); + +public: + EZSLogger() : m_log("EZSLogger", false) {} + + bool run(); +}; + +#endif