Models Im System Csi M
Models Im System Csi M
Models Im System Csi M
6 - SystemC simulation
Chapter contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . UM-158 UM-159 UM-159 UM-160 UM-161 UM-162 UM-162 UM-162 UM-165 UM-165 UM-166 UM-166 UM-167 UM-167 UM-168 UM-162 UM-170 UM-171 UM-171 UM-174 UM-174 UM-176 UM-174 UM-178 UM-179 UM-180 UM-180 UM-181 UM-182 UM-182 UM-182 Supported platforms and compiler versions . . . Building gcc with custom configuration options . HP Limitations for SystemC . . . . . . Usage flow for SystemC-only designs . . . . .
Compiling SystemC files . . . . . . . . . Creating a design library . . . . . . . . Modifying SystemC source code . . . . . . Invoking the SystemC compiler . . . . . . Compiling optimized and/or debug code . . . . Specifying an alternate g++ installation . . . . Maintaining portability between OSCI and ModelSim Restrictions on compiling with HP aCC . . . . Switching platforms and compilation . . . . . Using sccom vs. raw C++ compiler . . . . . Linking the compiled source . sccom -link . . . . Simulating SystemC designs . Running simulation . . Debugging the design . . . Viewable SystemC objects Source-level debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
SystemC object and type display in ModelSim Support for aggregates . . . . . Viewing FIFOs . . . . . . .
Differences between ModelSim and the OSCI simulator . Fixed point types . . . . . . . . . . OSCI 2.1 features supported . . . . . . . Troubleshooting SystemC errors . Errors during loading . . . Errors during loading . . . . . . . . . . . . . . . . . . . . .
Introduction
This chapter describes how to compile and simulate SystemC designs with ModelSim. ModelSim implements the SystemC language based on the Open SystemC Initiative (OSCI) SystemC 2.0.1 reference simulator. It is recommended that you obtain the OSCI functional specification, or the latest version of the SystemC Language Reference Manual as a reference manual. Visit http://www.systemc.org for details. In addition to the functionality described in the OSCI specification, ModelSim for SystemC includes the following features: Single common Graphic Interface for SystemC and HDL languages. Extensive support for mixing SystemC, VHDL, and Verilog in the same design (SDF annotation for HDL only). For detailed information on mixing SystemC with HDL see Chapter 7 - Mixed-language simulation.
Important: ModelSim SystemC has been tested with the gcc versions available from ftp.model.com/pub/gcc. Customized versions of gcc may cause problems. We strongly encourage you to download and use the gcc versions available on our FTP site (login as anonymous).
If you don't have a GNU binutils2.14 assembler and linker handy, you can use the as and ld programs distributed with ModelSim. They are located inside the built-in gcc in directory <install_dir>/modeltech/gcc-3.2-<mtiplatform>/lib/gcc-lib/<gnuplatform>/3.2. By default ModelSim also uses the following options when configuring built-in gcc. --disable-nls --enable-languages=c,c++ These are not mandatory, but they do reduce the size of the gcc installation.
This creates a library named work. By default, compilation results are stored in the work library. The work library is actually a subdirectory named work. This subdirectory contains a special file named _info. Do not create libraries using UNIX commands always use the vlib command (CR-361). See "Design libraries" (UM-55) for additional information on working with libraries.
Replacing the sc_start() function with the run command and options
ModelSim uses the run command and its options in place of the sc_start() function. If sc_main() has multiple sc_start() calls mixed in with the testbench code, then use an SC_THREAD() with wait statements to emulate the same behavior. An example of this is shown below.
SC_NS)
statement is:
Example 2
This next example is slightly more complex, illustrating the use of sc_main() and signal assignments, and how you would get the same behavior using ModelSim. Original OSCI code #2 (partial)
int sc_main(int, char**) { sc_signal<bool> reset; counter_top top("top"); sc_clock CLK("CLK", 10, SC_NS, 0.5, 0.0, SC_NS, false); top.reset(reset); reset.write(1); sc_start(5, SC_NS); reset.write(0); sc_start(100, SC_NS); reset.write(1); sc_start(5, SC_NS); reset.write(0); sc_start(100, SC_NS); } void new_top::sc_main_body() { reset.write(1); wait(5, SC_NS); reset.write(0); wait(100, SC_NS); reset.write(1); wait(5, SC_NS); reset.write(0); wait(100, SC_NS); } SC_MODULE_EXPORT(new_top); SC_CTOR(new_top) : reset("reset"), top("top") CLK("CLK", 10, SC_NS, 0.5, 0.0, SC_NS, false) { top.reset(reset); SC_THREAD(sc_main_body); } };
Example 3
One last example illustrates the correct way to modify a design using an SCV transaction database. ModelSim requires that the transaction database be created before calling the constructors on the design subelements. The example is as follows: Original OSCI code # 3 (partial)
int sc_main(int argc, char* argv[]) { scv_startup(); scv_tr_text_init(); scv_tr_db db("my_db"); scv_tr_db db::set_default_db(&db); sc_clock clk ("clk",20,0.5,0,true); sc_signal<bool> rw; test t("t"); t.clk(clk);; t.rw(rw); sc_start(100); } }; SC_MODULE_EXPORT(new_top); }
Take care to preserve the order of functions called in sc_main() of the original code. Sub-elements cannot be placed in the initializer list, since the constructor body must be executed prior to their construction. Therefore, the sub-elements must be made pointer types, created with "new" in the SC_CTOR() module.
You can type verror 3197 at the vsim command prompt and get details about what caused the error and how to fix it.
You can specialize the module by setting T = int, thereby removing the template, as follows:
class top : public sc_module { sc_signal<int> sig 1; . . . };
Or, alternatively, you could write a wrapper to be used over the template module:
class modelsim_top : public sc_module { top<int> actual_top; . . . }; SC_MODULE_EXPORT(modelsim_top);
sccom -link
The sccom -link command collects the object files created in the different design libraries, and uses them to build a shared library (.so) in the current work library or the library specified by the -work option. If you have changed your SystemC source code and recompiled it using sccom, then you must relink the design by running sccom -link before invoking vsim. Otherwise, your changes to the code are not recognized by the simulator. Remember that any dependent .a or .o files should be listed on the sccom -link command line before the .a or .o on which it depends. For more details on dependencies and other syntax issues, see sccom (CR-259).
When the GUI comes up, you can expand the hierarchy of the design to view the SystemC modules. SystemC objects are denoted by green icons (see "Design object icons and their meaning" (GR-12) for more information).
To simulate from a command shell, without the GUI, invoke vsim with the -c option:
vsim -c <top_level_module>
Running simulation
Run the simulation using the run (CR-257) command or select one of the Simulate > Run options from the menu bar.
The rules vary if you have mixed-language designs. Please see "Simulator resolution limit" for details on mixed designs.
a simulator resolution of 10ps would be fine. No rounding off of the ones digits in the time units would occur. However, a specification of:
sc_wait(9, SC_PS);
would require you to set the resolution limit to 1ps in order to avoid inaccuracies caused by rounding.
Usage of callbacks
The start_of_simulation() callback is used to initialize any state-based code. The corresponding cleanup code should be placed in the end_of_simulation() callback. These callbacks are only called during simulation by vsim and thus, are safe. If you have a design in which some state-based code must be placed in the constructor, destructor, or the elaboration callbacks, you can use the mti_IsVoptMode() function to determine if the elaboration is being run by vopt (CR-376). You can use this function to prevent vopt from executing any state-based code.
Types (<type>) of the objects which may be viewed for debugging are the following: Types bool, sc_bit sc_logic sc_bv<width> sc_lv<width> sc_int<width> sc_uint<width> sc_fix sc_fix_fast sc_fixed<W,I,Q,O,N> sc_fixed_fast<W,I,Q,O,N> sc_ufix sc_ufix_fast sc_ufixed sc_ufixed_fast sc_signed sc_unsigned char, unsigned char int, unsigned int short, unsigned short long, unsigned long sc_bigint<width> sc_biguint<width> sc_ufixed<W,I,Q,O,N> short, unsigned short long long, unsigned long long float double enum pointer class struct union bit_fields
Source-level debug
In order to debug your SystemC source code, you must compile the design for debug using the -g C++ compiler option. You can add this option directly to the sccom (CR-259) command line on a per run basis, with a command such as:
sccom mytop -g
Or, if you plan to use it every time you run the compiler, you can specify it in the modelsim.ini file with the SccomCppOptions variable. See "[sccom] SystemC compiler control variables" (UM-501) for more information. The source code debugger, C Debug (UM-399), is automatically invoked when the design is compiled for debug in this way. You can set breakpoints in a Source window, and single-step through your SystemC/C++ source code. .
The gdb debugger has a known bug that makes it impossible to set breakpoints reliably in constructors or destructors. Try to avoid setting breakpoints in constructors of SystemC objects; it may crash the debugger.
You can view and expand SystemC objects in the Objects pane and processes in the Active Processes pane.
is equivalent to:
sc_signal <sc_lv<3>> a;
for debug purposes. ModelSim shows one signal - object "a" - in both cases. The following aggregate
sc_signal <float> fbus [6];
Viewing FIFOs
In ModelSim, the values contained in an sc_fifo appear in a definite order. The top-most or left-most value is always the next to be read from the FIFO. Elements of the FIFO that are not in use are not displayed. Example of a signal where the FIFO has five elements:
# examine f_char # {} VSIM 4> # run 10 VSIM 6> # examine f_char # A VSIM 8> # run 10 VSIM 10> # examine f_char # {A B} VSIM 12> # run 10 VSIM 14> # examine f_char # {A B C} VSIM 16> # run 10 VSIM 18> # examine f_char # {A B C D} VSIM 20> # run 10 VSIM 22> # examine f_char # {A B C D E} VSIM 24> # run 10 VSIM 26> # examine f_char # {B C D E} VSIM 28> # run 10 VSIM 30> # examine f_char # {C D E} VSIM 32> # run 10 VSIM 34> # examine f_char # {D E}
add a define statement to the C++ source code before the inclusion of the systemc.h, as shown below:
#define SC_INCLUDE_FX #include "systemc.h"
Phase callback
The following functions are supported for phase callbacks: before_end_of_elaboration() start_of_simulation() end_of_simulation() For more information regarding the use of these functions, see "Initialization and cleanup of SystemC state-based code" (UM-173).
The number of arguments (argc) is now 4. argv[0] is "vsim" argv[1] is "-a" argv[2] is "-b -c" argv[3] is "-d"
Missing definition
If the undefined symbol is a C function in your code or a library you are linking with, be sure that you declared it as an extern "C" function:
extern "C" void myFunc();
This should appear in any header files include in your C++ sources compiled by sccom. It tells the compiler to expect a regular C function; otherwise the compiler decorates the name for C++ and then the symbol can't be found. Also, be sure that you actually linked with an object file that fully defines the symbol. You can use the "nm" utility on Unix platforms to test your SystemC object files and any libraries you link with your SystemC sources. For example, assume you ran the following commands:
sccom test.cpp sccom -link libSupport.a
If there is an unresolved symbol and it is not defined in your sources, it should be correctly defined in any linked libraries:
nm libSupport.a | grep "mySymbol"
and
sccom liblocal.a -link
The first command ensures that your SystemC object files are seen by the linker before the library "liblocal.a" and the second command ensures that "liblocal.a" is seen first. Some linkers can look for undefined symbols in libraries that follow the undefined reference while others can look both ways. For more information on command syntax and dependencies, see sccom (CR-259).
A common cause of multiple symbol definitions involves incorrect definition of symbols in header files. If you have an out-of-line function (one that isnt preceded by the "inline" keyword) or a variable defined (i.e. not just referenced or prototyped, but truly defined) in a .h file, you can't include that .h file in more than one .cpp file. Text in .h files is included into .cpp files by the C++ preprocessor. By the time the compiler sees the text, it's just as if you had typed the entire text from the .h file into the .cpp file. So a .h file included into two .cpp files results in lots of duplicate text being processed by the C++ compiler when it starts up. Include guards are a common technique to avoid duplicate text problems. See "Errors during loading" (UM-182) for more information on include guards. If an .h file has an out-of-line function defined, and that .h file is included into two .c files, then the out-of-line function symbol will be defined in the two corresponding. o files. This leads to a multiple symbol definition error during sccom -link. To solve this problem, add the "inline" keyword to give the function "internal linkage". This makes the function internal to the .o file, and prevents the function's symbol from colliding with a symbol in another .o file. For free functions or variables, you could modify the function definition by adding the "static" keyword instead of "inline", although "inline" is better for efficiency. Sometimes compilers do not honor the "inline" keyword. In such cases, you should move your function(s) from a header file into an out-of-line implementation in a .cpp file.