/Turna

A CFG reconstructor for RISC-V architecture

Primary LanguagePythonMIT LicenseMIT

Turna

Turna is a control flow graph (CFG) reconstructor for RISC-V architecture.

It performs hybrid CFG reconstruction. It analyzes RISC-V assembly code with the help of trace information generated by gem5 architecture simulator. After analysis, Turna detects basic blocks of the program and reconstructs its CFG. The CFG is printed to command line as text and drawn to pdf file as a directed graph.

Turna is open-source and licensed under the MIT license.

License Note

The license of Turna only applies to the source code of Turna. For the licenses of the benchmark programs found in the test data section please check their source codes.

Test Data

In the test data section, you can find the dump files (assembly code files), trace files (generated by gem5), and test results of the benchmarks.

The following benchmark programs in the test data section are from Malardalen benchmarks. Source codes of the programs can be accessed through Malardalen Benchmarks web page (http://www.mrtc.mdh.se/projects/wcet/benchmarks.html).

Malardalen benchmarks used in the test of Turna: adpcm, bs, bsort100, cnt, compress, cover, crc, duff, expint, fac, fdct, fft1, fibcall, insertsort, janne_complex, jfdctint, lcdnum, lms, matmult, ns, nsichneu, qsort-exam, qurt, select, statemate

How to Use Turna

Prerequisites

Turna is a python application. You need python 3x to run Turna.

Turna works on RISC-V executables. Make sure you have installed the RISC-V Compiler Toolchain.

Turna uses the trace files generated by gem5 architecture simulator. Make sure you installed gem5 architecture simulator with RISC-V support.

Usage

1- Build program as a static executable.

riscv64-linux-gnu-gcc -o program_name program_name.c -lm -static

2- Dissassemble the program executable.

riscv64-linux-gnu-objdump -d program_name > program_name.dump

3- Copy program_name.dump file to Turna's current working directory.

4- Generate trace information.

Run program using gem5 with trace output information. After the following call, trace information will be stored in gem5/m5out directory.

./build/RISCV/gem5.opt --debug-flags=Exec,-ExecSymbol --debug-file=trace.out configs/example/se.py -c ./program_name

5- Copy the trace.out from gem5/m5out directory to the Turna's current working directory.

Optionally if you want to store the statistics regarding the running of the program, copy the stats.txt file from gem5/m5out directory to the Turna's current working directory.

6- Rename trace.out file.

mv trace.out program_name.trc

7- Run Turna.

./python3 turna.py

8- Examine outputs.

cfg.pdf file is the graphical CFG output.

Textual CFG output will be seen in the command line.