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
The following are valid <psim-option>s:
The `-H' option gives a long usage output. This includes a complete list of all the pre-configured devices.
The <spec>
argument to the -o
option has the syntax
described below.
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).
<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 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.
<property-name> " " <text> <property-name> " " "\"" <text>
<property-name> " " [ "true" | "false" ]
<property-name> " " <number> { <number> }
<property-name> " " "&" <path-to-device>
<property-name> " " "*" <path-to-device-to-open>
<property-name> " " "!" <path-to-original-property>
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>
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 . . .
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.
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
$cycles
$stalls
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
).
PSIM includes a number of performance monitoring (profiling) facilities:
As discussed in the file INSTALL, each can be configured to individual requirements.
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
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:
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).