Install TRAP (TRansaction level Automatic Processor generator)

安裝完 SystemC-2.2.0 and TLM 後,
在來安裝 TRAP 來玩玩看,這裡有詳細的安裝步驟說明。

一些準備工作
請先確認系統是否已安裝以下的 Library or Tools
libELF, SystemC, TLM, Boots, Python, networkx

Checkout TRAP Source Code

% svn checkout http://trap-gen.googlecode.com/svn/trunk/ trap-gen

Compile and Install TRAP

% cd trap-gen
% ./waf configure --with-systemc=/opt/systemc/systemc-2.2.0 --prefix=/opt/systemc/trap
% ./waf
% ./waf install

Compile LEON3 Processor

% cd processors/LEON3
% python LEON3Arch.py
% cd processors
% ./waf configure --with-systemc=/opt/systemc/systemc-2.2.0 --with-tlm=/opt/systemc/TLM-2009-07-15 --with-trap=/opt/systemc/trap
% ./waf

TRAP 產生的 CPU Simulator 可以有四種類型:funcLT, funcAT, accLT, accAT

    funcLT : Instruction-Accurate with loosely-timed TLM interfaces
    funcAT : Instruction-Accurate with accurate-timed TLM interfaces
    accLT : Cycle-Accurate with loosely-timed TLM interfaces
    accAT : Cycle-Accurate with accurate-timed TLM interfaces

但這次編譯,只會生出 funcLT and funcAT。

Install cross compiler
有已經做好的 sparc-elf, arm-elf compiler,替我省下不少時間!
若要自己做 cross compiler,要記得 compiler 安裝完後要將 BSP 檔案 copy 到 compiler 安裝目錄,以 sparc-elf 為例:

