The Simics command line interface (CLI) has some built-in scripting capabilities. When that is not enough, Python can be used instead.
We will use a trace object as our example object:
simics> new-tracer Trace object 'trace0' created. Enable tracing with 'trace0.start'. simics>
There are two commands available for this object: <trace>.start and <trace>.stop.
For example, to start tracing:
simics> trace0.start Tracing enabled. Writing text output to standard output. simics>
It is also possible to access an object's attributes using CLI. The state of an object is contained in its attributes.
simics> trace0->classname base-trace-mem-hier simics> trace0->enabled 1 simics>
Variables in CLI are prefixed with $, and can hold a string, a number, or an object reference. In the following example the variable my_tracer references our trace0 object (i.e. it is not a copy).
simics> $my_tracer = trace0 simics> $my_tracer->enabled 1 simics>
It is also possible to access the tracer from Python. All lines begin with a @ are evaluated as a Python statement.
simics> @trace_obj = SIM_get_object("trace0") simics> @trace_obj <the base-trace-mem-hier 'trace0'> simics> @trace_obj.enabled 1 simics>
The Simics API is directly accessible from Python. The script below counts the number of instructions that are executed until the register msr is modified. It imitates the functionality of break-cr msr.
simics> @start_cycle = SIM_cycle_count(conf.cpu0) simics> @msr = conf.cpu0.msr simics> @while conf.cpu0.msr == msr: SIM_continue(1) [...] simics> @end_cycle = SIM_cycle_count(conf.cpu0) simics> @print "Executed", end_cycle - start_cycle, "instructions" Executed 56 instructions simics>
After you enter @while conf.cpu0.msr [...] command, the simulation starts, and continues until the msr register is modified. When that happens (which should not take any noticeable time), the simulation stops and the rest of the commands can be entered.
You can read more about scripting in chapter 8. The full description of the Simics API is available in the Reference Manual.