Go to the first, previous, next, last section; table of contents; home; full screen; PSIM.

Using PSIM

Using PSIM from the command line

The compressed tar archive psim-test available from:

	ftp://sourceware.cygnus.com/pub/psim/psim-test-1998-11-20.tar.gz

contains a number of pre-built programs for running under PSIM. Each pre-built binary is built both big and little endian. The suffixes .be/.le (executables) .bo/.lo (object files) and .ba/.la (libraries) are used.

To run one of these programs, use:

	powerpc-unknown-eabi-run <image>

for instance:

	powerpc-unknown-eabi-run psim-test/uea/envp

The program envp prints out your shells environment - very useful! More generally psim is run as (this is part of the output from the -h option):

        psim [ <psim-option> ... ] <image> [ <image-arg> ... ]

Where

<image>
Name of the PowerPC program to run. This can either be a PowerPC binary or a text file containing a device tree specification. PSIM will attempt to determine from the specified <image> the intended emulation environment. If PSIM gets it wrong, the emulation environment can be specified using the `-e' option (described below).
<image-arg>
Argument to be passed to <image> These arguments will be passed to <image> (as standard C argv, argc) when <image> is started.
<psim-option>
See below

The following are valid <psim-option>s:

-m <model>
Specify the processor to model (604) Selects the processor to use when modeling execution units. Includes: 604, 603 and 603e
-e <os-emul>
specify an OS or platform to model Can be any of the following: bug - OEA + MOTO BUG ROM calls netbsd - UEA + NetBSD system calls chirp - OEA + a few OpenBoot calls
-i
Print instruction counting statistics
-I
Print execution unit statistics
-r <size>
Set RAM size in bytes (OEA environments)
-t [!]<trace>
Enable (disable) <trace> option
-o <spec>
add device <spec> to the device tree
-h -? -H
give more detailed usage

The `-H' option gives a long usage output. This includes a complete list of all the pre-configured devices.

A device specification

The <spec> argument to the -o option has the syntax described below.

Path

The path to a device or property can either be absolute (leading `/') or relative (leading `.' or `..'). Relative paths start from the CURRENT node. The new current node is returned as the result. In addition, a path may start with a leading alias (resolved by looking in /aliases).

Device name

   <name> "@" <unit> [ ":" <args> ]

Where <name> is the name of the template device, <unit> is a textual specification of the devices unit address (that is converted into a numeric form by the devices parent) and <args> are optional additional information to be passed to the device-template when it creates the device.

Properties

Properties are specified in a similar way to devices except that the last element on the path (which would have been the device) is the property name. This path is then followed by the property value. Unlike OpenBoot, the property values in the device tree are strongly typed.

String property
     <property-name> " " <text>
     <property-name> " " "\"" <text>
Boolean property
     <property-name> " " [ "true" | "false" ]
Integer property or integer array property:
     <property-name> " " <number> { <number> }
Phandle property
     <property-name> " " "&" <path-to-device>
Ihandle property
     <property-name> " " "*" <path-to-device-to-open>
Duplicate existing property
     <property-name> " " "!" <path-to-original-property>

Interrupts

In addition to properties, the wiring of interrupts can be specified:

Attach interrupt <line> of <device> to <controller>:

     <device> " " ">" <my-port>  <dest-port> <dest-device>

Using PSIM from within GDB

If you built PSIM with gdb then the following is a quick start tutorial.

At present GDB, if configured big-endian (say) unlike PSIM, does not support the debugging of little endian binaries. If you find that your program won't run at all, make certain that GDB and your program's endianness match.

The most important thing is that before you can run the simulator you must enable it. For the simulator, gdb is started like any program:

	$ powerpc-unknown-eabi-gdb psim-test/uea/envp.be

Next the simulator is enabled. The command target sim accepts the same options as can be specified on the PSIM command line.

	(gdb) target sim

