diff --git a/configs/common/MemConfig.py b/configs/common/MemConfig.py index cf0fb1632..0191554a7 100644 --- a/configs/common/MemConfig.py +++ b/configs/common/MemConfig.py @@ -151,6 +151,15 @@ def config_mem(options, system): them. """ + if options.tlm_memory: + system.external_memory = m5.objects.ExternalSlave( + port_type="tlm", + port_data=options.tlm_memory, + port=system.membus.master, + addr_ranges=system.mem_ranges) + system.kernel_addr_check = False + return + if options.external_memory_system: system.external_memory = m5.objects.ExternalSlave( port_type=options.external_memory_system, diff --git a/configs/common/Options.py b/configs/common/Options.py index 35d453d24..1922f78a6 100644 --- a/configs/common/Options.py +++ b/configs/common/Options.py @@ -106,6 +106,8 @@ def addCommonOptions(parser): # Cache Options parser.add_option("--external-memory-system", type="string", help="use external ports of this port_type for caches") + parser.add_option("--tlm-memory", type="string", + help="use external port for SystemC TLM cosimulation") parser.add_option("--caches", action="store_true") parser.add_option("--l2cache", action="store_true") parser.add_option("--fastmem", action="store_true") diff --git a/util/tlm/Makefile b/util/tlm/Makefile new file mode 100644 index 000000000..1fda3b113 --- /dev/null +++ b/util/tlm/Makefile @@ -0,0 +1,76 @@ +# Copyright (c) 2015, University of Kaiserslautern +# 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. +# +# Authors: Matthias Jung + + +ARCH = ARM +VARIANT = opt +#VARIANT = debug + +SYSTEMC_INC = /opt/systemc/include +SYSTEMC_LIB = /opt/systemc/lib-linux64 + +CXXFLAGS = -I../../build/$(ARCH) -L../../build/$(ARCH) +CXXFLAGS += -I../systemc/ +CXXFLAGS += -I$(SYSTEMC_INC) -L$(SYSTEMC_LIB) +CXXFLAGS += -std=c++0x +CXXFLAGS += -g +CXXFLAGS += -DSC_INCLUDE_DYNAMIC_PROCESSES -DDEBUG -DTRACING_ON + +LIBS = -lgem5_$(VARIANT) -lsystemc + +ALL = gem5.$(VARIANT).sc + +all: $(ALL) + +.cc.o: + $(CXX) $(CXXFLAGS) -c -o $@ $< + +sc_gem5_control.o: ../systemc/sc_gem5_control.cc \ + ../systemc/sc_gem5_control.hh +sc_logger.o: ../systemc/sc_logger.cc ../systemc/sc_logger.hh +sc_module.o: ../systemc/sc_module.cc ../systemc/sc_module.hh +sc_mm.o: sc_mm.cc sc_mm.hh +sc_ext.o: sc_ext.cc sc_ext.hh +sc_port.o: sc_port.cc sc_port.hh +sc_target.o: sc_target.cc sc_target.hh +stats.o: ../systemc/stats.cc ../systemc/stats.hh +main.o: main.cc ../systemc/sc_logger.hh ../systemc/sc_module.hh \ + ../systemc/stats.hh + +gem5.$(VARIANT).sc: main.o ../systemc/stats.o ../systemc/sc_gem5_control.o \ + ../systemc/sc_logger.o ../systemc/sc_module.o sc_mm.o sc_ext.o sc_port.o sc_target.o + $(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS) + +clean: + $(RM) $(ALL) + $(RM) *.o + $(RM) -r m5out diff --git a/util/tlm/README b/util/tlm/README new file mode 100644 index 000000000..f3cb4fbfd --- /dev/null +++ b/util/tlm/README @@ -0,0 +1,96 @@ +This directory contains a demo of a coupling between gem5 and SystemC-TLM. +It is based on the gem5-systemc implementation in utils/systemc. +First a simple example with gem5's traffic generator is shown, later an full +system example. + +Files: + + main.cc -- demonstration top level + sc_port.{cc,hh} -- transactor that translates beween gem5 and tlm + sc_mm.{cc,hh} -- implementation of a tlm memory manager + sc_ext.{cc,hh} -- a TLM extension that carries the gem5 packet + sc_target.{cc,hh} -- an example TLM LT/AT memory module + tlm.py -- simple gem5 configuration + tgen.cfg -- configuration file for the traceplayer + +Other Files will be used from utils/systemc example: + + sc_logger.{cc,hh}, + sc_module.{cc,hh}, + sc_gem5_control.{cc,hh}, + stats.{cc,hh} + + +I. Traffic Generator Setup +========================== + +To build: + +First build a normal gem5 (cxx-config not needed, Python needed). +Second build gem5 as a library with cxx-config support and (optionally) +without python. + +> cd ../.. +> scons build/ARM/gem5.opt +> scons --with-cxx-config --without-python build/ARM/libgem5_opt.so +> cd util/systemc_tlm + +Set a proper LD_LIBRARY_PATH e.g. for bash: +> export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/path/to/gem5/build/ARM/" + +Then edit the Makefile to set the paths for SystemC and run make + +> make + +Make a config file for the C++-configured gem5 using normal gem5 + +> ../../build/ARM/gem5.opt ./tlm.py + +The message "fatal: Can't find port handler type 'tlm'" is okay. +The configuration will be stored in the m5out/ directory + +The binary 'gem5.opt.sc', that has been created in the make step, +can now be used to load in the generated config file from the previous +normal gem5 run. + +Try: + +> ./gem5.opt.sc m5out/config.ini -e 1000000 + +It should run a simulation for 1us. + +To see more information what happens inside the TLM module use the -D flag: + +> ./gem5.opt.sc m5out/config.ini -e 1000000 -D + +To see more information about the port coupling use: + +> ./gem5.opt.sc m5out/config.ini -e 1000000 -d ExternalPort + +II. Full System Setup +===================== + +Build gem5 as discribed in Section I. Then, make a config file for the +C++-configured gem5 using normal gem5 + +> ../../build/ARM/gem5.opt ../../configs/example/fs.py --tlm-memory=memory \ + --cpu-type=timing --num-cpu=1 --mem-type=SimpleMemory --mem-size=512MB \ + --mem-channels=1 --caches --l2cache --machine-type=VExpress_EMM \ + --dtb-filename=vexpress.aarch32.ll_20131205.0-gem5.1cpu.dtb \ + --kernel=vmlinux.aarch32.ll_20131205.0-gem5 \ + --disk-image=linux-aarch32-ael.img + +The message "fatal: Can't find port handler type 'tlm'" is okay. +The configuration will be stored in the m5out/ directory + +The binary 'gem5.opt.sc' can now be used to load in the generated config +file from the previous normal gem5 run. + +Try: + +> ./gem5.opt.sc m5out/config.ini -o 2147483648 + +The parameter -o specifies the begining of the memory region (0x80000000). +The system should boot now. + +For conveniance a run_gem5.sh file holds all those commands diff --git a/util/tlm/main.cc b/util/tlm/main.cc new file mode 100644 index 000000000..517e4ad43 --- /dev/null +++ b/util/tlm/main.cc @@ -0,0 +1,323 @@ +/* + * Copyright (c) 2015, University of Kaiserslautern + * 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. + * + * Authors: Matthias Jung + */ + +/** + * @file + * + * Example top level file for SystemC-TLM integration with C++-only + * instantiation. + * + */ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "base/statistics.hh" +#include "base/str.hh" +#include "base/trace.hh" +#include "cpu/base.hh" +#include "sc_logger.hh" +#include "sc_module.hh" +#include "sc_port.hh" +#include "sc_target.hh" +#include "sim/cxx_config_ini.hh" +#include "sim/cxx_manager.hh" +#include "sim/init_signals.hh" +#include "sim/serialize.hh" +#include "sim/simulate.hh" +#include "sim/stat_control.hh" +#include "sim/system.hh" +#include "stats.hh" + +void usage(const std::string &prog_name) +{ + std::cerr << "Usage: " << prog_name << ( + " [