From 75789063107b8c125a0b840f248fa17c9fa8b343 Mon Sep 17 00:00:00 2001 From: Eyck-Alexander Jentzsch Date: Mon, 31 Jan 2022 21:38:18 +0100 Subject: [PATCH] adds coverage plugin --- CMakeLists.txt | 2 + incl/iss/plugin/cov.h | 84 +++++++++++++++++++++++++++++++++++++++ src/plugin/cov.cpp | 32 +++++++++++++++ src/sysc/core_complex.cpp | 6 +++ 4 files changed, 124 insertions(+) create mode 100644 incl/iss/plugin/cov.h create mode 100644 src/plugin/cov.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ac3bf7f..8c94083 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,8 @@ set(LIB_SOURCES src/vm/fp_functions.cpp src/plugin/instruction_count.cpp src/plugin/cycle_estimate.cpp + src/plugin/cov.cpp + ${TGC_SOURCES} ${TGC_VM_SOURCES} ) diff --git a/incl/iss/plugin/cov.h b/incl/iss/plugin/cov.h new file mode 100644 index 0000000..1f0c9bd --- /dev/null +++ b/incl/iss/plugin/cov.h @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (C) 2017, 2018, MINRES Technologies GmbH + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Contributors: + * eyck@minres.com - initial API and implementation + ******************************************************************************/ + +#ifndef _ISS_PLUGIN_COV_H_ +#define _ISS_PLUGIN_COV_H_ + +#include +#include "iss/instrumentation_if.h" +#include +#include +#include + + +namespace iss { +namespace plugin { + +class cov : public iss::vm_plugin { + struct instr_delay { + std::string instr_name; + size_t size; + size_t not_taken_delay; + size_t taken_delay; + }; + +public: + + cov(const cov &) = delete; + + cov(const cov &&) = delete; + + cov(); + + virtual ~cov(); + + cov &operator=(const cov &) = delete; + + cov &operator=(const cov &&) = delete; + + bool registration(const char *const version, vm_if &arch) override; + + sync_type get_sync() override { return POST_SYNC; }; + + void callback(instr_info_t, exec_info const&) override; + +private: + iss::instrumentation_if *instr_if {nullptr}; + int counter {0}; + std::ofstream output; +}; +} +} + +#endif /* _ISS_PLUGIN_COV_H_ */ diff --git a/src/plugin/cov.cpp b/src/plugin/cov.cpp new file mode 100644 index 0000000..46b1d32 --- /dev/null +++ b/src/plugin/cov.cpp @@ -0,0 +1,32 @@ +#include +#include +#include + + +iss::plugin::cov::cov() { + std::cout << "Entering Constructor"<get_instrumentation_if(); + return true; +} +void iss::plugin::cov::callback(instr_info_t iinfo, const exec_info&) { +// if((instr_if->get_next_pc() - instr_if->get_pc() != 4) ||( instr_if->get_next_pc() - instr_if->get_pc() != 2)){ +// std::cout << "jump from " << std::hex << instr_if->get_pc() << " to " << instr_if->get_next_pc()<< " after " << std::dec << counter <<" linear instructions" <get_pc() << std::endl; +} diff --git a/src/sysc/core_complex.cpp b/src/sysc/core_complex.cpp index ed21bb8..c89f61f 100644 --- a/src/sysc/core_complex.cpp +++ b/src/sysc/core_complex.cpp @@ -69,6 +69,8 @@ using tgc_d_xrb_nn_plat_type = iss::arch::riscv_hart_mu_p #include #include +#include + // clang-format on #define STR(X) #X @@ -423,6 +425,10 @@ void core_complex::before_end_of_elaboration() { auto *plugin = new iss::plugin::cycle_estimate(filename); cpu->vm->register_plugin(*plugin); plugin_list.push_back(plugin); + } else if (plugin_name == "cov") { + auto *plugin = new iss::plugin::cov(); + cpu->vm->register_plugin(*plugin); + plugin_list.push_back(plugin); } else { std::array a{{filename.c_str()}}; iss::plugin::loader l(plugin_name, {{"initPlugin"}});