To trace the communication between psim and gdb specify `target sim -t gdb'. Once enabled, the binary needs to be loaded, any breakpoints of interest set, and the program run:

	(gdb) load
	(gdb) break main
	(gdb) run
	.
	.
	.

Using a device tree specification

If you are wanting to run a program described by a device tree you can `attach' to the simulation using (I assume that you have applied the attach patch):

	$ cd psim-test/tree
	$ powerpc-unknown-eabi-gdb
	(gdb) target sim
	(gdb) attach device-tree
	(gdb) run

Here GDB takes the programs initial state from the attached device-tree instead of forcing initialisation.

Using profile variables ($insns $stalls $cycles)

As mentioned in the GDB documentation, some of the simulators integrated into gdb include phony registers that facilitate access to the simulators performace counters.

For instance, the phony $insns register would return the number of instructions executed since the start of the simulation run.

The following phony registers are available within GDB + PSIM:

$insns
Count of the number of instructions executed since the start of the current simulation run.
$cycles
Count of the number of processor cycles scheduled since the start of the current simulation run.
$stalls
Count of the number of stalled processor cycles since the start of the current simulation run.

For the pseudo registers $cycles and $stalls require PSIM's functional unit model to be enabled before they are available. The functional unit model is enabled by specifying the -I option when enabling the simulator (target sim -I).

Profiling

PSIM includes a number of performance monitoring (profiling) facilities:

As discussed in the file INSTALL, each can be configured to individual requirements.

-i
Enable instruction counting. The frequency of all instructions is tabulated. In addition (f configured) the hit/miss rate of the instruction cache is output.
-I
Enable execution unit analysis. In addition to counting basic instructions also model the performance of the processors execution units
-m <processor>
Select the processor to be modelled. For execution unit analysis specify the processor that is to be analysed. By default the 604 is modelled however, support for other processors such as the 603 and 603e is included.

The output from a performance run (on a P90) for the program psim-test/profile/bench is below. In this run psim was fairly agressively configured (see the file INSTALL for compile time configuration).

	CPU #1 executed     41,994 AND instructions.
	CPU #1 executed    519,785 AND Immediate instructions.
	CPU #1 executed    680,058 Add instructions.
	CPU #1 executed     41,994 Add Extended instructions.
	CPU #1 executed    921,916 Add Immediate instructions.
	CPU #1 executed    221,199 Add Immediate Carrying instructions.
	CPU #1 executed    943,823 Add Immediate Shifted instructions.
	CPU #1 executed    471,909 Add to Zero Extended instructions.
	CPU #1 executed    571,915 Branch instructions.
	CPU #1 executed  1,992,403 Branch Conditional instructions.
	CPU #1 executed    571,910 Branch Conditional to Link Register instructions.
	CPU #1 executed    320,431 Compare instructions.
	CPU #1 executed    471,911 Compare Immediate instructions.
	CPU #1 executed    145,867 Compare Logical instructions.
	CPU #1 executed    442,414 Compare Logical Immediate instructions.
	CPU #1 executed          1 Condition Register XOR instruction.
	CPU #1 executed    103,873 Divide Word instructions.
	CPU #1 executed    104,275 Divide Word Unsigned instructions.
	CPU #1 executed    132,510 Extend Sign Byte instructions.
	CPU #1 executed    178,895 Extend Sign Half Word instructions.
	CPU #1 executed    871,920 Load Word and Zero instructions.
	CPU #1 executed     41,994 Move From Condition Register instructions.
	CPU #1 executed    100,005 Move from Special Purpose Register instructions.
	CPU #1 executed    100,002 Move to Special Purpose Register instructions.
	CPU #1 executed    804,619 Multiply Low Word instructions.
	CPU #1 executed    421,201 OR instructions.
	CPU #1 executed    471,910 OR Immediate instructions.
	CPU #1 executed  1,292,020 Rotate Left Word Immediate then AND with Mask instructions.
	CPU #1 executed    663,613 Shift Left Word instructions.
	CPU #1 executed  1,151,564 Shift Right Algebraic Word Immediate instructions.
	CPU #1 executed    871,922 Store Word instructions.
	CPU #1 executed    100,004 Store Word with Update instructions.
	CPU #1 executed    887,804 Subtract From instructions.
	CPU #1 executed     83,988 Subtract From Immediate Carrying instructions.
	CPU #1 executed          1 System Call instruction.
	CPU #1 executed    207,746 XOR instructions.
	
	CPU #1 executed 23,740,856 cycles.
	CPU #1 executed 10,242,780 stalls waiting for data.
	CPU #1 executed          1 stall waiting for a function unit.
	CPU #1 executed          1 stall waiting for serialization.
	CPU #1 executed  1,757,900 times a write-back slot was unavailable.
	CPU #1 executed  1,088,135 branches.
	CPU #1 executed  2,048,093 conditional branches fell through.
	CPU #1 executed  1,088,135 successful branch predictions.
	CPU #1 executed    904,268 unsuccessful branch predictions.
	CPU #1 executed    742,557 branch if the condition is FALSE conditional branches.
	CPU #1 executed  1,249,846 branch if the condition is TRUE conditional branches.
	CPU #1 executed    571,910 branch always conditional branches.
	CPU #1 executed  9,493,653 1st single cycle integer functional unit instructions.
	CPU #1 executed  1,220,900 2nd single cycle integer functional unit instructions.
	CPU #1 executed  1,254,768 multiple cycle integer functional unit instructions.
	CPU #1 executed  1,843,846 load/store functional unit instructions.
	CPU #1 executed  3,136,229 branch functional unit instructions.
	CPU #1 executed 16,949,396 instructions that were accounted for in timing info.
	CPU #1 executed    871,920 data reads.
	CPU #1 executed    971,926 data writes.
	CPU #1 executed        221 icache misses.
	CPU #1 executed 16,949,396 instructions in total.
	
	Simulator speed was 250,731 instructions/second

