diff --git a/src/core/comm/ExperimentData.hpp b/src/core/comm/ExperimentData.hpp index efada9b05c40094b674c5f7ea2062f29c0643554..7cc3c6d83793afd2b9bad260f764baeac258bd46 100644 --- a/src/core/comm/ExperimentData.hpp +++ b/src/core/comm/ExperimentData.hpp @@ -1,5 +1,5 @@ #ifndef __EXPERIMENT_DATA_HPP__ - #define __EXPERIMENT_DATA_HPP__ +#define __EXPERIMENT_DATA_HPP__ #include <string> #include <google/protobuf/message.h> diff --git a/src/core/comm/SocketComm.cc b/src/core/comm/SocketComm.cc index bd74465d805dbfa284255994a749b59ae3258905..7b8f4b23792c7090ce1ea3a98617fe884cc0d3d0 100644 --- a/src/core/comm/SocketComm.cc +++ b/src/core/comm/SocketComm.cc @@ -16,52 +16,52 @@ void SocketComm::init() bool SocketComm::sendMsg(int sockfd, google::protobuf::Message& msg) { - int size = htonl(msg.ByteSize()); - std::string buf; - if (safe_write(sockfd, &size, sizeof(size)) == -1 - || !msg.SerializeToString(&buf) - || safe_write(sockfd, buf.c_str(), buf.size()) == -1) { - return false; - } - return true; + int size = htonl(msg.ByteSize()); + std::string buf; + if (safe_write(sockfd, &size, sizeof(size)) == -1 + || !msg.SerializeToString(&buf) + || safe_write(sockfd, buf.c_str(), buf.size()) == -1) { + return false; + } + return true; } - + bool SocketComm::rcvMsg(int sockfd, google::protobuf::Message& msg) { - char *buf; - int bufsiz; - if ((buf = getBuf(sockfd, &bufsiz))) { - std::string st(buf, bufsiz); - delete [] buf; - return msg.ParseFromString(st); - } - return false; + char *buf; + int bufsiz; + if ((buf = getBuf(sockfd, &bufsiz))) { + std::string st(buf, bufsiz); + delete [] buf; + return msg.ParseFromString(st); + } + return false; } bool SocketComm::dropMsg(int sockfd) { - char *buf; - int bufsiz; - if ((buf = getBuf(sockfd, &bufsiz))) { - delete [] buf; - return true; - } - return false; + char *buf; + int bufsiz; + if ((buf = getBuf(sockfd, &bufsiz))) { + delete [] buf; + return true; + } + return false; } char * SocketComm::getBuf(int sockfd, int *size) { - char *buf; - if (safe_read(sockfd, size, sizeof(int)) == -1) { - return 0; - } - *size = ntohl(*size); - buf = new char[*size]; - if (safe_read(sockfd, buf, *size) == -1) { - delete [] buf; - return 0; - } - return buf; + char *buf; + if (safe_read(sockfd, size, sizeof(int)) == -1) { + return 0; + } + *size = ntohl(*size); + buf = new char[*size]; + if (safe_read(sockfd, buf, *size) == -1) { + delete [] buf; + return 0; + } + return buf; } int SocketComm::timedAccept(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int timeout) diff --git a/src/core/comm/SocketComm.hpp b/src/core/comm/SocketComm.hpp index 56af18de2b91cc499c66749c8b93f783197d2f76..5bb1084eb3caca1dcf9e840c9544a3e4ecc41691 100644 --- a/src/core/comm/SocketComm.hpp +++ b/src/core/comm/SocketComm.hpp @@ -3,7 +3,7 @@ */ #ifndef __SOCKET_COMM_HPP__ - #define __SOCKET_COMM_HPP__ +#define __SOCKET_COMM_HPP__ #include <stdio.h> #include <unistd.h> @@ -56,11 +56,11 @@ public: static int timedAccept(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int timeout); private: - static char * getBuf(int sockfd, int *size); + static char *getBuf(int sockfd, int *size); static ssize_t safe_write(int fd, const void *buf, size_t count); static ssize_t safe_read(int fd, void *buf, size_t count); }; - + } // end-of-namespace: fail #endif // __SOCKET_COMM_HPP__ diff --git a/src/core/config/FailConfig.hpp.in b/src/core/config/FailConfig.hpp.in index ab64f6cc390a19a7ca236b697b6594e0777a2b6c..0670129476ca06457eae362d9deaa8b802d1949c 100644 --- a/src/core/config/FailConfig.hpp.in +++ b/src/core/config/FailConfig.hpp.in @@ -1,5 +1,5 @@ #ifndef __FAIL_CONFIG_HPP__ - #define __FAIL_CONFIG_HPP__ +#define __FAIL_CONFIG_HPP__ // #define / #undef the following configuration macros to enable/disable the // various event sources, fault injection sinks, and miscellaneous other diff --git a/src/core/cpn/Campaign.hpp b/src/core/cpn/Campaign.hpp index 1fd155a319c0fd6efb295fc6f71215955e9d0966..8f70360f8645db2afefb7f933faf47f42ef7e266 100644 --- a/src/core/cpn/Campaign.hpp +++ b/src/core/cpn/Campaign.hpp @@ -1,5 +1,5 @@ #ifndef __CAMPAIGN_HPP__ - #define __CAMPAIGN_HPP__ +#define __CAMPAIGN_HPP__ namespace fail { diff --git a/src/core/cpn/CampaignManager.hpp b/src/core/cpn/CampaignManager.hpp index c943443b35567616399acb310a9aee9e4da6350a..4da35611304c27688bf046a93a4bcfedbdbefe5d 100644 --- a/src/core/cpn/CampaignManager.hpp +++ b/src/core/cpn/CampaignManager.hpp @@ -4,7 +4,7 @@ */ #ifndef __CAMPAIGN_MANAGER_HPP__ - #define __CAMPAIGN_MANAGER_HPP__ +#define __CAMPAIGN_MANAGER_HPP__ #include "sal/SALInst.hpp" #include "comm/ExperimentData.hpp" @@ -16,7 +16,7 @@ namespace fail { /** * \class CampaignManager * - * The CampaignManager allows a user-campaign access to all constant + * The CampaignManager allows a user-campaign access to all constant * simulator information and forwards single experiments to the JobServer. */ class CampaignManager { @@ -30,12 +30,12 @@ public: * Executes a user campaign */ bool runCampaign(Campaign* c) - { + { if (!m_jobserver) { m_jobserver = new JobServer; } m_currentCampaign = c; - bool ret = c->run(); + bool ret = c->run(); m_jobserver->done(); return ret; } @@ -43,7 +43,7 @@ public: * Returns a const reference for acquiring constant simulator specific information. * e.g., Registernames, to ease experiment data construction. * The campaign description is not allowed to change the simulator - * state, as the actual simulation runs within another process (Minion) + * state, as the actual simulation runs within another process (Minion) * @return constant reference to the current simulator backend. */ SimulatorController const& getSimulator() const { return simulator; } diff --git a/src/core/cpn/DatabaseCampaign.cc b/src/core/cpn/DatabaseCampaign.cc index db2ea39bea49a53e0231ff8eb8ed9fd55eacde29..8d3f2364fc8026bfed7cb67d0bc082b20f2531fa 100644 --- a/src/core/cpn/DatabaseCampaign.cc +++ b/src/core/cpn/DatabaseCampaign.cc @@ -29,13 +29,13 @@ bool DatabaseCampaign::run() { if (!cb_commandline_init()) return false; CommandLine::option_handle VARIANT = cmd.addOption("v", "variant", Arg::Required, - "-v/--variant \tVariant label (default: \"none\")"); + "-v/--variant \tVariant label (default: \"none\"; use % and _ as wildcard characters)"); CommandLine::option_handle BENCHMARK = cmd.addOption("b", "benchmark", Arg::Required, - "-b/--benchmark \tBenchmark label (default: \"none\")\n"); + "-b/--benchmark \tBenchmark label (default: \"none\"; use % and _ as wildcard characters)\n"); CommandLine::option_handle PRUNER = cmd.addOption("p", "prune-method", Arg::Required, "-p/--prune-method \tWhich import method to use (default: basic)"); - if(!cmd.parse()) { + if (!cmd.parse()) { log_send << "Error parsing arguments." << std::endl; exit(-1); } @@ -82,7 +82,7 @@ bool DatabaseCampaign::run() { std::vector<Database::Variant> variants = db->get_variants(variant, benchmark); for (std::vector<Database::Variant>::const_iterator it = variants.begin(); it != variants.end(); ++it) { - if(!run_variant(*it)) { + if (!run_variant(*it)) { log_send << "run_variant failed for " << it->variant << "/" << it->benchmark <<std::endl; return false; } @@ -147,7 +147,7 @@ bool DatabaseCampaign::run_variant(Database::Variant variant) { MYSQL_RES *pilots = db->query_stream ((sql_select + sql_body).c_str()); - log_send << "Found " << experiment_count << " unfinished experiments in database. (" + log_send << "Found " << experiment_count << " unfinished experiments in database. (" << variant.variant << "/" << variant.benchmark << ")" << std::endl; sent_pilots = 0; diff --git a/src/core/cpn/DatabaseCampaign.hpp b/src/core/cpn/DatabaseCampaign.hpp index f81815d1f29dfdf0bc99587620010f49d6ed4eb5..1fbb75dd1a5bc59fed7af85dcfd13d2339fd9801 100644 --- a/src/core/cpn/DatabaseCampaign.hpp +++ b/src/core/cpn/DatabaseCampaign.hpp @@ -61,7 +61,7 @@ public: virtual bool cb_commandline_init() { return true; } /** - * Callback to the campagin to get the result message descriptor + * Callback to the campaign to get the result message descriptor */ virtual const google::protobuf::Descriptor * cb_result_message() = 0; diff --git a/src/core/cpn/JobServer.cc b/src/core/cpn/JobServer.cc index 250e6e566f6e4a0cd35cc0fa8b79524f4d465c6a..dc7b7913757b216dafd4714b23ebf72c963c5906 100644 --- a/src/core/cpn/JobServer.cc +++ b/src/core/cpn/JobServer.cc @@ -159,7 +159,7 @@ void JobServer::run() // TODO: Log-level? #ifndef __puma boost::thread* th; - while (!m_finish){ + while (!m_finish) { // Accept connection int cs = SocketComm::timedAccept(s, (struct sockaddr*)&clientaddr, &clen, 100); if (cs < 0) { diff --git a/src/core/cpn/JobServer.hpp b/src/core/cpn/JobServer.hpp index 99255a79df356fcd7bbf87ff826a7a0b2c2b081d..6cbe56aca00d476301cf47eb72877b953f6afb7c 100644 --- a/src/core/cpn/JobServer.hpp +++ b/src/core/cpn/JobServer.hpp @@ -1,5 +1,5 @@ #ifndef __JOB_SERVER_H__ - #define __JOB_SERVER_H__ +#define __JOB_SERVER_H__ #include "Minion.hpp" #include "util/SynchronizedQueue.hpp" @@ -110,7 +110,7 @@ public: /** * Adds a new experiment data set to the job queue. * @param data Pointer to an expoeriment data object - */ + */ void addParam(ExperimentData* data); /** * Retrieve an experiment result. Blocks if we currently have no results. diff --git a/src/core/cpn/Minion.hpp b/src/core/cpn/Minion.hpp index 732d34a98ada09087701182b80afcf605492979d..8f461e0eabf62d1deb361847dfccf0dcec8b6d9c 100644 --- a/src/core/cpn/Minion.hpp +++ b/src/core/cpn/Minion.hpp @@ -4,7 +4,7 @@ */ #ifndef __MINION_HPP__ - #define __MINION_HPP__ +#define __MINION_HPP__ #include <string> @@ -14,14 +14,14 @@ namespace fail { /** * \class Minion - * - * Contains all informations about a minion. + * + * Contains all informations about a minion. */ class Minion { private: std::string hostname; bool isWorking; - ExperimentData* currentExperimentData; + ExperimentData* currentExperimentData; int sockfd; public: Minion() : isWorking(false), currentExperimentData(0), sockfd(-1) { } diff --git a/src/core/efw/CoroutineManager.hpp b/src/core/efw/CoroutineManager.hpp index ec550f8ec98a95ee7caa6e514d7bde1e51251248..9a98b3c23d4994cedc19c932dd70c9577df58924 100644 --- a/src/core/efw/CoroutineManager.hpp +++ b/src/core/efw/CoroutineManager.hpp @@ -1,5 +1,5 @@ #ifndef __COROUTINE_MANAGER_HPP__ - #define __COROUTINE_MANAGER_HPP__ +#define __COROUTINE_MANAGER_HPP__ #include <map> #include <stack> diff --git a/src/core/efw/ExperimentFlow.hpp b/src/core/efw/ExperimentFlow.hpp index 0166a2feb3e41e6a4f7096e1801c7b77d1f09652..e87991cb5d86f9136c53a023e39354074d102bc7 100644 --- a/src/core/efw/ExperimentFlow.hpp +++ b/src/core/efw/ExperimentFlow.hpp @@ -1,5 +1,5 @@ #ifndef __EXPERIMENT_FLOW_HPP__ - #define __EXPERIMENT_FLOW_HPP__ +#define __EXPERIMENT_FLOW_HPP__ #include "sal/SALInst.hpp" diff --git a/src/core/efw/JobClient.cc b/src/core/efw/JobClient.cc index ffb004af5e52a8158b1924094b4cbb54349975bc..eedb18f3b5c71a49e7c50ed2c2f7062a2339c65c 100644 --- a/src/core/efw/JobClient.cc +++ b/src/core/efw/JobClient.cc @@ -15,8 +15,10 @@ JobClient::JobClient(const std::string& server, int port) { SocketComm::init(); m_server_ent = gethostbyname(m_server.c_str()); - cout << "JobServer: " << m_server.c_str() << endl; - if(m_server_ent == NULL) { + + cout << "JobServer: " << m_server.c_str() << endl; + + if (m_server_ent == NULL) { perror("[Client@gethostbyname()]"); // TODO: Log-level? exit(1); @@ -109,7 +111,6 @@ bool JobClient::getParam(ExperimentData& exp) FailControlMessage_Command JobClient::tryToGetExperimentData(ExperimentData& exp) { - FailControlMessage ctrlmsg; //Are there other jobs for the experiment @@ -144,7 +145,7 @@ FailControlMessage_Command JobClient::tryToGetExperimentData(ExperimentData& exp switch (ctrlmsg.command()) { case FailControlMessage::WORK_FOLLOWS: uint32_t i; - for (i = 0 ; i < ctrlmsg.job_size() ; i++) { + for (i = 0; i < ctrlmsg.job_size(); i++) { ExperimentData* temp_exp = new ExperimentData(exp.getMessage().New()); if (!SocketComm::rcvMsg(m_sockfd, temp_exp->getMessage())) { @@ -187,8 +188,6 @@ FailControlMessage_Command JobClient::tryToGetExperimentData(ExperimentData& exp } else { return ctrlmsg.command(); } - - } bool JobClient::sendResult(ExperimentData& result) @@ -198,7 +197,7 @@ bool JobClient::sendResult(ExperimentData& result) temp_exp->getMessage().CopyFrom(result.getMessage()); temp_exp->setWorkloadID(result.getWorkloadID()); - m_results.push_back( temp_exp ); + m_results.push_back(temp_exp); if (m_parameters.size() != 0) { //If job request time is over send back all existing results @@ -259,7 +258,7 @@ bool JobClient::sendResultsToServer() cout << "[Client] Sending back result ["; uint32_t i; - for (i = 0; i < m_results.size() ; i++) { + for (i = 0; i < m_results.size(); i++) { ctrlmsg.add_workloadid(m_results[i]->getWorkloadID()); cout << std::dec << m_results[i]->getWorkloadID(); cout << " "; @@ -272,7 +271,7 @@ bool JobClient::sendResultsToServer() return false; } - for (i = 0; i < ctrlmsg.job_size() ; i++) { + for (i = 0; i < ctrlmsg.job_size(); i++) { if (!SocketComm::sendMsg(m_sockfd, m_results.front()->getMessage())) { close(m_sockfd); return false; diff --git a/src/core/efw/JobClient.hpp b/src/core/efw/JobClient.hpp index f0d0315790217b8dc94a826809058ac087f612a2..f7a0c7c26d105748b92ba0b47438664aa0125ab3 100644 --- a/src/core/efw/JobClient.hpp +++ b/src/core/efw/JobClient.hpp @@ -1,5 +1,5 @@ #ifndef __JOB_CLIENT_H__ - #define __JOB_CLIENT_H__ +#define __JOB_CLIENT_H__ #include <string> #include <ctime> diff --git a/src/core/sal/Architecture.hpp b/src/core/sal/Architecture.hpp index 01419379252619b647354df75a8d9e2f78ae8051..0ce8f57ff8f33878f05a79f58a0cf84891989b31 100644 --- a/src/core/sal/Architecture.hpp +++ b/src/core/sal/Architecture.hpp @@ -1,6 +1,6 @@ // Architecture.hpp: wraps architecture definition headers #ifndef __ARCHITECTURE_HPP__ - #define __ARCHITECTURE_HPP__ +#define __ARCHITECTURE_HPP__ #include "config/FailConfig.hpp" diff --git a/src/core/sal/CPU.hpp b/src/core/sal/CPU.hpp index 23a020f563b6a0f35756332406dcd383476f25e0..17217257f483e8828e0cb2ad97ce21613e223820 100644 --- a/src/core/sal/CPU.hpp +++ b/src/core/sal/CPU.hpp @@ -1,5 +1,5 @@ #ifndef __CPU_HPP__ - #define __CPU_HPP__ +#define __CPU_HPP__ #include <cstring> #include <vector> diff --git a/src/core/sal/CPUState.cc b/src/core/sal/CPUState.cc index 857c68542bbd60b2082bd5d0243cda47011f8de3..52f3bdba35f2df69b87c58c7092ce08658c6053e 100644 --- a/src/core/sal/CPUState.cc +++ b/src/core/sal/CPUState.cc @@ -26,7 +26,7 @@ bool CPUState::addSuppressedInterrupt(unsigned interruptNum) // Check if already existing: if (isSuppressedInterrupt(interruptNum+32)) return false; // already added: nothing to do here - + // FIXME: addSuppressedInterrupt(ANY_INTERRUPT) can still be called more // than once. This is not handled by the if-statement above. if (interruptNum == ANY_INTERRUPT) diff --git a/src/core/sal/CPUState.hpp b/src/core/sal/CPUState.hpp index 44618941f42b1c504bede0509f24c42f8799592b..1705e594dd9ce707aceb5a44b52266f9b7347c3c 100644 --- a/src/core/sal/CPUState.hpp +++ b/src/core/sal/CPUState.hpp @@ -1,5 +1,5 @@ #ifndef __CPU_STATE_HPP__ - #define __CPU_STATE_HPP__ +#define __CPU_STATE_HPP__ #include <cstring> #include <vector> diff --git a/src/core/sal/ConcreteCPU.hpp b/src/core/sal/ConcreteCPU.hpp index f7d40c6d7b7aadd493557059fd9cb1787e8f56dc..31cadfe3870dfc30ace8d85b7cc764c4305746cd 100644 --- a/src/core/sal/ConcreteCPU.hpp +++ b/src/core/sal/ConcreteCPU.hpp @@ -1,25 +1,25 @@ #ifndef __CONCRETE_CPU_HPP__ - #define __CONCRETE_CPU_HPP__ +#define __CONCRETE_CPU_HPP__ #if defined BUILD_BOCHS - #include "bochs/BochsCPU.hpp" + #include "bochs/BochsCPU.hpp" #elif defined BUILD_GEM5 - #if defined BUILD_ARM - #include "gem5/Gem5ArmCPU.hpp" - #else - #error Active config currently not supported! - #endif + #if defined BUILD_ARM + #include "gem5/Gem5ArmCPU.hpp" + #else + #error Active config currently not supported! + #endif #elif defined BUILD_QEMU - #include "qemu/QEMUConfig.hpp" + #include "qemu/QEMUConfig.hpp" #elif defined BUILD_T32 - #include "t32/T32Config.hpp" - #if defined BUILD_ARM - #include "t32/T32ArmCPU.hpp" - #else - #error Active config currently not supported! - #endif + #include "t32/T32Config.hpp" + #if defined BUILD_ARM + #include "t32/T32ArmCPU.hpp" + #else + #error Active config currently not supported! + #endif #else - #error SAL Config Target not defined + #error SAL Config Target not defined #endif #endif // __CONCRETE_CPU_HPP__ diff --git a/src/core/sal/Event.hpp b/src/core/sal/Event.hpp index fb19652755f2ccc2183f4a700d66afa6a554985a..17c2a9225d6710ef42e94a4ba2eb195307b39c87 100644 --- a/src/core/sal/Event.hpp +++ b/src/core/sal/Event.hpp @@ -1,5 +1,5 @@ #ifndef __EVENT_HPP__ - #define __EVENT_HPP__ +#define __EVENT_HPP__ #include <ctime> #include <string> diff --git a/src/core/sal/Listener.hpp b/src/core/sal/Listener.hpp index 9bf7a683d4193254629611fa9817799d070bf673..af9b750dc9fa9a2fe1a74e0f4cecf628e5bb9318 100644 --- a/src/core/sal/Listener.hpp +++ b/src/core/sal/Listener.hpp @@ -1,5 +1,5 @@ #ifndef __LISTENER_HPP__ - #define __LISTENER_HPP__ +#define __LISTENER_HPP__ #include <string> #include <cassert> @@ -205,12 +205,12 @@ public: }; #if defined CONFIG_EVENT_BREAKPOINTS - #define BP_CTOR_SCOPE public + #define BP_CTOR_SCOPE public #else - #define BP_CTOR_SCOPE protected - // This prevents an experiment from instantiating an object of BPSingleListener - // without having enabled the appropriate configuration flag, i.e., - // CONFIG_EVENT_BREAKPOINTS = ON. + #define BP_CTOR_SCOPE protected + // This prevents an experiment from instantiating an object of BPSingleListener + // without having enabled the appropriate configuration flag, i.e., + // CONFIG_EVENT_BREAKPOINTS = ON. #endif /** * \class BPSingleListener @@ -252,9 +252,9 @@ public: // reset scope in order to allow compiling the various other Fail* sourc }; #if defined CONFIG_EVENT_BREAKPOINTS_RANGE - #define BPRANGE_CTOR_SCOPE public + #define BPRANGE_CTOR_SCOPE public #else - #define BPRANGE_CTOR_SCOPE protected + #define BPRANGE_CTOR_SCOPE protected #endif /** * \class BPRangeListener @@ -300,12 +300,12 @@ public: }; #if defined CONFIG_EVENT_MEMREAD || defined CONFIG_EVENT_MEMWRITE - #define WP_CTOR_SCOPE public + #define WP_CTOR_SCOPE public #else - #define WP_CTOR_SCOPE protected - // Note: "private" works only in case of a "final class" (a leaf class) because when using - // "private", the derived classes wouldn't compile anymore (even if they are not used anyway). - // Clearly, MemAccessListener is *not* a leaf class. + #define WP_CTOR_SCOPE protected + // Note: "private" works only in case of a "final class" (a leaf class) because when using + // "private", the derived classes wouldn't compile anymore (even if they are not used anyway). + // Clearly, MemAccessListener is *not* a leaf class. #endif /** * \class MemAccessListener @@ -413,9 +413,9 @@ public: }; #ifdef CONFIG_EVENT_MEMREAD - #define WPREAD_CTOR_SCOPE public + #define WPREAD_CTOR_SCOPE public #else - #define WPREAD_CTOR_SCOPE protected + #define WPREAD_CTOR_SCOPE protected #endif /** * \class MemReadListener @@ -430,9 +430,9 @@ WPREAD_CTOR_SCOPE: }; #ifdef CONFIG_EVENT_MEMWRITE - #define WPWRITE_CTOR_SCOPE public + #define WPWRITE_CTOR_SCOPE public #else - #define WPWRITE_CTOR_SCOPE protected + #define WPWRITE_CTOR_SCOPE protected #endif /** * \class MemWriteListener @@ -447,9 +447,9 @@ WPWRITE_CTOR_SCOPE: }; #if defined CONFIG_EVENT_INTERRUPT || defined CONFIG_EVENT_TRAP - #define TROUBLE_CTOR_SCOPE public + #define TROUBLE_CTOR_SCOPE public #else - #define TROUBLE_CTOR_SCOPE protected + #define TROUBLE_CTOR_SCOPE protected #endif /** * \class TroubleListener @@ -513,9 +513,9 @@ public: }; #ifdef CONFIG_EVENT_INTERRUPT - #define INT_CTOR_SCOPE public + #define INT_CTOR_SCOPE public #else - #define INT_CTOR_SCOPE protected + #define INT_CTOR_SCOPE protected #endif /** * \class InterruptListener @@ -540,9 +540,9 @@ public: }; #ifdef CONFIG_EVENT_TRAP - #define TRAP_CTOR_SCOPE public + #define TRAP_CTOR_SCOPE public #else - #define TRAP_CTOR_SCOPE protected + #define TRAP_CTOR_SCOPE protected #endif /** * \class TrapListener @@ -556,9 +556,9 @@ TRAP_CTOR_SCOPE: }; #ifdef CONFIG_EVENT_GUESTSYS - #define GUESTSYS_CTOR_SCOPE public + #define GUESTSYS_CTOR_SCOPE public #else - #define GUESTSYS_CTOR_SCOPE protected + #define GUESTSYS_CTOR_SCOPE protected #endif /** * \class GuestListener @@ -592,9 +592,9 @@ public: }; #ifdef CONFIG_EVENT_IOPORT - #define IOPORT_CTOR_SCOPE public + #define IOPORT_CTOR_SCOPE public #else - #define IOPORT_CTOR_SCOPE protected + #define IOPORT_CTOR_SCOPE protected #endif /** * \class IOPortListener @@ -661,9 +661,9 @@ public: }; #ifdef CONFIG_EVENT_JUMP - #define JUMP_CTOR_SCOPE public + #define JUMP_CTOR_SCOPE public #else - #define JUMP_CTOR_SCOPE protected + #define JUMP_CTOR_SCOPE protected #endif /** * \class JumpListener diff --git a/src/core/sal/ListenerManager.cc b/src/core/sal/ListenerManager.cc index 4377379f0b522acbd501d7dbcf165222defd092b..dbe7808edd627853cba5207a7d7483b377e759f5 100644 --- a/src/core/sal/ListenerManager.cc +++ b/src/core/sal/ListenerManager.cc @@ -37,7 +37,7 @@ void ListenerManager::remove(BaseListener* li) for (index_t i = 0; i < m_BufferList.size(); ) { if (m_BufferList[i]->getParent() == simulator.m_Flows.getCurrent()) { m_BufferList[i]->onDeletion(); - if(m_BufferList[i]->getPerformanceBuffer() != NULL) + if (m_BufferList[i]->getPerformanceBuffer() != NULL) m_BufferList[i]->getPerformanceBuffer()->remove(i); m_remove(i); // Inspect the element at m_BufferList[i] a 2nd time @@ -117,7 +117,7 @@ void ListenerManager::remove(ExperimentFlow* flow) std::set<PerfBufferBase*> perfBufLists; for (bufferlist_t::iterator it = m_BufferList.begin(); it != m_BufferList.end(); it++) { (*it)->onDeletion(); // invoke listener handler - if((*it)->getPerformanceBuffer() != NULL) + if ((*it)->getPerformanceBuffer() != NULL) perfBufLists.insert((*it)->getPerformanceBuffer()); (*it)->setPerformanceBuffer(NULL); (*it)->setLocation(INVALID_INDEX); @@ -184,7 +184,7 @@ ListenerManager::iterator ListenerManager::makeActive(iterator it) // this slot stores the element which has previously been stored in the last slot): // This is required because the provided iterator "it" isn't valid anymore (due // to the deletion of the last element within m_remove(index_t)). - + iterator it_next = begin() + dist; // O(1) // Note: "begin() + dist" yields end() if dist is "large enough" (as computed above) diff --git a/src/core/sal/ListenerManager.hpp b/src/core/sal/ListenerManager.hpp index 2d997b78273eb406308785cf9763d1cc07ce9aed..70ece0ebc3994afbdbdcc08b224a7f76fa8d6dee 100644 --- a/src/core/sal/ListenerManager.hpp +++ b/src/core/sal/ListenerManager.hpp @@ -1,5 +1,5 @@ #ifndef __LISTENER_MANAGER_HPP__ - #define __LISTENER_MANAGER_HPP__ +#define __LISTENER_MANAGER_HPP__ #include <cassert> #include <list> @@ -184,7 +184,7 @@ public: * regarding their location and performance-buffer reference, i.e. their index and * performance-buffer pointer will be invalidated (by setting \c INVALID_INDEX and * \c NULL, respectively). - * To actually fire the listeners, call triggerActiveListeners(). + * To actually fire the listeners, call triggerActiveListeners(). * @param pLi the listener object pointer to trigger; \c pLi will be removed in * \c pLi->getPerformanceBuffer(). If the performance buffer-list ptr is * \c NULL, nothing will be done. diff --git a/src/core/sal/Memory.hpp b/src/core/sal/Memory.hpp index 9af56417d436587271799691c5e02db16799b35d..fb9ca3ab28b22655868a4e916d653f4fa6e37faa 100644 --- a/src/core/sal/Memory.hpp +++ b/src/core/sal/Memory.hpp @@ -1,5 +1,5 @@ #ifndef __MEMORY_HPP__ - #define __MEMORY_HPP__ +#define __MEMORY_HPP__ #include <vector> #include <stdint.h> diff --git a/src/core/sal/MemoryInstruction.hpp b/src/core/sal/MemoryInstruction.hpp index 5e4b6a9aae17f15398a69d0b5269b59a9dc12be9..336ff8196c94ce88ac86b429c4bc1c66f8c59479 100644 --- a/src/core/sal/MemoryInstruction.hpp +++ b/src/core/sal/MemoryInstruction.hpp @@ -6,34 +6,34 @@ namespace fail { - class MemoryInstruction { - regdata_t address; - regdata_t value; - uint8_t width; - bool writeAccess; - public: - MemoryInstruction(regdata_t address = ADDR_INV, regdata_t value = 0, uint8_t width = 0, bool writeAccess = false) : - address(address), value(value), width(width), writeAccess(writeAccess) { }; - - bool isWriteAccess(void) const { return writeAccess; } - regdata_t getAddress() const { return address; } - regdata_t getValue() const { return value; } - uint8_t getWidth() const { return width; } - - bool isValid(void) const { return address != ADDR_INV; } - - void setAddress(regdata_t addr) { address = addr; } - void setValue(regdata_t val) { value = val; } - void setWidth(uint8_t w) { width = w; } - void setWriteAccess(bool iswrite) { writeAccess = iswrite; } - }; - - class MemoryInstructionAnalyzer { - public: - virtual bool eval(address_t opcode, MemoryInstruction & result) = 0; - }; - - extern MemoryInstructionAnalyzer & meminstruction; +class MemoryInstruction { + regdata_t address; + regdata_t value; + uint8_t width; + bool writeAccess; +public: + MemoryInstruction(regdata_t address = ADDR_INV, regdata_t value = 0, uint8_t width = 0, bool writeAccess = false) : + address(address), value(value), width(width), writeAccess(writeAccess) { }; + + bool isWriteAccess(void) const { return writeAccess; } + regdata_t getAddress() const { return address; } + regdata_t getValue() const { return value; } + uint8_t getWidth() const { return width; } + + bool isValid(void) const { return address != ADDR_INV; } + + void setAddress(regdata_t addr) { address = addr; } + void setValue(regdata_t val) { value = val; } + void setWidth(uint8_t w) { width = w; } + void setWriteAccess(bool iswrite) { writeAccess = iswrite; } +}; + +class MemoryInstructionAnalyzer { +public: + virtual bool eval(address_t opcode, MemoryInstruction& result) = 0; +}; + +extern MemoryInstructionAnalyzer& meminstruction; } // end of namespace fail #endif // __MEMORYINSTRUCTION_HPP__ diff --git a/src/core/sal/Register.hpp b/src/core/sal/Register.hpp index 379220aa1a18500fb1c3b87c1d9591571f00a8dd..1831be0dfc49d66bfee57ff8046612c4b7f7a425 100644 --- a/src/core/sal/Register.hpp +++ b/src/core/sal/Register.hpp @@ -1,5 +1,5 @@ #ifndef __REGISTER_HPP__ - #define __REGISTER_HPP__ +#define __REGISTER_HPP__ #include <vector> #include <cstdlib> diff --git a/src/core/sal/SALConfig.cc b/src/core/sal/SALConfig.cc index 29354f1f18e9bbaee05cc740067a8b7d1e89b281..9838dae1fb3f8e65c55a2c04a7fd7f2c21be3c99 100644 --- a/src/core/sal/SALConfig.cc +++ b/src/core/sal/SALConfig.cc @@ -13,7 +13,7 @@ const unsigned ANY_TRAP = static_cast<unsigned> (-1); const unsigned ANY_INTERRUPT = static_cast<unsigned> (-1); const timer_id_t INVALID_TIMER = static_cast<timer_id_t> (0); #else - #error SAL Config Target not defined + #error SAL Config Target not defined #endif } // end-of-namespace: fail diff --git a/src/core/sal/SALConfig.hpp b/src/core/sal/SALConfig.hpp index 23ef54d9c3051435535a407eb2fb3f9382eab5bb..e4bbb00c315166dde9edbee104d08f8dafe7b9a1 100644 --- a/src/core/sal/SALConfig.hpp +++ b/src/core/sal/SALConfig.hpp @@ -1,5 +1,5 @@ #ifndef __SAL_CONFIG_HPP__ - #define __SAL_CONFIG_HPP__ +#define __SAL_CONFIG_HPP__ #include <stdint.h> @@ -7,15 +7,15 @@ // Type-config depends on the current selected simulator: #if defined BUILD_BOCHS - #include "bochs/BochsConfig.hpp" + #include "bochs/BochsConfig.hpp" #elif defined BUILD_GEM5 - #include "gem5/Gem5Config.hpp" + #include "gem5/Gem5Config.hpp" #elif defined BUILD_QEMU - #include "qemu/QEMUConfig.hpp" + #include "qemu/QEMUConfig.hpp" #elif defined BUILD_T32 - #include "t32/T32Config.hpp" + #include "t32/T32Config.hpp" #else - #error SAL Config Target not defined + #error SAL Config Target not defined #endif namespace fail { diff --git a/src/core/sal/SALInst.hpp b/src/core/sal/SALInst.hpp index 464e663a13202385f09001c19d053bbca9e6953b..c083fb1ccafb3a94c6e0c15a8d2a89df9fd91ba9 100644 --- a/src/core/sal/SALInst.hpp +++ b/src/core/sal/SALInst.hpp @@ -1,5 +1,5 @@ #ifndef __SAL_INSTANCE_HPP__ - #define __SAL_INSTANCE_HPP__ +#define __SAL_INSTANCE_HPP__ #include "SALConfig.hpp" #include "config/VariantConfig.hpp" diff --git a/src/core/sal/SimulatorController.cc b/src/core/sal/SimulatorController.cc index 1d121d276e36b7fda4cddec146399b544a11f560..39e34b1ce85c913a5b251596ef3bcdad9412241a 100644 --- a/src/core/sal/SimulatorController.cc +++ b/src/core/sal/SimulatorController.cc @@ -84,7 +84,7 @@ void SimulatorController::onBreakpoint(ConcreteCPU* cpu, address_t instrPtr, add } void SimulatorController::onMemoryAccess(ConcreteCPU* cpu, address_t addr, size_t len, - bool is_write, address_t instrPtr) + bool is_write, address_t instrPtr) { MemAccessEvent::access_type_t accesstype = is_write ? MemAccessEvent::MEM_WRITE @@ -114,7 +114,7 @@ void SimulatorController::onInterrupt(ConcreteCPU* cpu, unsigned interruptNum, b { ListenerManager::iterator it = m_LstList.begin(); InterruptEvent tmp(nmi, interruptNum, cpu); - while (it != m_LstList.end()) { // check for active listeners + while (it != m_LstList.end()) { // check for active listeners BaseListener* pev = *it; InterruptListener* pie = dynamic_cast<InterruptListener*>(pev); if (!pie || !pie->isMatching(&tmp)) { diff --git a/src/core/sal/SimulatorController.hpp b/src/core/sal/SimulatorController.hpp index d526616e55eb8a247b17f61c84a0d1edf56611a6..3763f7a4b74babcc20fca5a340b1282903a5c87e 100644 --- a/src/core/sal/SimulatorController.hpp +++ b/src/core/sal/SimulatorController.hpp @@ -1,5 +1,5 @@ #ifndef __SIMULATOR_CONTROLLER_HPP__ - #define __SIMULATOR_CONTROLLER_HPP__ +#define __SIMULATOR_CONTROLLER_HPP__ #include <iostream> #include <string> @@ -83,7 +83,7 @@ public: * @param is_write \c true if memory is written, \c false if read * @param instrPtr the address of the instruction causing the memory * access - * + * * FIXME: should instrPtr be part of this interface? */ void onMemoryAccess(ConcreteCPU* cpu, address_t addr, size_t len, bool is_write, address_t instrPtr); diff --git a/src/core/sal/arm/ArmArchitecture.hpp b/src/core/sal/arm/ArmArchitecture.hpp index e360c5b578475d26e186c957783b41b7ab9440af..1aa2844ab6204db7bf14c88cef7409dc33937751 100644 --- a/src/core/sal/arm/ArmArchitecture.hpp +++ b/src/core/sal/arm/ArmArchitecture.hpp @@ -1,5 +1,5 @@ #ifndef __ARM_ARCHITECURE_HPP__ - #define __ARM_ARCHITECURE_HPP__ +#define __ARM_ARCHITECURE_HPP__ #include "../CPU.hpp" #include "../CPUState.hpp" diff --git a/src/core/sal/arm/ArmCPUState.hpp b/src/core/sal/arm/ArmCPUState.hpp index 127d0723c40c5cb6b18f30eaa44b8add01490b3b..7735e333418bf4d45adfdfb068db6f5a58712300 100644 --- a/src/core/sal/arm/ArmCPUState.hpp +++ b/src/core/sal/arm/ArmCPUState.hpp @@ -1,5 +1,5 @@ #ifndef __ARM_CPU_STATE_HPP__ - #define __ARM_CPU_STATE_HPP__ +#define __ARM_CPU_STATE_HPP__ #include "../CPU.hpp" #include "../CPUState.hpp" diff --git a/src/core/sal/arm/ArmDisassembler.cc b/src/core/sal/arm/ArmDisassembler.cc index 506b3fa49f1c9026a9529fb6c0630e7a7de53207..e9a14955ea008132448a82921f63cde4f4177236 100644 --- a/src/core/sal/arm/ArmDisassembler.cc +++ b/src/core/sal/arm/ArmDisassembler.cc @@ -1266,7 +1266,7 @@ static int evaluate_mrs_msr(uint32_t opcode, uint32_t address, struct arm_instruction *instruction) { int R = (opcode & 0x00400000) >> 22; - std::string PSR = (R) ? "SPSR" : "CPSR"; + std::string PSR = (R) ? "SPSR" : "CPSR"; /* Move register to status register (MSR) */ if (opcode & 0x00200000) { @@ -1922,64 +1922,64 @@ int arm_evaluate_opcode(uint32_t opcode, uint32_t address, } void arm_load_store_instr::evaluate() { - fail::Register * reg = fail::simulator.getCPU(0).getRegister(Rd); - value = fail::simulator.getCPU(0).getRegisterContent(reg); - uint32_t offs = 0; - - std::cout << " Value Register: r" << (int)(Rd) << " = 0x" << std::hex << value << std::endl; - - // Address holding register: - reg = fail::simulator.getCPU(0).getRegister(Rn); - address = fail::simulator.getCPU(0).getRegisterContent(reg); - - if(offset_mode == 0) { // immediate - offs = offset.offset; - } else { // (scaled) register - reg = fail::simulator.getCPU(0).getRegister(offset.reg.Rm); - // get scale register - uint32_t rm = fail::simulator.getCPU(0).getRegisterContent(reg); - // get shift value - uint8_t shimm = offset.reg.shift_imm; - - switch(offset.reg.shift) { - case 0: // LSL - offs = rm << shimm; - break; - case 1: // LSR - offs = rm >> shimm; - break; - case 2: // ASR - offs = (rm >> shimm) | (rm & (1 << 31)); - break; - case 3: // ROR - offs = ror(rm, shimm); - break; - case 4: // RRX - // This might be wrong! - // RRX rotates right 1 bit, the carry flag is moved to 31 - // and to original bit 0 is moved to the carry flag. - // Now we have a problem: The original carry flag is updated, - - // The offset is either: - offs = rm >> 1; - // OR: offs = (rm >> 1) | (1 << 31); // if CF = 1 - break; - default: break; - } - } - - // Apply the offset to the address register - if(index_mode == 1) { // pre indexed - // the calculated address was already written back into Rn - } else if (index_mode == 2) { // post indexed - // the address got the offset after the mem access - address = address - offs; - } else { // we have to apply the offset ourselfs - address = address + offs; - } - - - std::cout << " Address Register: r" << (int)(Rn) << " = 0x" << std::hex << address << std::endl; + fail::Register * reg = fail::simulator.getCPU(0).getRegister(Rd); + value = fail::simulator.getCPU(0).getRegisterContent(reg); + uint32_t offs = 0; + + std::cout << " Value Register: r" << (int)(Rd) << " = 0x" << std::hex << value << std::endl; + + // Address holding register: + reg = fail::simulator.getCPU(0).getRegister(Rn); + address = fail::simulator.getCPU(0).getRegisterContent(reg); + + if (offset_mode == 0) { // immediate + offs = offset.offset; + } else { // (scaled) register + reg = fail::simulator.getCPU(0).getRegister(offset.reg.Rm); + // get scale register + uint32_t rm = fail::simulator.getCPU(0).getRegisterContent(reg); + // get shift value + uint8_t shimm = offset.reg.shift_imm; + + switch (offset.reg.shift) { + case 0: // LSL + offs = rm << shimm; + break; + case 1: // LSR + offs = rm >> shimm; + break; + case 2: // ASR + offs = (rm >> shimm) | (rm & (1 << 31)); + break; + case 3: // ROR + offs = ror(rm, shimm); + break; + case 4: // RRX + // This might be wrong! + // RRX rotates right 1 bit, the carry flag is moved to 31 + // and to original bit 0 is moved to the carry flag. + // Now we have a problem: The original carry flag is updated, + + // The offset is either: + offs = rm >> 1; + // OR: offs = (rm >> 1) | (1 << 31); // if CF = 1 + break; + default: break; + } + } + + // Apply the offset to the address register + if (index_mode == 1) { // pre indexed + // the calculated address was already written back into Rn + } else if (index_mode == 2) { // post indexed + // the address got the offset after the mem access + address = address - offs; + } else { // we have to apply the offset ourselfs + address = address + offs; + } + + + std::cout << " Address Register: r" << (int)(Rn) << " = 0x" << std::hex << address << std::endl; } @@ -2793,7 +2793,7 @@ static int evaluate_ifthen_thumb(uint16_t opcode, uint32_t address, struct arm_instruction *instruction) { unsigned cond = (opcode >> 4) & 0x0f; - std::string x = "", y = "", z = ""; + std::string x = "", y = "", z = ""; if (opcode & 0x01) z = (opcode & 0x02) ? "T" : "E"; @@ -3431,7 +3431,7 @@ static int t2ev_store_single(uint32_t opcode, uint32_t address, if (rn == 0xf) return ERROR_COMMAND_SYNTAX_ERROR; - instruction->type = ARM_STR; + instruction->type = ARM_STR; if (opcode & 0x0800) op |= 1; switch (op) { @@ -3439,29 +3439,29 @@ static int t2ev_store_single(uint32_t opcode, uint32_t address, case 0x8: case 0x9: size = "B"; - instruction->type = ARM_STRB; + instruction->type = ARM_STRB; goto imm12; case 0x1: size = "B"; - instruction->type = ARM_STRB; + instruction->type = ARM_STRB; goto imm8; case 0x0: size = "B"; - instruction->type = ARM_STRB; + instruction->type = ARM_STRB; break; /* halfword */ case 0xa: case 0xb: size = "H"; - instruction->type = ARM_STRH; + instruction->type = ARM_STRH; goto imm12; case 0x3: size = "H"; - instruction->type = ARM_STRH; + instruction->type = ARM_STRH; goto imm8; case 0x2: size = "H"; - instruction->type = ARM_STRH; + instruction->type = ARM_STRH; break; /* word */ case 0xc: @@ -3479,12 +3479,12 @@ static int t2ev_store_single(uint32_t opcode, uint32_t address, sprintf(cp, "STR%s.W\tr%d, [r%d, r%d, LSL #%d]", size, rt, rn, (int) opcode & 0x0f, (int) (opcode >> 4) & 0x03); - instruction->info.load_store.Rn = rn; //MH - instruction->info.load_store.Rd = rt; //MH - instruction->info.load_store.offset_mode = 1; // scaled reg - instruction->info.load_store.offset.reg.Rm = (int)(opcode & 0x0f); - instruction->info.load_store.offset.reg.shift = 0; // LSL = 0 - instruction->info.load_store.offset.reg.shift_imm = (int)((opcode >> 4) & 0x03); + instruction->info.load_store.Rn = rn; //MH + instruction->info.load_store.Rd = rt; //MH + instruction->info.load_store.offset_mode = 1; // scaled reg + instruction->info.load_store.offset.reg.Rm = (int)(opcode & 0x0f); + instruction->info.load_store.offset.reg.shift = 0; // LSL = 0 + instruction->info.load_store.offset.reg.shift_imm = (int)((opcode >> 4) & 0x03); return ERROR_OK; @@ -3493,17 +3493,17 @@ imm12: sprintf(cp, "STR%s.W\tr%d, [r%d, #%u]\t; %#3.3x", size, rt, rn, immed, immed); instruction->info.load_store.Rn = rn; //MH - instruction->info.load_store.Rd = rt; //MH - instruction->info.load_store.offset_mode = 0; // immediate - instruction->info.load_store.offset.offset = immed; + instruction->info.load_store.Rd = rt; //MH + instruction->info.load_store.offset_mode = 0; // immediate + instruction->info.load_store.offset.offset = immed; return ERROR_OK; imm8: immed = opcode & 0x00ff; instruction->info.load_store.Rn = rn; //MH - instruction->info.load_store.Rd = rt; //MH - instruction->info.load_store.offset_mode = 0; // immediate - instruction->info.load_store.offset.offset = immed; + instruction->info.load_store.Rd = rt; //MH + instruction->info.load_store.offset_mode = 0; // immediate + instruction->info.load_store.offset.offset = immed; switch (opcode & 0x700) { case 0x600: @@ -3518,11 +3518,11 @@ imm8: if (opcode & 0x100) { if (opcode & 0x400) { /* pre-indexed */ p2 = "]!"; - instruction->info.load_store.index_mode = 1; // pre indexed - } else { /* post-indexed */ + instruction->info.load_store.index_mode = 1; // pre indexed + } else { /* post-indexed */ p1 = "]"; p2 = ""; - instruction->info.load_store.index_mode = 2; // post indexed + instruction->info.load_store.index_mode = 2; // post indexed } } @@ -3684,11 +3684,11 @@ static int t2ev_ldrex_strex(uint32_t opcode, uint32_t address, switch (op1op2) { case 0: mnemonic = "STREX"; - instruction->type = ARM_STREX; + instruction->type = ARM_STREX; goto strex; case 1: mnemonic = "LDREX"; - instruction->type = ARM_LDREX; + instruction->type = ARM_LDREX; goto ldrex; case 2: case 6: @@ -3697,7 +3697,7 @@ static int t2ev_ldrex_strex(uint32_t opcode, uint32_t address, case 12: case 14: mnemonic = "STRD"; - instruction->type = ARM_LDRD; + instruction->type = ARM_LDRD; goto immediate; case 3: case 7: @@ -3706,7 +3706,7 @@ static int t2ev_ldrex_strex(uint32_t opcode, uint32_t address, case 13: case 15: mnemonic = "LDRD"; - instruction->type = ARM_LDRD; + instruction->type = ARM_LDRD; if (rn == 15) goto literal; else @@ -3715,11 +3715,11 @@ static int t2ev_ldrex_strex(uint32_t opcode, uint32_t address, switch (op3) { case 4: mnemonic = "STREXB"; - instruction->type = ARM_STREXB; + instruction->type = ARM_STREXB; break; case 5: mnemonic = "STREXH"; - instruction->type = ARM_STREXH; + instruction->type = ARM_STREXH; break; default: return ERROR_COMMAND_SYNTAX_ERROR; @@ -3737,11 +3737,11 @@ static int t2ev_ldrex_strex(uint32_t opcode, uint32_t address, return ERROR_OK; case 4: mnemonic = "LDREXB"; - instruction->type = ARM_LDREXB; + instruction->type = ARM_LDREXB; break; case 5: mnemonic = "LDREXH"; - instruction->type = ARM_LDREXH; + instruction->type = ARM_LDREXH; break; default: return ERROR_COMMAND_SYNTAX_ERROR; @@ -3756,10 +3756,10 @@ strex: if (imm) { sprintf(cp, "%s\tr%u, r%u, [r%u, #%u]\t; %#2.2x", mnemonic, rd, rt, rn, imm, imm); - } else { + } else { sprintf(cp, "%s\tr%u, r%u, [r%u]", mnemonic, rd, rt, rn); - } + } return ERROR_OK; ldrex: @@ -4093,7 +4093,7 @@ static int t2ev_load_word(uint32_t opcode, uint32_t address, sprintf(cp, "LDR\tr%d, %#8.8" PRIx32, (int) (opcode >> 12) & 0xf, thumb_alignpc4(address) + immed); - //MH TODO pc relative + //MH TODO pc relative return ERROR_OK; } @@ -4103,9 +4103,9 @@ static int t2ev_load_word(uint32_t opcode, uint32_t address, (int) (opcode >> 12) & 0xf, rn, immed, immed); - instruction->info.load_store.Rn = rn; - instruction->info.load_store.Rd = (int) (opcode >> 12) & 0xf; - instruction->info.load_store.offset.offset = immed; + instruction->info.load_store.Rn = rn; + instruction->info.load_store.Rd = (int) (opcode >> 12) & 0xf; + instruction->info.load_store.offset.offset = immed; return ERROR_OK; } @@ -4115,12 +4115,12 @@ static int t2ev_load_word(uint32_t opcode, uint32_t address, rn, (int) (opcode >> 0) & 0xf, (int) (opcode >> 4) & 0x3); - instruction->info.load_store.Rd = (int) (opcode >> 12) & 0xf; - instruction->info.load_store.Rn = rn; - instruction->info.load_store.offset_mode = 1; - instruction->info.load_store.offset.reg.Rm = (int) (opcode >> 0) & 0xf; - instruction->info.load_store.offset.reg.shift = 0; // LSL - instruction->info.load_store.offset.reg.shift_imm = (int) (opcode >> 4) & 0x3; + instruction->info.load_store.Rd = (int) (opcode >> 12) & 0xf; + instruction->info.load_store.Rn = rn; + instruction->info.load_store.offset_mode = 1; + instruction->info.load_store.offset.reg.Rm = (int) (opcode >> 0) & 0xf; + instruction->info.load_store.offset.reg.shift = 0; // LSL + instruction->info.load_store.offset.reg.shift_imm = (int) (opcode >> 4) & 0x3; return ERROR_OK; } @@ -4132,10 +4132,10 @@ static int t2ev_load_word(uint32_t opcode, uint32_t address, (int) (opcode >> 12) & 0xf, rn, immed, immed); - instruction->info.load_store.Rn = rn; - instruction->info.load_store.Rd = (int) (opcode >> 12) & 0xf; - instruction->info.load_store.offset.offset = immed; - return ERROR_OK; + instruction->info.load_store.Rn = rn; + instruction->info.load_store.Rd = (int) (opcode >> 12) & 0xf; + instruction->info.load_store.offset.offset = immed; + return ERROR_OK; } if (((opcode >> 8) & 0xf) == 0xc || (opcode & 0x0900) == 0x0900) { @@ -4150,11 +4150,11 @@ static int t2ev_load_word(uint32_t opcode, uint32_t address, if (opcode & 0x100) { if (opcode & 0x400) { /* pre-indexed */ p2 = "]!"; - instruction->info.load_store.index_mode = 1; - } else { /* post-indexed */ + instruction->info.load_store.index_mode = 1; + } else { /* post-indexed */ p1 = "]"; p2 = ""; - instruction->info.load_store.index_mode = 2; + instruction->info.load_store.index_mode = 2; } } @@ -4164,10 +4164,10 @@ static int t2ev_load_word(uint32_t opcode, uint32_t address, (opcode & 0x200) ? "" : "-", immed, p2, immed); - instruction->info.load_store.Rd = (int) (opcode >> 12) & 0xf; - instruction->info.load_store.Rn = rn; - instruction->info.load_store.offset_mode = 0; - instruction->info.load_store.offset.offset = immed; + instruction->info.load_store.Rd = (int) (opcode >> 12) & 0xf; + instruction->info.load_store.Rn = rn; + instruction->info.load_store.offset_mode = 0; + instruction->info.load_store.offset.offset = immed; return ERROR_OK; } @@ -4181,7 +4181,7 @@ static int t2ev_load_byte_hints(uint32_t opcode, uint32_t address, int rt = (opcode >> 12) & 0xf; int op2 = (opcode >> 6) & 0x3f; unsigned immed; - std::string p1 = "", p2 = "]"; + std::string p1 = "", p2 = "]"; char *mnemonic; switch ((opcode >> 23) & 0x3) { @@ -4450,7 +4450,7 @@ int thumb2_opcode(uint32_t address, uint32_t opcode, struct arm_instruction *ins case 0xe8000000: /* 32-bit instructions */ instruction->instruction_size = 4; - instruction->opcode = opcode; + instruction->opcode = opcode; break; default: /* 16-bit: Thumb1 + IT + CBZ/CBNZ + ... */ diff --git a/src/core/sal/arm/ArmDisassembler.hpp b/src/core/sal/arm/ArmDisassembler.hpp index c9ebf64dbc3dc2c7fe52df845c778f91558b22fe..b4040a6dbb41161331f48fadb0705c7684f1983c 100644 --- a/src/core/sal/arm/ArmDisassembler.hpp +++ b/src/core/sal/arm/ArmDisassembler.hpp @@ -58,9 +58,9 @@ enum arm_instruction_type { ARM_LDRH, ARM_LDRSB, ARM_LDRSH, - ARM_LDREX, - ARM_LDREXB, - ARM_LDREXH, + ARM_LDREX, + ARM_LDREXB, + ARM_LDREXH, ARM_LDM, ARM_STR, @@ -69,9 +69,9 @@ enum arm_instruction_type { ARM_STRBT, ARM_STRH, - ARM_STREX, - ARM_STREXB, - ARM_STREXH, + ARM_STREX, + ARM_STREXB, + ARM_STREXH, ARM_STM, /* Status register access instructions */ @@ -167,10 +167,10 @@ struct arm_load_store_instr { } reg; } offset; - uint32_t address; - uint32_t value; - uint8_t width; - void evaluate(void); + uint32_t address; + uint32_t value; + uint8_t width; + void evaluate(void); }; struct arm_load_store_multiple_instr { @@ -196,21 +196,21 @@ struct arm_instruction { struct arm_load_store_multiple_instr load_store_multiple; } info; - bool isBranchInstruction(void) const { - return (type == ARM_B) || (type == ARM_BL) || (type == ARM_BX) || (type == ARM_BLX); - }; + bool isBranchInstruction(void) const { + return (type == ARM_B) || (type == ARM_BL) || (type == ARM_BX) || (type == ARM_BLX); + }; - bool isLoadInstruction(void) const { - return (type >= ARM_LDR) && (type <= ARM_LDM); - } + bool isLoadInstruction(void) const { + return (type >= ARM_LDR) && (type <= ARM_LDM); + } - bool isStoreInstruction(void) const { - return (type >= ARM_STR) && (type <= ARM_STM); - } + bool isStoreInstruction(void) const { + return (type >= ARM_STR) && (type <= ARM_STM); + } - bool isMemoryAccess(void) const { - return isLoadInstruction() || isStoreInstruction(); - }; + bool isMemoryAccess(void) const { + return isLoadInstruction() || isStoreInstruction(); + }; }; int arm_evaluate_opcode(uint32_t opcode, uint32_t address, diff --git a/src/core/sal/arm/ArmMemoryInstruction.cc b/src/core/sal/arm/ArmMemoryInstruction.cc index ca95b65adc925390d620f3c8223a9c5f6ac0c915..d483e9c10c2a8eb8a473d3edfd826ed44c2d88f2 100644 --- a/src/core/sal/arm/ArmMemoryInstruction.cc +++ b/src/core/sal/arm/ArmMemoryInstruction.cc @@ -4,113 +4,112 @@ using namespace std; namespace fail { - static ArmMemoryInstructionAnalyzer anal; - MemoryInstructionAnalyzer & meminstruction = anal; - - address_t ArmMemoryInstructionAnalyzer::findPrevious(address_t address){ - if(m_dis.hasInstructionAt(address)) { - return address; - } else if (m_dis.hasInstructionAt(address - 2)) { - return address - 2; - } else { - return ADDR_INV; - } - } - - void ArmMemoryInstructionAnalyzer::evaluate(arm_instruction & inst, MemoryInstruction& result){ - cout << "Memory Access: " << inst.text << " - Size: " << inst.instruction_size << " Type " << inst.type << endl; - inst.info.load_store.evaluate(); - result.setValue(inst.info.load_store.value); - result.setAddress(inst.info.load_store.address); - result.setWidth(4); // TODO; - result.setWriteAccess(inst.isStoreInstruction()); - } - - // The Cortex M3 Lauterbach is a pain in the ass, as a Memory Watchpoint does not stop - // at the accessing instruction, but 1 or 2 instructions later. - bool ArmMemoryInstructionAnalyzer::eval_cm3(address_t address, MemoryInstruction& result){ - - arm_instruction inst; - uint32_t opcode =0; - address = findPrevious(address); - opcode = m_dis.disassemble(address).opcode; - - // OpenOCDs thumb2_opcode evaluation is not complete yet. :( - thumb2_opcode(address, opcode, &inst); - - if(inst.isMemoryAccess()){ - evaluate(inst, result); - return true; - }else{ - return false; - } +static ArmMemoryInstructionAnalyzer anal; +MemoryInstructionAnalyzer& meminstruction = anal; + +address_t ArmMemoryInstructionAnalyzer::findPrevious(address_t address){ + if (m_dis.hasInstructionAt(address)) { + return address; + } else if (m_dis.hasInstructionAt(address - 2)) { + return address - 2; + } else { + return ADDR_INV; + } +} + +void ArmMemoryInstructionAnalyzer::evaluate(arm_instruction & inst, MemoryInstruction& result){ + cout << "Memory Access: " << inst.text << " - Size: " << inst.instruction_size << " Type " << inst.type << endl; + inst.info.load_store.evaluate(); + result.setValue(inst.info.load_store.value); + result.setAddress(inst.info.load_store.address); + result.setWidth(4); // TODO; + result.setWriteAccess(inst.isStoreInstruction()); +} + +// The Cortex M3 Lauterbach is a pain in the ass, as a Memory Watchpoint does not stop +// at the accessing instruction, but 1 or 2 instructions later. +bool ArmMemoryInstructionAnalyzer::eval_cm3(address_t address, MemoryInstruction& result){ + + arm_instruction inst; + uint32_t opcode =0; + address = findPrevious(address); + opcode = m_dis.disassemble(address).opcode; + + // OpenOCDs thumb2_opcode evaluation is not complete yet. :( + thumb2_opcode(address, opcode, &inst); + + if (inst.isMemoryAccess()) { + evaluate(inst, result); + return true; + } else { + return false; + } #if 0 - arm_instruction inst; - uint32_t opcode =0; - address = findPrevious(address); // Cortex M3: memory access is at the previous instruction - opcode = m_dis.disassemble(address).opcode; - - // OpenOCDs thumb2_opcode evaluation is not complete yet. :( - thumb2_opcode(address, opcode, &inst); - - if(inst.isMemoryAccess()){ - evaluate(inst, result); - return true; - } else if(inst.isBranchInstruction()){ - // The memory access took place within the function previously branched - int regop = inst.info.b_bl_bx_blx.reg_operand; - uint32_t addr = inst.info.b_bl_bx_blx.target_address; - //cout << " Reg:" << hex << regop << " address " << hex << addr << endl; - // Lets look into this function - if( regop == -1 ){ - // address should be set.. - const ElfSymbol & sym = m_elf.getSymbol(addr|1); // | 1 to set first bit -> thumbmode - addr += sym.getSize(); // Go to end of function. - // THIS IS DANGEROUS: The memory access can be anywhere within this function, one instruction before a ret. - // OR, the memory access itself can result in leaving the function :e.g., ldr pc, [r3] - // We cannot be sure :( Here we assume the first memory access from the back. - do { // go backwards until there is a memory instruction. - addr = findPrevious(addr); // find previous - thumb2_opcode(addr, m_dis.disassemble(addr).opcode, &inst); - } while( !inst.isMemoryAccess() ); - evaluate(inst, result); - return true; - } - } else { - // There was a memory access before, but the previous instruction - // is neither an access nor a branch. - // This can happen if we came here from anywhere, e.g. by ldr pc, [r4] - } - return false; + arm_instruction inst; + uint32_t opcode =0; + address = findPrevious(address); // Cortex M3: memory access is at the previous instruction + opcode = m_dis.disassemble(address).opcode; + + // OpenOCDs thumb2_opcode evaluation is not complete yet. :( + thumb2_opcode(address, opcode, &inst); + + if (inst.isMemoryAccess()) { + evaluate(inst, result); + return true; + } else if (inst.isBranchInstruction()) { + // The memory access took place within the function previously branched + int regop = inst.info.b_bl_bx_blx.reg_operand; + uint32_t addr = inst.info.b_bl_bx_blx.target_address; + //cout << " Reg:" << hex << regop << " address " << hex << addr << endl; + // Lets look into this function + if ( regop == -1 ) { + // address should be set.. + const ElfSymbol & sym = m_elf.getSymbol(addr|1); // | 1 to set first bit -> thumbmode + addr += sym.getSize(); // Go to end of function. + // THIS IS DANGEROUS: The memory access can be anywhere within this function, one instruction before a ret. + // OR, the memory access itself can result in leaving the function :e.g., ldr pc, [r3] + // We cannot be sure :( Here we assume the first memory access from the back. + do { // go backwards until there is a memory instruction. + addr = findPrevious(addr); // find previous + thumb2_opcode(addr, m_dis.disassemble(addr).opcode, &inst); + } while ( !inst.isMemoryAccess() ); + evaluate(inst, result); + return true; + } + } else { + // There was a memory access before, but the previous instruction + // is neither an access nor a branch. + // This can happen if we came here from anywhere, e.g. by ldr pc, [r4] + } + return false; #endif - } - - bool ArmMemoryInstructionAnalyzer::eval_ca9(address_t address, MemoryInstruction& result){ - arm_instruction inst; - uint32_t opcode = m_dis.disassemble(address).opcode; - arm_evaluate_opcode(address, opcode, &inst); - if( inst.isMemoryAccess() ){ - evaluate(inst, result); - return true; - } - return false; - } +} + +bool ArmMemoryInstructionAnalyzer::eval_ca9(address_t address, MemoryInstruction& result){ + arm_instruction inst; + uint32_t opcode = m_dis.disassemble(address).opcode; + arm_evaluate_opcode(address, opcode, &inst); + if ( inst.isMemoryAccess() ) { + evaluate(inst, result); + return true; + } + return false; +} #define CORTEXM3 - bool ArmMemoryInstructionAnalyzer::eval(address_t address, MemoryInstruction & result){ +bool ArmMemoryInstructionAnalyzer::eval(address_t address, MemoryInstruction & result){ #ifdef CORTEXM3 #warning "Memory Accesses cannot be evaluated completely!" - return eval_cm3(address, result); + return eval_cm3(address, result); #elif defined CORTEXA9 - return eval_ca9(address, result); + return eval_ca9(address, result); #else #warning "Memory Accesses are not evaluated!" - return false; + return false; #endif - } - +} }; diff --git a/src/core/sal/arm/ArmMemoryInstruction.hpp b/src/core/sal/arm/ArmMemoryInstruction.hpp index c77857686c29def5ec25da7a74a3e281c69025c3..032b496ce905ec2e4b856859ed3a866f1012eb8d 100644 --- a/src/core/sal/arm/ArmMemoryInstruction.hpp +++ b/src/core/sal/arm/ArmMemoryInstruction.hpp @@ -8,27 +8,24 @@ namespace fail { - class ArmMemoryInstructionAnalyzer : public MemoryInstructionAnalyzer { - fail::ElfReader m_elf; - fail::Disassembler m_dis; +class ArmMemoryInstructionAnalyzer : public MemoryInstructionAnalyzer { + fail::ElfReader m_elf; + fail::Disassembler m_dis; - address_t findPrevious(address_t addr); - void evaluate(arm_instruction & inst, MemoryInstruction& result); - bool eval_ca9(address_t address, MemoryInstruction& result); - bool eval_cm3(address_t address, MemoryInstruction& result); + address_t findPrevious(address_t addr); + void evaluate(arm_instruction & inst, MemoryInstruction& result); + bool eval_ca9(address_t address, MemoryInstruction& result); + bool eval_cm3(address_t address, MemoryInstruction& result); - public: + public: - ArmMemoryInstructionAnalyzer() { - m_dis.init(); - }; + ArmMemoryInstructionAnalyzer() { + m_dis.init(); + }; - bool eval(address_t opcode, MemoryInstruction & result); - - }; + bool eval(address_t opcode, MemoryInstruction & result); +}; } //end of namespace fail - #endif // __ARMMEMORYINSTRUCITON_HPP__ - diff --git a/src/core/sal/bochs/BochsCPU.cc b/src/core/sal/bochs/BochsCPU.cc index b52b93e7e0440d52a98403710613a970f10fc4f8..4eb0a544d67dcf339c0c0d4328bcf3a4de693dfb 100644 --- a/src/core/sal/bochs/BochsCPU.cc +++ b/src/core/sal/bochs/BochsCPU.cc @@ -12,19 +12,19 @@ regdata_t BochsCPU::getRegisterContent(const Register* reg) const if (reg->getId() == RID_FLAGS) { // EFLAGS register? return static_cast<regdata_t>(BX_CPU(id)->read_eflags()); - } + } - #ifdef SIM_SUPPORT_64 +#ifdef SIM_SUPPORT_64 if (reg->getId() == RID_PC) // program counter? return static_cast<regdata_t>(BX_CPU(id)->gen_reg[BX_64BIT_REG_RIP].rrx); else // 64 bit general purpose registers return static_cast<regdata_t>(BX_CPU(id)->gen_reg[reg->getId()].rrx); - #else // 32 bit mode +#else // 32 bit mode if (reg->getId() == RID_PC) return static_cast<regdata_t>(BX_CPU(id)->gen_reg[BX_32BIT_REG_EIP].dword.erx); else // 32 bit general purpose registers return static_cast<regdata_t>(BX_CPU(id)->gen_reg[reg->getId()].dword.erx); - #endif // SIM_SUPPORT_64 +#endif // SIM_SUPPORT_64 } void BochsCPU::setRegisterContent(const Register* reg, regdata_t value) @@ -46,17 +46,17 @@ void BochsCPU::setRegisterContent(const Register* reg, regdata_t value) } regdata_t* pData; - #ifdef SIM_SUPPORT_64 +#ifdef SIM_SUPPORT_64 if (reg->getId() == RID_PC) // program counter? pData = &(BX_CPU(id)->gen_reg[BX_64BIT_REG_RIP].rrx); else // 64 bit general purpose registers pData = &(BX_CPU(id)->gen_reg[reg->getId()].rrx); - #else // 32 bit mode +#else // 32 bit mode if (reg->getId() == RID_PC) pData = &(BX_CPU(id)->gen_reg[BX_32BIT_REG_EIP].dword.erx); else // 32 bit general purpose registers pData = &(BX_CPU(id)->gen_reg[reg->getId()].dword.erx); - #endif // SIM_SUPPORT_64 +#endif // SIM_SUPPORT_64 *pData = value; } diff --git a/src/core/sal/bochs/BochsCPU.hpp b/src/core/sal/bochs/BochsCPU.hpp index 9a0870a0a09a4f630bcadbfe9442c06eab31d26d..353a90956503243fc32ee5e6b2f23439791b90a4 100644 --- a/src/core/sal/bochs/BochsCPU.hpp +++ b/src/core/sal/bochs/BochsCPU.hpp @@ -1,5 +1,5 @@ #ifndef __BOCHS_CPU_HPP__ - #define __BOCHS_CPU_HPP__ +#define __BOCHS_CPU_HPP__ #include "../x86/X86Architecture.hpp" #include "../x86/X86CPUState.hpp" @@ -11,12 +11,12 @@ namespace fail { /** * \class BochsCPU - * + * * \c BochsCPU is the concrete CPU implementation for the Bochs x86 simulator. It * implements the CPU interfaces \c X86Architecture and \c X86CPUState. * \c X86Architecture refers to architectural information (e.g. register \a count) * while \c X86CPUState encapsulates the CPU state (e.g. register \a content). - * + * */ class BochsCPU : public X86Architecture, public X86CPUState { private: @@ -29,7 +29,7 @@ public: BochsCPU(unsigned int id) : m_Id(id) { } /** * Virtual Destructor is required. - */ + */ virtual ~BochsCPU() { } /** * Retrieves the content of the register \c reg. diff --git a/src/core/sal/bochs/BochsConfig.hpp b/src/core/sal/bochs/BochsConfig.hpp index 93e9fc7374f1957bcf241f1fa6a7c718a58fb4aa..04f372948a323ecb68aa3bfcd25846ef25970d14 100644 --- a/src/core/sal/bochs/BochsConfig.hpp +++ b/src/core/sal/bochs/BochsConfig.hpp @@ -5,7 +5,7 @@ */ #ifndef __BOCHS_CONFIG_HPP__ - #define __BOCHS_CONFIG_HPP__ +#define __BOCHS_CONFIG_HPP__ #include "bochs.h" #include "config.h" @@ -15,15 +15,15 @@ namespace fail { typedef bx_address guest_address_t; //!< the guest memory address type typedef Bit8u* host_address_t; //!< the host memory address type #if BX_SUPPORT_X86_64 - typedef Bit64u register_data_t; //!< register data type (64 bit) +typedef Bit64u register_data_t; //!< register data type (64 bit) #else - typedef Bit32u register_data_t; //!< register data type (32 bit) +typedef Bit32u register_data_t; //!< register data type (32 bit) #endif typedef int timer_t; //!< type of timer IDs // 'Publish' 64 bit ability (if enabled in Bochs): #if BX_SUPPORT_X86_64 - #define SIM_SUPPORT_64 + #define SIM_SUPPORT_64 #endif } // end-of-namespace: fail diff --git a/src/core/sal/bochs/BochsController.cc b/src/core/sal/bochs/BochsController.cc index 6095f71f14789c28bd28a37d78b13e599eeee415..a6decf86df3c5b6bab1669a8e4d0aca6767fa8f7 100644 --- a/src/core/sal/bochs/BochsController.cc +++ b/src/core/sal/bochs/BochsController.cc @@ -80,14 +80,14 @@ void BochsController::onIOPort(ConcreteCPU* cpu, unsigned char data, unsigned po bool BochsController::save(const std::string& path) { int stat; - + stat = mkdir(path.c_str(), 0777); if (!(stat == 0 || errno == EEXIST)) { return false; // std::cout << "[FAIL] Can not create target-directory to save!" << std::endl; // TODO: (Non-)Verbose-Mode? Log-level? Maybe better: use return value to indicate failure? } - + save_bochs_request = true; BX_CPU(0)->async_event |= 1; sr_path = path; @@ -164,12 +164,12 @@ const std::string& BochsController::getMnemonic() const ConcreteCPU& BochsController::detectCPU(BX_CPU_C* pCPU) const { unsigned i = 0; - #if BX_SUPPORT_SMP +#if BX_SUPPORT_SMP for (; i < BX_SMP_PROCESSORS; i++) { if (BX_CPU_C[i] == pCPU) // cmp this ptr with all possible CPU objects break; // index "i" found! -> stop! } - #endif +#endif return getCPU(i); } diff --git a/src/core/sal/bochs/BochsController.hpp b/src/core/sal/bochs/BochsController.hpp index 70deabe3351b5839d8f808563762db2366214288..4b2e3abfeeaf23a7726bdf613c1b11e9f91ea8d5 100644 --- a/src/core/sal/bochs/BochsController.hpp +++ b/src/core/sal/bochs/BochsController.hpp @@ -1,5 +1,5 @@ #ifndef __BOCHS_CONTROLLER_HPP__ - #define __BOCHS_CONTROLLER_HPP__ +#define __BOCHS_CONTROLLER_HPP__ #include <string> #include <cassert> @@ -25,7 +25,7 @@ class ExperimentFlow; /** * \class BochsController * Bochs-specific implementation of a SimulatorController. - * + * * @note The instruction (IP) pointer modification handler (onBreakpoint()) * is called (from the Breakpoints aspect) *every* time the Bochs-internal IP * changes. The handler itself evaluates if a breakpoint event needs to be @@ -65,7 +65,7 @@ public: * object within the ListenerManager and fires such an event by calling * \c triggerActiveListeners(). * @param thisPtr a pointer to the TimerListener-object triggered - * + * * FIXME: Due to Bochs internal timer and ips-configuration related stuff, * the simulator sometimes panics with "keyboard error:21" (see line * 1777 in bios/rombios.c, function keyboard_init()) if a TimerListener @@ -112,7 +112,7 @@ public: */ void fireInterrupt(unsigned irq); /** - * Fire done: Callback from Simulator + * Fire done: Callback from Simulator */ void fireInterruptDone(); virtual simtime_t getTimerTicks() { return bx_pc_system.time_ticks(); } diff --git a/src/core/sal/bochs/BochsHelpers.hpp b/src/core/sal/bochs/BochsHelpers.hpp index 9138c9e92cf47458f0f2ea82556429391ba8ab82..1ad125f4be70861416642fa62f16e2f9643579c0 100644 --- a/src/core/sal/bochs/BochsHelpers.hpp +++ b/src/core/sal/bochs/BochsHelpers.hpp @@ -1,5 +1,5 @@ #ifndef __BOCHS_HELPERS_HPP__ - #define __BOCHS_HELPERS_HPP__ +#define __BOCHS_HELPERS_HPP__ #include "cpu/cpu.h" diff --git a/src/core/sal/bochs/BochsListener.hpp b/src/core/sal/bochs/BochsListener.hpp index f08a32980b1072da2976350704dfc5748fe57e74..26c1bf946d89535b800d2fcabad1e2d9f81e89c8 100644 --- a/src/core/sal/bochs/BochsListener.hpp +++ b/src/core/sal/bochs/BochsListener.hpp @@ -1,5 +1,5 @@ #ifndef __BOCHS_LISTENER_HPP__ - #define __BOCHS_LISTENER_HPP__ +#define __BOCHS_LISTENER_HPP__ namespace fail { diff --git a/src/core/sal/bochs/BochsMemory.hpp b/src/core/sal/bochs/BochsMemory.hpp index 750e0868da2a8c617da0b4d86fce68775b1db899..98d2455beba17eddfb42c27adb028258a4acdcfe 100644 --- a/src/core/sal/bochs/BochsMemory.hpp +++ b/src/core/sal/bochs/BochsMemory.hpp @@ -1,5 +1,5 @@ #ifndef __BOCHS_MEMORY_HPP__ - #define __BOCHS_MEMORY_HPP__ +#define __BOCHS_MEMORY_HPP__ #include "../Memory.hpp" diff --git a/src/core/sal/bochs/FailBochsGlobals.hpp b/src/core/sal/bochs/FailBochsGlobals.hpp index df32201d10249e5ac879a717cc86f13c25dce59c..8ee30bbfc2c2a91394bfc0435ec3313814070bf4 100644 --- a/src/core/sal/bochs/FailBochsGlobals.hpp +++ b/src/core/sal/bochs/FailBochsGlobals.hpp @@ -1,5 +1,5 @@ #ifndef __FAIL_BOCHS_GLOBALS_HPP__ - #define __FAIL_BOCHS_GLOBALS_HPP__ +#define __FAIL_BOCHS_GLOBALS_HPP__ #include <string> @@ -8,9 +8,9 @@ namespace fail { #ifdef DANCEOS_RESTORE - extern bx_bool restore_bochs_request; - extern bx_bool save_bochs_request; - extern std::string sr_path; +extern bx_bool restore_bochs_request; +extern bx_bool save_bochs_request; +extern std::string sr_path; #endif extern bx_bool reboot_bochs_request; diff --git a/src/core/sal/gem5/Gem5ArmCPU.hpp b/src/core/sal/gem5/Gem5ArmCPU.hpp index 2d0b0ffdd065c71e5fc75709722654daf3c45982..333b8686f97c0d08aa5fc45e0879943d35c8b5a6 100644 --- a/src/core/sal/gem5/Gem5ArmCPU.hpp +++ b/src/core/sal/gem5/Gem5ArmCPU.hpp @@ -1,5 +1,5 @@ #ifndef __GEM5_ARM_CPU_HPP__ - #define __GEM5_ARM_CPU_HPP__ +#define __GEM5_ARM_CPU_HPP__ #include "../arm/ArmArchitecture.hpp" #include "../arm/ArmCPUState.hpp" diff --git a/src/core/sal/gem5/Gem5Config.hpp b/src/core/sal/gem5/Gem5Config.hpp index fbac43eddb48aec7831b6a09c6ca769ef47c285a..de2fec16222c5b59b2c6667bf2637c7dbac6da05 100644 --- a/src/core/sal/gem5/Gem5Config.hpp +++ b/src/core/sal/gem5/Gem5Config.hpp @@ -5,7 +5,7 @@ */ #ifndef __GEM5_CONFIG_HPP__ - #define __GEM5_CONFIG_HPP__ +#define __GEM5_CONFIG_HPP__ #include <stdint.h> diff --git a/src/core/sal/gem5/Gem5Controller.hpp b/src/core/sal/gem5/Gem5Controller.hpp index d1bd566c38ef898ccd0af2439b861fed2c4e8bc7..5b90e849ce0dacab8497cb8d0c8aedeaa9dfe6ce 100644 --- a/src/core/sal/gem5/Gem5Controller.hpp +++ b/src/core/sal/gem5/Gem5Controller.hpp @@ -1,5 +1,5 @@ #ifndef __GEM5_CONTROLLER_HPP__ - #define __GEM5_CONTROLLER_HPP__ +#define __GEM5_CONTROLLER_HPP__ #include <string> @@ -42,7 +42,7 @@ public: virtual simtime_t getTimerTicksPerSecond(); #if defined(CONFIG_EVENT_BREAKPOINTS) ||\ defined(CONFIG_EVENT_BREAKPOINTS_RANGE) - void setMnemonic(const std::string& mn) { m_Mnemonic = mn; } + void setMnemonic(const std::string& mn) { m_Mnemonic = mn; } const std::string& getMnemonic() const { return m_Mnemonic; } #endif }; diff --git a/src/core/sal/gem5/Gem5Memory.hpp b/src/core/sal/gem5/Gem5Memory.hpp index 750d9abf2fb3b27c2c350fa7454ea86543d62d23..65e8a6956d1800d8d8beeae912d654db55fe198a 100644 --- a/src/core/sal/gem5/Gem5Memory.hpp +++ b/src/core/sal/gem5/Gem5Memory.hpp @@ -1,5 +1,5 @@ #ifndef __GEM5_MEMORY_HPP__ - #define __GEM5_MEMORY_HPP__ +#define __GEM5_MEMORY_HPP__ #include "../Memory.hpp" #include "Gem5Wrapper.hpp" diff --git a/src/core/sal/gem5/Gem5Wrapper.hpp b/src/core/sal/gem5/Gem5Wrapper.hpp index 1c5699e8d39461d27093bc295a1a85956361c2a5..e1deb0e3c7647c467b18b24a676439a3ec5f1ae5 100644 --- a/src/core/sal/gem5/Gem5Wrapper.hpp +++ b/src/core/sal/gem5/Gem5Wrapper.hpp @@ -1,5 +1,5 @@ #ifndef __GEM5_WRAPPER_HPP__ - #define __GEM5_WRAPPER_HPP__ +#define __GEM5_WRAPPER_HPP__ #include "../Register.hpp" #include "../SALConfig.hpp" diff --git a/src/core/sal/perf/BreakpointBuffer.cc b/src/core/sal/perf/BreakpointBuffer.cc index 9214959bde2a1d7bf6d54c5f865c52b6ce83eaaf..1d56a55c62e01cd3f890ec3201112401c5ad25ca 100644 --- a/src/core/sal/perf/BreakpointBuffer.cc +++ b/src/core/sal/perf/BreakpointBuffer.cc @@ -10,7 +10,7 @@ ResultSet& PerfVectorBreakpoints::gather(BPEvent* pData) static ResultSet res; res.clear(); // FIXME: This should not free the memory of the underlying std::vector. // Search for all indices of matching listener objects: - for(std::vector<index_t>::iterator it = m_BufList.begin(); it != m_BufList.end(); ++it) { + for (std::vector<index_t>::iterator it = m_BufList.begin(); it != m_BufList.end(); ++it) { BPListener* pLi = static_cast<BPListener*>(simulator.dereference(*it)); if (pLi->isMatching(pData)) { // Update trigger IPtr: diff --git a/src/core/sal/perf/BreakpointBuffer.hpp b/src/core/sal/perf/BreakpointBuffer.hpp index 9b4537da45462d6335266a0c13860580d0d15075..9fe03eb2fac079a743a76bbf6d33abda98460db5 100644 --- a/src/core/sal/perf/BreakpointBuffer.hpp +++ b/src/core/sal/perf/BreakpointBuffer.hpp @@ -1,9 +1,9 @@ #ifndef __BREAKPOINT_BUFFER_HPP__ - #define __BREAKPOINT_BUFFER_HPP__ +#define __BREAKPOINT_BUFFER_HPP__ #include "BufferInterface.hpp" -// TODOs: +// TODOs: // - Make these implementations even faster (see below: continue PerfVecSortedSingleBP). namespace fail { @@ -20,7 +20,7 @@ public: /** * \class PerfVecSortedSingleBP - * + * * This class implements a faster mechanism to store BPSingleListener * based on binary search on their corresponding instruction pointer. */ @@ -52,7 +52,7 @@ public: // } } } - + static bool CompareInstrPtr(index_t arg1, index_t arg2, void* pStuff) { SimulatorController* pSim = static_cast<SimulatorController*>(pStuff); @@ -80,9 +80,9 @@ public: while (first <= last) { int mid = (first + last) / 2; // compute mid point. - if (VAL(key) > VAL(vec[mid])) + if (VAL(key) > VAL(vec[mid])) first = mid + 1; // repeat search in top half. - else if (VAL(key) < VAL(vec[mid])) + else if (VAL(key) < VAL(vec[mid])) last = mid - 1; // repeat search in bottom half. else return mid; // found it. return position @@ -100,7 +100,7 @@ public: // TODO: Improve this by using binary search, too! ResultSet res; // Search for all indices of matching listener objects: - for(std::vector<index_t>::iterator it = m_BufList.begin(); it != m_BufList.end(); ++it) { + for (std::vector<index_t>::iterator it = m_BufList.begin(); it != m_BufList.end(); ++it) { BPListener* pLi = static_cast<BPListener*>(simulator.dereference(*it)); if (pLi->isMatching(pData)) { // Update trigger IPtr: diff --git a/src/core/sal/perf/BufferInterface.hpp b/src/core/sal/perf/BufferInterface.hpp index b1fe622c203c786fff841d85e29d8a5e9cf09c7d..d612a79b065075b9a5407029581888fee06ab5d6 100644 --- a/src/core/sal/perf/BufferInterface.hpp +++ b/src/core/sal/perf/BufferInterface.hpp @@ -1,5 +1,5 @@ #ifndef __BUFFER_INTERFACE_HPP__ - #define __BUFFER_INTERFACE_HPP__ +#define __BUFFER_INTERFACE_HPP__ #include <cstddef> #include <vector> @@ -58,7 +58,7 @@ public: /** * \class DefPerfVector - * + * * Default \c std::vector based performance implementation (abstract) */ template<class T> diff --git a/src/core/sal/perf/WatchpointBuffer.cc b/src/core/sal/perf/WatchpointBuffer.cc index d74b1c3c6dbb02fa5abdf0285de73d14582082a6..1a66ff7e52be4ede4f7e7675370107535bc72f14 100644 --- a/src/core/sal/perf/WatchpointBuffer.cc +++ b/src/core/sal/perf/WatchpointBuffer.cc @@ -11,7 +11,7 @@ ResultSet& PerfVectorWatchpoints::gather(MemAccessEvent* pData) static ResultSet res; res.clear(); // FIXME: This should not free the memory of the underlying std::vector. // Search for all indices of matching listener objects: - for(std::vector<index_t>::iterator it = m_BufList.begin(); it != m_BufList.end(); ++it) { + for (std::vector<index_t>::iterator it = m_BufList.begin(); it != m_BufList.end(); ++it) { MemAccessListener* pmal = static_cast<MemAccessListener*>(simulator.dereference(*it)); if (pmal->isMatching(pData)) { // Update trigger data: diff --git a/src/core/sal/perf/WatchpointBuffer.hpp b/src/core/sal/perf/WatchpointBuffer.hpp index 32c40ce63a85060fe48a949bb7969ee2be9212e1..a5a6ac703b9c87cd5602353ff0fbd5b8a06dbdd7 100644 --- a/src/core/sal/perf/WatchpointBuffer.hpp +++ b/src/core/sal/perf/WatchpointBuffer.hpp @@ -1,5 +1,5 @@ #ifndef __WATCHPOINT_BUFFER_HPP__ - #define __WATCHPOINT_BUFFER_HPP__ +#define __WATCHPOINT_BUFFER_HPP__ #include "BufferInterface.hpp" diff --git a/src/core/sal/qemu/QEMUConfig.hpp b/src/core/sal/qemu/QEMUConfig.hpp index c47573a7de2ab941d884f84a8c109ebd92d4b66b..5671fda63a97b914ffe7db07b1b4107e6747a8d3 100644 --- a/src/core/sal/qemu/QEMUConfig.hpp +++ b/src/core/sal/qemu/QEMUConfig.hpp @@ -5,7 +5,7 @@ */ #ifndef __QEMU_CONFIG_HPP__ - #define __QEMU_CONFIG_HPP__ +#define __QEMU_CONFIG_HPP__ // FIXME: qemu/targphys.h defines address types (but relies on a global preprocessor macro) diff --git a/src/core/sal/qemu/QEMUController.hpp b/src/core/sal/qemu/QEMUController.hpp index 04408e135af9446c59be47aa64463fab3ca87eb4..2b4a21621e4db9ba407452e34996ceea3ecfdae5 100644 --- a/src/core/sal/qemu/QEMUController.hpp +++ b/src/core/sal/qemu/QEMUController.hpp @@ -1,5 +1,5 @@ #ifndef __QEMU_CONTROLLER_HPP__ - #define __QEMU_CONTROLLER_HPP__ +#define __QEMU_CONTROLLER_HPP__ #include <string> #include <cassert> diff --git a/src/core/sal/qemu/QEMUMemory.hpp b/src/core/sal/qemu/QEMUMemory.hpp index c01903fd1af86e08a02fab280c67275e7879a0a0..415c6058522f09fa7cecaff93007f6f72cda558c 100644 --- a/src/core/sal/qemu/QEMUMemory.hpp +++ b/src/core/sal/qemu/QEMUMemory.hpp @@ -1,5 +1,5 @@ #ifndef __QEMU_MEMORY_HPP__ - #define __QEMU_MEMORY_HPP__ +#define __QEMU_MEMORY_HPP__ #include "../Memory.hpp" diff --git a/src/core/sal/qemu/QEMURegister.hpp b/src/core/sal/qemu/QEMURegister.hpp index 2f966802ada575f13e59f94b538d5a597115d6c9..5bad44b35eff4191fe034650c3bba7d01a592e72 100644 --- a/src/core/sal/qemu/QEMURegister.hpp +++ b/src/core/sal/qemu/QEMURegister.hpp @@ -1,5 +1,5 @@ #ifndef __QEMU_REGISTER_HPP__ - #define __QEMU_REGISTER_HPP__ +#define __QEMU_REGISTER_HPP__ #include "../Register.hpp" diff --git a/src/core/sal/t32/T32ArmCPU.cc b/src/core/sal/t32/T32ArmCPU.cc index 8f8f8ed1a3e61df180ca406e9d235088e60366c1..ebab73224a7be9a5b60bdaa2cfe5309f1ebf9aa5 100644 --- a/src/core/sal/t32/T32ArmCPU.cc +++ b/src/core/sal/t32/T32ArmCPU.cc @@ -8,50 +8,50 @@ static const uint64_t lower = 0x00000000ffffffff; regdata_t T32ArmCPU::getRegisterContent(const Register* reg) const { - // T32_ReadRegister wants a mask of bits representig the registers to read: - // e.g., reading R1 and R4 and R63 - // mask1 - // 0000 0000 0000 0000 0001 0010 -> R1/R4 - // mask2 - // 1000 0000 0000 0000 0000 0000 -> R63 - uint64_t mask = (1 << reg->getIndex()); - - if(mask){ - if( T32_ReadRegister(static_cast<dword>(mask & lower ), static_cast<dword>(mask >> 32), m_regbuffer) == 0 ){ - // No error, return value. - return m_regbuffer[reg->getIndex()]; - } else { - /// TODO Error handling! - std::cout << "could not read register :(" << std::endl; - } - } + // T32_ReadRegister wants a mask of bits representig the registers to read: + // e.g., reading R1 and R4 and R63 + // mask1 + // 0000 0000 0000 0000 0001 0010 -> R1/R4 + // mask2 + // 1000 0000 0000 0000 0000 0000 -> R63 + uint64_t mask = (1 << reg->getIndex()); + + if (mask) { + if ( T32_ReadRegister(static_cast<dword>(mask & lower ), static_cast<dword>(mask >> 32), m_regbuffer) == 0 ) { + // No error, return value. + return m_regbuffer[reg->getIndex()]; + } else { + /// TODO Error handling! + std::cout << "could not read register :(" << std::endl; + } + } return 0; // we should not come here. } void T32ArmCPU::setRegisterContent(const Register* reg, regdata_t value) { - uint64_t mask = (1 << reg->getIndex()); - - // set value to be set by T32: - m_regbuffer[reg->getIndex()] = value; - if(mask){ - if( T32_WriteRegister(static_cast<dword>(mask & lower), static_cast<dword>(mask >> 32), m_regbuffer) == 0 ){ - // No error, return value. - return; - } else { - /// TODO Error handling! - std::cout << "could not write register :(" << std::endl; - } - } + uint64_t mask = (1 << reg->getIndex()); + + // set value to be set by T32: + m_regbuffer[reg->getIndex()] = value; + if (mask) { + if ( T32_WriteRegister(static_cast<dword>(mask & lower), static_cast<dword>(mask >> 32), m_regbuffer) == 0 ) { + // No error, return value. + return; + } else { + /// TODO Error handling! + std::cout << "could not write register :(" << std::endl; + } + } } address_t T32ArmCPU::getInstructionPointer() const { - // TODO: programpointer is only valid when Emulation is stopped! -> T32_GetState) - address_t programpointer; - T32_ReadPP( &programpointer ); - return programpointer; + // TODO: programpointer is only valid when Emulation is stopped! -> T32_GetState) + address_t programpointer; + T32_ReadPP( &programpointer ); + return programpointer; } } // end-of-namespace: fail diff --git a/src/core/sal/t32/T32ArmCPU.hpp b/src/core/sal/t32/T32ArmCPU.hpp index 4fc58bfbb06150a60ebf64f8831a6d8263b9f05a..6d10e4c66a1ebc138c849f385321731048be49aa 100644 --- a/src/core/sal/t32/T32ArmCPU.hpp +++ b/src/core/sal/t32/T32ArmCPU.hpp @@ -1,5 +1,5 @@ #ifndef __T32_ARM_CPU_HPP__ - #define __T32_ARM_CPU_HPP__ +#define __T32_ARM_CPU_HPP__ #include "../arm/ArmArchitecture.hpp" #include "../arm/ArmCPUState.hpp" @@ -39,7 +39,7 @@ public: /** * Retrieves the current instruction pointer (IP aka program counter, PC for short) * for the current CPU \c this. - * @return the current instruction ptr address + * @return the current instruction ptr address */ address_t getInstructionPointer() const; @@ -63,8 +63,8 @@ public: unsigned int getId() const { return m_Id; } private: unsigned int m_Id; //!< the unique ID of this CPU - mutable dword m_regbuffer[64]; //!< internal buffer for reading/writing registers, wow mutable really makes sense sometimes. - // char* cpuname? OMAP4430APP1 ?? + mutable dword m_regbuffer[64]; //!< internal buffer for reading/writing registers, wow mutable really makes sense sometimes. + // char* cpuname? OMAP4430APP1 ?? }; diff --git a/src/core/sal/t32/T32Constants.hpp b/src/core/sal/t32/T32Constants.hpp index 85c27375ecf4277b1b1494beb62fa4ff60e72c6c..55a596c21e50be52d98c9a1624399f473d7144fb 100644 --- a/src/core/sal/t32/T32Constants.hpp +++ b/src/core/sal/t32/T32Constants.hpp @@ -6,35 +6,36 @@ #define __T32_CONSTANTS_HPP__ namespace fail { - namespace T32 { - //!< Breakpoint configuration - struct BP { - enum { - EXECUTION = 1<<0, - HLL_STEP = 1<<1, - SPOT = 1<<2, - READ = 1<<3, - WRITE = 1<<4, - ALPHA = 1<<5, - BETA = 1<<6, - CHARLY = 1<<7, - CLEAR = 1<<8, - }; - }; // struct BP +namespace T32 { +//!< Breakpoint configuration +struct BP { + enum { + EXECUTION = 1<<0, + HLL_STEP = 1<<1, + SPOT = 1<<2, + READ = 1<<3, + WRITE = 1<<4, + ALPHA = 1<<5, + BETA = 1<<6, + CHARLY = 1<<7, + CLEAR = 1<<8, + }; +}; // struct BP - //!< Memory access variants - struct MEMACCESS { - enum { - DATA = 0, - PROGRAM = 1, - AD = 12, - AP = 13, - USR = 15, - }; - }; // struct MEMACCESS - }; // namespace T32 +//!< Memory access variants +struct MEMACCESS { + enum { + DATA = 0, + PROGRAM = 1, + AD = 12, + AP = 13, + USR = 15, + }; +}; // struct MEMACCESS + +}; // namespace T32 }; // namespace fail #endif // __T32_CONSTANTS_HPP__ diff --git a/src/core/sal/t32/T32Controller.cc b/src/core/sal/t32/T32Controller.cc index b9a394e9225bd0481a1e3f62315e910f7e782a7b..7e19eb3e56a28d3d3af81a5e794cfcf6ad17fc5c 100644 --- a/src/core/sal/t32/T32Controller.cc +++ b/src/core/sal/t32/T32Controller.cc @@ -4,11 +4,11 @@ namespace fail { void T32Controller::startup(){ - // Do some T32-specific startup - addCPU(new ConcreteCPU(0)); - // Startup generic SimulatorController - // TODO pass on command-line parameters - SimulatorController::startup(); + // Do some T32-specific startup + addCPU(new ConcreteCPU(0)); + // Startup generic SimulatorController + // TODO pass on command-line parameters + SimulatorController::startup(); } diff --git a/src/core/sal/t32/T32Controller.hpp b/src/core/sal/t32/T32Controller.hpp index b8b52c10c7bb930a59c3906886df05cbea63ee7a..de86e4a5789a97e7c26c1f717c926368824d62be 100644 --- a/src/core/sal/t32/T32Controller.hpp +++ b/src/core/sal/t32/T32Controller.hpp @@ -12,8 +12,8 @@ namespace fail { */ class T32Controller : public SimulatorController { public: - void startup(); - T32Controller() : SimulatorController(new T32MemoryManager()) { }; + void startup(); + T32Controller() : SimulatorController(new T32MemoryManager()) { }; ~T32Controller(); /* ******************************************************************** diff --git a/src/core/sal/t32/T32Memory.hpp b/src/core/sal/t32/T32Memory.hpp index 68adc8d2b42c5430ce30e32ce9287fd7e236a28c..7032fe516202d59812e53480fab7e0ffa5220519 100644 --- a/src/core/sal/t32/T32Memory.hpp +++ b/src/core/sal/t32/T32Memory.hpp @@ -1,5 +1,5 @@ #ifndef __T32_MEMORY_HPP__ - #define __T32_MEMORY_HPP__ +#define __T32_MEMORY_HPP__ #include "../Memory.hpp" #include <t32.h> @@ -21,26 +21,26 @@ public: byte_t getByte(guest_address_t addr) { - char b; - getBytes(addr, 1, &b); - return b; - } + char b; + getBytes(addr, 1, &b); + return b; + } void getBytes(guest_address_t addr, size_t cnt, void *dest) { - int access = T32::MEMACCESS::DATA; // TODO what access class do we need?! - T32_ReadMemory( addr, access, (byte*)(dest), cnt); + int access = T32::MEMACCESS::DATA; // TODO what access class do we need?! + T32_ReadMemory( addr, access, (byte*)(dest), cnt); } void setByte(guest_address_t addr, byte_t data) { - setBytes(addr, 1, &data); + setBytes(addr, 1, &data); } void setBytes(guest_address_t addr, size_t cnt, void const *src) { - int access = T32::MEMACCESS::DATA; // TODO what access class do we really need?! - T32_WriteMemory(addr, access, (byte*)(src), cnt); + int access = T32::MEMACCESS::DATA; // TODO what access class do we really need?! + T32_WriteMemory(addr, access, (byte*)(src), cnt); } }; diff --git a/src/core/sal/x86/X86Architecture.cc b/src/core/sal/x86/X86Architecture.cc index 10fd45bf5cc2a88797aa6c96ace57792b123e115..84f751c85f32b6a677684ddbccfbd2e866f004b1 100644 --- a/src/core/sal/x86/X86Architecture.cc +++ b/src/core/sal/x86/X86Architecture.cc @@ -8,35 +8,35 @@ X86Architecture::X86Architecture() { // ------------------------------------- // Add the general purpose register: - #ifdef SIM_SUPPORT_64 +#ifdef SIM_SUPPORT_64 // -- 64 bit register -- - const std::string names[] = { "RAX", "RCX", "RDX", "RBX", "RSP", "RBP", "RSI", "RDI", "R8", - "R9", "R10", "R11", "R12", "R13", "R14", "R15" }; + const std::string names[] = { "RAX", "RCX", "RDX", "RBX", "RSP", "RBP", "RSI", "RDI", "R8", + "R9", "R10", "R11", "R12", "R13", "R14", "R15" }; for (unsigned short i = 0; i < 16; i++) { Register* pReg = new Register(i, 64); pReg->setName(names[i]); m_addRegister(pReg, RT_GP); } - #else - // -- 32 bit register -- - const std::string names[] = { "EAX", "ECX", "EDX", "EBX", "ESP", "EBP", "ESI", "EDI" }; +#else + // -- 32 bit register -- + const std::string names[] = { "EAX", "ECX", "EDX", "EBX", "ESP", "EBP", "ESI", "EDI" }; for (unsigned short i = 0; i < 8; i++) { Register* pReg = new Register(i, 32); pReg->setName(names[i]); m_addRegister(pReg, RT_GP); } - #endif // SIM_SUPPORT_64 +#endif // SIM_SUPPORT_64 // ------------------------------------- // Add the program counter (PC) register: - #ifdef SIM_SUPPORT_64 +#ifdef SIM_SUPPORT_64 Register* pPCReg = new Register(RID_PC, 64); pPCReg->setName("RIP"); - #else - Register* pPCReg = new Register(RID_PC, 32); +#else + Register* pPCReg = new Register(RID_PC, 32); pPCReg->setName("EIP"); - #endif // SIM_SUPPORT_64 +#endif // SIM_SUPPORT_64 m_addRegister(pPCReg, RT_IP); - // ------------------------------------- + // ------------------------------------- // Add the status register (EFLAGS): Register* pFlagReg = new Register(RID_FLAGS, 32); pFlagReg->setName("EFLAGS"); diff --git a/src/core/sal/x86/X86Architecture.hpp b/src/core/sal/x86/X86Architecture.hpp index fa1e64f35eb7f9cb6e1ba9fff4f92d5e7f4dbde1..c867836a1778dbfcb0dcdf018e0d9dffa5445057 100644 --- a/src/core/sal/x86/X86Architecture.hpp +++ b/src/core/sal/x86/X86Architecture.hpp @@ -1,5 +1,5 @@ #ifndef __X86_ARCHITECTURE_HPP__ - #define __X86_ARCHITECTURE_HPP__ +#define __X86_ARCHITECTURE_HPP__ #include "../CPU.hpp" #include "../CPUState.hpp" @@ -35,8 +35,8 @@ enum GPRegisterId { #else // 32 bit register id's: RID_EAX = 0, RID_ECX, RID_EDX, RID_EBX, RID_ESP, RID_EBP, RID_ESI, RID_EDI, #endif // common register id's (independent of the current register width): - RID_CAX = 0, RID_CCX, RID_CDX, RID_CBX, RID_CSP, RID_CBP, RID_CSI, RID_CDI, - RID_LAST_GP_ID + RID_CAX = 0, RID_CCX, RID_CDX, RID_CBX, RID_CSP, RID_CBP, RID_CSI, RID_CDI, + RID_LAST_GP_ID }; /** diff --git a/src/core/sal/x86/X86CPUState.hpp b/src/core/sal/x86/X86CPUState.hpp index 4bb7af27d27315c53b5ce11ed7b7df0bc3e7a5d6..1a10630515c06e8d55803b34add9f974b29f26e7 100644 --- a/src/core/sal/x86/X86CPUState.hpp +++ b/src/core/sal/x86/X86CPUState.hpp @@ -1,5 +1,5 @@ #ifndef __X86_CPU_STATE_HPP__ - #define __X86_CPU_STATE_HPP__ +#define __X86_CPU_STATE_HPP__ #include "../CPU.hpp" #include "../CPUState.hpp" @@ -23,7 +23,7 @@ public: * @return the current (E)FLAGS processor register content */ virtual regdata_t getFlagsRegister() const = 0; - + /** * Returns \c true if the corresponding flag is set, or \c false * otherwise. diff --git a/src/core/util/CommandLine.cc b/src/core/util/CommandLine.cc index 711a7b7d4b3acfc067ccf26ad1c1b82b97449537..33f6c333ca1c452abc6c35bef5070b051036dde5 100644 --- a/src/core/util/CommandLine.cc +++ b/src/core/util/CommandLine.cc @@ -5,65 +5,65 @@ namespace fail { - CommandLine CommandLine::m_instance; - - void CommandLine::collect_args(argument_count &argc, argument_value &argv) { - // Filter out all command line arguments that start with -Wf, - for (int i = 0; i < argc; ++i) { - if (strncmp(argv[i], "-Wf,", 4) == 0) { - this->argv.push_back(argv[i] + 4); - - // also copy argv[argc], which equals 0 - for (int x = i + 1; x <= argc; ++x) { - argv[x - 1] = argv[x]; - } - i --; - argc --; - } - - } - } - - CommandLine::option_handle CommandLine::addOption(const std::string &shortopt, - const std::string &longopt, - const option::CheckArg & check_arg, - const std::string &help) { - - const unsigned int handle = this->options.size(); - option::Descriptor desc = {handle, 0, strdup(shortopt.c_str()), - strdup(longopt.c_str()), - check_arg, strdup(help.c_str())}; - this->options.push_back(desc); - return handle; - } - - bool CommandLine::parse() { - // Terminate the descriptor list - option::Descriptor desc = {0, 0, 0, 0, 0, 0}; - this->options.push_back(desc); - - // Generate the options stats - option::Stats stats(this->options.data(), argv.size(), argv.data()); - - if (parsed_options) - delete[] parsed_options; - if (parsed_buffer) - delete[] parsed_buffer; - if (m_parser) - delete m_parser; - - parsed_options = new option::Option[stats.options_max]; - parsed_buffer = new option::Option[stats.buffer_max]; - - m_parser = new option::Parser(this->options.data(), argv.size(), argv.data(), - parsed_options, parsed_buffer); - - - // Pop the terminating entry - this->options.pop_back(); - - return !m_parser->error(); - } - +CommandLine CommandLine::m_instance; + +void CommandLine::collect_args(argument_count &argc, argument_value &argv) { + // Filter out all command line arguments that start with -Wf, + for (int i = 0; i < argc; ++i) { + if (strncmp(argv[i], "-Wf,", 4) == 0) { + this->argv.push_back(argv[i] + 4); + + // also copy argv[argc], which equals 0 + for (int x = i + 1; x <= argc; ++x) { + argv[x - 1] = argv[x]; + } + i --; + argc --; + } + + } +} + +CommandLine::option_handle CommandLine::addOption( + const std::string &shortopt, + const std::string &longopt, + const option::CheckArg & check_arg, + const std::string &help) { + + const unsigned int handle = this->options.size(); + option::Descriptor desc = {handle, 0, strdup(shortopt.c_str()), + strdup(longopt.c_str()), + check_arg, strdup(help.c_str())}; + this->options.push_back(desc); + return handle; +} + +bool CommandLine::parse() { + // Terminate the descriptor list + option::Descriptor desc = {0, 0, 0, 0, 0, 0}; + this->options.push_back(desc); + + // Generate the options stats + option::Stats stats(this->options.data(), argv.size(), argv.data()); + + if (parsed_options) + delete[] parsed_options; + if (parsed_buffer) + delete[] parsed_buffer; + if (m_parser) + delete m_parser; + + parsed_options = new option::Option[stats.options_max]; + parsed_buffer = new option::Option[stats.buffer_max]; + + m_parser = new option::Parser(this->options.data(), argv.size(), argv.data(), + parsed_options, parsed_buffer); + + + // Pop the terminating entry + this->options.pop_back(); + + return !m_parser->error(); +} } // end of namespace diff --git a/src/core/util/CommandLine.hpp b/src/core/util/CommandLine.hpp index f26e73cf10008c52387f39a24dadabf07f38d26b..21dfd2a3e2595f05ef7322830adf4d5abb5c48ff 100644 --- a/src/core/util/CommandLine.hpp +++ b/src/core/util/CommandLine.hpp @@ -17,93 +17,94 @@ #pragma GCC diagnostic pop namespace fail { - /** - * @class CommandLine - * @brief Implements a command line interface, that filters the - * simulators command line. It is a Singleton. - */ - class CommandLine { - public: - typedef int argument_count; - typedef char **argument_value; - private: - static CommandLine m_instance; - std::vector<const char *> argv; - std::vector<option::Descriptor> options; - option::Option *parsed_options, *parsed_buffer; - option::Parser *m_parser; - public: - /// Handle for accessing the parsed data of an option - typedef int option_handle; +/** + * @class CommandLine + * @brief Implements a command line interface, that filters the + * simulators command line. It is a Singleton. + */ +class CommandLine { +public: + typedef int argument_count; + typedef char **argument_value; +private: + static CommandLine m_instance; - /** - * Singleton accessor - * - * @return reference to the CommandLine singleton object - */ - static CommandLine &Inst() { return m_instance; } + std::vector<const char *> argv; + std::vector<option::Descriptor> options; + option::Option *parsed_options, *parsed_buffer; + option::Parser *m_parser; +public: + /// Handle for accessing the parsed data of an option + typedef int option_handle; - /** - * Called by the simulator to filter all fail arguments from - * argc, argv - */ - void collect_args(argument_count &, argument_value &); + /** + * Singleton accessor + * + * @return reference to the CommandLine singleton object + */ + static CommandLine &Inst() { return m_instance; } - /** - * Add a argument manually - */ - void add_args(const char *value) { argv.push_back(value); } + /** + * Called by the simulator to filter all fail arguments from + * argc, argv + */ + void collect_args(argument_count &, argument_value &); - /** - * Add a option to the command line interface of the fail-client - * - * @param shortopt e.g "m" for -m - * @param longopt e.g. "memory-region" for --memory-region= - * @param check_arg argument is required. - * @param help help text to be printed for -h - * - * @return return handle to option - */ - option_handle addOption(const std::string &shortopt, - const std::string &longopt, - const option::CheckArg & check_arg, - const std::string &help); + /** + * Add a argument manually + */ + void add_args(const char *value) { argv.push_back(value); } - /** - * - * do the actual parsing, called by the experiment - * - * @return true on success - */ - bool parse(); + /** + * Add a option to the command line interface of the fail-client + * + * @param shortopt e.g "m" for -m + * @param longopt e.g. "memory-region" for --memory-region= + * @param check_arg argument is required. + * @param help help text to be printed for -h + * + * @return return handle to option + */ + option_handle addOption(const std::string &shortopt, + const std::string &longopt, + const option::CheckArg & check_arg, + const std::string &help); - /** - * Accessor for the command line option objects - * - * @param handle option handle - * - * @return reference to the option parser object - */ - option::Option &operator[](option_handle handle) { - assert(parsed_options != 0); - assert(handle >= 0 && handle < (int)options.size()); - return parsed_options[handle]; - } - /** - * Print help message. - */ - void printUsage() { - int columns = getenv("COLUMNS")? atoi(getenv("COLUMNS")) : 80; - option::printUsage(fwrite, stdout, options.data(), columns); - } - /** - * Return the internal option::Parser object for further usage. - */ - option::Parser *parser() { - return m_parser; - } - }; + /** + * + * do the actual parsing, called by the experiment + * + * @return true on success + */ + bool parse(); + + /** + * Accessor for the command line option objects + * + * @param handle option handle + * + * @return reference to the option parser object + */ + option::Option &operator[](option_handle handle) { + assert(parsed_options != 0); + assert(handle >= 0 && handle < (int)options.size()); + return parsed_options[handle]; + } + /** + * Print help message. + */ + void printUsage() { + int columns = getenv("COLUMNS")? atoi(getenv("COLUMNS")) : 80; + option::printUsage(fwrite, stdout, options.data(), columns); + } + /** + * Return the internal option::Parser object for further usage. + */ + option::Parser *parser() { + return m_parser; + } +}; } // end of namespace diff --git a/src/core/util/Demangler.cc b/src/core/util/Demangler.cc index 7ed34574bb24083bcca69e3c5b0c98967eccde98..b92f5338bc5893d33cc186182806ff07d39257b6 100644 --- a/src/core/util/Demangler.cc +++ b/src/core/util/Demangler.cc @@ -6,15 +6,15 @@ namespace fail { - const std::string Demangler::DEMANGLE_FAILED = "[Demangler] Demangle failed."; +const std::string Demangler::DEMANGLE_FAILED = "[Demangler] Demangle failed."; - std::string Demangler::demangle(const std::string& name){ - const char* res = cplus_demangle(name.c_str(), 0); - if(res != NULL){ - return std::string(res); - }else{ - return Demangler::DEMANGLE_FAILED; - } - } +std::string Demangler::demangle(const std::string& name){ + const char* res = cplus_demangle(name.c_str(), 0); + if (res != NULL) { + return std::string(res); + } else { + return Demangler::DEMANGLE_FAILED; + } +} } // end of namespace diff --git a/src/core/util/Demangler.hpp b/src/core/util/Demangler.hpp index 3daeba551cfbf0323b5e102630e8ab386d640fac..2b79b3d23bf60b31f0695a66fd160355342d3b2a 100644 --- a/src/core/util/Demangler.hpp +++ b/src/core/util/Demangler.hpp @@ -5,19 +5,19 @@ namespace fail { - class Demangler { - public: +class Demangler { +public: - /** - * Get the demangled symbol name of a mangled string. - * @param name The mangled symbol - * @return The according demangled name if found, else Demangler::DEMANGLE_FAILED - */ - static std::string demangle(const std::string & name); + /** + * Get the demangled symbol name of a mangled string. + * @param name The mangled symbol + * @return The according demangled name if found, else Demangler::DEMANGLE_FAILED + */ + static std::string demangle(const std::string & name); - //! Inform about failed demangling. - static const std::string DEMANGLE_FAILED; - }; + //! Inform about failed demangling. + static const std::string DEMANGLE_FAILED; +}; } // end of namespace diff --git a/src/core/util/Disassembler.cc b/src/core/util/Disassembler.cc index 8172c10309236f413a8fbbe4d4b2b07fd4725aa4..677cdd3a577ee6253c11fc03957f9f7f7c33211f 100644 --- a/src/core/util/Disassembler.cc +++ b/src/core/util/Disassembler.cc @@ -13,100 +13,99 @@ namespace fail { - const std::string DISASSEMBLER::FAILED = "[Disassembler] Disassemble failed."; +const std::string DISASSEMBLER::FAILED = "[Disassembler] Disassemble failed."; - Disassembler::Disassembler() : m_log("Fail*Disassembler", false){ } +Disassembler::Disassembler() : m_log("Fail*Disassembler", false) { } - int Disassembler::init() { - // try to open elf file from environment variable - char * elfpath = getenv("FAIL_ELF_PATH"); - if(elfpath == NULL){ - m_log << "FAIL_ELF_PATH not set :(" << std::endl; - exit(EXIT_FAILURE); - }else{ - return init(elfpath); - } - } +int Disassembler::init() { + // try to open elf file from environment variable + char * elfpath = getenv("FAIL_ELF_PATH"); + if (elfpath == NULL) { + m_log << "FAIL_ELF_PATH not set :(" << std::endl; + exit(EXIT_FAILURE); + } else { + return init(elfpath); + } +} - int Disassembler::init(const char* path){ - // Disassemble ELF +int Disassembler::init(const char* path) { + // Disassemble ELF #ifndef __puma - std::string command = std::string(ARCH_TOOL_PREFIX) + std::string("objdump -d ") + std::string(path); - m_log << "Executing: " << command << std::endl; - redi::ipstream objdump( command ); - std::string str; - while(std::getline(objdump, str)){ - evaluate(str); - } + std::string command = std::string(ARCH_TOOL_PREFIX) + std::string("objdump -d ") + std::string(path); + m_log << "Executing: " << command << std::endl; + redi::ipstream objdump( command ); + std::string str; + while (std::getline(objdump, str)) { + evaluate(str); + } - objdump.close(); - if(objdump.rdbuf()->exited()){ - int ex = objdump.rdbuf()->status(); - if(ex != 0){ - m_code.clear(); - m_log << "Could not disassemble!" << std::endl; - exit(EXIT_FAILURE); - } - } - m_log << "disassembled " << m_code.size() << " lines." << std::endl; + objdump.close(); + if (objdump.rdbuf()->exited()) { + int ex = objdump.rdbuf()->status(); + if (ex != 0) { + m_code.clear(); + m_log << "Could not disassemble!" << std::endl; + exit(EXIT_FAILURE); + } + } + m_log << "disassembled " << m_code.size() << " lines." << std::endl; #endif - return m_code.size(); - } + return m_code.size(); +} - std::ostream& operator <<(std::ostream & os, const fail::Instruction & i) { +std::ostream& operator <<(std::ostream & os, const fail::Instruction & i) { #ifndef __puma - os << std::hex << ((int)(i.address)) << "\t" << i.opcode << "\t" << i.instruction << "\t" << i.comment; + os << std::hex << ((int)(i.address)) << "\t" << i.opcode << "\t" << i.instruction << "\t" << i.comment; #endif - return os; - } + return os; +} - void Disassembler::evaluate(const std::string& line){ +void Disassembler::evaluate(const std::string& line) { #ifndef __puma - // Only read in real code lines: - // Code lines start with a leading whitespace! (hopefully in each objdump implementation!) - if(line.size() > 0 && isspace(line[0])){ - // a line looks like: 800156c:\tdd14 \tble.n 8001598 <_ZN2hw3hal7T32Term8PutBlockEPci+0x30> - boost::regex expr("\\s+([A-Fa-f0-9]+):\\t(.*?)\\t(.+?)(;.*)?$"); - boost::smatch res; - if(boost::regex_search(line, res, expr)){ - std::string address = res[1]; - std::stringstream ss; - ss << std::hex << address; - address_t addr = 0; - ss >> addr; - ss.clear(); - ss.str(""); + // Only read in real code lines: + // Code lines start with a leading whitespace! (hopefully in each objdump implementation!) + if (line.size() > 0 && isspace(line[0])) { + // a line looks like: 800156c:\tdd14 \tble.n 8001598 <_ZN2hw3hal7T32Term8PutBlockEPci+0x30> + boost::regex expr("\\s+([A-Fa-f0-9]+):\\t(.*?)\\t(.+?)(;.*)?$"); + boost::smatch res; + if (boost::regex_search(line, res, expr)) { + std::string address = res[1]; + std::stringstream ss; + ss << std::hex << address; + address_t addr = 0; + ss >> addr; + ss.clear(); + ss.str(""); - std::string opcode = res[2]; - // delete trailing/leading whitespaces - boost::trim(opcode); - // delete inner whitespaces and merge nibbles - opcode.erase(std::remove(opcode.begin(), opcode.end(), ' '), opcode.end()); - ss << std::hex << opcode; - unsigned opc = 0; - ss >> opc; + std::string opcode = res[2]; + // delete trailing/leading whitespaces + boost::trim(opcode); + // delete inner whitespaces and merge nibbles + opcode.erase(std::remove(opcode.begin(), opcode.end(), ' '), opcode.end()); + ss << std::hex << opcode; + unsigned opc = 0; + ss >> opc; - std::string instruction = res[3]; - boost::trim(instruction); - std::string comment = res[4]; - boost::trim(comment); + std::string instruction = res[3]; + boost::trim(instruction); + std::string comment = res[4]; + boost::trim(comment); - m_code.insert(std::make_pair(addr, Instruction(addr, opc, instruction, comment))); - } - } + m_code.insert(std::make_pair(addr, Instruction(addr, opc, instruction, comment))); + } + } #endif - } - - static Instruction g_InstructionNotFound; - const Instruction & Disassembler::disassemble(address_t address) const { - InstructionMap_t::const_iterator it = m_code.find(address); - if(it == m_code.end()){ - return g_InstructionNotFound; - }else{ - return it->second; - } - } +} +static Instruction g_InstructionNotFound; +const Instruction & Disassembler::disassemble(address_t address) const { + InstructionMap_t::const_iterator it = m_code.find(address); + if (it == m_code.end()) { + return g_InstructionNotFound; + } else { + return it->second; + } +} } // end of namespace diff --git a/src/core/util/Disassembler.hpp b/src/core/util/Disassembler.hpp index fc281bec1b00e2b492cc46c5dacab9125841985c..2c1b3c51e646abb3cffacc5028a92b4c1d505d45 100644 --- a/src/core/util/Disassembler.hpp +++ b/src/core/util/Disassembler.hpp @@ -1,5 +1,5 @@ #ifndef __DISASSEMBLER_HPP -#define __DISASSEMBLER_HPP +#define __DISASSEMBLER_HPP #include <string> #include "Logger.hpp" @@ -9,70 +9,70 @@ namespace fail { - struct DISASSEMBLER { - //! Inform about failed disassembly - static const std::string FAILED; - }; +struct DISASSEMBLER { + //! Inform about failed disassembly + static const std::string FAILED; +}; - /** - * @class Instruction - * @brief An Instruction represents an disassembled opcode - */ - struct Instruction { - address_t address; //!< The instruction address - regdata_t opcode; //!< The opcode itself - std::string instruction; //!< The disassembled instruction - std::string comment; //!< Comment (rest of line after ; ) - Instruction(address_t address = ADDR_INV, regdata_t opcode = 0, const std::string& instr = DISASSEMBLER::FAILED, const std::string& comment = "") - : address(address), opcode(opcode), instruction(instr), comment(comment) { }; - }; - //<! This allows to print an Instruction via Logger or cout - std::ostream& operator <<(std::ostream & os, const fail::Instruction & i); +/** + * @class Instruction + * @brief An Instruction represents an disassembled opcode + */ +struct Instruction { + address_t address; //!< The instruction address + regdata_t opcode; //!< The opcode itself + std::string instruction; //!< The disassembled instruction + std::string comment; //!< Comment (rest of line after ; ) + Instruction(address_t address = ADDR_INV, regdata_t opcode = 0, const std::string& instr = DISASSEMBLER::FAILED, const std::string& comment = "") + : address(address), opcode(opcode), instruction(instr), comment(comment) { }; +}; +//<! This allows to print an Instruction via Logger or cout +std::ostream& operator <<(std::ostream & os, const fail::Instruction & i); - class Disassembler { +class Disassembler { - public: - /** - * Constructor. - */ - Disassembler(); +public: + /** + * Constructor. + */ + Disassembler(); - /** - * Get disassembler instruction - * @param address The instruction address - * @return The according disassembled instruction if found, else DISASSEMBLER::FAILED - */ - const Instruction & disassemble(address_t address) const; + /** + * Get disassembler instruction + * @param address The instruction address + * @return The according disassembled instruction if found, else DISASSEMBLER::FAILED + */ + const Instruction & disassemble(address_t address) const; - /** - * Test if there is an instruction at a given address - * @param address The address to test - * @return true if found, else false - */ - bool hasInstructionAt(address_t address) const { - return m_code.find(address) != m_code.end();; - }; + /** + * Test if there is an instruction at a given address + * @param address The address to test + * @return true if found, else false + */ + bool hasInstructionAt(address_t address) const { + return m_code.find(address) != m_code.end();; + }; - /** - * Evaluate new ELF file - * @param elfpath Path to ELF file. - * @return Number of disassembled lines. - */ - int init(const char* elfpath); + /** + * Evaluate new ELF file + * @param elfpath Path to ELF file. + * @return Number of disassembled lines. + */ + int init(const char* elfpath); - /** - * Evaluate new ELF file from env variable $FAIL_ELF_PATH - * @return Number of disassembled lines. - * @note The path is guessed from a FAIL_ELF_PATH environment variable - */ - int init(void); + /** + * Evaluate new ELF file from env variable $FAIL_ELF_PATH + * @return Number of disassembled lines. + * @note The path is guessed from a FAIL_ELF_PATH environment variable + */ + int init(void); - private: - Logger m_log; - typedef std::map<address_t, Instruction> InstructionMap_t; - InstructionMap_t m_code; - void evaluate(const std::string &); - }; +private: + Logger m_log; + typedef std::map<address_t, Instruction> InstructionMap_t; + InstructionMap_t m_code; + void evaluate(const std::string &); +}; } // end of namespace #endif // DISASSEMBLER_HPP diff --git a/src/core/util/ElfReader.cc b/src/core/util/ElfReader.cc index 16ceabe804d89ad9efd0336998160873309eb685..3f2291377644339e27bcfb0012be9333372488a4 100644 --- a/src/core/util/ElfReader.cc +++ b/src/core/util/ElfReader.cc @@ -11,245 +11,243 @@ const std::string ELF::NOTFOUND = "[ELFReader] Function not found."; static const ElfSymbol g_SymbolNotFound; bool operator==(const std::string & str, const ElfSymbol & sym) { - return sym.getName() == str; + return sym.getName() == str; } bool operator==(guest_address_t address, const ElfSymbol & sym) { - return sym.getAddress() == address; + return sym.getAddress() == address; } std::ostream& operator<< (std::ostream &out, const ElfSymbol &symbol) { - return (out << symbol.getName() - << " @ 0x" << std::hex << symbol.getAddress() - << " size " << std::dec << symbol.getSize()); + return (out << symbol.getName() + << " @ 0x" << std::hex << symbol.getAddress() + << " size " << std::dec << symbol.getSize()); } -ElfReader::ElfReader() : m_log("Fail*Elfinfo", false){ - // try to open elf file from environment variable - char * elfpath = getenv("FAIL_ELF_PATH"); - if(elfpath == NULL){ - m_log << "FAIL_ELF_PATH not set :(" << std::endl; - }else{ - setup(elfpath); - } +ElfReader::ElfReader() : m_log("Fail*Elfinfo", false) { + // try to open elf file from environment variable + char * elfpath = getenv("FAIL_ELF_PATH"); + if (elfpath == NULL) { + m_log << "FAIL_ELF_PATH not set :(" << std::endl; + } else { + setup(elfpath); + } } -ElfReader::ElfReader(const char* path) : m_log("Fail*Elfinfo", false){ - setup(path); +ElfReader::ElfReader(const char* path) : m_log("Fail*Elfinfo", false) { + setup(path); } void ElfReader::setup(const char* path) { - // Try to open the ELF file - FILE * fp = fopen(path, "r"); - if (!fp) { - m_log << "Error: Could not open " << path << std::endl; - return; - } - - m_filename = std::string(path); - - // Evaluate headers - Elf32_Ehdr ehdr; - Elf32_Shdr sec_hdr; - int num_hdrs,i; - fseek(fp,(off_t)0,SEEK_SET); - read_ELF_file_header(fp, &ehdr); - num_hdrs=ehdr.e_shnum; - m_log << "Evaluating ELF File: " << path << std::endl; - // Parse symbol table and generate internal map - for(i=0;i<num_hdrs;i++) - { - if(read_ELF_section_header(i,&sec_hdr,fp)==-1) - { - m_log << "Wrong Section to read" << std::endl; - } - else - { - if((sec_hdr.sh_type==SHT_SYMTAB)||(sec_hdr.sh_type==SHT_DYNSYM)) - { - process_symboltable(i,fp); - } - else - { - continue; - } - } - } - // Parse section information - if(read_ELF_section_header(ehdr.e_shstrndx,&sec_hdr,fp)==-1) - { - m_log << "Error: reading section string table sect_num = " << ehdr.e_shstrndx << std::endl; - } - - char* buff=(char*)malloc(sec_hdr.sh_size); - if (!buff) - { - m_log << "Malloc failed to allocate buffer for shstrtab" << std::endl; - exit(0); - } - //seek to the offset in the file, - fseek(fp,(off_t)sec_hdr.sh_offset,SEEK_SET); - fread(buff,sec_hdr.sh_size,1,fp); - m_log << "Total number of sections: " << num_hdrs << std::endl; - - for(i=0;i<num_hdrs;i++) - { - if(read_ELF_section_header(i,&sec_hdr,fp)==-1) - { - m_log << "Wrong Section to read\n" << std::endl; - } - else - { - process_section(&sec_hdr, buff); - } - } - if(buff) - free(buff); - - fclose(fp); - - // printDemangled(); - // printSections(); + // Try to open the ELF file + FILE * fp = fopen(path, "r"); + if (!fp) { + m_log << "Error: Could not open " << path << std::endl; + return; + } + + m_filename = std::string(path); + + // Evaluate headers + Elf32_Ehdr ehdr; + Elf32_Shdr sec_hdr; + int num_hdrs,i; + fseek(fp,(off_t)0,SEEK_SET); + read_ELF_file_header(fp, &ehdr); + num_hdrs=ehdr.e_shnum; + m_log << "Evaluating ELF File: " << path << std::endl; + // Parse symbol table and generate internal map + for (i=0;i<num_hdrs;i++) + { + if (read_ELF_section_header(i,&sec_hdr,fp)==-1) + { + m_log << "Wrong Section to read" << std::endl; + } + else + { + if ((sec_hdr.sh_type==SHT_SYMTAB)||(sec_hdr.sh_type==SHT_DYNSYM)) + { + process_symboltable(i,fp); + } + else + { + continue; + } + } + } + // Parse section information + if (read_ELF_section_header(ehdr.e_shstrndx,&sec_hdr,fp)==-1) + { + m_log << "Error: reading section string table sect_num = " << ehdr.e_shstrndx << std::endl; + } + + char* buff=(char*)malloc(sec_hdr.sh_size); + if (!buff) + { + m_log << "Malloc failed to allocate buffer for shstrtab" << std::endl; + exit(0); + } + // seek to the offset in the file, + fseek(fp,(off_t)sec_hdr.sh_offset,SEEK_SET); + fread(buff,sec_hdr.sh_size,1,fp); + m_log << "Total number of sections: " << num_hdrs << std::endl; + + for (i=0;i<num_hdrs;i++) + { + if (read_ELF_section_header(i,&sec_hdr,fp)==-1) + { + m_log << "Wrong Section to read\n" << std::endl; + } + else + { + process_section(&sec_hdr, buff); + } + } + if (buff) + free(buff); + + fclose(fp); + + // printDemangled(); + // printSections(); } -int ElfReader::process_section(Elf32_Shdr *sect_hdr, char* sect_name_buff){ - // Add section name, start address and size to list - int idx=sect_hdr->sh_name; -// m_sections_map.push_back( sect_hdr->sh_addr, sect_hdr->sh_size, sect_name_buff+idx ); - m_sectiontable.push_back( ElfSymbol(sect_name_buff+idx, sect_hdr->sh_addr, sect_hdr->sh_size, ElfSymbol::SECTION) ); +int ElfReader::process_section(Elf32_Shdr *sect_hdr, char* sect_name_buff) { + // Add section name, start address and size to list + int idx=sect_hdr->sh_name; + // m_sections_map.push_back( sect_hdr->sh_addr, sect_hdr->sh_size, sect_name_buff+idx ); + m_sectiontable.push_back( ElfSymbol(sect_name_buff+idx, sect_hdr->sh_addr, sect_hdr->sh_size, ElfSymbol::SECTION) ); - return 0; + return 0; } -int ElfReader::process_symboltable(int sect_num, FILE* fp){ - - Elf32_Shdr sect_hdr; - Elf32_Sym mysym; - char *name_buf=NULL; - int num_sym,link,i,idx; - off_t sym_data_offset; - int sym_data_size; - if(read_ELF_section_header(sect_num,§_hdr,fp)==-1) - { - return -1; - } - //we have to check to which strtab it is linked - link=sect_hdr.sh_link; - sym_data_offset=sect_hdr.sh_offset; - sym_data_size=sect_hdr.sh_size; - num_sym=sym_data_size/sizeof(Elf32_Sym); - - //read the coresponding strtab - if(read_ELF_section_header(link,§_hdr,fp)==-1) - { - return -1; - } - //get the size of strtab in file and allocate a buffer - name_buf=(char*)malloc(sect_hdr.sh_size); - if(!name_buf) - return -1; - //get the offset of strtab in file and seek to it - fseek(fp,sect_hdr.sh_offset,SEEK_SET); - //read all data from the section to the buffer. - fread(name_buf,sect_hdr.sh_size,1,fp); - //so we have the namebuf now seek to symtab data - fseek(fp,sym_data_offset,SEEK_SET); - - for(i=0;i<num_sym;i++) - { - - fread(&mysym,sizeof(Elf32_Sym),1,fp); - idx=mysym.st_name; - - int type = ELF32_ST_TYPE(mysym.st_info); - if((type != STT_SECTION) && (type != STT_FILE)){ - m_symboltable.push_back( ElfSymbol(name_buf+idx, mysym.st_value, mysym.st_size, ElfSymbol::SYMBOL, - type) ); - } - } - free (name_buf); - return 0; +int ElfReader::process_symboltable(int sect_num, FILE* fp) { + + Elf32_Shdr sect_hdr; + Elf32_Sym mysym; + char *name_buf=NULL; + int num_sym,link,i,idx; + off_t sym_data_offset; + int sym_data_size; + if (read_ELF_section_header(sect_num,§_hdr,fp)==-1) + { + return -1; + } + // we have to check to which strtab it is linked + link=sect_hdr.sh_link; + sym_data_offset=sect_hdr.sh_offset; + sym_data_size=sect_hdr.sh_size; + num_sym=sym_data_size/sizeof(Elf32_Sym); + + // read the coresponding strtab + if (read_ELF_section_header(link,§_hdr,fp)==-1) + { + return -1; + } + // get the size of strtab in file and allocate a buffer + name_buf=(char*)malloc(sect_hdr.sh_size); + if (!name_buf) + return -1; + // get the offset of strtab in file and seek to it + fseek(fp,sect_hdr.sh_offset,SEEK_SET); + // read all data from the section to the buffer. + fread(name_buf,sect_hdr.sh_size,1,fp); + // so we have the namebuf now seek to symtab data + fseek(fp,sym_data_offset,SEEK_SET); + + for (i=0;i<num_sym;i++) + { + + fread(&mysym,sizeof(Elf32_Sym),1,fp); + idx=mysym.st_name; + + int type = ELF32_ST_TYPE(mysym.st_info); + if ((type != STT_SECTION) && (type != STT_FILE)) { + m_symboltable.push_back( ElfSymbol(name_buf+idx, mysym.st_value, mysym.st_size, ElfSymbol::SYMBOL, + type) ); + } + } + free (name_buf); + return 0; } -const ElfSymbol& ElfReader::getSymbol(guest_address_t address){ - for(container_t::const_iterator it = m_symboltable.begin(); it !=m_symboltable.end(); ++it){ - if(it->contains(address)){ - return *it; - } - } +const ElfSymbol& ElfReader::getSymbol(guest_address_t address) { + for (container_t::const_iterator it = m_symboltable.begin(); it !=m_symboltable.end(); ++it) { + if (it->contains(address)) { + return *it; + } + } - return g_SymbolNotFound; + return g_SymbolNotFound; } // Symbol search -const ElfSymbol& ElfReader::getSymbol( const std::string& name ){ - container_t::const_iterator it; - // Fist, try to find as mangled symbol - it = std::find(m_symboltable.begin(), m_symboltable.end(), name); - if(it != m_symboltable.end()){ - return *it; - } - - // Then, try to find as demangled symbol - std::string dname = Demangler::demangle(name); - if(dname == Demangler::DEMANGLE_FAILED){ - return g_SymbolNotFound; - } - - it = std::find(m_symboltable.begin(), m_symboltable.end(), dname); - if(it != m_symboltable.end()){ - return *it; - } - - return g_SymbolNotFound; +const ElfSymbol& ElfReader::getSymbol( const std::string& name ) { + container_t::const_iterator it; + // Fist, try to find as mangled symbol + it = std::find(m_symboltable.begin(), m_symboltable.end(), name); + if (it != m_symboltable.end()) { + return *it; + } + + // Then, try to find as demangled symbol + std::string dname = Demangler::demangle(name); + if (dname == Demangler::DEMANGLE_FAILED) { + return g_SymbolNotFound; + } + + it = std::find(m_symboltable.begin(), m_symboltable.end(), dname); + if (it != m_symboltable.end()) { + return *it; + } + + return g_SymbolNotFound; } // Section search -const ElfSymbol& ElfReader::getSection(guest_address_t address){ - for(container_t::const_iterator it = m_sectiontable.begin(); it != m_sectiontable.end(); ++it){ - if(it->contains(address)){ - return *it; - } - } - return g_SymbolNotFound; +const ElfSymbol& ElfReader::getSection(guest_address_t address) { + for (container_t::const_iterator it = m_sectiontable.begin(); it != m_sectiontable.end(); ++it) { + if (it->contains(address)) { + return *it; + } + } + return g_SymbolNotFound; } -const ElfSymbol& ElfReader::getSection( const std::string& name ){ - for(container_t::const_iterator it = m_sectiontable.begin(); it !=m_sectiontable.end(); ++it){ - if(it->getName() == name){ - return *it; - } - } - return g_SymbolNotFound; +const ElfSymbol& ElfReader::getSection( const std::string& name ) { + for (container_t::const_iterator it = m_sectiontable.begin(); it !=m_sectiontable.end(); ++it) { + if (it->getName() == name) { + return *it; + } + } + return g_SymbolNotFound; } // "Pretty" Print -void ElfReader::printDemangled(){ - m_log << "Demangled: " << std::endl; - for(container_t::const_iterator it = m_symboltable.begin(); it !=m_symboltable.end(); ++it){ - std::string str = Demangler::demangle(it->getName()); - if(str == Demangler::DEMANGLE_FAILED){ - str = it->getName(); - } - m_log << "0x" << std::hex << it->getAddress() << "\t" << str.c_str() << "\t" << it->getSize() << std::endl; - } +void ElfReader::printDemangled() { + m_log << "Demangled: " << std::endl; + for (container_t::const_iterator it = m_symboltable.begin(); it !=m_symboltable.end(); ++it) { + std::string str = Demangler::demangle(it->getName()); + if (str == Demangler::DEMANGLE_FAILED) { + str = it->getName(); + } + m_log << "0x" << std::hex << it->getAddress() << "\t" << str.c_str() << "\t" << it->getSize() << std::endl; + } } -void ElfReader::printMangled(){ - for(container_t::const_iterator it = m_symboltable.begin(); it !=m_symboltable.end(); ++it){ - m_log << "0x" << std::hex << it->getAddress() << "\t" << it->getName().c_str() << "\t" << it->getSize() << std::endl; - } +void ElfReader::printMangled() { + for (container_t::const_iterator it = m_symboltable.begin(); it !=m_symboltable.end(); ++it) { + m_log << "0x" << std::hex << it->getAddress() << "\t" << it->getName().c_str() << "\t" << it->getSize() << std::endl; + } } void ElfReader::printSections() { - for(container_t::const_iterator it = m_sectiontable.begin(); it !=m_sectiontable.end(); ++it){ - m_log << "0x" << it->getAddress() << "\t" << it->getName().c_str() << "\t" << it->getSize() << std::endl; - } + for (container_t::const_iterator it = m_sectiontable.begin(); it !=m_sectiontable.end(); ++it) { + m_log << "0x" << it->getAddress() << "\t" << it->getName().c_str() << "\t" << it->getSize() << std::endl; + } } - } // end-of-namespace fail - diff --git a/src/core/util/ElfReader.hpp b/src/core/util/ElfReader.hpp index 8cf120939815657a8c812a99daaa1f599d5c1f5c..c1c61283a726f65d5d331fc3434ff4becfa896bc 100644 --- a/src/core/util/ElfReader.hpp +++ b/src/core/util/ElfReader.hpp @@ -12,164 +12,163 @@ namespace fail { - struct ELF { - static const std::string NOTFOUND; - }; - - class ElfSymbol { - std::string name; - guest_address_t address; - size_t size; - int m_type; - int m_symbol_type; - - public: - enum { SECTION = 1, SYMBOL = 2, UNDEF = 3, }; - - ElfSymbol(const std::string & name = ELF::NOTFOUND, guest_address_t addr = ADDR_INV, size_t size = -1, int type = UNDEF, - int symbol_type = 0) - : name(name), address(addr), size(size), m_type(type), m_symbol_type(symbol_type) {}; - - const std::string& getName() const { return name; }; - std::string getDemangledName() const { return Demangler::demangle(name); }; - guest_address_t getAddress() const { return address; }; - size_t getSize() const { return size; }; - guest_address_t getStart() const { return getAddress(); }; // alias - guest_address_t getEnd() const { return address + size; }; - int getSymbolType() const { return m_symbol_type; }; - - bool isSection() const { return m_type == SECTION; }; - bool isSymbol() const { return m_type == SYMBOL; }; - bool isValid() const { return name != ELF::NOTFOUND; }; - - bool operator==(const std::string& rhs) const { - if(rhs == name){ - return true; - } - if( rhs == Demangler::demangle(name) ){ - return true; - } - - return false; - } - - bool operator==(const guest_address_t rhs) const { - return rhs == address; - } - - bool contains(guest_address_t ad) const { - return (ad >= address) && (ad < address+size); - } - }; - /** - * \fn - * \relates ElfSymbol - * overloaded stream operator for printing ElfSymbol - */ - std::ostream& operator<< (std::ostream &out, const ElfSymbol &symbol); - - /** - * \class ElfReader - * Parses an ELF file and provides a list of symbol names - * and corresponding addresses - */ - - class ElfReader { - public: - typedef ElfSymbol entry_t; - typedef std::vector<entry_t> container_t; - typedef container_t::const_iterator symbol_iterator; - typedef container_t::const_iterator section_iterator; - - - /** - * Constructor. - * @param path Path to the ELF file. - */ - ElfReader(const char* path); - - /** - * Constructor. - * @note The path is guessed from a FAIL_ELF_PATH environment variable - */ - ElfReader(); - - /** - * Print the list of available mangled symbols - * @note This includes both C and C++ symbols - */ - void printMangled(); - - /** - * Print a list of demangled symbols. - */ - void printDemangled(); - - /** - * Print the list of all available sections. - */ - void printSections(); - - /** - * Get symbol by address - * @param address Address within range of the symbol - * @return The according symbol name if symbol.address <= address < symbol.address + symbol.size , else g_SymbolNotFound - */ - const ElfSymbol& getSymbol(guest_address_t address); - - /** - * Get symbol by name - * @param address Name of the symbol - * @return The according symbol name if section was found, else g_SymbolNotFound - */ - const ElfSymbol& getSymbol( const std::string& name ); - - /** - * Get section by address - * @param address An address to search for a section containing that address. - * @return The according section name if section was found, else g_SymbolNotFound - */ - const ElfSymbol& getSection(guest_address_t address); - - /** - * Get section by name - * @param name The name of the section - * @return The according section if section was found, else g_SymbolNotFound - */ - const ElfSymbol& getSection( const std::string& name ); - - /** - * Get symboltable iterator. Derefences to a ElfSymbol - * @return iterator - */ - container_t::const_iterator sym_begin() { return m_symboltable.begin(); } - container_t::const_iterator sym_end() { return m_symboltable.end(); } - - /** - * Get section iterator. Derefences to a ElfSymbol - * @return iterator - */ - container_t::const_iterator sec_begin() { return m_sectiontable.begin(); } - container_t::const_iterator sec_end() { return m_sectiontable.end(); } - - const std::string & getFilename() { return m_filename; } - - private: - Logger m_log; - std::string m_filename; - - void setup(const char*); - int process_symboltable(int sect_num, FILE* fp); - int process_section(Elf32_Shdr *sect_hdr, char* sect_name_buff); - - container_t m_symboltable; - container_t m_sectiontable; - - guest_address_t getAddress(const std::string& name); - std::string getName(guest_address_t address); - }; +struct ELF { + static const std::string NOTFOUND; +}; + +class ElfSymbol { + std::string name; + guest_address_t address; + size_t size; + int m_type; + int m_symbol_type; + + public: + enum { SECTION = 1, SYMBOL = 2, UNDEF = 3, }; + + ElfSymbol(const std::string & name = ELF::NOTFOUND, guest_address_t addr = ADDR_INV, + size_t size = -1, int type = UNDEF, int symbol_type = 0) + : name(name), address(addr), size(size), m_type(type), m_symbol_type(symbol_type) {}; + + const std::string& getName() const { return name; }; + std::string getDemangledName() const { return Demangler::demangle(name); }; + guest_address_t getAddress() const { return address; }; + size_t getSize() const { return size; }; + guest_address_t getStart() const { return getAddress(); }; // alias + guest_address_t getEnd() const { return address + size; }; + int getSymbolType() const { return m_symbol_type; }; + + bool isSection() const { return m_type == SECTION; }; + bool isSymbol() const { return m_type == SYMBOL; }; + bool isValid() const { return name != ELF::NOTFOUND; }; + + bool operator==(const std::string& rhs) const { + if (rhs == name) { + return true; + } + if ( rhs == Demangler::demangle(name) ) { + return true; + } + + return false; + } + + bool operator==(const guest_address_t rhs) const { + return rhs == address; + } + + bool contains(guest_address_t ad) const { + return (ad >= address) && (ad < address+size); + } +}; +/** + * \fn + * \relates ElfSymbol + * overloaded stream operator for printing ElfSymbol + */ +std::ostream& operator<< (std::ostream &out, const ElfSymbol &symbol); + +/** + * \class ElfReader + * Parses an ELF file and provides a list of symbol names + * and corresponding addresses + */ + +class ElfReader { +public: + typedef ElfSymbol entry_t; + typedef std::vector<entry_t> container_t; + typedef container_t::const_iterator symbol_iterator; + typedef container_t::const_iterator section_iterator; + + + /** + * Constructor. + * @param path Path to the ELF file. + */ + ElfReader(const char* path); + + /** + * Constructor. + * @note The path is guessed from a FAIL_ELF_PATH environment variable + */ + ElfReader(); + + /** + * Print the list of available mangled symbols + * @note This includes both C and C++ symbols + */ + void printMangled(); + + /** + * Print a list of demangled symbols. + */ + void printDemangled(); + + /** + * Print the list of all available sections. + */ + void printSections(); + + /** + * Get symbol by address + * @param address Address within range of the symbol + * @return The according symbol name if symbol.address <= address < symbol.address + symbol.size , else g_SymbolNotFound + */ + const ElfSymbol& getSymbol(guest_address_t address); + + /** + * Get symbol by name + * @param address Name of the symbol + * @return The according symbol name if section was found, else g_SymbolNotFound + */ + const ElfSymbol& getSymbol( const std::string& name ); + + /** + * Get section by address + * @param address An address to search for a section containing that address. + * @return The according section name if section was found, else g_SymbolNotFound + */ + const ElfSymbol& getSection(guest_address_t address); + + /** + * Get section by name + * @param name The name of the section + * @return The according section if section was found, else g_SymbolNotFound + */ + const ElfSymbol& getSection( const std::string& name ); + + /** + * Get symboltable iterator. Derefences to a ElfSymbol + * @return iterator + */ + container_t::const_iterator sym_begin() { return m_symboltable.begin(); } + container_t::const_iterator sym_end() { return m_symboltable.end(); } + + /** + * Get section iterator. Derefences to a ElfSymbol + * @return iterator + */ + container_t::const_iterator sec_begin() { return m_sectiontable.begin(); } + container_t::const_iterator sec_end() { return m_sectiontable.end(); } + + const std::string & getFilename() { return m_filename; } + +private: + Logger m_log; + std::string m_filename; + + void setup(const char*); + int process_symboltable(int sect_num, FILE* fp); + int process_section(Elf32_Shdr *sect_hdr, char* sect_name_buff); + + container_t m_symboltable; + container_t m_sectiontable; + + guest_address_t getAddress(const std::string& name); + std::string getName(guest_address_t address); +}; } // end-of-namespace fail #endif //__ELFREADER_HPP__ - diff --git a/src/core/util/Logger.hpp b/src/core/util/Logger.hpp index 092273d24bd9ee3793664e96a769248b41ea2063..ea2f584d7700fccb0ae773a9486e06f9b1dc1eaa 100644 --- a/src/core/util/Logger.hpp +++ b/src/core/util/Logger.hpp @@ -1,5 +1,5 @@ #ifndef __LOGGER_HPP__ - #define __LOGGER_HPP__ +#define __LOGGER_HPP__ #include <iostream> #include <sstream> diff --git a/src/core/util/MemoryMap.hpp b/src/core/util/MemoryMap.hpp index 3aa06118cc3cca610b0ad09a35890931e6b525a3..dca92c944411f82c21c5f1ad10d5ba46db72d5b4 100644 --- a/src/core/util/MemoryMap.hpp +++ b/src/core/util/MemoryMap.hpp @@ -1,5 +1,5 @@ #ifndef __MEMORYMAP_HPP__ - #define __MEMORYMAP_HPP__ +#define __MEMORYMAP_HPP__ #ifdef BOOST_1_46_OR_NEWER #include <boost/icl/interval_set.hpp> @@ -47,7 +47,7 @@ public: } /** * Determines whether a given memory access at address \a addr with width - * \a size hits the map. + * \a size hits the map. */ bool isMatching(address_t addr, int size = 1) { diff --git a/src/core/util/ProtoStream.cc b/src/core/util/ProtoStream.cc index c9d4f1713cdec63aef549dccd2dcd6a554370ca7..10f6436456e33f7700ea9a0d9ae68a605ebd735b 100644 --- a/src/core/util/ProtoStream.cc +++ b/src/core/util/ProtoStream.cc @@ -9,20 +9,20 @@ ProtoOStream::ProtoOStream(std::ostream *outfile) : m_outfile(outfile) m_log.showTime(false); } -bool ProtoOStream::writeMessage(google::protobuf::Message* m) +bool ProtoOStream::writeMessage(google::protobuf::Message *m) { m_size = htonl(m->ByteSize()); m_outfile->write(reinterpret_cast<char*>(&m_size), sizeof(m_size)); - + if (m_outfile->bad()) { m_log << "Could not write to file!" << std::endl; // TODO: log-Level? return false; } - + m->SerializeToOstream(m_outfile); - - return true; + + return true; } ProtoIStream::ProtoIStream(std::istream *infile) : m_infile(infile) @@ -38,23 +38,23 @@ void ProtoIStream::reset() m_infile->seekg(0, std::ios::beg); } -bool ProtoIStream::getNext(google::protobuf::Message* m) -{ +bool ProtoIStream::getNext(google::protobuf::Message *m) +{ m_infile->read(reinterpret_cast<char*>(&m_size), sizeof(m_size)); if (!m_infile->good()) return false; m_size = ntohl(m_size); - + // FIXME reuse buffer (efficiency) // FIXME new[] may fail (i.e., return 0) char *buf = new char[m_size]; m_infile->read(buf, m_size); if (!m_infile->good()) // FIXME we're leaking buf[] - return false; + return false; std::string st(buf, m_size); m->ParseFromString(st); - + delete [] buf; return true; } diff --git a/src/core/util/ProtoStream.hpp b/src/core/util/ProtoStream.hpp index c465d7cc29bc8c1b7127c5d8379b2b32c3ca3e93..b9abea6bc3f504a68b69a8f1594a82a7909d8241 100644 --- a/src/core/util/ProtoStream.hpp +++ b/src/core/util/ProtoStream.hpp @@ -1,4 +1,4 @@ -/** +/** * \brief One way to manage large protobuf-messages * * Google protobuf is not designed for large messages. That leads to @@ -8,14 +8,14 @@ * written sequentially in a file. Written in the format: * * \code - * | 4 bytes length-information of the first message | first message - * | 4 bytes length-information of the second message | second message + * | 4 bytes length-information of the first message | first message + * | 4 bytes length-information of the second message | second message * | ... * \endcode */ #ifndef __PROTOSTREAM_HPP__ - #define __PROTOSTREAM_HPP__ +#define __PROTOSTREAM_HPP__ #include <iostream> #include <sys/types.h> @@ -28,7 +28,7 @@ namespace fail { /** * \class ProtoOStream - * + * * This class can be used to sequentially write a large number of * protocol buffer messages to a \c std::ostream. */ @@ -41,16 +41,16 @@ public: ProtoOStream(std::ostream *outfile); virtual ~ProtoOStream() { } /** - * Writes a message to a file. + * Writes a message to a file. * @param m The protobuf-message to be written * @return Returns \c true on success, \c false otherwise */ - bool writeMessage(google::protobuf::Message* m); + bool writeMessage(google::protobuf::Message *m); }; /** * \class ProtoIStream - * + * * This class can be used to read protocol buffer messages sequentially * from a \c std::istream. */ @@ -73,7 +73,7 @@ public: * @param m The output protobuf message * @return Returns \c true on success, \c false otherwise */ - bool getNext(google::protobuf::Message* m); + bool getNext(google::protobuf::Message * m); }; } // end-of-namespace: fail diff --git a/src/core/util/StringJoiner.hpp b/src/core/util/StringJoiner.hpp index 7ab43dccabf9b205e72db41f1756b8b3284889a4..509fd409c124259a5dd077c77067e925f81a4b78 100644 --- a/src/core/util/StringJoiner.hpp +++ b/src/core/util/StringJoiner.hpp @@ -14,54 +14,54 @@ namespace fail { * concatenating strings with a separator. * * The behaviour is similar to the python list().join(",") construct. - * + * */ struct StringJoiner : public std::deque<std::string> { - /** - * \brief join all strings in the container, - * - * Join all the collected strings to one string. The separator is - * inserted between each element. - */ - std::string join(const char *j) { - std::stringstream ss; - if (size() == 0) - return ""; + /** + * \brief join all strings in the container, + * + * Join all the collected strings to one string. The separator is + * inserted between each element. + */ + std::string join(const char *j) { + std::stringstream ss; + if (size() == 0) + return ""; - ss << front(); + ss << front(); - std::deque<std::string>::const_iterator i = begin() + 1; + std::deque<std::string>::const_iterator i = begin() + 1; - while (i != end()) { - ss << j << *i; - i++; - } - return ss.str(); - } + while (i != end()) { + ss << j << *i; + i++; + } + return ss.str(); + } - /** - * \brief append strings to list. - * - * Appends the given value to the list of values if it isn't the - * empty string. "" will be ignored. - */ - void push_back(const value_type &x) { - if (x.compare("") == 0) - return; - std::deque<value_type>::push_back(x); - } + /** + * \brief append strings to list. + * + * Appends the given value to the list of values if it isn't the + * empty string. "" will be ignored. + */ + void push_back(const value_type &x) { + if (x.compare("") == 0) + return; + std::deque<value_type>::push_back(x); + } - /** - * \brief append strings to list. - * - * Appends the given value to the list of values if it isn't the - * empty string. "" will be ignored. - */ - void push_front(const value_type &x) { - if (x.compare("") == 0) - return; - std::deque<value_type>::push_front(x); - } + /** + * \brief append strings to list. + * + * Appends the given value to the list of values if it isn't the + * empty string. "" will be ignored. + */ + void push_front(const value_type &x) { + if (x.compare("") == 0) + return; + std::deque<value_type>::push_front(x); + } }; } diff --git a/src/core/util/SynchronizedCounter.hpp b/src/core/util/SynchronizedCounter.hpp index 9ae8674105f81496c44fe7736884986122c0321b..8191669c66a64fb0a1319a7169472aae51173c51 100644 --- a/src/core/util/SynchronizedCounter.hpp +++ b/src/core/util/SynchronizedCounter.hpp @@ -3,7 +3,7 @@ */ #ifndef __SYNCHRONIZED_COUNTER_HPP__ - #define __SYNCHRONIZED_COUNTER_HPP__ +#define __SYNCHRONIZED_COUNTER_HPP__ #ifndef __puma #include <boost/thread.hpp> @@ -14,7 +14,7 @@ namespace fail { /** * \class ssd - * + * * Provides a thread safe (synchronized) counter. When a method is called, * the internal mutex is automatically locked. On return, the lock is * automatically released ("scoped lock"). diff --git a/src/core/util/SynchronizedMap.hpp b/src/core/util/SynchronizedMap.hpp index 61ee62e0129e0751de80430e24a637e90a215118..0155a2655599a11465661739f18553ba1c32cfc2 100644 --- a/src/core/util/SynchronizedMap.hpp +++ b/src/core/util/SynchronizedMap.hpp @@ -3,7 +3,7 @@ */ #ifndef __SYNCHRONIZED_MAP_HPP__ - #define __SYNCHRONIZED_MAP_HPP__ +#define __SYNCHRONIZED_MAP_HPP__ #include <map> @@ -20,7 +20,7 @@ class SynchronizedMap { private: typedef std::map< Tkey, Tvalue > Tmap; typedef typename Tmap::iterator Tit; - + Tmap m_map; //! Use STL map to store data #ifndef __puma boost::mutex m_mutex; //! The mutex to synchronise on @@ -75,7 +75,7 @@ public: * Add data to the map, return false if already present * @param key Map key * @param value value according to key - * @return false if key already present + * @return false if key already present */ bool insert(const Tkey& key, const Tvalue& value) { @@ -83,20 +83,20 @@ public: #ifndef __puma boost::unique_lock<boost::mutex> lock(m_mutex); #endif - if( m_map.find(key) == m_map.end() ){ // not present, add it + if ( m_map.find(key) == m_map.end() ) { // not present, add it m_map[key] = value; return true; - }else{ // item is already in, oops + } else { // item is already in, oops return false; } - + } // Lock is automatically released here /** * Remove value from the map. * @param key The Map key to remove * @return false if key was not present - * + * */ bool remove(const Tkey& key, Tvalue& value) { diff --git a/src/core/util/SynchronizedQueue.hpp b/src/core/util/SynchronizedQueue.hpp index 45d523303f489283edc07e05f3cbbc330ad41b56..e40da6695e3d8c4dbef4c414cfc09f6500ce3f80 100644 --- a/src/core/util/SynchronizedQueue.hpp +++ b/src/core/util/SynchronizedQueue.hpp @@ -3,7 +3,7 @@ */ #ifndef __SYNCHRONIZED_QUEUE_HPP__ - #define __SYNCHRONIZED_QUEUE_HPP__ +#define __SYNCHRONIZED_QUEUE_HPP__ #include <queue> @@ -32,7 +32,7 @@ public: #ifndef __puma boost::unique_lock<boost::mutex> lock(m_mutex); #endif - return m_queue.size(); + return m_queue.size(); } // Add data to the queue and notify others void Enqueue(const T& data) @@ -95,7 +95,7 @@ public: * Get data from the queue. Non blocking variant. * @param d Pointer to copy queue element to * @return false if no element in queue - * + * */ bool Dequeue_nb(T& d) { diff --git a/src/core/util/WallclockTimer.cc b/src/core/util/WallclockTimer.cc index 53325da10e65aa581a3f37d909b5f4c7e3338262..35e17049463bdd210ba461677f5f0afc7b75c3dd 100644 --- a/src/core/util/WallclockTimer.cc +++ b/src/core/util/WallclockTimer.cc @@ -18,7 +18,7 @@ std::string WallclockTimer::getRuntimeAsString() const { std::stringstream result; result << getRuntimeAsDouble(); - + return result.str().c_str(); } @@ -26,7 +26,7 @@ double WallclockTimer::getRuntimeAsDouble() const { double result; struct timeval current; - + if (m_IsRunning) { gettimeofday(¤t, NULL); result = current.tv_sec - m_Start.tv_sec; @@ -35,7 +35,7 @@ double WallclockTimer::getRuntimeAsDouble() const result = m_End.tv_sec - m_Start.tv_sec; result = result + (((double)m_End.tv_usec-m_Start.tv_usec)/1000000); } - + return result; } @@ -44,7 +44,7 @@ void WallclockTimer::stopTimer() if (m_IsRunning) { m_IsRunning = false; gettimeofday(&m_End, NULL); - } + } } void WallclockTimer::reset() diff --git a/src/core/util/WallclockTimer.hpp b/src/core/util/WallclockTimer.hpp index 3dee316c8e99c91387d4077e89d02a7adefd08f6..33ddc45a6c6adf2bdafc9176803ae97cbe6def82 100644 --- a/src/core/util/WallclockTimer.hpp +++ b/src/core/util/WallclockTimer.hpp @@ -1,12 +1,12 @@ -/** +/** * \brief The WallclockTimer measures the elapsed time - * + * * The WallclockTimer measures the time which is elapsed between start * and stop of the timer. */ #ifndef __WALLCLOCKTIMER_HPP__ - #define __WALLCLOCKTIMER_HPP__ +#define __WALLCLOCKTIMER_HPP__ #include <string> #include <stdlib.h> @@ -16,7 +16,7 @@ namespace fail { /** * \class WallclockTimer - * + * * The class WallclockTimer contains all functions for start, * stop, reset and to get the elapsed time. */ diff --git a/src/core/util/llvmdisassembler/LLVMDisassembler.cpp b/src/core/util/llvmdisassembler/LLVMDisassembler.cpp index aff689e2c3c6192b62e807c1717e8f7cd9cf5f82..c97ddc3e5c3ad70edf6ab16a6c500eae0f9605b0 100644 --- a/src/core/util/llvmdisassembler/LLVMDisassembler.cpp +++ b/src/core/util/llvmdisassembler/LLVMDisassembler.cpp @@ -6,7 +6,7 @@ using namespace llvm::object; LLVMtoFailTranslator & LLVMDisassembler::getTranslator() { - if ( ltofail == 0 ){ + if ( ltofail == 0 ) { std::cout << "ArchType: " << llvm::Triple::getArchTypeName( llvm::Triple::ArchType(object->getArch()) ) << std::endl; switch ( llvm::Triple::ArchType(object->getArch()) ) { diff --git a/src/core/util/llvmdisassembler/LLVMtoFailTranslator.cpp b/src/core/util/llvmdisassembler/LLVMtoFailTranslator.cpp index ea8d6a43439e59754c65cf537befce6bb2f542e3..f17be92b0fed1814182c40b12e335116f874011e 100644 --- a/src/core/util/llvmdisassembler/LLVMtoFailTranslator.cpp +++ b/src/core/util/llvmdisassembler/LLVMtoFailTranslator.cpp @@ -5,7 +5,7 @@ using namespace fail; const LLVMtoFailTranslator::reginfo_t & LLVMtoFailTranslator::getFailRegisterID(unsigned int regid) { ltof_map_t::iterator it = llvm_to_fail_map.find(regid); - if( it != llvm_to_fail_map.end() ) {// found + if ( it != llvm_to_fail_map.end() ) {// found return (*it).second; } else { // not found std::cout << "Fail ID for LLVM Register id " << std::dec << regid << " not found :(" << std::endl; diff --git a/src/experiments/abo-simple-arm/experiment.hpp b/src/experiments/abo-simple-arm/experiment.hpp index dd73b7bc37ac0e098db5a18faa4e274f7b7d5e10..e3216e631ee2ea05d2e17f6226f0ca3260e00869 100644 --- a/src/experiments/abo-simple-arm/experiment.hpp +++ b/src/experiments/abo-simple-arm/experiment.hpp @@ -1,6 +1,6 @@ #ifndef __ABO_SIMPLE_ARM_EXPERIMENT_HPP__ - #define __ABO_SIMPLE_ARM_EXPERIMENT_HPP__ - +#define __ABO_SIMPLE_ARM_EXPERIMENT_HPP__ + #include "efw/ExperimentFlow.hpp" #include "efw/JobClient.hpp" diff --git a/src/experiments/checksum-oostubs/campaign.hpp b/src/experiments/checksum-oostubs/campaign.hpp index 332b168739217dbdf9d74844f8519f515376c85b..72327aab998b618aa79627bf6b2919c0824c45cd 100644 --- a/src/experiments/checksum-oostubs/campaign.hpp +++ b/src/experiments/checksum-oostubs/campaign.hpp @@ -1,5 +1,5 @@ #ifndef __CHECKSUM_OOSTUBS_CAMPAIGN_HPP__ - #define __CHECKSUM_OOSTUBS_CAMPAIGN_HPP__ +#define __CHECKSUM_OOSTUBS_CAMPAIGN_HPP__ #include "cpn/Campaign.hpp" #include "comm/ExperimentData.hpp" diff --git a/src/experiments/checksum-oostubs/experiment.cc b/src/experiments/checksum-oostubs/experiment.cc index 336f11ee3edbade9d8be7603ecb06e198c22bda6..e584938158c553f393beb1f862ddce158d5fff5b 100644 --- a/src/experiments/checksum-oostubs/experiment.cc +++ b/src/experiments/checksum-oostubs/experiment.cc @@ -36,7 +36,7 @@ bool ChecksumOOStuBSExperiment::run() char const *statename = "checksum-oostubs.state"; Logger log("Checksum-OOStuBS", false); BPSingleListener bp; - + log << "startup" << endl; #if 0 @@ -107,7 +107,7 @@ bool ChecksumOOStuBSExperiment::run() } log << dec << "tracing finished after " << instr_counter << endl; - + uint32_t results[OOSTUBS_RESULTS_BYTES / sizeof(uint32_t)]; simulator.getMemoryManager().getBytes(OOSTUBS_RESULTS_ADDR, sizeof(results), results); for (unsigned i = 0; i < sizeof(results) / sizeof(*results); ++i) { @@ -124,7 +124,7 @@ bool ChecksumOOStuBSExperiment::run() } of.close(); log << "trace written to " << tracefile << endl; - + #elif 1 // STEP 3: The actual experiment. #if !LOCAL diff --git a/src/experiments/checksum-oostubs/experiment.hpp b/src/experiments/checksum-oostubs/experiment.hpp index c17037497cfbbf4bc63db9e7e2dc195b622e8015..bef947fd5bb75b2006fc57673c8bea785ebd1bf3 100644 --- a/src/experiments/checksum-oostubs/experiment.hpp +++ b/src/experiments/checksum-oostubs/experiment.hpp @@ -1,6 +1,6 @@ #ifndef __CHECKSUM_OOSTUBS_EXPERIMENT_HPP__ - #define __CHECKSUM_OOSTUBS_EXPERIMENT_HPP__ - +#define __CHECKSUM_OOSTUBS_EXPERIMENT_HPP__ + #include "efw/ExperimentFlow.hpp" #include "efw/JobClient.hpp" diff --git a/src/experiments/checksum-oostubs/experimentInfo.hpp b/src/experiments/checksum-oostubs/experimentInfo.hpp index 298fa45df536556e6f2b1d3c232eeae2a91dbdd9..06f6e455d1ab6222f133161383fc6e67c3994611 100644 --- a/src/experiments/checksum-oostubs/experimentInfo.hpp +++ b/src/experiments/checksum-oostubs/experimentInfo.hpp @@ -1,5 +1,5 @@ #ifndef __EXPERIMENT_INFO_HPP__ - #define __EXPERIMENT_INFO_HPP__ +#define __EXPERIMENT_INFO_HPP__ // FIXME autogenerate this diff --git a/src/experiments/cool-checksum/campaign.cc b/src/experiments/cool-checksum/campaign.cc index 31003ad531a3eaa5084edf2348951c3c762fdb25..6ccc4c1148a73dc51edca3ff6dba1189854ea0a9 100644 --- a/src/experiments/cool-checksum/campaign.cc +++ b/src/experiments/cool-checksum/campaign.cc @@ -52,7 +52,7 @@ bool CoolChecksumCampaign::run() CoolChecksumExperimentData *d = new CoolChecksumExperimentData; d->msg.set_instr_offset(instr_offset); d->msg.set_bit_offset(bit_offset); - + campaignmanager.addParam(d); ++count; } @@ -107,8 +107,8 @@ bool CoolChecksumCampaign::run() address_t instr_absolute = 0; // FIXME this one probably should also be recorded ... Trace_Event ev; ps.reset(); - - while(ps.getNext(&ev)) { + + while (ps.getNext(&ev)) { // only count instruction events if (!ev.has_memaddr()) { // new instruction @@ -131,7 +131,7 @@ bool CoolChecksumCampaign::run() // we now have an interval-terminating R/W // event to the memaddr we're currently looking // at: - + // complete the equivalence interval current_ec.instr2 = instr; current_ec.instr2_absolute = instr_absolute; @@ -150,7 +150,7 @@ bool CoolChecksumCampaign::run() } else { log << "WAT" << endl; } - + // next interval must start at next // instruction; the aforementioned // skipping mechanism wouldn't work diff --git a/src/experiments/cool-checksum/campaign.hpp b/src/experiments/cool-checksum/campaign.hpp index 47c034d28f3bd947f44de22bbfdb13a74609e927..782a1b574fe8290864a52268881df15994c1edcf 100644 --- a/src/experiments/cool-checksum/campaign.hpp +++ b/src/experiments/cool-checksum/campaign.hpp @@ -1,5 +1,5 @@ #ifndef __COOLCAMPAIGN_HPP__ - #define __COOLCAMPAIGN_HPP__ +#define __COOLCAMPAIGN_HPP__ #include "cpn/Campaign.hpp" #include "comm/ExperimentData.hpp" diff --git a/src/experiments/cool-checksum/experiment.cc b/src/experiments/cool-checksum/experiment.cc index 64b910ad178a49241607720fca2aa1f10aefdef0..1977cbb68f0d3d9d95a12be69f5359dd58015f66 100644 --- a/src/experiments/cool-checksum/experiment.cc +++ b/src/experiments/cool-checksum/experiment.cc @@ -30,7 +30,7 @@ bool CoolChecksumExperiment::run() { Logger log("CoolChecksum", false); BPSingleListener bp; - + log << "startup" << endl; #if 1 diff --git a/src/experiments/cool-checksum/experiment.hpp b/src/experiments/cool-checksum/experiment.hpp index a502ef49c1ce53b8b89d32f4e815a1770e0c3fe8..a67642f4333315f435881c2f801056aee5a7cbed 100644 --- a/src/experiments/cool-checksum/experiment.hpp +++ b/src/experiments/cool-checksum/experiment.hpp @@ -1,6 +1,6 @@ #ifndef __COOLEXPERIMENT_HPP__ - #define __COOLEXPERIMENT_HPP__ - +#define __COOLEXPERIMENT_HPP__ + #include "efw/ExperimentFlow.hpp" #include "efw/JobClient.hpp" diff --git a/src/experiments/cool-checksum/experimentInfo.hpp b/src/experiments/cool-checksum/experimentInfo.hpp index 95a1dfcd9f356e86ec96770f881c2b572aaff90f..3c4fca62cdad7fef5015be0e2da63acc87452b56 100644 --- a/src/experiments/cool-checksum/experimentInfo.hpp +++ b/src/experiments/cool-checksum/experimentInfo.hpp @@ -1,5 +1,5 @@ #ifndef __EXPERIMENT_INFO_HPP__ - #define __EXPERIMENT_INFO_HPP__ +#define __EXPERIMENT_INFO_HPP__ #define COOL_FAULTSPACE_PRUNING 0 diff --git a/src/experiments/ecos_kernel_test/campaign.cc b/src/experiments/ecos_kernel_test/campaign.cc index ac665de9ffd34a72effa92ee437ce07466fac520..71d9215dfae39a8e93b2aa3e89ba8c383e8bc4d3 100644 --- a/src/experiments/ecos_kernel_test/campaign.cc +++ b/src/experiments/ecos_kernel_test/campaign.cc @@ -60,7 +60,7 @@ bool EcosKernelTestCampaign::readTraceInfo(unsigned &instr_counter, unsigned &ti while (getline(file, buf)) { stringstream ss(buf, ios::in); - switch(count) { + switch (count) { case 0: ss >> instr_counter; break; diff --git a/src/experiments/ecos_kernel_test/experiment.cc b/src/experiments/ecos_kernel_test/experiment.cc index 218ab2452b34c14aad547d5a9a7004bc154d1c3b..40e2e6094eba545a45cfdec58423d19b1e4d0b4f 100644 --- a/src/experiments/ecos_kernel_test/experiment.cc +++ b/src/experiments/ecos_kernel_test/experiment.cc @@ -27,7 +27,7 @@ #define LOCAL 0 #ifndef PREREQUISITES - #error Configure experimentInfo.hpp properly! + #error Configure experimentInfo.hpp properly! #endif // create/use multiple snapshots to speed up long experiments @@ -113,7 +113,7 @@ bool EcosKernelTestExperiment::establishState(guest_address_t addr_entry, guest_ while (true) { simulator.addListenerAndResume(&g); - if(g.getData() == 'Q') { + if (g.getData() == 'Q') { log << "Guest system triggered: " << g.getData() << endl; break; } @@ -203,15 +203,15 @@ bool EcosKernelTestExperiment::performTrace(guest_address_t addr_entry, guest_ad // do the job, 'till the end BaseListener* ev = simulator.resume(); - while(ev != &bp) { - if(ev == &ev_count) { - if(instr_counter++ == 0xFFFFFFFFU) { + while (ev != &bp) { + if (ev == &ev_count) { + if (instr_counter++ == 0xFFFFFFFFU) { log << "ERROR: instr_counter overflowed" << endl; return false; } simulator.addListener(&ev_count); } - else if(ev == &ev_mem) { + else if (ev == &ev_mem) { unsigned lo = ev_mem.getTriggerAddress(); unsigned hi = lo + ev_mem.getTriggerWidth() - 1; @@ -259,7 +259,7 @@ bool EcosKernelTestExperiment::performTrace(guest_address_t addr_entry, guest_ad } of.close(); log << "trace written to " << EcosKernelTestCampaign::filename_trace(m_variant, m_benchmark) << endl; - + return true; } @@ -301,7 +301,7 @@ bool EcosKernelTestExperiment::faultInjection() { addr_data_start, addr_data_end; BPSingleListener bp; - + int experiments = 0; #if !LOCAL for (experiments = 0; @@ -511,7 +511,7 @@ bool EcosKernelTestExperiment::faultInjection() { //BPSingleListener ev_end(ANY_ADDR); //ev_end.setCounter(instr_counter - instr_offset + ECOS_RECOVERYINSTR); //simulator.addListener(&ev_end); - + // function called by ecc aspects, when an uncorrectable error is detected BPSingleListener func_ecc_panic(addr_panic); if (addr_panic != ADDR_INV) { @@ -558,7 +558,7 @@ bool EcosKernelTestExperiment::faultInjection() { } else { result->set_error_corrected(0); } - + // record ecos_test_result if ( (ecos_test_passed == true) && (ecos_test_failed == false) ) { result->set_ecos_test_result(result->PASS); diff --git a/src/experiments/fault-coverage/experiment.cc b/src/experiments/fault-coverage/experiment.cc index 1f96812329eb5cb34d9ef366643f6a3b10e6de03..ff09d3ac963825cf007cf04d300adbd7c77929c0 100644 --- a/src/experiments/fault-coverage/experiment.cc +++ b/src/experiments/fault-coverage/experiment.cc @@ -33,7 +33,7 @@ bool FaultCoverageExperiment::run() d) trap triggered ---- restore previously saved simulator state */ - + // log the results on std::cout Logger log("FaultCoverageExperiment", false); @@ -55,7 +55,7 @@ bool FaultCoverageExperiment::run() // Note: This heavily uses the save-restore feature which causes // causes a memory leak after several rounds (seg-fault). - + // iterate over all registers ConcreteCPU cpu = simulator.getCPU(0); for (ConcreteCPU::iterator it = cpu.begin(); it != cpu.end(); it++) { diff --git a/src/experiments/fault-coverage/experiment.hpp b/src/experiments/fault-coverage/experiment.hpp index e0e109aa85b1e74220b1ab2b6cba5c746c1f8a1f..aebfe6f859864a38218d543771e3b381bc1a0f5b 100644 --- a/src/experiments/fault-coverage/experiment.hpp +++ b/src/experiments/fault-coverage/experiment.hpp @@ -1,5 +1,5 @@ #ifndef __FAULT_COVERAGE_EXPERIMENT_HPP__ - #define __FAULT_COVERAGE_EXPERIMENT_HPP__ +#define __FAULT_COVERAGE_EXPERIMENT_HPP__ #include <iostream> #include <fstream> @@ -7,7 +7,7 @@ #include "config/FailConfig.hpp" #include "efw/ExperimentFlow.hpp" -#define INST_ADDR_FUNC_START 0x4ae6 +#define INST_ADDR_FUNC_START 0x4ae6 #define INST_ADDR_FUNC_END 0x4be6 // Check if configuration dependencies are satisfied: diff --git a/src/experiments/fire-interrupt/experiment.cc b/src/experiments/fire-interrupt/experiment.cc index 1be47ddb6a6a30b5202ae40ef57ff9f3d217d420..21629c3a29eb920eab792338994e69999e0354ec 100644 --- a/src/experiments/fire-interrupt/experiment.cc +++ b/src/experiments/fire-interrupt/experiment.cc @@ -30,7 +30,7 @@ bool FireInterruptExperiment::run() log << "experiment start" << endl; #if 1 - while (true) { + while (true) { int j = 0; for (j = 0; j <= 100; j++) { BPSingleListener mainbp(0x1045f5); diff --git a/src/experiments/fire-interrupt/experiment.hpp b/src/experiments/fire-interrupt/experiment.hpp index 2785bd9711c5a2a67a900f6d32155e749c9978b3..91a30499e0b989f3bad2996dcbf1c91280efbdc7 100644 --- a/src/experiments/fire-interrupt/experiment.hpp +++ b/src/experiments/fire-interrupt/experiment.hpp @@ -1,5 +1,5 @@ #ifndef __FIREINTERRUPT_EXPERIMENT_HPP__ - #define __FIREINTERRUPT_EXPERIMENT_HPP__ +#define __FIREINTERRUPT_EXPERIMENT_HPP__ #include "efw/ExperimentFlow.hpp" diff --git a/src/experiments/generic-tracing/experiment.cc b/src/experiments/generic-tracing/experiment.cc index 0d57f0490311d3bf2009ccb0cc397c725b7b1cd9..5d7b06193ccd71cef4d08fe1d61a951597b59e10 100644 --- a/src/experiments/generic-tracing/experiment.cc +++ b/src/experiments/generic-tracing/experiment.cc @@ -22,7 +22,7 @@ using namespace fail; void GenericTracing::parseOptions() { CommandLine &cmd = CommandLine::Inst(); - CommandLine::option_handle IGNORE = cmd.addOption("", "", Arg::None, "USAGE: fail-client -Wf,[option] -Wf,[option] ... <BochsOptions...>\n\n"); + cmd.addOption("", "", Arg::None, "USAGE: fail-client -Wf,[option] -Wf,[option] ... <BochsOptions...>\n\n"); CommandLine::option_handle HELP = cmd.addOption("h", "help", Arg::None, "-h,--help \tPrint usage and exit"); @@ -35,18 +35,18 @@ void GenericTracing::parseOptions() { CommandLine::option_handle SAVE_SYMBOL = cmd.addOption("S", "save-symbol", Arg::Required, "-S,--save-symbol \tELF symbol to save the state of the machine (default: main)\n"); CommandLine::option_handle STATE_FILE = cmd.addOption("f", "state-file", Arg::Required, - "-f,--state-file \tFile/dir to save the state to (default state)"); + "-f,--state-file \tFile/dir to save the state to (default: state)"); CommandLine::option_handle TRACE_FILE = cmd.addOption("t", "trace-file", Arg::Required, - "-t,--trace-file \tFile to save the execution trace to\n"); + "-t,--trace-file \tFile to save the execution trace to (default: trace.pb)\n"); CommandLine::option_handle FULL_TRACE = cmd.addOption("", "full-trace", Arg::None, "--full-trace \tDo a full trace (more data, default: off)"); CommandLine::option_handle MEM_SYMBOL = cmd.addOption("m", "memory-symbol", Arg::Required, "-m,--memory-symbol \tELF symbol(s) to trace accesses (default: all mem read/writes are traced)"); CommandLine::option_handle MEM_REGION = cmd.addOption("M", "memory-region", Arg::Required, "-M,--memory-region \trestrict memory region which is traced" - " Possible formats: 0x<address>, 0x<address>:0x<address>, 0x<address>:<length>"); + " (Possible formats: 0x<address>, 0x<address>:0x<address>, 0x<address>:<length>)"); - if(!cmd.parse()) { + if (!cmd.parse()) { cerr << "Error parsing arguments." << endl; exit(-1); } @@ -60,7 +60,7 @@ void GenericTracing::parseOptions() { elf_file = cmd[ELF_FILE].first()->arg; else { char * elfpath = getenv("FAIL_ELF_PATH"); - if(elfpath == NULL){ + if (elfpath == NULL) { m_log << "FAIL_ELF_PATH not set :( (alternative: --elf-file) " << std::endl; exit(-1); } @@ -102,7 +102,7 @@ void GenericTracing::parseOptions() { use_memory_map = true; option::Option *opt = cmd[MEM_SYMBOL].first(); - while(opt != 0) { + while (opt != 0) { const ElfSymbol &symbol = m_elf->getSymbol(opt->arg); assert(symbol.isValid()); @@ -118,7 +118,7 @@ void GenericTracing::parseOptions() { use_memory_map = true; option::Option *opt = cmd[MEM_REGION].first(); - while(opt != 0) { + while (opt != 0) { char *endptr; guest_address_t begin = strtol(opt->arg, &endptr, 16); guest_address_t size; @@ -130,14 +130,14 @@ void GenericTracing::parseOptions() { char delim = *endptr; if (delim == 0) { size = 1; - } else if(delim == ':') { + } else if (delim == ':') { char *p = endptr +1; size = strtol(p, &endptr, 16) - begin; if (p == endptr || *endptr != 0) { m_log << "Couldn't parse " << opt->arg << std::endl; exit(-1); } - } else if(delim == '+') { + } else if (delim == '+') { char *p = endptr +1; size = strtol(p, &endptr, 10); if (p == endptr || *endptr != 0) { diff --git a/src/experiments/hsc-simple/experiment.cc b/src/experiments/hsc-simple/experiment.cc index 6f492b101929792e873d1b5ac7c694e708995c54..72c40442efa8f33a1386e0eafd42a2f180bae3ba 100644 --- a/src/experiments/hsc-simple/experiment.cc +++ b/src/experiments/hsc-simple/experiment.cc @@ -22,13 +22,13 @@ bool HSCSimpleExperiment::run() // do funny things here... #if 1 - // STEP 1 + // STEP 1 BPSingleListener mainbp(0x00003c34); simulator.addListenerAndResume(&mainbp); log << "breakpoint reached, saving" << endl; simulator.save("hello.state"); #elif 0 - // STEP 2 + // STEP 2 log << "restoring ..." << endl; simulator.restore("hello.state"); log << "restored!" << endl; diff --git a/src/experiments/hsc-simple/experiment.hpp b/src/experiments/hsc-simple/experiment.hpp index bb3b7e11be55db141ac167986d585752ad8e440e..302667368b9c92f54e6036b100de7f92954e1db6 100644 --- a/src/experiments/hsc-simple/experiment.hpp +++ b/src/experiments/hsc-simple/experiment.hpp @@ -1,5 +1,5 @@ #ifndef __HSC_SIMPLE_EXPERIMENT_HPP__ - #define __HSC_SIMPLE_EXPERIMENT_HPP__ +#define __HSC_SIMPLE_EXPERIMENT_HPP__ #include "efw/ExperimentFlow.hpp" diff --git a/src/experiments/kesorefs/experiment.cc b/src/experiments/kesorefs/experiment.cc index 2decaf799106c6eda65135213709c055365f45f1..0e1e9a840c8edfb0a526db3401c2e58cde93865a 100644 --- a/src/experiments/kesorefs/experiment.cc +++ b/src/experiments/kesorefs/experiment.cc @@ -132,7 +132,7 @@ bool KESOrefs::run() while (executed_jobs < 25 || m_jc.getNumberOfUndoneJobs() > 0) { m_log << "asking jobserver for parameters" << endl; KesoRefExperimentData param; - if(!m_jc.getParam(param)){ + if (!m_jc.getParam(param)) { m_log << "Dying." << endl; // We were told to die. simulator.terminate(1); } @@ -218,7 +218,7 @@ bool KESOrefs::run() m_log << "CDX has ended" << std::endl; // Evaluate result - if(l == &l_error) { + if (l == &l_error) { handleEvent(*result, result->EXC_ERROR, "exc error"); } else if ( l == &l_nullp ) { handleEvent(*result, result->EXC_NULLPOINTER, "exc nullpointer"); @@ -241,10 +241,10 @@ bool KESOrefs::run() sstr << "trap #" << l_trap.getTriggerNumber(); handleEvent(*result, result->TRAP, sstr.str()); - } else if (l == &l_mem_text){ + } else if (l == &l_mem_text) { handleMemoryAccessEvent(*result, l_mem_text); - } else if (l == &l_mem_outerspace){ + } else if (l == &l_mem_outerspace) { handleMemoryAccessEvent(*result, l_mem_outerspace); } else { diff --git a/src/experiments/l4-sys/experiment.cc b/src/experiments/l4-sys/experiment.cc index f3b91132820882e7319025c34825aa993699604a..df69ddb5308f176e485736ade11e3752857f3759 100644 --- a/src/experiments/l4-sys/experiment.cc +++ b/src/experiments/l4-sys/experiment.cc @@ -452,7 +452,7 @@ void L4SysExperiment::collectInstructionTrace(fail::BPSingleListener* bp) log << "mem accesses: " << mem << ", valid: " << mem_valid << std::endl; #else bp->setWatchInstructionPointer(ANY_ADDR); - while(bp->getTriggerInstructionPointer() != L4SYS_FUNC_EXIT) + while (bp->getTriggerInstructionPointer() != L4SYS_FUNC_EXIT) { fail::BaseListener *res = simulator.resume(); address_t curr_addr = 0; diff --git a/src/experiments/nanojpeg/experiment.cc b/src/experiments/nanojpeg/experiment.cc index 17c313df647b89214960103421b57f78cf7846a9..7f9f75a07bae0367fcae713f4b4374e51a7a30ad 100644 --- a/src/experiments/nanojpeg/experiment.cc +++ b/src/experiments/nanojpeg/experiment.cc @@ -36,7 +36,7 @@ using namespace fail; bool NanoJPEGExperiment::run() { Logger log("nJPEG", true); - + log << "startup" << endl; #if PREPARATION == 1 diff --git a/src/experiments/nanojpeg/experiment.hpp b/src/experiments/nanojpeg/experiment.hpp index 43a80b27a664dccf7c32c852bc714e2b120b03ab..76a03d95f15abb30c12e0b5afbc3002c880fa6eb 100644 --- a/src/experiments/nanojpeg/experiment.hpp +++ b/src/experiments/nanojpeg/experiment.hpp @@ -1,6 +1,6 @@ #ifndef __NANOJPEG_EXPERIMENT_HPP__ - #define __NANOJPEG_EXPERIMENT_HPP__ - +#define __NANOJPEG_EXPERIMENT_HPP__ + #include "efw/ExperimentFlow.hpp" #include "efw/JobClient.hpp" diff --git a/src/experiments/nanojpeg/psnr.cc b/src/experiments/nanojpeg/psnr.cc index 14c402cc06877d133122e2870ec840a75be49c1a..9a9e873ee0fc2c0d52ed2e355871ea3fc137438d 100644 --- a/src/experiments/nanojpeg/psnr.cc +++ b/src/experiments/nanojpeg/psnr.cc @@ -70,7 +70,7 @@ bool PSNR::load_refimage(char const *refimage_filename) // one whitespace character fs.ignore(); - + get_remaining_file_contents(fs, refimg); if (refimg.size() < refimg_width * refimg_height * 3) { std::cerr << "image too small" << std::endl; diff --git a/src/experiments/nanojpeg/udis86_helper.cc b/src/experiments/nanojpeg/udis86_helper.cc index ff03107802b72c1a3a7f918a46657793f785c96d..e6e12dbdaa602fa0ca1b9cbcbe5e4ab9dfa8b43a 100644 --- a/src/experiments/nanojpeg/udis86_helper.cc +++ b/src/experiments/nanojpeg/udis86_helper.cc @@ -30,7 +30,7 @@ char const * Udis86Helper::mnemonicToString(unsigned mnemonic) { - switch(mnemonic) { + switch (mnemonic) { CASE(UD_Iinvalid) CASE(UD_I3dnow) CASE(UD_Inone) CASE(UD_Idb) CASE(UD_Ipause) CASE(UD_Iaaa) CASE(UD_Iaad) CASE(UD_Iaam) CASE(UD_Iaas) CASE(UD_Iadc) CASE(UD_Iadd) CASE(UD_Iaddpd) CASE(UD_Iaddps) CASE(UD_Iaddsd) CASE(UD_Iaddss) CASE(UD_Iand) CASE(UD_Iandpd) CASE(UD_Iandps) @@ -141,67 +141,67 @@ char const * Udis86Helper::typeToString(ud_type type) { switch (type) { - CASE(UD_NONE) + CASE(UD_NONE) /* 8 bit GPRs */ - CASE(UD_R_AL) CASE(UD_R_CL) CASE(UD_R_DL) CASE(UD_R_BL) - CASE(UD_R_AH) CASE(UD_R_CH) CASE(UD_R_DH) CASE(UD_R_BH) - CASE(UD_R_SPL) CASE(UD_R_BPL) CASE(UD_R_SIL) CASE(UD_R_DIL) - CASE(UD_R_R8B) CASE(UD_R_R9B) CASE(UD_R_R10B) CASE(UD_R_R11B) - CASE(UD_R_R12B) CASE(UD_R_R13B) CASE(UD_R_R14B) CASE(UD_R_R15B) + CASE(UD_R_AL) CASE(UD_R_CL) CASE(UD_R_DL) CASE(UD_R_BL) + CASE(UD_R_AH) CASE(UD_R_CH) CASE(UD_R_DH) CASE(UD_R_BH) + CASE(UD_R_SPL) CASE(UD_R_BPL) CASE(UD_R_SIL) CASE(UD_R_DIL) + CASE(UD_R_R8B) CASE(UD_R_R9B) CASE(UD_R_R10B) CASE(UD_R_R11B) + CASE(UD_R_R12B) CASE(UD_R_R13B) CASE(UD_R_R14B) CASE(UD_R_R15B) /* 16 bit GPRs */ - CASE(UD_R_AX) CASE(UD_R_CX) CASE(UD_R_DX) CASE(UD_R_BX) - CASE(UD_R_SP) CASE(UD_R_BP) CASE(UD_R_SI) CASE(UD_R_DI) - CASE(UD_R_R8W) CASE(UD_R_R9W) CASE(UD_R_R10W) CASE(UD_R_R11W) - CASE(UD_R_R12W) CASE(UD_R_R13W) CASE(UD_R_R14W) CASE(UD_R_R15W) - + CASE(UD_R_AX) CASE(UD_R_CX) CASE(UD_R_DX) CASE(UD_R_BX) + CASE(UD_R_SP) CASE(UD_R_BP) CASE(UD_R_SI) CASE(UD_R_DI) + CASE(UD_R_R8W) CASE(UD_R_R9W) CASE(UD_R_R10W) CASE(UD_R_R11W) + CASE(UD_R_R12W) CASE(UD_R_R13W) CASE(UD_R_R14W) CASE(UD_R_R15W) + /* 32 bit GPRs */ - CASE(UD_R_EAX) CASE(UD_R_ECX) CASE(UD_R_EDX) CASE(UD_R_EBX) - CASE(UD_R_ESP) CASE(UD_R_EBP) CASE(UD_R_ESI) CASE(UD_R_EDI) - CASE(UD_R_R8D) CASE(UD_R_R9D) CASE(UD_R_R10D) CASE(UD_R_R11D) - CASE(UD_R_R12D) CASE(UD_R_R13D) CASE(UD_R_R14D) CASE(UD_R_R15D) - + CASE(UD_R_EAX) CASE(UD_R_ECX) CASE(UD_R_EDX) CASE(UD_R_EBX) + CASE(UD_R_ESP) CASE(UD_R_EBP) CASE(UD_R_ESI) CASE(UD_R_EDI) + CASE(UD_R_R8D) CASE(UD_R_R9D) CASE(UD_R_R10D) CASE(UD_R_R11D) + CASE(UD_R_R12D) CASE(UD_R_R13D) CASE(UD_R_R14D) CASE(UD_R_R15D) + /* 64 bit GPRs */ - CASE(UD_R_RAX) CASE(UD_R_RCX) CASE(UD_R_RDX) CASE(UD_R_RBX) - CASE(UD_R_RSP) CASE(UD_R_RBP) CASE(UD_R_RSI) CASE(UD_R_RDI) - CASE(UD_R_R8) CASE(UD_R_R9) CASE(UD_R_R10) CASE(UD_R_R11) - CASE(UD_R_R12) CASE(UD_R_R13) CASE(UD_R_R14) CASE(UD_R_R15) + CASE(UD_R_RAX) CASE(UD_R_RCX) CASE(UD_R_RDX) CASE(UD_R_RBX) + CASE(UD_R_RSP) CASE(UD_R_RBP) CASE(UD_R_RSI) CASE(UD_R_RDI) + CASE(UD_R_R8) CASE(UD_R_R9) CASE(UD_R_R10) CASE(UD_R_R11) + CASE(UD_R_R12) CASE(UD_R_R13) CASE(UD_R_R14) CASE(UD_R_R15) /* segment registers */ - CASE(UD_R_ES) CASE(UD_R_CS) CASE(UD_R_SS) CASE(UD_R_DS) - CASE(UD_R_FS) CASE(UD_R_GS) + CASE(UD_R_ES) CASE(UD_R_CS) CASE(UD_R_SS) CASE(UD_R_DS) + CASE(UD_R_FS) CASE(UD_R_GS) /* control registers*/ - CASE(UD_R_CR0) CASE(UD_R_CR1) CASE(UD_R_CR2) CASE(UD_R_CR3) - CASE(UD_R_CR4) CASE(UD_R_CR5) CASE(UD_R_CR6) CASE(UD_R_CR7) - CASE(UD_R_CR8) CASE(UD_R_CR9) CASE(UD_R_CR10) CASE(UD_R_CR11) - CASE(UD_R_CR12) CASE(UD_R_CR13) CASE(UD_R_CR14) CASE(UD_R_CR15) - + CASE(UD_R_CR0) CASE(UD_R_CR1) CASE(UD_R_CR2) CASE(UD_R_CR3) + CASE(UD_R_CR4) CASE(UD_R_CR5) CASE(UD_R_CR6) CASE(UD_R_CR7) + CASE(UD_R_CR8) CASE(UD_R_CR9) CASE(UD_R_CR10) CASE(UD_R_CR11) + CASE(UD_R_CR12) CASE(UD_R_CR13) CASE(UD_R_CR14) CASE(UD_R_CR15) + /* debug registers */ - CASE(UD_R_DR0) CASE(UD_R_DR1) CASE(UD_R_DR2) CASE(UD_R_DR3) - CASE(UD_R_DR4) CASE(UD_R_DR5) CASE(UD_R_DR6) CASE(UD_R_DR7) - CASE(UD_R_DR8) CASE(UD_R_DR9) CASE(UD_R_DR10) CASE(UD_R_DR11) - CASE(UD_R_DR12) CASE(UD_R_DR13) CASE(UD_R_DR14) CASE(UD_R_DR15) + CASE(UD_R_DR0) CASE(UD_R_DR1) CASE(UD_R_DR2) CASE(UD_R_DR3) + CASE(UD_R_DR4) CASE(UD_R_DR5) CASE(UD_R_DR6) CASE(UD_R_DR7) + CASE(UD_R_DR8) CASE(UD_R_DR9) CASE(UD_R_DR10) CASE(UD_R_DR11) + CASE(UD_R_DR12) CASE(UD_R_DR13) CASE(UD_R_DR14) CASE(UD_R_DR15) /* mmx registers */ - CASE(UD_R_MM0) CASE(UD_R_MM1) CASE(UD_R_MM2) CASE(UD_R_MM3) - CASE(UD_R_MM4) CASE(UD_R_MM5) CASE(UD_R_MM6) CASE(UD_R_MM7) + CASE(UD_R_MM0) CASE(UD_R_MM1) CASE(UD_R_MM2) CASE(UD_R_MM3) + CASE(UD_R_MM4) CASE(UD_R_MM5) CASE(UD_R_MM6) CASE(UD_R_MM7) /* x87 registers */ - CASE(UD_R_ST0) CASE(UD_R_ST1) CASE(UD_R_ST2) CASE(UD_R_ST3) - CASE(UD_R_ST4) CASE(UD_R_ST5) CASE(UD_R_ST6) CASE(UD_R_ST7) + CASE(UD_R_ST0) CASE(UD_R_ST1) CASE(UD_R_ST2) CASE(UD_R_ST3) + CASE(UD_R_ST4) CASE(UD_R_ST5) CASE(UD_R_ST6) CASE(UD_R_ST7) /* extended multimedia registers */ - CASE(UD_R_XMM0) CASE(UD_R_XMM1) CASE(UD_R_XMM2) CASE(UD_R_XMM3) - CASE(UD_R_XMM4) CASE(UD_R_XMM5) CASE(UD_R_XMM6) CASE(UD_R_XMM7) - CASE(UD_R_XMM8) CASE(UD_R_XMM9) CASE(UD_R_XMM10) CASE(UD_R_XMM11) - CASE(UD_R_XMM12) CASE(UD_R_XMM13) CASE(UD_R_XMM14) CASE(UD_R_XMM15) + CASE(UD_R_XMM0) CASE(UD_R_XMM1) CASE(UD_R_XMM2) CASE(UD_R_XMM3) + CASE(UD_R_XMM4) CASE(UD_R_XMM5) CASE(UD_R_XMM6) CASE(UD_R_XMM7) + CASE(UD_R_XMM8) CASE(UD_R_XMM9) CASE(UD_R_XMM10) CASE(UD_R_XMM11) + CASE(UD_R_XMM12) CASE(UD_R_XMM13) CASE(UD_R_XMM14) CASE(UD_R_XMM15) - CASE(UD_R_RIP) + CASE(UD_R_RIP) /* Operand Types */ - CASE(UD_OP_REG) CASE(UD_OP_MEM) CASE(UD_OP_PTR) CASE(UD_OP_IMM) + CASE(UD_OP_REG) CASE(UD_OP_MEM) CASE(UD_OP_PTR) CASE(UD_OP_IMM) CASE(UD_OP_JIMM) CASE(UD_OP_CONST) default: return "???"; diff --git a/src/experiments/perf-test/experiment.cc b/src/experiments/perf-test/experiment.cc index ff667aa9e37518d65d11a4bcbc68a77e5c6127ba..1c00e1844dc1da53720c8e24b02160278f6c9208 100644 --- a/src/experiments/perf-test/experiment.cc +++ b/src/experiments/perf-test/experiment.cc @@ -48,7 +48,7 @@ bool PerfTestExperiment::run() #if 1 log << "Activated: CASE A (Best-Case)..." << endl; // Case A): A lot of non-BP listeners a only one (or none) BPs: - + log << "Adding " << NON_BP_COUNT << " non-BP listeners..." << endl; MemReadListener mrl[NON_BP_COUNT]; for (unsigned i = 0; i < NON_BP_COUNT; ++i) { diff --git a/src/experiments/rampage/campaign.cc b/src/experiments/rampage/campaign.cc index f69f164e46072ad51acf038cc46104bc0809ca4a..8d984229e40ec2c3d96b7163be3e1b0fccc11d2a 100644 --- a/src/experiments/rampage/campaign.cc +++ b/src/experiments/rampage/campaign.cc @@ -112,7 +112,7 @@ uint64_t RAMpageCampaign::reverse_bits(uint64_t v) int s = sizeof(v) * CHAR_BIT - 1; // extra shift needed at end for (v >>= 1; v; v >>= 1) - { + { r <<= 1; r |= v & 1; s--; diff --git a/src/experiments/rampage/experiment.hpp b/src/experiments/rampage/experiment.hpp index de282fe8128d9f782a7a2e588b595cb91a3bf72e..d4f0718f060c0a7a09a589f707aa8a610919f2ce 100644 --- a/src/experiments/rampage/experiment.hpp +++ b/src/experiments/rampage/experiment.hpp @@ -1,6 +1,6 @@ #ifndef __RAMPAGE_EXPERIMENT_HPP__ - #define __RAMPAGE_EXPERIMENT_HPP__ - +#define __RAMPAGE_EXPERIMENT_HPP__ + #include <string> #include <ctime> diff --git a/src/experiments/regression-test/experiment.cc b/src/experiments/regression-test/experiment.cc index 43e9ba82b35a797900f2eba363dff02f8aa6ccaf..01843f1badc7f5444423f3cad53da16c0dbb2d95 100644 --- a/src/experiments/regression-test/experiment.cc +++ b/src/experiments/regression-test/experiment.cc @@ -17,7 +17,7 @@ || !defined(CONFIG_EVENT_GUESTSYS) || !defined(CONFIG_EVENT_INTERRUPT) \ || !defined(CONFIG_EVENT_IOPORT) || !defined(CONFIG_EVENT_JUMP) || !defined(CONFIG_EVENT_MEMREAD) \ || !defined(CONFIG_EVENT_MEMWRITE) || !defined(CONFIG_EVENT_TRAP) || !defined(CONFIG_SR_REBOOT) \ -|| !defined(CONFIG_SR_SAVE) || !defined(CONFIG_SR_RESTORE) || !defined(CONFIG_SUPPRESS_INTERRUPTS) +|| !defined(CONFIG_SR_SAVE) || !defined(CONFIG_SR_RESTORE) || !defined(CONFIG_SUPPRESS_INTERRUPTS) #error This experiment needs: all CONFIG_EVENT_*, all CONFIG_SR_* and the CONFIG_SUPPRESS_INTERRUPTS flag. Enable these in the configuration. #endif @@ -25,17 +25,17 @@ using namespace std; using namespace fail; bool RegressionTest::run() -{ +{ unsigned instrAddr_at_save = 0; BaseListener *ev; - + //Result-File fstream file ("regression-test.results", ios::out | ios::trunc); file << "experiment start" << endl; - + //Wait for correct start point GuestListener g; - + while (simulator.addListenerAndResume(&g) == &g) { if (g.getData() == 'A') { file << "Found start-point with signal: " << g.getData() << endl; @@ -43,25 +43,25 @@ bool RegressionTest::run() break; } } - + //Watchdog-Timer TimerListener watchdog(100000); simulator.addListener(&watchdog); - + //Save state file << "Saving state." << endl; simulator.save("regression-save"); instrAddr_at_save = simulator.getCPU(0).getInstructionPointer(); - + //Start Plugins TracingPlugin tp; ofstream of("regression-trace.results"); tp.setOstream(&of); simulator.addFlow(&tp); - + SerialOutput so(0x3F8); simulator.addFlow(&so); - + //BPListener BPSingleListener bp_test(REGRESSION_FUNC_BP); BPSingleListener mem_read_test(REGRESSION_FUNC_MEM_READ); @@ -76,53 +76,53 @@ bool RegressionTest::run() simulator.addListener(&trap_test); simulator.addListener(&jump_test); simulator.addListener(&interrupt_test); - + while (true) { simulator.removeListener(&watchdog); simulator.addListener(&watchdog); ev = simulator.resume(); - + if (ev == &bp_test) { file << "Breakpoint-Test start." << endl; - - BPSingleListener mainbp(ANY_ADDR); + + BPSingleListener mainbp(ANY_ADDR); mainbp.setCounter(1000); - + BPRangeListener bprange(REGRESSION_FUNC_LOOP_DONE, REGRESSION_FUNC_LOOP_DONE); BPSingleListener breakcounter(REGRESSION_FUNC_LOOP_DONE); simulator.addListener(&breakcounter); int count = 0; - while(true){ - + while (true) { + BaseListener* ev = simulator.resume(); - - if(ev == &breakcounter || ev == &bprange) { - + + if (ev == &breakcounter || ev == &bprange) { + count++; //First 5 times test BPSingleListener - if(count < 5){ + if (count < 5) { simulator.addListener(&breakcounter); //Next 5 times test BPRangeListener - }else if(count < 10){ + } else if (count < 10) { simulator.addListener(&bprange); - //At 10 run of loop start BPSingleListener, BPRangeListener, mainListener - //which waits 1000 instructions. - }else if(count == 10){ + //At 10 run of loop start BPSingleListener, BPRangeListener, mainListener + //which waits 1000 instructions. + } else if (count == 10) { simulator.addListener(&breakcounter); simulator.addListener(&bprange); simulator.addListener(&mainbp); //If mainListener fires not first the test failes. - }else if(count >= 10){ + }else if (count >= 10) { file << "Breakpoint-Test FAILED."<< endl; break; } //If mainListener fires first the test success. - }else if(ev == &mainbp) { + } else if (ev == &mainbp) { file << "Breakpoint-Test SUCCESSFUL." <<endl; break; - }else if (ev == &watchdog) { + } else if (ev == &watchdog) { file << "Breakpoint-Test FAILED --> Watchdog fired. Timeout!" << endl; } } @@ -130,63 +130,63 @@ bool RegressionTest::run() simulator.removeListener(&breakcounter); simulator.removeListener(&bprange); simulator.removeListener(&mainbp); - + } else if (ev == &mem_read_test) { file << "Memory-Read-Test start." << endl; - + MemReadListener memread(REGRESSION_VAR_MTEST_READ); simulator.addListener(&memread); simulator.resume(); - + file << "Memaddr-Read: " << hex << memread.getTriggerAddress() << dec << endl; - - if(memread.getTriggerAddress() == REGRESSION_VAR_MTEST_READ) { + + if (memread.getTriggerAddress() == REGRESSION_VAR_MTEST_READ) { file << "Memory-Read-Test SUCCESSFUL." << endl; } else { file << "Memory-Read-Test FAILED." << endl; } - + file << "Memory-Read-Test end." << endl; simulator.removeListener(&memread); } else if (ev == &mem_write_test) { - + file << "Memory-Write-Test start." << endl; - + MemWriteListener memwrite(REGRESSION_VAR_MTEST_WRITE); simulator.addListener(&memwrite); simulator.resume(); - + file << "Memaddr-WRITE: " << hex << memwrite.getTriggerAddress() << dec << endl; - if(memwrite.getTriggerAddress() == REGRESSION_VAR_MTEST_WRITE) { + if (memwrite.getTriggerAddress() == REGRESSION_VAR_MTEST_WRITE) { file << "Memory-Write-Test SUCCESSFUL." << endl; } else { file << "Memory-Write-Test FAILED." << endl; } file << "Memory-Write-Test end." << endl; - - + + } else if (ev == &trap_test) { - + file << "Trap-Test start" << endl; - + TrapListener trap(ANY_TRAP); simulator.addListener(&trap); simulator.resume(); file << "Trap found: " << trap.getTriggerNumber() << endl; - + file << "Trap-Test end" << endl; - + simulator.removeListener(&trap); - + //After a division-error trap ecos halts the cpu //Because of this a restore to start point is needed - + simulator.restore("regression-save"); - + if (simulator.getCPU(0).getInstructionPointer() == instrAddr_at_save) { file << "Save-/Restore-Test SUCCESSFUL." << endl; } else { @@ -196,44 +196,44 @@ bool RegressionTest::run() file << "Instructionpointer after restore: " << \ simulator.getCPU(0).getInstructionPointer() << endl; } - + // Reboot test file << "Reboot-Test start" << endl; BPSingleListener bpReboot(ANY_ADDR); - + simulator.addListener(&bpReboot); simulator.resume(); long beforeReboot = bpReboot.getTriggerInstructionPointer(); - + file << "Before Reboot-Addr: 0x" << hex << beforeReboot << dec << endl; - - simulator.reboot(); - + + simulator.reboot(); + bpReboot.setWatchInstructionPointer(beforeReboot); simulator.addListener(&bpReboot); simulator.resume(); - + long afterReboot = bpReboot.getTriggerInstructionPointer(); - + file << "After Reboot-Addr: 0x" << hex << afterReboot << dec << endl; - - if (beforeReboot == afterReboot){ + + if (beforeReboot == afterReboot) { file << "Reboot-Test SUCCESSFUL." << endl; - }else { + } else { file << "Reboot-Test FAILED." << endl; } file << "Reboot-Test end" << endl; simulator.removeListener(&bpReboot); - + file << "Serial-Output: " << so.getOutput() << endl; - + file.flush(); of.flush(); - + simulator.terminate(); } else if (ev == &jump_test) { @@ -242,36 +242,36 @@ bool RegressionTest::run() JumpListener jump(ANY_INSTR); simulator.addListener(&jump); simulator.resume(); - + file << "Jump-Instruction found: " << jump.getOpcode() << endl; file << "current Instruction-Pointer: 0x" << hex <<\ simulator.getCPU(0).getInstructionPointer() << dec << endl; - + file << "Jump-Test end" << endl; - + simulator.removeListener(&jump); - + } else if (ev == &interrupt_test) { - + file << "Interrupt-Test start" << endl; - + InterruptListener interrupt(32); simulator.addListener(&interrupt); ev = simulator.resume(); - + if (ev == &interrupt) { file << "Interrupt-Test SUCCESSFUL. Interruptnum: " << interrupt.getTriggerNumber() \ << endl; } - + file << "Interrupt-Test end" << endl; } else if (ev == &watchdog) { file << "Watchdog fired. Timeout!" << endl; } } - + file << "experiment end" << endl; - + return true; - + } diff --git a/src/experiments/regression-test/experiment.hpp b/src/experiments/regression-test/experiment.hpp index 6cea7bd927eafd6557b7a05bac82f0824f2a9cca..17340014a2e9bf23ebb43d3c374496119ae66680 100644 --- a/src/experiments/regression-test/experiment.hpp +++ b/src/experiments/regression-test/experiment.hpp @@ -7,7 +7,7 @@ class RegressionTest : public fail::ExperimentFlow { public: RegressionTest() { } - + bool run(); }; diff --git a/src/experiments/weather-monitor-gem5/campaign.cc b/src/experiments/weather-monitor-gem5/campaign.cc index 205cb5daf326e4703b16087c57d46b5a6e72edde..ed9ed9f4641d0c9f3b94ad25ca7aa98e74fdcbf4 100755 --- a/src/experiments/weather-monitor-gem5/campaign.cc +++ b/src/experiments/weather-monitor-gem5/campaign.cc @@ -305,7 +305,7 @@ bool WeatherMonitorCampaign::run() // is not the case in this experiment, and with -1 we'll get a result // comparable to the non-pruned campaign. // XXX still true for weathermonitor? - + current_ec.instr2 = instr - 1; current_ec.instr2_absolute = 0; // unknown current_ec.data_address = data_address; diff --git a/src/experiments/weather-monitor-gem5/experiment.cc b/src/experiments/weather-monitor-gem5/experiment.cc index 327f0cd8af405b5cef99915efb36b76f4849bf7d..71ea0b9fe9d3263947355cb598dc80b4a63c30e9 100755 --- a/src/experiments/weather-monitor-gem5/experiment.cc +++ b/src/experiments/weather-monitor-gem5/experiment.cc @@ -36,7 +36,7 @@ bool WeatherMonitorExperiment::run() char const *statename = "bochs.state" WEATHER_SUFFIX; Logger log("Weathermonitor", false); BPSingleListener bp; - + log << "startup" << endl; #if 1 @@ -160,11 +160,11 @@ bool WeatherMonitorExperiment::run() int id = param.getWorkloadID(); int instr_offset = param.msg.instr_offset(); int mem_addr = param.msg.mem_addr(); - // Choose the bit_offset for this gem5 build. + // Choose the bit_offset for this gem5 build. // To test all 8 bits, 8 campaign runs are needed. int bit_offset = 0; - + // 8 results in one job WeathermonitorProtoMsg_Result *result = param.msg.add_result(); result->set_bit_offset(bit_offset); diff --git a/src/experiments/weather-monitor-gem5/experiment.hpp b/src/experiments/weather-monitor-gem5/experiment.hpp index 2b7036e0d9d0c9ebfd3c20bb8615e1c67960c7fb..980369821b042fbb27107dad4171befc79c155f2 100644 --- a/src/experiments/weather-monitor-gem5/experiment.hpp +++ b/src/experiments/weather-monitor-gem5/experiment.hpp @@ -1,6 +1,6 @@ #ifndef __WEATHERMONITOR_EXPERIMENT_HPP__ - #define __WEATHERMONITOR_EXPERIMENT_HPP__ - +#define __WEATHERMONITOR_EXPERIMENT_HPP__ + #include "efw/ExperimentFlow.hpp" #include "efw/JobClient.hpp" diff --git a/src/experiments/weather-monitor/experiment.cc b/src/experiments/weather-monitor/experiment.cc index e1bcb7e7974a05020880bb4da9975223c29f7ddd..412b7d499b4abef66841147a9c02b2e4a8ab450b 100644 --- a/src/experiments/weather-monitor/experiment.cc +++ b/src/experiments/weather-monitor/experiment.cc @@ -37,7 +37,7 @@ bool WeatherMonitorExperiment::run() char const *statename = "bochs.state" WEATHER_SUFFIX; Logger log("Weathermonitor", false); BPSingleListener bp; - + log << "startup" << endl; /* @@ -179,7 +179,7 @@ bool WeatherMonitorExperiment::run() for (int bit_offset = 0; bit_offset < 8; ++bit_offset) { // 8 results in one job WeathermonitorProtoMsg_Result *result = param.msg.add_result(); - result->set_bitoffset(bit_offset); + result->set_bitoffset(bit_offset); log << dec << "job " << id << " instr " << injection_instr << " mem " << data_address << "+" << bit_offset << endl; diff --git a/src/experiments/weather-monitor/experiment.hpp b/src/experiments/weather-monitor/experiment.hpp index 2b7036e0d9d0c9ebfd3c20bb8615e1c67960c7fb..980369821b042fbb27107dad4171befc79c155f2 100644 --- a/src/experiments/weather-monitor/experiment.hpp +++ b/src/experiments/weather-monitor/experiment.hpp @@ -1,6 +1,6 @@ #ifndef __WEATHERMONITOR_EXPERIMENT_HPP__ - #define __WEATHERMONITOR_EXPERIMENT_HPP__ - +#define __WEATHERMONITOR_EXPERIMENT_HPP__ + #include "efw/ExperimentFlow.hpp" #include "efw/JobClient.hpp" diff --git a/src/plugins/realtimelogger/RealtimeLogger.cc b/src/plugins/realtimelogger/RealtimeLogger.cc index 29660e10d58b2eca454e477eefde5e0aa9027153..e5705e7f557a26ac7b9f8ef81d483d3aea7ae472 100644 --- a/src/plugins/realtimelogger/RealtimeLogger.cc +++ b/src/plugins/realtimelogger/RealtimeLogger.cc @@ -7,35 +7,35 @@ using namespace fail; bool RealtimeLogger::run() { - MemoryManager& mm = simulator.getMemoryManager(); + MemoryManager& mm = simulator.getMemoryManager(); - uint32_t value; //! @todo more generic datatype + uint32_t value; //! @todo more generic datatype - m_log << "Realtime Logger started. Listening to: " << m_symbol << std::endl; - MemAccessListener ev_mem(m_symbol.getAddress()); + m_log << "Realtime Logger started. Listening to: " << m_symbol << std::endl; + MemAccessListener ev_mem(m_symbol.getAddress()); - if(m_ostream.is_open()) { - m_log << "Writing output to: " << m_outputfile << std::endl; - while (true) { - simulator.addListenerAndResume(&ev_mem); - /* A Memory Accesses happend: Get simulation time and log it */ - fail::simtime_t simtime = simulator.getTimerTicks(); - mm.getBytes(m_symbol.getAddress(), m_symbol.getSize(), &value); - handleEvent(simtime, value); - } - } else { - m_log << "No output file." << std::endl; - } - return true; + if (m_ostream.is_open()) { + m_log << "Writing output to: " << m_outputfile << std::endl; + while (true) { + simulator.addListenerAndResume(&ev_mem); + /* A Memory Accesses happend: Get simulation time and log it */ + fail::simtime_t simtime = simulator.getTimerTicks(); + mm.getBytes(m_symbol.getAddress(), m_symbol.getSize(), &value); + handleEvent(simtime, value); + } + } else { + m_log << "No output file." << std::endl; + } + return true; } void RealtimeLogger::handleEvent(fail::simtime_t simtime, uint32_t value) { - simtime_t per_second = simulator.getTimerTicksPerSecond(); - double sec = (double)simtime / per_second; - double msec = sec*1000; - if(m_ostream.is_open()){ - m_ostream << std::dec << msec << ";" << value << std::endl; - } + simtime_t per_second = simulator.getTimerTicksPerSecond(); + double sec = (double)simtime / per_second; + double msec = sec*1000; + if (m_ostream.is_open()) { + m_ostream << std::dec << msec << ";" << value << std::endl; + } } diff --git a/src/plugins/realtimelogger/RealtimeLogger.hpp b/src/plugins/realtimelogger/RealtimeLogger.hpp index 9670d97cf112f0fed0a8acab7c96265519e50f8e..47b6e69f9576d43d431536f68c67d06a51653021 100644 --- a/src/plugins/realtimelogger/RealtimeLogger.hpp +++ b/src/plugins/realtimelogger/RealtimeLogger.hpp @@ -1,5 +1,5 @@ #ifndef __REALTIMELOGGER_HPP__ - #define __REALTIMELOGGER_HPP__ +#define __REALTIMELOGGER_HPP__ #include <string> #include <unistd.h> @@ -11,39 +11,38 @@ /** * @class RealtimeLogger - * @brief Listens to a memory location and outputs content on write access + * @brief Listens to a memory location and outputs content on write access * from SUT to file */ class RealtimeLogger : public fail::ExperimentFlow { private: - const fail::ElfSymbol m_symbol; //!< the target's memory symbol the plugin is listening on - std::string m_outputfile; //!< the output filename - fail::Logger m_log; //!< debug output - std::ofstream m_ostream; //!< Outputfile stream + const fail::ElfSymbol m_symbol; //!< the target's memory symbol the plugin is listening on + std::string m_outputfile; //!< the output filename + fail::Logger m_log; //!< debug output + std::ofstream m_ostream; //!< Outputfile stream public: - /** - * Constructor of RealtimeLogger. - * - * @param symbol The global memory address the plugin listens to - * @param outputfile The path to the file to write the output to - */ - RealtimeLogger( const fail::ElfSymbol & symbol, const std::string& outputfile ) : m_symbol(symbol), m_outputfile(outputfile) , m_log("RTLogger", false) { - m_ostream.open(m_outputfile.c_str() ); - if(!m_ostream.is_open()){ - m_log << "Could not open " << m_outputfile.c_str() << " for writing." << std::endl; - } - } + /** + * Constructor of RealtimeLogger. + * + * @param symbol The global memory address the plugin listens to + * @param outputfile The path to the file to write the output to + */ + RealtimeLogger( const fail::ElfSymbol & symbol, const std::string& outputfile ) : m_symbol(symbol), m_outputfile(outputfile) , m_log("RTLogger", false) { + m_ostream.open(m_outputfile.c_str() ); + if (!m_ostream.is_open()) { + m_log << "Could not open " << m_outputfile.c_str() << " for writing." << std::endl; + } + } - bool run(); + bool run(); private: - /** - * Handle the memory event - */ - void handleEvent(fail::simtime_t simtime, uint32_t value); - + /** + * Handle the memory event + */ + void handleEvent(fail::simtime_t simtime, uint32_t value); }; #endif // __REALTIMELOGGER_HPP__ diff --git a/src/plugins/serialoutput/SerialOutput.hpp b/src/plugins/serialoutput/SerialOutput.hpp index efe3af5e3ad15bfa6cd64e880711644c965181ad..2a91f4d86c6edddf1ee3d158a5f4a4384d6d701b 100644 --- a/src/plugins/serialoutput/SerialOutput.hpp +++ b/src/plugins/serialoutput/SerialOutput.hpp @@ -1,5 +1,5 @@ #ifndef __SERIAL_OUTPUT_HPP__ - #define __SERIAL_OUTPUT_HPP__ +#define __SERIAL_OUTPUT_HPP__ #include <string> @@ -8,7 +8,7 @@ // Check if configuration dependencies are satisfied: #if !defined(CONFIG_EVENT_IOPORT) - #warning The serialoutput plugin may (depending on its use) need ioport event. Enable these in the cmake configuration tool. + #warning The serialoutput plugin may (depending on its use) need ioport event. Enable these in the cmake configuration tool. #endif /** @@ -18,7 +18,7 @@ */ class SerialOutput : public fail::ExperimentFlow { - + private: bool m_out; //!< Defines the direction of the listener. unsigned m_port; //!< the port the listener is listening on @@ -27,7 +27,7 @@ private: public: /** * Constructor of SerialOutput. - * + * * @param port the port the listener is listening on * @param out Defines the direction of the listener. * \arg \c true Output on the given port is captured. This is default. @@ -37,7 +37,7 @@ public: bool run(); /** * Resets the output variable which contains the traffic of - * ioport. + * ioport. */ void resetOutput(); /** diff --git a/src/plugins/signalgenerator/SignalGenerator.cc b/src/plugins/signalgenerator/SignalGenerator.cc index 9a1df0dea1ad5b4814f15a06b1c0b931ccbfec74..d3e7a40e4733f775375c8a109fa697b4b7fce0ef 100644 --- a/src/plugins/signalgenerator/SignalGenerator.cc +++ b/src/plugins/signalgenerator/SignalGenerator.cc @@ -7,59 +7,58 @@ using namespace fail; bool SignalGenerator::run() { - m_log << "Signalgenerator started. @ " << m_symbol << std::endl; + m_log << "Signalgenerator started. @ " << m_symbol << std::endl; - MemoryManager& mm = simulator.getMemoryManager(); - MemReadListener l_mem(m_symbol.getAddress()); + MemoryManager& mm = simulator.getMemoryManager(); + MemReadListener l_mem(m_symbol.getAddress()); - /** - * for EZS we currently use 8bit ADCs. - * @todo Make more versatile for future use. - */ - uint8_t value; + /** + * for EZS we currently use 8bit ADCs. + * @todo Make more versatile for future use. + */ + uint8_t value; - while (true) { - simulator.addListenerAndResume(&l_mem); - value = handleEvent(); - mm.setBytes(m_symbol.getAddress(), sizeof(value), &value); - } - return true; + while (true) { + simulator.addListenerAndResume(&l_mem); + value = handleEvent(); + mm.setBytes(m_symbol.getAddress(), sizeof(value), &value); + } + return true; } uint8_t SignalGenerator::handleEvent(void) { - double val = m_signal->calculate(); - // Scale to uint8: 0 .. 255 - val = val * 127; // -1: -127 .. +1: +127 - val = val + 127; // -127: 0 .. +127 : 254 - return (uint8_t) val; + double val = m_signal->calculate(); + // Scale to uint8: 0 .. 255 + val = val * 127; // -1: -127 .. +1: +127 + val = val + 127; // -127: 0 .. +127 : 254 + return (uint8_t) val; } Sine::Sine(const SineParams_t param) { - m_params.push_back(param); + m_params.push_back(param); } double Sine::calculate() const { - simtime_t tps = ticksPerSecond(); - if(tps == 0){ - // Simulator speed not valid. - return 0; - } + simtime_t tps = ticksPerSecond(); + if (tps == 0) { + // Simulator speed not valid. + return 0; + } - // Get simulation time in seconds. - double sec = (double)simulator.getTimerTicks() / tps; + // Get simulation time in seconds. + double sec = (double)simulator.getTimerTicks() / tps; - // Sum up all sine waves - double val = 0; - for(Sine::SineParamsList_t::const_iterator it = m_params.begin(); - it != m_params.end(); it++) - { - val += it->amplitude * sinus(it->freq_in_hz, sec); - } - return val; + // Sum up all sine waves + double val = 0; + for (Sine::SineParamsList_t::const_iterator it = m_params.begin(); + it != m_params.end(); it++) + { + val += it->amplitude * sinus(it->freq_in_hz, sec); + } + return val; } - diff --git a/src/plugins/signalgenerator/SignalGenerator.hpp b/src/plugins/signalgenerator/SignalGenerator.hpp index a5afae5453fa8b4146dbd5e885fbe3e241d15312..f3a421f7c073c111302963d9966efe7960b6aa8e 100644 --- a/src/plugins/signalgenerator/SignalGenerator.hpp +++ b/src/plugins/signalgenerator/SignalGenerator.hpp @@ -1,5 +1,5 @@ #ifndef __SIGNALGENERATOR_HPP__ - #define __SIGNALGENERATOR_HPP__ +#define __SIGNALGENERATOR_HPP__ #include <unistd.h> #include "efw/ExperimentFlow.hpp" @@ -22,26 +22,26 @@ static const float MYPI = 3.14159265358979323846f; */ class SignalForm { - mutable fail::Logger m_log; + mutable fail::Logger m_log; public: - /** - * Signalgenerator just calls the calculate method of a derived signal - * form. - */ - virtual double calculate(void) const = 0; + /** + * Signalgenerator just calls the calculate method of a derived signal + * form. + */ + virtual double calculate(void) const = 0; protected: - SignalForm() : m_log("SigForm", false) {}; - - fail::simtime_t ticksPerSecond(void) const - { - fail::simtime_t ticksPerSec = fail::simulator.getTimerTicksPerSecond(); - if(ticksPerSec == 0){ - m_log << "Warning: Timer ticks per second equals 0" << std::endl; - } - return ticksPerSec; - } + SignalForm() : m_log("SigForm", false) {}; + + fail::simtime_t ticksPerSecond(void) const + { + fail::simtime_t ticksPerSec = fail::simulator.getTimerTicksPerSecond(); + if (ticksPerSec == 0) { + m_log << "Warning: Timer ticks per second equals 0" << std::endl; + } + return ticksPerSec; + } }; @@ -55,25 +55,25 @@ protected: class SignalGenerator : public fail::ExperimentFlow { private: - const fail::ElfSymbol m_symbol; //!< the target's memory symbol the plugin is listening on to generate value - fail::Logger m_log; //!< debug output - const SignalForm *const m_signal; //!< Abstract signal form provided by the user + const fail::ElfSymbol m_symbol; //!< the target's memory symbol the plugin is listening on to generate value + fail::Logger m_log; //!< debug output + const SignalForm *const m_signal; //!< Abstract signal form provided by the user public: - /** - * Constructor - * - * @param symbol The resulting signal value is placed in the SUT symbol - * @param signal The Signal form to be generated @see SignalForm - */ - SignalGenerator( const fail::ElfSymbol & symbol, SignalForm *signal ) : m_symbol(symbol), m_log("SigGen", false), m_signal(signal){} + /** + * Constructor + * + * @param symbol The resulting signal value is placed in the SUT symbol + * @param signal The Signal form to be generated @see SignalForm + */ + SignalGenerator( const fail::ElfSymbol & symbol, SignalForm *signal ) : m_symbol(symbol), m_log("SigGen", false), m_signal(signal){} - bool run(); + bool run(); private: - /** - * Handle the memory event - */ - uint8_t handleEvent(void); + /** + * Handle the memory event + */ + uint8_t handleEvent(void); }; #include <vector> @@ -89,31 +89,31 @@ class Sine : public SignalForm { public: - //! Parameter set for a single wave - struct SineParams_t { - double freq_in_hz; //!< Freqency in Hz - double amplitude; //!< between 0..1 - SineParams_t(double f, double a) : freq_in_hz(f), amplitude(a) {}; - }; - - //! Multiple sine waves can be superimposed (e.g., summed up) - typedef std::vector<SineParams_t> SineParamsList_t; - SineParamsList_t m_params; - - Sine(const SineParams_t param); - Sine(const SineParamsList_t paramlist) : m_params(paramlist) {}; - - /** - * Calculate sinus value of frequency freq_hertz based on the given - * simulator time t (in seconds): - * \f$x = sin(2 pi f t)\f$ - **/ - double sinus(double freq_hertz, double t) const - { - return sin((2. * MYPI * freq_hertz) * t); - } - - double calculate(void) const; + //! Parameter set for a single wave + struct SineParams_t { + double freq_in_hz; //!< Freqency in Hz + double amplitude; //!< between 0..1 + SineParams_t(double f, double a) : freq_in_hz(f), amplitude(a) {}; + }; + + //! Multiple sine waves can be superimposed (e.g., summed up) + typedef std::vector<SineParams_t> SineParamsList_t; + SineParamsList_t m_params; + + Sine(const SineParams_t param); + Sine(const SineParamsList_t paramlist) : m_params(paramlist) {}; + + /** + * Calculate sinus value of frequency freq_hertz based on the given + * simulator time t (in seconds): + * \f$x = sin(2 pi f t)\f$ + **/ + double sinus(double freq_hertz, double t) const + { + return sin((2. * MYPI * freq_hertz) * t); + } + + double calculate(void) const; }; #endif // __SIGNALGENERATOR_HPP__ diff --git a/src/plugins/tracing/TracingPlugin.cc b/src/plugins/tracing/TracingPlugin.cc index 0bfdeac9d6c40c9df527a8de7654806004f4223b..3b9555d8b93abf780b99937a6c90e68c5ac65046 100644 --- a/src/plugins/tracing/TracingPlugin.cc +++ b/src/plugins/tracing/TracingPlugin.cc @@ -23,7 +23,7 @@ bool TracingPlugin::run() if (m_tracetype | TRACE_MEM) { simulator.addListener(&ev_mem); } - if(m_protoStreamFile) { + if (m_protoStreamFile) { ps = new ProtoOStream(m_protoStreamFile); } diff --git a/src/plugins/tracing/TracingPlugin.hpp b/src/plugins/tracing/TracingPlugin.hpp index 1004e949b4187ba5ffd637a6d044b4f15a9800a3..4cd37fc20850b27f73bc7f6f1f5dece5f92fe944 100644 --- a/src/plugins/tracing/TracingPlugin.hpp +++ b/src/plugins/tracing/TracingPlugin.hpp @@ -1,5 +1,5 @@ #ifndef __TRACING_PLUGIN_HPP__ - #define __TRACING_PLUGIN_HPP__ +#define __TRACING_PLUGIN_HPP__ #include <ostream> @@ -12,7 +12,7 @@ // Check if configuration dependencies are satisfied: #if !defined(CONFIG_EVENT_BREAKPOINTS) || !defined(CONFIG_EVENT_MEMREAD) || !defined(CONFIG_EVENT_MEMWRITE) - #warning The tracing plugin may (depending on its use) need breakpoints and/or read/write memory access events. Enable these in the cmake configuration tool. + #warning The tracing plugin may (depending on its use) need breakpoints and/or read/write memory access events. Enable these in the cmake configuration tool. #endif /** @@ -31,8 +31,6 @@ * FIXME: more explicit startup/shutdown; listener-based event interface needed? * -> should simulator.removeFlow make sure all remaining active events * are delivered? - * FIXME: trace a sequence of pb messages, not a giant single one (pb weren't - * made for huge messages) * FIXME: destructor -> removeFlow? */ class TracingPlugin : public fail::ExperimentFlow diff --git a/tools/import-trace/ElfImporter.cc b/tools/import-trace/ElfImporter.cc index aaa2828680b8031b9f277d62e27da81a6bcf3c73..6656fa7a7de85c7adc4fac9465c8a8fad196e2f0 100644 --- a/tools/import-trace/ElfImporter.cc +++ b/tools/import-trace/ElfImporter.cc @@ -75,16 +75,16 @@ bool ElfImporter::import_with_objdump(const std::string &binary) { LOG << "Executing: " << command << std::endl; redi::ipstream objdump( command ); std::string str; - while(std::getline(objdump, str)){ + while (std::getline(objdump, str)) { if (!evaluate_objdump_line(str)) { objdump.close(); return false; } } objdump.close(); - if(objdump.rdbuf()->exited()){ + if (objdump.rdbuf()->exited()) { int ex = objdump.rdbuf()->status(); - if(ex != 0){ + if (ex != 0) { clear_database(); LOG << "Could not disassemble!" << std::endl; return false; @@ -99,11 +99,11 @@ bool ElfImporter::evaluate_objdump_line(const std::string& line){ #ifndef __puma // Only read in real code lines: // Code lines start with a leading whitespace! (hopefully in each objdump implementation!) - if(line.size() > 0 && isspace(line[0])){ + if (line.size() > 0 && isspace(line[0])) { // a line looks like: 800156c:\tdd14 \tble.n 8001598 <_ZN2hw3hal7T32Term8PutBlockEPci+0x30> static boost::regex expr("\\s+([A-Fa-f0-9]+):((?:\\s+[A-Fa-f0-9]{2})+)\\s+(.+?)(;.*)?$"); boost::smatch res; - if(boost::regex_search(line, res, expr)){ + if (boost::regex_search(line, res, expr)) { std::string address = res[1]; std::stringstream ss; ss << std::hex << address; diff --git a/tools/import-trace/Importer.cc b/tools/import-trace/Importer.cc index a2f6c02adf21e0ac588cec109dc5e5b34ac47fda..019dc5d95622e5ed8e4e1ef2a074c0f635c8b041 100644 --- a/tools/import-trace/Importer.cc +++ b/tools/import-trace/Importer.cc @@ -88,7 +88,7 @@ bool Importer::copy_to_database(fail::ProtoIStream &ps) { curtime += ev.time_delta(); } - // instruction events just get counted + // instruction event? if (!ev.has_memaddr()) { // new instruction // sanity check for overflow diff --git a/tools/import-trace/main.cc b/tools/import-trace/main.cc index 751da65c844912f927b6bf6f2a51ff332e116e54..14832c82f5f0fec78c6801bfe5f563156ad1b502 100644 --- a/tools/import-trace/main.cc +++ b/tools/import-trace/main.cc @@ -146,7 +146,7 @@ int main(int argc, char *argv[]) { importer = new ElfImporter(); #endif } else { - LOG << "Unkown import method: " << imp << endl; + LOG << "Unknown import method: " << imp << endl; exit(-1); } LOG << "Using " << imp << endl; diff --git a/tools/prune-trace/BasicPruner.cc b/tools/prune-trace/BasicPruner.cc index 263fcd9342beb41c19b3540ed327b5fba561eca3..9c77b988e1ca938c2c40dc635a6e22cba5dd67a1 100644 --- a/tools/prune-trace/BasicPruner.cc +++ b/tools/prune-trace/BasicPruner.cc @@ -20,7 +20,7 @@ bool BasicPruner::prune_all() { " data_address, width, " << m_method_id << " " "FROM trace " "WHERE variant_id IN (" << m_variant_id_query << ") AND accesstype = 'R'"; - if (!db->query(ss.str().c_str())) return false; + if (!db->query(ss.str().c_str())) return false; ss.str(""); int rows = db->affected_rows(); diff --git a/tools/prune-trace/BasicPruner.hpp b/tools/prune-trace/BasicPruner.hpp index 435d47d0455893ef65e7bf15053b1c2433e4d422..67167ee543714cdea94734ea40603d0978ec6481 100644 --- a/tools/prune-trace/BasicPruner.hpp +++ b/tools/prune-trace/BasicPruner.hpp @@ -6,7 +6,7 @@ class BasicPruner : public Pruner { bool use_instr1; public: - BasicPruner(bool use_instr1 = false) : Pruner(), use_instr1(use_instr1) {} + BasicPruner(bool use_instr1 = false) : use_instr1(use_instr1) {} virtual std::string method_name() { return std::string("basic") + (use_instr1 ? "-left" : ""); } virtual bool prune_all(); }; diff --git a/tools/prune-trace/main.cc b/tools/prune-trace/main.cc index 0dc606c492194ef04b4de3a6d8d7bcaff3c6d658..6861e81cd5ba7fd55dff51de9ec71db9cd192332 100644 --- a/tools/prune-trace/main.cc +++ b/tools/prune-trace/main.cc @@ -17,8 +17,9 @@ int main(int argc, char *argv[]) { // Manually fill the command line option parser CommandLine &cmd = CommandLine::Inst(); - for (int i = 1; i < argc; ++i) + for (int i = 1; i < argc; ++i) { cmd.add_args(argv[i]); + } cmd.addOption("", "", Arg::None, "USAGE: import-trace [options]"); CommandLine::option_handle HELP = cmd.addOption("h", "help", Arg::None, "-h,--help \tPrint usage and exit"); @@ -44,23 +45,23 @@ int main(int argc, char *argv[]) { cmd.addOption("", "no-delete", Arg::None, "--no-delete \tAssume there are no DB entries for this variant/benchmark, don't issue a DELETE"); - if(!cmd.parse()) { + if (!cmd.parse()) { std::cerr << "Error parsing arguments." << std::endl; exit(-1); } Pruner *pruner; - if (cmd[PRUNER].count() > 0) { + if (cmd[PRUNER]) { std::string imp(cmd[PRUNER].first()->arg); - if (imp == "basic") { + if (imp == "BasicPruner" || imp == "basic") { LOG << "Using BasicPruner" << endl; pruner = new BasicPruner(); - } else if (imp == "basic-left") { + } else if (imp == "BasicPrunerLeft" || imp == "basic-left") { LOG << "Using BasicPruner (use left border, instr1)" << endl; pruner = new BasicPruner(true); } else { - LOG << "Unkown import method: " << imp << endl; + LOG << "Unknown pruning method: " << imp << endl; exit(-1); } @@ -77,7 +78,7 @@ int main(int argc, char *argv[]) { Database *db = Database::cmdline_connect(); std::vector<std::string> variants, benchmarks, variants_exclude, benchmarks_exclude; - if (cmd[VARIANT].count() > 0) { + if (cmd[VARIANT]) { for (option::Option *o = cmd[VARIANT]; o; o = o->next()) { variants.push_back(std::string(o->arg)); } @@ -85,13 +86,13 @@ int main(int argc, char *argv[]) { variants.push_back(std::string("none")); } - if (cmd[VARIANT_EXCLUDE].count() > 0) { + if (cmd[VARIANT_EXCLUDE]) { for (option::Option *o = cmd[VARIANT_EXCLUDE]; o; o = o->next()) { variants_exclude.push_back(std::string(o->arg)); } } - if (cmd[BENCHMARK].count() > 0) { + if (cmd[BENCHMARK]) { for (option::Option *o = cmd[BENCHMARK]; o; o = o->next()) { benchmarks.push_back(std::string(o->arg)); } @@ -99,7 +100,7 @@ int main(int argc, char *argv[]) { benchmarks.push_back(std::string("none")); } - if (cmd[BENCHMARK_EXCLUDE].count() > 0) { + if (cmd[BENCHMARK_EXCLUDE]) { for (option::Option *o = cmd[BENCHMARK_EXCLUDE]; o; o = o->next()) { benchmarks_exclude.push_back(std::string(o->arg)); } @@ -118,7 +119,7 @@ int main(int argc, char *argv[]) { exit(-1); } - if (cmd[NO_DELETE].count() == 0 && !pruner->clear_database()) { + if (!cmd[NO_DELETE] && !pruner->clear_database()) { LOG << "clear_database() failed" << endl; exit(-1); }