The functionality of Simics can be extended by user-written modules. Modules can, among other things, contain new device models, new commands, new components, and new extension to Simics. All of need to be compiled or built to be used in simulation and the environment in which that is done is referred to as the build environment.
This chapter will describe how to configure, maintain and use that environment to build new modules for use with Simics. A project is used to contain and build user-written modules, this permits many users to share a system-wide (read-only) Simics installation. The Model Builder product contains the necessary files and tools to develop your own modules.
To develop new modules for Simics on the Windows platform, you need the MinGW compiler suite and make tools installed. See the Simics Installation Guide for more information.
If you do not wish to use the GCC compiler, you can use the Microsoft Visual C++ compiler to compile C++ modules (n.b., the Visual C++ compiler is not supported for C modules). See section 3.5.2 for more information.
The commands below should be invoked in a cmd.exe
command prompt window, and the path names should be entered with backslashes as directory separators, and bin\make.bat
(a shortcut to the MinGW installation) should be used when instructed to run make
.
On Linux, the project makefiles require GNU make (a.k.a. gmake
), which is available from ftp.gnu.org/gnu/make
. In the following text, when you are asked to run gmake
, this refers to running the GNU make binary, which may be called gmake
or make
, depending on your installation.
Simics supplies own version of libraries, for example libstdc++.so.6, under [simics-base]/[host]/sys/lib/ directory. They are actually for machines with older libraries or none at all. If user has a more recent copy than one supplied with Simics, error like "GLIBCXX... not found" would happen when try to run a binary or load a module compiled from this newer library from within Simics. If this happens the suggested workaround is to remove the older library supplied with Simics.
A project is a directory which contains all necessary user-specific files needed to run Simics and develop modules. Setting up a project is done with the File → Create Project… or using the project-setup
script, like this:
Windows
> [simics]\bin\project-setup.bat my-simics-project
Linux
$ [simics]/bin/project-setup my-simics-project
where [simics] is the location of the Simics-installation.
The script will create a project directory with the following contents:
bin/ | compiler.mk | config.mk |
---|---|---|
doc/ | GNUmakefile | modules/ |
.project-properties | simics | simics-eclipse |
simics-gui | targets/ | host/ |
simics
simics-gui
bin/
doc/
GNUmakefile
modules
directory. The file is called GNUmakefile
to signify that it requires GNU make. Do not edit this file: you should probably create the config-user.mk
or module-user.mk
files to change the compilation parameters compiler.mk
CC
variable. A matching C++ compiler will be searched for by config.mk
in the same path as CC
if CXX
is not set. config.mk
[simics]/config/project/config.mk
that contains default definition of make flags for different compilers, such as CFLAGS
. Do not edit this file: you should probably create the config-user.mk
or module-user.mk
files to change the compilation parameters config-user.mk
D
or USER_BUILD_ID
. For information about USER_BUILD_ID
, see chapter 38. module-user.mk
config.mk
and [simics]/config/project/module.mk
. modules/
GNUmakefile
builds all modules in the modules
directory. targets/
linux64
or win64
. The host directory is not present until a module has been compiled. When a module is compiled, any intermediate build files, like dependency and object files (.d
.o
) are generated in the <host>/obj/modules/<module>/
directory. The resulting module file is placed in <host>/lib/
, and the Python command file for the module is placed in the <host>/lib/python/
directory..project-properties
When the project has been created, you may type make
(or possibly gmake
) to build all the modules, or ./simics-gui
to start Simics.
In order to rebuild all modules, type make clean
, followed by make
. In order to rebuild just a single module, type make clean-modulename
, for example:
project$ make # builds all modules
project$ make clean-mymodule # removes all objectfiles for "mymodule"
project$ make mymodule # builds "mymodule"
The clean
targets only remove object files and similar intermediates for the module not needed when running. To remove the actual module files as well, use make clobber
or make clobber-modulename
.
The project setup script is used to create and upgrade projects. It can also create module skeletons to start with when writing new devices.
See Simics Reference Manual for the full documentation of the script.
To upgrade your project to a new Simics version, run the script again with no arguments. It is also possible to update the project from the Simics GUI. The project will then be updated to match the version of the running Simics.
Windows
> cd my-simics-project
> [path-to-new-simics]\bin\project-setup.bat
Linux
$ cd my-simics-project
$ [path-to-new-simics]/bin/project-setup
It will do the necessary updates in the project, but leave the user-modifiable files intact. (Modified files that need to be overwritten are saved in backup versions with the extension ".~N~
" (Linux) or "~N~.backup
" (Windows), where N is the first free number.)
If you upgrade to Simics with a different major version number, the compiled modules will not be compatible and you need to do a make clobber
to force a rebuild when you issue make
.
The modules
subdirectory contains source code for modules, one module per directory entry.
To add a DML module to a project, specify the --device option.
Windows
> cd my-simics-project
project> bin\project-setup.bat --device mydevice
Linux
$ cd my-simics-project
project$ ./bin/project-setup --device mydevice
This will create some skeleton code under the modules/
directory.
After adding a module, you can build it using the top-level makefile:
project$ gmake
To emphasize that the makefile require GNU Make, it is called GNUmakefile
. The sub-makefiles in the module directories are named Makefile
.
When running make, command lines will not be printed by default. To see the commands, pass V=1
to make:
project$ gmake V=1
An example module written in C can be added in the same way as DML modules, but using the --c-device option. Similarly, a C++ module can be created using --c++-device.
Windows
> cd my-simics-project
project> bin\project-setup.bat --c-device my_c_device
project> bin\project-setup.bat --c++-device my_cc_device
Linux
$ cd my-simics-project
project$ ./bin/project-setup --c-device my_c_device
project$ ./bin/project-setup --c++-device my_cc_device
The top-level makefile will automatically attempt to build all modules under the modules/
directory. If you have located a module somewhere else, you must create a symlink or junction to the module from there:
Windows
> junction my-project\modules\mydevice c:\mydevice
Linux
$ ln -s $HOME/mydevice ./my-project/modules/
It is recommended to actually copy or move the module into the modules directory of your project.
You may need to adapt the Makefile for the project-based build environment. Use a generated skeleton Makefile as a template for your rewrite.
A module to which the source is distributed with Simics, can be copied into the project by using --copy-module.
Windows
> cd my-simics-project
project> bin\project-setup.bat --copy-module sample-memhier
Linux
$ cd my-simics-project
project$ ./bin/project-setup --copy-module sample-memhier
The project makefiles are configured to compile optimized modules by default. To turn off optimization and turn on debugging, set the following line in config-user.mk
:
D=1
Set D=0
or remove the line entirely to use optimization again.
The D flag can also be passed on the command line:
project$ gmake D=1
The project setup script has a default set of make-variables (CC
, CFLAGS
, BLD_CFLAGS
, etc.), which are set up in the compiler.mk
and [simics]/config/project/config.mk
files. The compiler.mk
may be edited by the user. Additional options can be specified in config-user.mk
.
The makefile with the actual build rules for all modules is [simics]/config/project/module.mk
. This file is included at the end of each module Makefile
. To override rules or variables in this module.mk
, add a module-user.mk
file in the project, similar to the config-user.mk
file described above.
The default set of variables assumes that you will be using GCC. If you want to use a different compiler, you need to change the CC
variable in compiler.mk
. The flags for the compiler are set up in [simics]/config/project/config.mk
.
On Windows host, the Microsoft Visual C++ compiler is supported for compiling C++ modules. To use it, you have to run all project setup and build commands from a Visual Studio command prompt, which can be started from the Start menu.
The exact names of the menu items varies with the version of Microsoft Visual C++ you have installed. For Visual C++ 2008 Express Edition, it defaults to Start menu → Microsoft Visual C++ 2008 Express Edition → Visual Studio Tools → Visual Studio 2008 Command Prompt.
Once you have started the Visual Studio command prompt, set both of the CC
and CXX
environment variables to cl
. This should allow you to run GNU make
as usual.
If your compiler is not supported by config.mk
, please report to Simics Support.
In order to make the build environment in Simics recognize a module as a build target, there must be a makefile called Makefile
in its source directory.
A module makefile must set up a number of make variables and then include the generic makefile for Simics modules. The following is an example of a module's Makefile
, for a module written in C:
MODULE_CLASSES=FAS366U
SRC_FILES=esp.c
MODULE_CFLAGS=-DFAS
SIMICS_API = 5
include $(MODULE_MAKEFILE)
A complete list of the available variables to set is provided below:
The current project as well as any installed Simics packages will be searched for the module source code. Note that only the first matching source code directory found will be used, allowing the project to override the version of an installed package.
See also section Restrictions in Defining New Interface Types in Model Builder User's Guide for restrictions and usage of Python bindings.
The names checkpoint_update.py and init.py are reserved for future use, and not allowed in the list of files.
The user can also add new rules to the makefile, after the inclusion of the generic $(MODULE_MAKEFILE)
. This is usually not needed.
The following variables can be used in the module's makefile (i.e., [project]/modules/<module>/Makefile
). They should be considered read-only, i.e., they should not be changed.
SIMICS_PROJECT
is the full path to the project directory.TARGET_DIR
is the directory in which compiled modules are placed ([project]/[host-type]/lib
).SRC_BASE
is the full path to the project modules directory ([project]/modules
). HOST_TYPE
is the Simics host architecture, i.e., what OS/hardware Simics has been compiled for, such as win64
or linux64
. LATEST_API_VERSION
is the API version you get if 'latest' is specified in the module's makefile. TARGET
is the name of the module being compiled. Note that SRC_BASE
and TARGET
gives you access to the module source code directory, so that you can refer to source code files with absolute paths when necessary, as in $(SRC_BASE)/$(TARGET)/foo.c
. There are a number of C/C++ pre-processor defines that are set depending on the host that the module is being compiled on. They are usually not needed, but useful in some special cases. Examples: HOST_64_BIT
, HOST_BIG_ENDIAN
and HOST_LITTLE_ENDIAN
. There are also defines specifying the host architecture and host operating system. All these defines are set in the Simics include file global.h
.
It is possible to set a user defined version string in loadable modules. This is done by setting the MODULE_USER_VERSION
variable in the module's Makefile
. The version string will be printed by the list-modules
and list-failed-modules
commands.
When Simics starts, it will read the supported architecture and word size for all modules on the Simics module path. Only modules that match the architecture and word size of the running Simics binary will be available for loading into Simics. While scanning the modules, Simics will also check what classes the module will register when it is loaded. This way modules can be loaded automatically when the classes that they define are used in a configuration.
If a module cannot be loaded into the current Simics, it will be added to the list of failed modules. This list can be displayed with list-failed-modules
, that takes an optional parameter -v
for more verbose output.
simics> list-failed-modules
Current module version number: 1050 Lowest version number supported: 1050
MODULE DUP VERSION USR_VERS LINK
---------------------------------------------
8042 1040
image 1040
spitfire-mmu.so X
The columns after the module name (or file name in the case of a link error) indicate different kinds of errors. An X
in the DUP
column means that this module could not be loaded because this module has the same name as another module found in the Simics module search path, and that this one was overridden. An X
in the VERSION
column means that the module was created for another, non-compatible, version of Simics. LINK
means that this module cannot be loaded into Simics because of unresolved symbols. Use list-failed-modules -v
to see the actual error message from the run-time module loader.
Modules compiled for other architectures or word lengths will not be listed
If a module requires linking against libraries that are not expected to be found on end user's systems, then these libraries can be included in a Simics package. They should be placed in host/sys/lib
. For testing and development, this can also be in a Simics project, by adding the project as a package path.
On Windows, Simics will add this directory to the DLL search path for every package.
On Linux, one must also make sure that the Simics module is linked in such a way that the library is found when the module is loaded at run time, by adding this to the module Makefile
:
MODULE_LDFLAGS += -Wl,-rpath,'$$ORIGIN/../sys/lib'
On all platforms, Simics will detect and warn if the same library exists in multiple packages. To avoid such problems, one can for example include a version number in the library filename.
Note that the Simics module resolution logic does not apply to these extra libraries.
If an extra library is dependent on the Simics API, it must link with the Simics library in order to make symbol lookup work correctly. This can be done by building the library as part of the Simics module that uses it, and adding these linker flags:
-L$(SIMICS_BASE)/$(HOST_TYPE)/bin -lsimics-common
The Emacs (http://www.gnu.org/software/emacs/) extensible editor is the first choice for many programmers, and Simics Model Builder includes a customized mode for editing DML source files. The DML mode is an extension of the standard Emacs editing mode for the C programming language.
Simics includes the Emacs file dml-mode.el
to add support for the DML major mode. This file can be found in the [simics]/scripts
directory. To use it, add the following lines to your Emacs configuration file (usually [home]/.emacs
or [home]/.xemacs/init.el
):
(setq load-path (cons "[simics]/scripts" load-path))
(autoload 'dml-mode "dml-mode" "DML mode" t)
(add-to-list 'auto-mode-alist '("\\.dml\\'" . dml-mode))
(you need to replace the text [simics]
in the above with the full path to your Simics Base installation which includes Model Builder). After restarting Emacs, the DML mode should be automatically enabled when you open a file whose name ends in ".dml
".
For more information, run the command M-x describe-mode
in an Emacs buffer using the DML mode, or read the "Editing Programs" section of the Emacs documentation.