Specifying devices

Internally PSIM's configuration is controlled by a tree data structure. This structure, created at run-time, intentionally resembles the device tree used by OpenBoot firmware to describe a machines hardware configuration.

PSIM can either create its device tree using a builtin emulation or from one read in from a file.

During startup, the device tree is created using the following steps:

Most importantly earlier additions to the tree are not overridden by later additions. Thus, command line options override information found in the program file and both override any builtin emulation entries.

The following is a summary of the most useful runtime configuration options:

-e <os-emul>
-o '/openprom/options/os-emul <os-emul>'
Run program using the <emulation> run-time environment.
-r <ram-size>
-o '/openprom/options/oea-memory-size <ram-size>'
Set the size of the first bank of memory (RAM from address 0 up).
-t print-device-tree
@xitem -o '/openprom/trace/print-device-tree 1'
-t dump-device-tree
@xitem -o '/openprom/trace/dump-device-tree 1' Print out the device tree once it has been fully populated. For dump-device-tree, exit simulator after dumping the tree. PSIM is able to reload the dumped device tree. The format of the dumped tree is under development.
-n <nr-smp>
@xitem -o '/openprom/options/smp <nr-smp>' Enable <N> processors for the simulation run. See the directory psim-test/oea for an example.
-o '/openprom/options/alignment <N>'
Where <N> is 1 - nonstrict or 2 - strict. Specify if the missaligned access are allowed (non-strict) or result in an alignment exception (strict).

Devices (if included in the file device_table.c) can also be specified in a similar way. For instance, to add a second serial port, a command like:

	-o '/iobus@0x400000/console@0x000010'

would create a `console' device at offset 0x10 within the `iobus' at memory address 0x400000.

For more detailed information on device specifiers see the notes on the function dump_device_tree in the file device.c (found in the source code).


Go to the first, previous, next, last section; table of contents; home; full screen.