KONRAD Frederic
Builds for 2 pipelines failed

introduce SimpleMemory

This introduces SimpleMemory.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
*~
# CMakeFiles
CMakeCache.txt
CMakeFiles
CTestTestfile.cmake
Makefile
Testing
cmake_install.cmake
install_manifest.txt
# Objects
test/SimpleMemory_testbench
... ...
# Copyright (C) 2014, GreenSocs ltd.
#
# CMakeLists.txt
#
# KONRAD Frederic <fred.konrad@greensocs.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses>.
#
# Linking GreenSocs code, statically or dynamically with other modules
# is making a combined work based on GreenSocs code. Thus, the terms and
# conditions of the GNU General Public License cover the whole
# combination.
#
# In addition, as a special exception, the copyright holders, GreenSocs
# Ltd, give you permission to combine GreenSocs code with free software
# programs or libraries that are released under the GNU LGPL, under the
# OSCI license, under the OCP TLM Kit Research License Agreement or
# under the OVP evaluation license.You may copy and distribute such a
# system following the terms of the GNU GPL and the licenses of the
# other code concerned.
#
# Note that people who make modified versions of GreenSocs code are not
# obligated to grant this special exception for their modified versions;
# it is their choice whether to do so. The GNU General Public License
# gives permission to release a modified version without this exception;
# this exception also makes it possible to release a modified version
# which carries forward this exception.
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(SIMPLECPU)
LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
FIND_PACKAGE(SystemC)
if(SystemC_FOUND)
INCLUDE_DIRECTORIES(${SystemC_INCLUDE_DIRS})
LINK_DIRECTORIES(${SystemC_LIBRARY_DIRS})
else()
MESSAGE(FATAL_ERROR "SystemC library not found.")
endif()
FIND_PACKAGE(TLM)
if(TLM_FOUND)
INCLUDE_DIRECTORIES(${TLM_INCLUDE_DIRS})
else()
MESSAGE( FATAL_ERROR "TLM library not found." )
endif()
FIND_PACKAGE(GREENLIB)
if(GREENLIB_FOUND)
INCLUDE_DIRECTORIES(${GREENLIB_INCLUDE_DIRS})
LINK_DIRECTORIES(${GREENLIB_LIBRARY_DIRS})
else()
MESSAGE(FATAL_ERROR "GreenLib not found.")
endif()
set (INCLUDE_DIRS ${INCLUDE_DIRS} include)
INCLUDE_DIRECTORIES(${INCLUDE_DIRS})
set(CMAKE_CXX_FLAGS "-Wall -Werror -DSC_INCLUDE_DYNAMIC_PROCESSES")
# Installation paths
INSTALL(DIRECTORY include/SimpleMemory
DESTINATION include
)
# Make tests
ENABLE_TESTING()
ADD_SUBDIRECTORY(test)
... ...
# - Find GreenLib
# This module finds if GreenLib is installed and determines where the
# include files and libraries are.
#
#=============================================================================
# Copyright 2014 GreenSocs
#
# KONRAD Frederic <fred.konrad@greensocs.com>
#
#=============================================================================
MESSAGE(STATUS "Searching for GreenLib")
# The HINTS option should only be used for values computed from the system.
SET(_GREENLIB_HINTS
${GREENLIB_PREFIX}/include
${GREENLIB_PREFIX}/lib
${GREENLIB_PREFIX}/lib-linux
${GREENLIB_PREFIX}/lib-linux64
${GREENLIB_PREFIX}/lib-macos
$ENV{GREENLIB_PREFIX}/include
$ENV{GREENLIB_PREFIX}/lib
$ENV{GREENLIB_PREFIX}/lib-linux
$ENV{GREENLIB_PREFIX}/lib-linux64
$ENV{GREENLIB_PREFIX}/lib-macos
${CMAKE_INSTALL_PREFIX}/include
${CMAKE_INSTALL_PREFIX}/lib
${CMAKE_INSTALL_PREFIX}/lib-linux
${CMAKE_INSTALL_PREFIX}/lib-linux64
${CMAKE_INSTALL_PREFIX}/lib-macos
)
# Hard-coded guesses should still go in PATHS. This ensures that the user
# environment can always override hard guesses.
SET(_GREENLIB_PATHS
/usr/include
/usr/lib
/usr/lib-linux
/usr/lib-linux64
/usr/lib-macos
/usr/local/lib
/usr/local/lib-linux
/usr/local/lib-linux64
/usr/local/lib-macos
)
FIND_PATH(GREENLIB_INCLUDE_DIRS
NAMES greencontrol/config.h
HINTS ${_GREENLIB_HINTS}
PATHS ${_GREENLIB_PATHS}
)
FIND_PATH(GREENLIB_LIBRARY_DIRS
NAMES libgreenreg.a
HINTS ${_GREENLIB_HINTS}
PATHS ${_GREENLIB_PATHS}
)
if("${GREENLIB_INCLUDE_DIRS}" MATCHES "GREENLIB_INCLUDE_DIRS-NOTFOUND")
SET(GREENLIB_FOUND FALSE)
else("${GREENLIB_INCLUDE_DIRS}" MATCHES "GREENLIB_INCLUDE_DIRS-NOTFOUND")
SET(GREENLIB_FOUND TRUE)
MESSAGE(STATUS "GreenLib include directory = ${GREENLIB_INCLUDE_DIRS}")
MESSAGE(STATUS "GreenLib library directory = ${GREENLIB_LIBRARY_DIRS}")
SET(GREENLIB_LIBRARIES ${GREENLIB_LIBRARY_DIRS})
endif("${GREENLIB_INCLUDE_DIRS}" MATCHES "GREENLIB_INCLUDE_DIRS-NOTFOUND")
... ...
# - Find SystemC
# This module finds if SystemC is installed and determines where the
# include files and libraries are. This code sets the following
# variables: (from kernel/sc_ver.h)
#
# SystemC_VERSION_MAJOR = The major version of the package found.
# SystemC_VERSION_MINOR = The minor version of the package found.
# SystemC_VERSION_REV = The patch version of the package found.
# SystemC_VERSION = This is set to: $major.$minor.$rev
#
# The minimum required version of SystemC can be specified using the
# standard CMake syntax, e.g. FIND_PACKAGE(SystemC 2.2)
#
# For these components the following variables are set:
#
# SystemC_INCLUDE_DIRS - Full paths to all include dirs.
# SystemC_LIBRARIES - Full paths to all libraries.
#
# Example Usages:
# FIND_PACKAGE(SystemC)
# FIND_PACKAGE(SystemC 2.3)
#
#=============================================================================
# Copyright 2012 GreenSocs
#
#=============================================================================
message(STATUS "Searching for SystemC")
# The HINTS option should only be used for values computed from the system.
SET(_SYSTEMC_HINTS
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\SystemC\\2.2;SystemcHome]/include"
${SYSTEMC_PREFIX}/include
${SYSTEMC_PREFIX}/lib
${SYSTEMC_PREFIX}/lib-linux
${SYSTEMC_PREFIX}/lib-linux64
${SYSTEMC_PREFIX}/lib-macos
$ENV{SYSTEMC_PREFIX}/include
$ENV{SYSTEMC_PREFIX}/lib
$ENV{SYSTEMC_PREFIX}/lib-linux
$ENV{SYSTEMC_PREFIX}/lib-linux64
$ENV{SYSTEMC_PREFIX}/lib-macos
${CMAKE_INSTALL_PREFIX}/include
${CMAKE_INSTALL_PREFIX}/lib
${CMAKE_INSTALL_PREFIX}/lib-linux
${CMAKE_INSTALL_PREFIX}/lib-linux64
${CMAKE_INSTALL_PREFIX}/lib-macos
)
# Hard-coded guesses should still go in PATHS. This ensures that the user
# environment can always override hard guesses.
SET(_SYSTEMC_PATHS
/usr/include/systemc
/usr/lib
/usr/lib-linux
/usr/lib-linux64
/usr/lib-macos
/usr/local/lib
/usr/local/lib-linux
/usr/local/lib-linux64
/usr/local/lib-macos
)
FIND_FILE(_SYSTEMC_VERSION_FILE
NAMES sc_ver.h
HINTS ${_SYSTEMC_HINTS}
PATHS ${_SYSTEMC_PATHS}
PATH_SUFFIXES sysc/kernel
)
EXEC_PROGRAM("cat ${_SYSTEMC_VERSION_FILE} |grep '#define SC_API_VERSION_STRING' | cut -d '_' -f 7 "
OUTPUT_VARIABLE SystemC_MAJOR)
EXEC_PROGRAM("cat ${_SYSTEMC_VERSION_FILE} |grep '#define SC_API_VERSION_STRING' | cut -d '_' -f 8 "
OUTPUT_VARIABLE SystemC_MINOR)
EXEC_PROGRAM("cat ${_SYSTEMC_VERSION_FILE} |grep '#define SC_API_VERSION_STRING' | cut -d '_' -f 9 "
OUTPUT_VARIABLE SystemC_REV)
set(SystemC_VERSION ${SystemC_MAJOR}.${SystemC_MINOR}.${SystemC_REV})
if("${SystemC_MAJOR}" MATCHES "2")
set(SystemC_FOUND TRUE)
endif("${SystemC_MAJOR}" MATCHES "2")
message(STATUS "SystemC version = ${SystemC_VERSION}")
FIND_PATH(SystemC_INCLUDE_DIRS
NAMES systemc.h
HINTS ${_SYSTEMC_HINTS}
PATHS ${_SYSTEMC_PATHS}
)
FIND_PATH(SystemC_LIBRARY_DIRS
NAMES libsystemc.a
HINTS ${_SYSTEMC_HINTS}
PATHS ${_SYSTEMC_PATHS}
)
set(SystemC_LIBRARIES ${SystemC_LIBRARY_DIRS}/libsystemc.a)
message(STATUS "SystemC library = ${SystemC_LIBRARIES}")
... ...
# - Find TLM
# This module finds if TLM is installed and determines where the
# include files and libraries are. This code sets the following
# variables: (from kernel/sc_ver.h)
#
# TLM_VERSION_STRING = Version of the package found, eg. "2.2.0"
# TLM_VERSION_MAJOR = The major version of the package found.
# TLM_VERSION_MINOR = The minor version of the package found.
# TLM_VERSION_PATCH = The patch version of the package found.
# TLM_VERSION_DATE = The date of release (from TLM_VERSION)
# TLM_VERSION = This is set to: $major.$minor.$patch
#
# The minimum required version of TLM can be specified using the
# standard CMake syntax, e.g. FIND_PACKAGE(TLM 2.2)
#
# For these components the following variables are set:
#
# TLM_FOUND - TRUE if all components are found.
# TLM_INCLUDE_DIRS - Full paths to all include dirs.
# TLM_LIBRARIES - Full paths to all libraries.
# TLM_<component>_FOUND - TRUE if <component> is found.
#
# Example Usages:
# FIND_PACKAGE(TLM)
# FIND_PACKAGE(TLM 2.3)
#
#=============================================================================
# Copyright 2012 GreenSocs
#
#=============================================================================
message(STATUS "Searching for TLM")
# The HINTS option should only be used for values computed from the system.
SET(_TLM_HINTS
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\TLM\\2.2;TLMHome]/include"
$ENV{TLM_HOME}
${SYSTEMC_PREFIX}/include
${SYSTEMC_PREFIX}/lib
${SYSTEMC_PREFIX}/lib-linux
${SYSTEMC_PREFIX}/lib-linux64
${SYSTEMC_PREFIX}/lib-macos
$ENV{SYSTEMC_PREFIX}/include
$ENV{SYSTEMC_PREFIX}/lib
$ENV{SYSTEMC_PREFIX}/lib-linux
$ENV{SYSTEMC_PREFIX}/lib-linux64
$ENV{SYSTEMC_PREFIX}/lib-macos
${CMAKE_INSTALL_PREFIX}/include
${CMAKE_INSTALL_PREFIX}/lib
${CMAKE_INSTALL_PREFIX}/lib-linux
${CMAKE_INSTALL_PREFIX}/lib-linux64
${CMAKE_INSTALL_PREFIX}/lib-macos
)
# Hard-coded guesses should still go in PATHS. This ensures that the user
# environment can always override hard guesses.
SET(_TLM_PATHS
/usr/include/TLM
/usr/include/systemc
/usr/lib
/usr/lib-linux
/usr/lib-linux64
/usr/lib-macos
/usr/local/lib
/usr/local/lib-linux
/usr/local/lib-linux64
/usr/local/lib-macos
)
FIND_PATH(TLM_INCLUDE_DIRS
NAMES tlm.h
HINTS ${_TLM_HINTS}
PATHS ${_TLM_PATHS}
PATH_SUFFIXES include/tlm
)
EXEC_PROGRAM("ls ${TLM_INCLUDE_DIRS}/tlm.h"
RETURN_VALUE ret)
if("${ret}" MATCHES "0")
set(TLM_FOUND TRUE)
endif("${ret}" MATCHES "0")
message(STATUS "TLM library = ${TLM_INCLUDE_DIRS}/tlm.h")
... ...
This is a SimpleMemory with DMI using GreenLib.
How to include this model in a project:
* Copy the misc/FindSIMPLEMEMORY.cmake in your project repository.
* Add the following lines into your CMakeLists.txt:
FIND_PACKAGE(SIMPLEMEMORY)
if(SIMPLEMEMORY_FOUND)
INCLUDE_DIRECTORIES(${SIMPLEMEMORY_INCLUDE_DIRS})
else()
MESSAGE(FATAL_ERROR "SimpleMemory not found.")
endif()
You're now able to use SimpleMemory headers.
... ...
/*
* simpleMemory.h
*
* Copyright (C) 2014, GreenSocs Ltd.
*
* Developped by Konrad Frederic <fred.konrad@greensocs.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses>.
*
* Linking GreenSocs code, statically or dynamically with other modules
* is making a combined work based on GreenSocs code. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders, GreenSocs
* Ltd, give you permission to combine GreenSocs code with free software
* programs or libraries that are released under the GNU LGPL, under the
* OSCI license, under the OCP TLM Kit Research License Agreement or
* under the OVP evaluation license.You may copy and distribute such a
* system following the terms of the GNU GPL and the licenses of the
* other code concerned.
*
* Note that people who make modified versions of GreenSocs code are not
* obligated to grant this special exception for their modified versions;
* it is their choice whether to do so. The GNU General Public License
* gives permission to release a modified version without this exception;
* this exception also makes it possible to release a modified version
* which carries forward this exception.
*
*/
/*
* This is a simple Memory for SystemC using GreenLib.
*/
#ifndef MEMORY_H
#define MEMORY_H
//#define MEMORY_DEBUG
#ifdef MEMORY_DEBUG
#define DCOUT(var) std::cout << "Memory: " << sc_core::sc_time_stamp() << " :" \
<< var << std::endl;
#else
#define DCOUT(var)
#endif
#include <systemc.h>
#include <sys/syscall.h>
#include <sys/mman.h>
#include "gsgpsocket/transport/GSGPSlaveSocket.h"
class Memory:
public sc_module,
public gs::tlm_b_if<gs::gp::GenericSlaveAccessHandle>
{
public:
Memory(sc_core::sc_module_name name):
sc_module(name),
target_port("target_port"),
m_size("size", 262144),
m_ro("read_only", false)
{
this->target_port.bind_b_if(*this);
this->target_port.register_get_direct_mem_ptr(this,
&Memory::get_direct_mem_ptr);
}
~Memory()
{
if (m_ptr) {
munmap(m_ptr, m_size * 1024);
}
DCOUT("destructor.");
}
void end_of_elaboration()
{
m_ptr = mmap(0, m_size * 1024, PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
if (!m_ptr)
{
std::cout << "Memory: error: can't create memory." << std::endl;
sc_core::sc_stop();
return;
}
}
void setReadOnly(bool read_only)
{
m_ro = read_only;
}
void b_transact(gs::gp::GenericSlaveAccessHandle ah)
{
gs::gp::GenericSlavePort<32>::accessHandle t = _getSlaveAccessHandle(ah);
uint32_t offset = t->getMAddr() - target_port.base_addr;
gs::GSDataType data;
size_t size;
data.set(t->getMData());
size = data.getSize();
if (offset + size > m_size * 1024)
{
std::cout << "error out of bound memory access.." << std::endl;
sc_core::sc_stop();
return;
}
if (t->getMCmd() == gs::Generic_MCMD_RD)
{
memcpy(data.getDataPtr(), &(((uint8_t *)m_ptr)[offset]), size);
}
else if (t->getMCmd() == gs::Generic_MCMD_WR)
{
/*
* FIXME: We should give a bad status for that...
*/
if (!m_ro)
{
memcpy(&(((uint8_t *)m_ptr)[offset]), data.getDataPtr(), size);
}
}
else
{
std::cout << "invalid command.." << std::endl;
sc_core::sc_stop();
return;
}
}
/*
* XXX: What about Read Only??
*/
bool get_direct_mem_ptr(unsigned int from,
tlm::tlm_generic_payload& trans,
tlm::tlm_dmi& dmi_data)
{
dmi_data.set_dmi_ptr((unsigned char *)m_ptr);
dmi_data.set_start_address(0);
dmi_data.set_end_address(m_size * 1024 - 1);
trans.set_dmi_allowed(true);
return true;
}
/*
* Socket for memory access.
*/
gs::gp::GenericSlavePort<32> target_port;
private:
gs::gs_param<uint32_t> m_size;
gs::gs_param<bool> m_ro; /*!< read only? */
void *m_ptr;
};
#endif /* MEMORY_H */
... ...
# This module looks for SimpleMemory module and determines where the header
# files and libraries are.
#=============================================================================
# Copyright 2014 GreenSocs
#
# KONRAD Frederic <fred.konrad@greensocs.com>
#
#=============================================================================
MESSAGE(STATUS "Searching for SimpleMemory model.")
# The HINTS option should only be used for values computed from the system.
SET(_SIMPLEMEMORY_HINTS
${SIMPLEMEMORY_PREFIX}/include
$ENV{SIMPLEMEMORY_PREFIX}/include
${CMAKE_INSTALL_PREFIX}/include
)
# Hard-coded guesses should still go in PATHS. This ensures that the user
# environment can always override hard guesses.
SET(_SIMPLEMEMORY_PATHS
/usr/include
)
FIND_PATH(SIMPLEMEMORY_INCLUDE_DIRS
NAMES SimpleMemory/simpleMemory.h
HINTS ${_SIMPLEMEMORY_HINTS}
PATHS ${_SIMPLEMEMORY_PATHS}
)
if("${SIMPLEMEMORY_INCLUDE_DIRS}" MATCHES "SIMPLEMEMORY_INCLUDE_DIRS-NOTFOUND")
SET(SIMPLEMEMORY_FOUND FALSE)
else("${SIMPLEMEMORY_INCLUDE_DIRS}" MATCHES "SIMPLEMEMORY_INCLUDE_DIRS-NOTFOUND")
SET(SIMPLEMEMORY_FOUND TRUE)
MESSAGE(STATUS "SimpleMemory include directory = ${SIMPLEMEMORY_INCLUDE_DIRS}")
endif("${SIMPLEMEMORY_INCLUDE_DIRS}" MATCHES "SIMPLEMEMORY_INCLUDE_DIRS-NOTFOUND")
... ...
#
# CMakeLists.txt
#
# Copyright (C) 2014, GreenSocs ltd.
#
# Developped by Konrad Frederic <fred.konrad@greensocs.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses>.
#
# Linking GreenSocs code, statically or dynamically with other modules
# is making a combined work based on GreenSocs code. Thus, the terms and
# conditions of the GNU General Public License cover the whole
# combination.
#
# In addition, as a special exception, the copyright holders, GreenSocs
# Ltd, give you permission to combine GreenSocs code with free software
# programs or libraries that are released under the GNU LGPL, under the
# OSCI license, under the OCP TLM Kit Research License Agreement or
# under the OVP evaluation license.You may copy and distribute such a
# system following the terms of the GNU GPL and the licenses of the
# other code concerned.
#
# Note that people who make modified versions of GreenSocs code are not
# obligated to grant this special exception for their modified versions;
# it is their choice whether to do so. The GNU General Public License
# gives permission to release a modified version without this exception;
# this exception also makes it possible to release a modified version
# which carries forward this exception.
ADD_EXECUTABLE(SimpleMemory_testbench
SimpleMemory_testbench.cpp
)
TARGET_LINK_LIBRARIES(SimpleMemory_testbench systemc greenreg)
ADD_TEST(NAME SimpleMemory COMMAND ./SimpleMemory_testbench)
... ...
#include "SimpleMemory/simpleMemory.h"
int sc_main(int argc, char *argv[])
{
/*
* TODO: To be completed.
*/
std::cout << "We have nothing to test yet. Just check it compiles correctly."
<< std::endl;
return 0;
}
... ...