% cp $(TRAP_SRC_DIR)/BSP_and_Compiler/sparc/* $(SPARC_ELF_INSTALL_DIR)/sparc-elf/lib
% sparc-elf-gcc -c exceptionTrap.S -o exceptionTrap.o
% sparc-elf-gcc -c libcStub.c -o libcStub.o
% sparc-elf-gcc -c osemu-crt0.S -o osemu-crt0.o

run Hello-World
hello.c

#include "stdio.h"
int main(void) {
    printf("Hello Worldn");
}

Compile hello.c

% sparc-elf-gcc -specs=osemu.specs -g -O2 hello.c -o hello

Simulate with funcAT

% $(TRAP-SRC-DIR)/processors/LEON3/processor/_build_/funcAT/funcAT -a hello

             SystemC 2.2.0 --- Apr 17 2012 12:05:44
        Copyright (c) 1996-2006 by all Contributors
                    ALL RIGHTS RESERVED

	
	      _/        _/_/_/_/    _/_/    _/      _/   _/_/_/
	     _/        _/        _/    _/  _/_/    _/         _/
	    _/        _/_/_/    _/    _/  _/  _/  _/     _/_/
	   _/        _/        _/    _/  _/    _/_/         _/
	  _/_/_/_/  _/_/_/_/    _/_/    _/      _/   _/_/_/
	


	Luca Fossati  -    email: fossati.l@gmail.com




Loading the application and initializing the tools ...
... tools initialized

Hello World

Program exited with value 10

SystemC: simulation stopped by user.

Elapsed 0 sec. (real time)
Executed 1924 instructions
Execution Speed: inf MIPS
Simulated time: 2330 us
Elapsed 2330 cycles

Simulate with funcCT

% $(TRAP-SRC-DIR)/processors/LEON3/processor/_build_/funcAT/funcAT -a hello

             SystemC 2.2.0 --- Apr 17 2012 12:05:44
        Copyright (c) 1996-2006 by all Contributors
                    ALL RIGHTS RESERVED

	
	      _/        _/_/_/_/    _/_/    _/      _/   _/_/_/
	     _/        _/        _/    _/  _/_/    _/         _/
	    _/        _/_/_/    _/    _/  _/  _/  _/     _/_/
	   _/        _/        _/    _/  _/    _/_/         _/
	  _/_/_/_/  _/_/_/_/    _/_/    _/      _/   _/_/_/
	


	Luca Fossati  -    email: fossati.l@gmail.com




Loading the application and initializing the tools ...
... tools initialized

Hello World

Program exited with value 10

SystemC: simulation stopped by user.

Elapsed 0.01 sec. (real time)
Executed 1924 instructions
Execution Speed: 0.1924 MIPS
Simulated time: 2330 us
Elapsed 2330 cycles
%

run Testsuite

% cd $(TRAP-SRC-DIR)/testsuite
% setenv CC_CROSS sparc-elf-gcc
% setenv CFLAGS "-DBIG_TARGET -specs=osemu.specs"
% setenv SIMULATOR "../processors/LEON3/processor/_build_/funcAT/funcAT"
% make test

run Benchmark

% cd $(TRAP-SRC-DIR)/benchmarks
% setenv CC_CROSS sparc-elf-gcc
% setenv CFLAGS "-DBIG_TARGET -specs=osemu.specs"
% setenv SIMULATOR "../processors/LEON3/processor/_build_/funcAT/funcAT"
% make run

安裝 SystemC and TLM on OpenSuSE 12.1 (64-bit Linux)

Setup Environment Variable
edit .cshrc by adding:

setenv SYSTEMC_HOME /opt/systemc/systemc-2.2.0
setenv TLM_HOME     /opt/systemc/TLM-2009-07-15

Install SystemC-2.2.0

照例,要先修改 ./systemc-2.2.0/src/sysc/utils/sc_utils_ids.cpp
加上下列兩行

#include "string.h"
#include "cstdlib"

開始編譯

% cd systemc-2.2.0
% mkdir objdir
% cd objdir
% ../configure --prefix=/opt/systemc/systemc-2.2.0
% make

嗯,跟之前安裝時不一樣,這次跑出來以下錯誤訊息:

../../../../systemc-2.2.0/src/sysc/datatypes/bit/sc_bit_proxies.h:716:16: error: reference ‘m_obj’ cannot be declared ‘mutable’ [-fpermissive]
../../../../systemc-2.2.0/src/sysc/datatypes/bit/sc_bit_proxies.h:1193:18: error: reference ‘m_left’ cannot be declared ‘mutable’ [-fpermissive]
../../../../systemc-2.2.0/src/sysc/datatypes/bit/sc_bit_proxies.h:1194:18: error: reference ‘m_right’ cannot be declared ‘mutable’ [-fpermissive]
../../../../systemc-2.2.0/src/sysc/datatypes/bit/sc_bit_proxies.h:1196:18: error: reference ‘m_refs’ cannot be declared ‘mutable’ [-fpermissive]

Google 一下之後,找到解法,將 src/sysc/datatypes/bit/sc_bit_proxies.h 中的 mutable 都去除
重新 compile

% ../configure --prefix=/opt/systemc/systemc-2.2.0
% make
% sudo make install

最後可以做一下測試

$ make check

Install TLM-2.0.1
Step.1 將 TLM-2.0.1 解到 /opt/systemc/systemc-2.2.0

sudo tar -C /opt/systemc -zxvf ~/work/SystemC/SystemC.org/download/TLM-2.0.1.tgz

Spte.2 修改 systemc-2.2.0/include/sysc/packages/boost/bind/placeholders.hpp

LINE.28 #if defined(__BORLANDC__) || defined(__GNUC__)

Spte.3 修改 systemc-2.2.0/include/sysc/datatypes/bit/sc_lv_base.h

LINE.309     return sc_logic_value_t( (m_data[wi] >> bi & SC_DIGIT_ONE) |
LINE.310                              (m_ctrl[wi] >> bi << 1 & SC_DIGIT_TWO) );

Run TLM-2.0.1 examples
Step.1 修改 TLM-2009-07-15/examples/tlm/build-unix/Makefile.config

LINE.2  DEFAULT_TARGET_ARCH  = linux64

Step.2 執行 examples

% cd TLM-2009-07-15/examples/tlm/build-unix
% make
% make run

Run TLM-2.0.1 unit_test
Step.1 修改 TLM-2009-07-15/unit_test/tlm/build-unix/Makefile.config

LINE.2  DEFAULT_TARGET_ARCH  = linux64

Step.2 執行 examples

$ cd TLM-2009-07-15/unit_test/tlm/build-unix
$ make
$ make run