7 DML Tips and Tricks 9 Advanced Programming with DML
Model Builder User’s Guide  /  II Device Modeling  / 

8 Model Development Checklist

This chapter provides a checklist for use when developing models of devices and systems for Simics. The intention is to help developers with creating high quality models that work well in Simics, including future versions, that behave in a way that Simics users expect models to, and that can be used together with other device models easily.

8.1 Generic Checklist

This section describes important generic items that should be taken into consideration when working with Simics. This applies if one is writing device models, components or general functionality to extend Simics.

The latest API is documented in the Reference Manuals included in each Simics package.

For more information see the application note on Debugging User-Developed Simics Modules.

For more information refer to the sections about attributes in “Programming with DML” and the section about configuration attributes in “Overview” in the Model Builder User’s Guide.

For more information refer to the sections about structuring DML code in “Building Well-Behaved Models” and “Adding New Commands” in the Model Builder User’s Guide.

Look at the existing naming for things not covered by the guidelines here.

This greatly helps in pinpointing bugs, as those are guaranteed to be repeatable in a deterministic simulation.

For more information refer to the section about general usability in “Building Well-Behaved Models” in the Model Builder User’s Guide.

8.2 Device Checklist

This section describes important items that, in addition to the generic checklist, should be taken into consideration when writing device models. For more in depth understanding of the importance of these items, please refer to the Model Builder User’s Guide.

A message is most of the time a fragment or, more rarely, one or more complete sentences. If it is a fragment, the message shall start with a lowercase letter (with the obvious exception for words and abbreviations that shall start with an uppercase letter) and have no period at the end. Sentences shall start with an uppercase letter and end with a period.

In DML, a typical log statement may read: `log info, 2, 0: "increased

counter: %d“, value;`.

Do not use exclamation marks and avoid question marks. Multiple question marks in a row shall never be used.

Do not start an “info” message with the words “error”, “unimplemented” or “spec_violation”, use the appropriate log-type instead.

Do not start an “error” message with the word “error”, it is just a repetition. The word “error” might be appropriate inside the message but should in most circumstances be avoided. Same goes for the “critical”, “spec_violation”, and “unimplemented” log-types.

Do not use newlines, in particular not at the end of the message. Also do not use multiple log statements to output longer messages, include everything in one statement. It is up to the presentation layer to output a long message in a readable format.

Do not mention the name of the object or class which the message refers to, as it is implicitly given by the log statement and output in the log message prefix.

For abbreviations and other special words, write them as specified in the “Dictionary” chapter of the “Writing Documentation” manual or in the src/docs/common/simics-documentation-word-list or src/docs/internal/documentation-manual/usage.docu files. Here are some examples: IRQ, DMA, CPU, CPUs.

A message followed by a more specific message, such as: "can't open file "abc": no such file or directory" should be (as above) separated by a colon. If even more specific messages follow, these are also appended using a colon as separator.

A message which contains some extra information at the end should be written as: "read from register XYZ (value = 0x5000)"

Do not use cryptic abbreviations such as @, addr, idx, reg, len. Instead use: at, address, index, register, length

Do not use variable names (if they aren’t complete words) in log messages with log levels 1-3. If values are output, it should be possible to understand what the value represents without reading the source code. I.e. it should be possible to understand the log message without reading the source code.

Do not use assert statements on conditions that can be triggered by users, see GE-15.

Use pre-defined DML templates for different implementations. Log level is automatically handled in some of these templates. For example, reserved, unimplemented and read_only. Full list and descriptions about these templates can be found in the Model Builder DML 1.2 reference manual.

Spec-violation and unimplemented messages are typically logged on level 1. Sometimes they are first logged at log level 1 then log level 3 for spam reduction when unimplemented registers or features are always accessed. log level 3 should be avoided for spec-violation.

For more information refer to "Logging" in the *Model Builder User's Guide*.

The image interface on objects of the Simics image class provides a way to mark an image object as holding persistent data. Custom disk and storage models must call this interface on their associated image objects, if they are persistent.

Device register and device state saved in attributes are marked as persistent by using the Sim_Attr_Persistent flag on the attribute when it is registered with Simics.

For NVRAMs the `persistent-ram` class can be used.

For more information see the section about saving and restoring persistent
data in "Configuration and Checkpointing" in the *Simics User's Guide*

Unimplemented registers, or registers with limited functionality, should use the standard Simics log mechanism with the Sim_Log_Unimplemented type to log any accesses.

8.2.1 Ethernet Devices

For more information see the section on Ethernet transceiver in “Modeling Ethernet Devices” in the Model Builder User’s Guide.

8.2.2 Interrupt Devices

8.2.3 PCI Devices

8.2.4 Serial Devices

8.3 Processor Model Checklist

This section describes important items that, in addition to the generic checklist, should be taken into consideration when writing processor models. For more information about processor models, see the Processor Model Integration Guide.

8.4 Component Checklist

This section describes important items that, in addition to the generic checklist, should be taken into consideration when writing components. For more in depth understanding of the importance of these items, please refer to the Model Builder User’s Guide.

8.5 System Checklist

This section describes important items that, in addition to the generic checklist, should be taken into consideration when assembling a larger system. See also the “Target Script Checklist”.

8.6 Target Script Checklist

This section describes important items that, in addition to previous checklists, should be taken into consideration when writing the target scripts for a virtual platforms.

The old component prefix support should not be used anymore as it will be removed in the future.

The following variables are automatically supported if the targets/common/add-eth-link.include script is used to create a virtual Ethernet network. Scripts creating their own Ethernet network without using add-eth-link.include should support some subset of these variables.

- <span class="term">$create\_network</span> Boolean variable specifying if
  a simulated Ethernet network link should be created together with the
  system.
- <span class="term">$eth\_link</span>    
    The name of an existing Ethernet link object. 
- <span class="term">$service\_node</span>    
    The name of an existing service node object. 
- <span class="term">$service\_node\_ip\_address</span>    
    The IP address of the `$service_node` object on the `$eth_link` link. 
- <span class="term">$dhcp\_pool\_ip</span> The first address in the pool of
  IP addresses used for DHCP in the $service\_node.
- <span class="term">$dhcp\_pool\_size</span> The size of the IP address
  pool used for DHCP in the `$service_node`. Set to 0 to disable DHCP.
- <span class="term">$network\_goal\_latency</span>    
    The requested network latency of the `$eth_link` link. 
- <span class="term">$eth\_link\_gid</span> The global identifier for the
  `$eth_link` link, used in distributed simulation.
</div>

If the OS awareness framework in Simics supports the operating system that is configured on the machine, then a parameter file should be created that matches the operating system and that is loaded in the software setup script (i.e. the <architecture>-<software>-setup.include file), typically using: $system.software.load-parameters <architecture>-<software>.params

For more details refer to the section “OS Awareness Details” in the Analyzer User’s Guide.

When referencing component and objects created by another machine script, the $system variable (ST-08) will provide a reference to the top-level component created by that script.

7 DML Tips and Tricks 9 Advanced Programming with DML