2 PSIM - model a PowerPC platform
4 Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 This directory contains the source code to the program PSIM.
26 PSIM is an ANSI C program that implements an instruction
27 level model of the PowerPC architecture.
29 It can be configured to model various PowerPC platforms
32 o A user program environment (UEA) complete
33 with emulated system calls
37 o A hardware platform with several processors
38 interacting with each other and various
39 modeled hardware devices.
41 For each of these models PSIM is able perform a detailed
42 analysis of the machines performance.
46 Who would be interested in PSIM?
50 Using psim, gdb, gcc and binutils the curious
51 user can contruct an environment that allows
52 them to play with PowerPC user programs with out
53 the need for real hardware.
58 PSIM includes many (contributed) monitoring
59 features which (unlike many other simulators)
60 do not come with a great penalty in performance.
62 Thus the performance analyst is able to use
63 this simulator to model the inpact of changes
64 to the system they are analysing. Be that
65 system a compiler or real hardware platform.
67 If PSIM doesn't monitor a components of interest,
68 the source code is freely available, and hence
69 there is no hinderance to changing things
70 to meet a specific analysts needs.
73 o the serious SW developer
75 PSIM models all three levels of the PowerPC
76 Architecture: UEA, VEA and OEA. Further,
77 the internal design is such that PSIM can
78 be extended to suport additional
79 development requirements. Such requirements
80 might include (for the UEA) a new Operating
81 System emulation through to (for the OEA)
82 a model of a different hardware platform.
85 What features does PSIM have?
88 Monitoring and modeling
90 PSIM includes (thanks to Michael Meissner)
91 a detailed model of the various PowerPC
92 implementations schedulers.
97 The PowerPC ISA defines SMP synchronizing instructions
98 this simulator models a limited subset of their
99 behavor. Consequently, if you limit code to the
100 use the modeled behavour, PSIM can be used to
101 model SMP PowerPC platforms.
103 People intending to use this system should study
104 the code implementing the lwarx etc instructions.
108 PSIM implements the PowerPC's big and little (xor
109 endian) modes and correctly simulates code that
110 switches between these two modes.
112 In addition, psim can model a true little-endian
115 ISA models (Instruction Set Architecture)
117 PSIM includes a model of the UEA, VEA and OEA. This
118 inclues the time base registers (VEA) and HTAB
121 In addition, a preliminary model of the 64 bit
122 PowerPC architecture is implemented.
126 PSIM's internals are based around the concept
127 of a Device Tree. This tree intentionaly
128 resembles that of the Device Tree found in
129 OpenBoot firmware. PSIM is flexable enough
130 to allow the user to fully configure the
131 actual hardware model from a device tree
132 specification that is read in from a file.
134 A user can either run a program using one of
135 PSIM's built in hardware models specify a
136 custom hardware model that should be simulated.
138 A user is also able to quickly add a model
139 of new hardware devices so that they can be
140 included in a custom hardware model.
144 PSIM's UEA model includes emulation for UNIX system
147 PSIM's OEA model includes emulation of either:
149 o OpenBoot client interface
151 o MOTO's BUG interface.
156 Preliminary suport for floating point is included.
160 What performance analysis measurements can PSIM perform?
162 Below is the output from a recent analysis run
163 (contributed by Michael Meissner):
165 For the following program:
170 static unsigned long seed = 47114711;
171 unsigned long this = seed * 1103515245 + 12345;
186 ran = simple_rand ();
187 n_bits = (ran >> 1) % 16;
196 x |= (1 << n_bits) - 1;
198 if (tot_bits > 8 * sizeof (long) + 6)
204 #define ABS(x) ((x) >= 0 ? (x) : -(x))
210 for (i = 0; i < 50000; i++)
213 x = random_bitstring ();
214 y = random_bitstring ();
216 if (sizeof (int) == sizeof (long))
219 { unsigned long xx = x, yy = y, r1, r2;
220 if (yy == 0) continue;
223 if (r2 >= yy || r1 * yy + r2 != xx)
226 { signed long xx = x, yy = y, r1, r2;
227 if ((unsigned long) xx << 1 == 0 && yy == -1)
231 if (ABS (r2) >= (unsigned long) ABS (yy) || (signed long) (r1 * yy + r2) != xx)
235 { unsigned int xx = x, yy = y, r1, r2;
236 if (yy == 0) continue;
239 if (r2 >= yy || r1 * yy + r2 != xx)
242 { signed int xx = x, yy = y, r1, r2;
243 if ((unsigned int) xx << 1 == 0 && yy == -1)
247 if (ABS (r2) >= (unsigned int) ABS (yy) || (signed int) (r1 * yy + r2) != xx)
250 { unsigned short xx = x, yy = y, r1, r2;
251 if (yy == 0) continue;
254 if (r2 >= yy || r1 * yy + r2 != xx)
257 { signed short xx = x, yy = y, r1, r2;
260 if (ABS (r2) >= (unsigned short) ABS (yy) || (signed short) (r1 * yy + r2) != xx)
263 { unsigned char xx = x, yy = y, r1, r2;
264 if (yy == 0) continue;
267 if (r2 >= yy || r1 * yy + r2 != xx)
270 { signed char xx = x, yy = y, r1, r2;
273 if (ABS (r2) >= (unsigned char) ABS (yy) || (signed char) (r1 * yy + r2) != xx)
281 Here is the current output generated with the -I switch on a 90 Mhz
282 pentium (the compiler used is the devlopment version of GCC with a new
283 scheduler replacing the old one):
285 CPU #1 executed 41,994 AND instructions.
286 CPU #1 executed 519,785 AND Immediate instructions.
287 CPU #1 executed 680,058 Add instructions.
288 CPU #1 executed 41,994 Add Extended instructions.
289 CPU #1 executed 921,916 Add Immediate instructions.
290 CPU #1 executed 221,199 Add Immediate Carrying instructions.
291 CPU #1 executed 943,823 Add Immediate Shifted instructions.
292 CPU #1 executed 471,909 Add to Zero Extended instructions.
293 CPU #1 executed 571,915 Branch instructions.
294 CPU #1 executed 1,992,403 Branch Conditional instructions.
295 CPU #1 executed 571,910 Branch Conditional to Link Register instructions.
296 CPU #1 executed 320,431 Compare instructions.
297 CPU #1 executed 471,911 Compare Immediate instructions.
298 CPU #1 executed 145,867 Compare Logical instructions.
299 CPU #1 executed 442,414 Compare Logical Immediate instructions.
300 CPU #1 executed 1 Condition Register XOR instruction.
301 CPU #1 executed 103,873 Divide Word instructions.
302 CPU #1 executed 104,275 Divide Word Unsigned instructions.
303 CPU #1 executed 132,510 Extend Sign Byte instructions.
304 CPU #1 executed 178,895 Extend Sign Half Word instructions.
305 CPU #1 executed 871,920 Load Word and Zero instructions.
306 CPU #1 executed 41,994 Move From Condition Register instructions.
307 CPU #1 executed 100,005 Move from Special Purpose Register instructions.
308 CPU #1 executed 100,002 Move to Special Purpose Register instructions.
309 CPU #1 executed 804,619 Multiply Low Word instructions.
310 CPU #1 executed 421,201 OR instructions.
311 CPU #1 executed 471,910 OR Immediate instructions.
312 CPU #1 executed 1,292,020 Rotate Left Word Immediate then AND with Mask instructions.
313 CPU #1 executed 663,613 Shift Left Word instructions.
314 CPU #1 executed 1,151,564 Shift Right Algebraic Word Immediate instructions.
315 CPU #1 executed 871,922 Store Word instructions.
316 CPU #1 executed 100,004 Store Word with Update instructions.
317 CPU #1 executed 887,804 Subtract From instructions.
318 CPU #1 executed 83,988 Subtract From Immediate Carrying instructions.
319 CPU #1 executed 1 System Call instruction.
320 CPU #1 executed 207,746 XOR instructions.
322 CPU #1 executed 23,740,856 cycles.
323 CPU #1 executed 10,242,780 stalls waiting for data.
324 CPU #1 executed 1 stall waiting for a function unit.
325 CPU #1 executed 1 stall waiting for serialization.
326 CPU #1 executed 1,757,900 times a writeback slot was unavilable.
327 CPU #1 executed 1,088,135 branches.
328 CPU #1 executed 2,048,093 conditional branches fell through.
329 CPU #1 executed 1,088,135 successful branch predictions.
330 CPU #1 executed 904,268 unsuccessful branch predictions.
331 CPU #1 executed 742,557 branch if the condition is FALSE conditional branches.
332 CPU #1 executed 1,249,846 branch if the condition is TRUE conditional branches.
333 CPU #1 executed 571,910 branch always conditional branches.
334 CPU #1 executed 9,493,653 1st single cycle integer functional unit instructions.
335 CPU #1 executed 1,220,900 2nd single cycle integer functional unit instructions.
336 CPU #1 executed 1,254,768 multiple cycle integer functional unit instructions.
337 CPU #1 executed 1,843,846 load/store functional unit instructions.
338 CPU #1 executed 3,136,229 branch functional unit instructions.
339 CPU #1 executed 16,949,396 instructions that were accounted for in timing info.
340 CPU #1 executed 871,920 data reads.
341 CPU #1 executed 971,926 data writes.
342 CPU #1 executed 221 icache misses.
343 CPU #1 executed 16,949,396 instructions in total.
345 Simulator speed was 250,731 instructions/second
351 As an idea, psim was first discussed seriously during mid
352 1994. At that time its main objectives were:
357 Many simulators loose out by only providing
358 a binary interface to the internals. This
359 interface eventually becomes a bottle neck
360 in the simulators performance.
362 It was intended that PSIM would avoid this
363 problem by giving the user access to the
366 Further, by exploiting the power of modern
367 compilers it was hoped that PSIM would achieve
368 good performance with out having to compromize
372 o practical portability
374 Rather than try to be portable to every
375 C compiler on every platform, it was decided
376 that PSIM would restrict its self to suporting
377 ANSI compilers that included the extension
380 GCC is one such compiler, consequenly PSIM
381 should be portable to any machine running GCC.
384 o flexability in its design
386 PSIM should allow the user to select the
387 features required and customize the build
388 accordingly. By having the source code,
389 the compler is able to eliminate any un
390 used features of the simulator.
392 After all, let the compiler do the work.
397 A model that allowed the simulation of
398 SMP platforms with out the large overhead
399 often encountered with such models.
402 PSIM achieves each of these objectives.
405 Is PSIM PowerPC Platform (PPCP) (nee CHRP) Compliant?
409 Among other things it does not have an Apple ROM socket.
412 Can PSIM be configured so that it models a CHRP machine?
416 PSIM has been designed with the CHRP spec in mind. To model
417 a CHRP desktop a user would need to add the following:
419 o An apple rom socket :-)
421 o Model of each of the desktop IO devices
422 (some may already be implemented).
424 o An OpenPIC (Open Programmable Interrupt
425 Controller) device. (it may by now be
428 o RTAS (Run Time Abstraction Services).
430 o A fully populated device tree.
433 Is the source code available?
437 The source code to PSIM is available under the terms of
438 the GNU Public Licence. This allows you to distribute
439 the source code for free but with certain conditions.
444 To build PSIM you will need the following files:
447 gdb-4.15.tar.gz From your favorite GNU ftp site.
448 I've also tested psim with
449 gdb-4.15.1. If you would prefer
450 a graphical development environment
451 then PSIM can also be built with
455 ftp://ftp.ci.com.au/pub/clayton/README.pim
460 ftp://ftp.ci.com.au/pub/clayton/gdb-4.15+psim.diff.gz
462 Firstly this file contains a few
463 minor changes to gdb-4.15 so that it
464 will build PSIM as part of GDB.
467 ftp://ftp.ci.com.au/pub/clayton/gdb-4.15+note.diff.gz
469 Add suport for note sections (used
470 by OpenBoot PowerPC programs).
473 ftp://ftp.ci.com.au/pub/clayton/gdb-4.15+attach.diff.gz
475 Allow the gdb attach command to
476 work with simulators.
479 ftp://ftp.ci.com.au/pub/clayton/psim-960119.tar.gz
481 This contains the psim files proper.
484 gcc Again available from your favorite
488 patch Sun's patch behaves a little wierd
489 and doesn't appear to like creating
490 empty files. You may want to consider
491 installing gnu's patch.
499 gdb-4.15+attach.diff.gz
500 gdb-4.15+note.diff.gz
501 gdb-4.15+psim.diff.gz
502 gdb-4.15+psim.diff.gz
509 $ gunzip < gdb-4.15.tar.gz | tar xf -
512 2. Change to the gdb directory, apply the psim patches and unpack
517 $ gunzip < ../gdb-4.15+psim.diff.gz | more
518 $ gunzip < ../gdb-4.15+psim.diff.gz | patch -p1
520 $ gunzip < ../gdb-4.15+psim-960119.tar.gz | tar tvf -
521 $ gunzip < ../gdb-4.15+psim-960119.tar.gz | tar xvf -
523 You may also want to consider applying the `attach' and
524 `note' patches that are available vis:
526 $ gunzip < ../gdb-4.15+attach.diff.gz | more
527 $ gunzip < ../gdb-4.15+attach.diff.gz | patch -p
529 $ gunzip < ../gdb-4.15+note.diff.gz | more
530 $ gunzip < ../gdb-4.15+note.diff.gz | patch -p
537 then something like (I assume SH):
539 $ CC=gcc ./configure --target=powerpc-unknown-eabisim
541 eabisim is needed as by default (because PSIM needs GCC) the
542 simulator is not built.
544 [If building with a more recent gdb snapshot then the
547 $CC=gcc ./configure --enable-sim-powerpc
555 alternativly, if you are short on disk space or just want the
558 $ ( cd libiberty && make CC=gcc )
559 $ ( cd bfd && make CC=gcc )
560 $ ( cd sim/ppc && make CC=gcc )
565 $ make CC=gcc install
569 $ cp gdb/gdb ~/bin/powerpc-unknown-eabisim-gdb
570 $ cp sim/ppc/run ~/bin/powerpc-unknown-eabisim-run
573 Is there a more recent version of PSIM and if so, how would I build it?
575 A PSIM is an ongoing development, occasional snapshots
576 (that include new features) are made available. Several of
577 the more recent snapshots are:
581 To build/install one of these snapshots, you replace the
582 current gdb/sim/ppc directory with the one in the update,
583 re-configure and rebuild.
592 1. Remove the old psim directory
594 $ mv sim/ppc sim/old.ppc
597 2. Unpack the new one
599 $ gunzip < ../psim-960105.tar.gz | tar tf -
600 $ gunzip < ../psim-960105.tar.gz | tar tf -
603 3. Reconfig/rebuild (as seen above):
605 $ CC=gcc ./configure --target=powerpc-unknown-eabisim
609 Are there any example programs that can be run on PSIM?
611 Psim has a simple test suite that is used to ensure
612 that fixes do not introduce new bugs. This test suite
613 like psim is updated:
615 ftp://ftp.ci.com.au/pub/clayton/psim-test-960118.tar.gz
617 Prebuilt test programs for PSIM.
618 Includes examples of UEA, VEA and
620 Requires gcc-2.7.2 and binutils-2.6
624 How do I use the simulator?
627 I assume that you've unpacked a psim-test archive.
630 1. As a standalone program
632 Print out the users environment:
634 $ powerpc-unknown-eabisim-run psim-test/uea/envp
636 Print out the arguments:
638 $ powerpc-unknown-eabisim-run psim-test/uea/argv a b c
640 Check that sbrk works:
642 $ powerpc-unknown-eabisim-run psim-test/uea/break
645 2. Example of running GDB:
647 The main thing to note is that before you can run the simulator
648 you must enable it. The example below illustrates this:
650 $ powerpc-unknown-eabisim-gdb psim-test/uea/envp
660 3. Using a device tree as a description of a machine
661 (I assume that you have applied the attach bug).
664 $ powerpc-unknown-eabisim-gdb
666 (gdb) attach device-tree
672 $ powerpc-unknown-eabisim-run device-tree
675 Where do I send bugs or report problems?
677 There is a mailing list (subscribe through majordomo@ci.com.au) (that
678 is almost never used) at:
680 powerpc-psim@ci.com.au
682 If I get the ftp archive updated I post a note to that mailing list.
683 In addition your welcome to send bugs or problems either to me or to
687 Does PSIM have any limitations or problems?
689 See the file PROBLEMS (included in the distribution) for any
695 Thanks go to the following who each helped in their own
698 Allen Briggs, Bett Koch, David Edelsohn, Gordon Irlam,
699 Michael Meissner, Bob Mercier, Richard Perini, Dale Rahn
700 Richard Stallman, Mitchele Walker