Previous - Up - Next

2.1   A Simple Device

The following DML program is an example of a "smallest device that does anything interesting":

  // A very simple device
  dml 1.0;
  device simple_device;
  import "io-memory.dml";

  bank b {
      parameter function = 0;
      register r0 size 4 @0x0000 {
          method read() -> (result) {
              log "info": "Hello, bus!";
              result = 42;
This models a memory-mapped device with a single 32-bit (4-byte) register at offset 0, which upon a read access will return the value 42 as the result of the operation, and as a side effect print a log message with the text "Hello, bus!" to the Simics console.

To compile this program, you first need to set up a Simics workspace, using the workspace-setup script (see the Simics Programming Guide for details). In order to create DML skeleton files for your new device, you need to pass the flag --device=modulename to the script, as follows:

  $ [simics]/bin/workspace-setup --dml=simple_device [home]/workspace
(If your workspace directory already exists and you just want to add a new module, you also need to specify the --force flag.) On Microsoft Windows, using Cygwin, you should use the script called [simics]/bin/workspace-setup.bat instead; also, make sure you have the default packages of the Cygwin "devel" category installed, as well as a working MinGW installation, before you try to set up the workspace; see Section 1.2 for details.

You will now have a directory [home]/workspace containing (among other things) a GNU Makefile and a subdirectory named modules, which is where your modules are located. Open the generated skeleton file [home]/workspace/modules/simple_device/simple_device.dml in your favorite text editor, and modify its contents to look like the above program. (The main DML source file name should be the module name plus the extension .dml. Although they are usually the same, the module name does not have to be the same as the device name; a module could potentially contain more than one device.)

Now, go to the [home]/workspace directory and run GNU make (possibly named gmake, depending on your system). By default, this builds all your modules.

  $ cd [home]/workspace
  $ ./simics targets/vacuum/vacuum.simics

When Simics has started, you should be prompted with "simics>". Congratulations, you now have a loadable Simics module! You can exit Simics by typing the quit command, or q for short.

  simics> q

Previous - Up - Next