1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
|
PSIM - model the PowerPC environment
Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>.
----------------------------------------------------------------------
Building PSIM
This file describes how to build the program PSIM
o Walk through a basic build
o Discussion of PSIM's components and
how they relate to the build process
o Detailed description of each of PSIM's
compile time configuration options
----------------------------------------------------------------------
BUILDING PSIM:
PSIM 1.0.2 is included in GDB-4.16. To build PSIM you will need the
following:
gdb-4.16.tar.gz Available from your favorite GNU
ftp site
gcc GCC version two includes suport
for long long (64bit integer)
arrithemetic which PSIM uses. Hence
it is recommended that you build PSIM
using GCC.
Method:
1. Unpack gdb
$ cd .../scratch
$ gunzip < gdb-4.16.tar.gz | tar xf -
2. Configure gdb
First consult the gdb documentation
$ cd .../scratch
$ cd gdb-4.16
$ more README
$ more gdb/README
then something like (I assume SH):
$ CC=gcc ./configure \
--enable-sim-powerpc \
--target=powerpc-unknown-eabi \
--prefix=/applications/psim
4. Build (again specifying GCC)
$ make CC=gcc
alternatively, if you are short on disk space or only
want to build the simulator:
$ ( cd libiberty && make CC=gcc )
$ ( cd bfd && make CC=gcc )
$ ( cd sim/ppc && make CC=gcc )
5. Install
$ make CC=gcc install
or just
$ cp gdb/gdb ~/bin/powerpc-unknown-eabisim-gdb
$ cp sim/ppc/run ~/bin/powerpc-unknown-eabisim-run
----------------------------------------------------------------------
UPDATING PSIM:
A PSIM is an ongoing development. Occasional snapshots which both contain new features and fix old bugs are made available. See the ftp directory:
ftp://ftp.ci.com.au/pub/psim/beta
or ftp://cambridge.cygnus.com/pub/psim/beta
for the latest version. To build/install one of these snapshots, you
replace the sim/ppc found in the gdb archive with with one from the
snapshot. Then just re-configure and rebuild/install.
Procedure:
0. A starting point
$ cd gdb-4.16
1. Remove the old psim directory
$ mv sim/ppc sim/old.ppc
2. Unpack the new one
$ gunzip < ../psim-NNNNNN.tar.gz | tar tf -
$ gunzip < ../psim-NNNNNN.tar.gz | tar tf -
3. Reconfigure/rebuild (as seen above):
$ CC=gcc ./configure \
--enable-sim-powerpc \
--target=powerpc-unknown-eabi \
--prefix=/applications/psim
$ make CC=gcc
----------------------------------------------------------------------
UPDATES TO GDB:
From time to time, problems involving the integration of PSIM into gdb
are found. While eventually each of these problems is resolved there
can be periouds during which a local hack may be needed.
At the time of writing the following were outstanding:
ATTACH command:
ftp://ftp.ci.com.au/pub/psim/gdb-4.15+attach.diff.gz
or ftp://cambridge.cygnus.com/pub/psim/gdb-4.15+attach.diff.gz
PSIM, unlike the other simulators found in GDB, is able to load
the description of a target machine (including the initial
state of all processor registers) from a file.
Unfortunatly GDB does not yet have a standard command that
facilitates the use of this feature. Until such a command is
added, the patch (hack?) gdb-4.15+attach.diff.gz can be used to
extend GDB's attach command so that it can be used to initialize
the simulators configuration from a file.
----------------------------------------------------------------------
RUNNING PROGRAMS:
See the file:
ftp://ftp.ci.com.au/pub/psim/RUN
or ftp://cambridge.cygnus.com/pub/psim/RUN
----------------------------------------------------------------------
COMPILE TIME CONFIGURATION OPTIONS:
PSIM's compile time configuration is controlled by autoconf. PSIM's
configure script recognises options of the form:
--enable-sim-<option>[=<val>]
And can be specified on the configure command line (at the top level
of the gdb directory tree) vis:
$ cd gdb-4.15
$ CC=gcc ./configure \
--target=powerpc-unknown-eabisim \
--prefix=/applications/psim \
--enable-sim-inline
$ make CC=gcc
For a brief list of PSIM's configuration options, configure --help
will list them vis:
$ cd sim/ppc
$ ./configure --help
Each PSIM specific option is discussed in detail below.
--enable-sim-cflags=<opts>
Specify additional C compiler flags that are to be used when compiling
just PSIM.
PSIM places heavy demands on both the host machine and its C compiler.
So that the builder has better control over the compiler the above
option can be used to pass additional options to the compiler while PSIM is being built.
Ex: No debug information
PSIM can be built with everything inline. Unfortunately, because of
all the debugging information generated the C compiler can grow very
very large as a result. For GCC, the debug information can be
restricted with the `-g0' option. To specify that this option should
be include in the CFLAGS when compiling the psim source code use:
--enable-sim-cflags=-g0
Ex: Additional optimization flags
A significant gain in performance can be achieved by tuning the
optimization flags passed to the C compiler. For instance on an x86
you may consider:
--enable-sim-cflags='-g0 -O2 -fno-strength-reduce -f...'
--enable-sim-warnings=<flags>
Turn on additional GCC specific checks.
Some hosts (NetBSD, Linux, Solaris-2.5) have complete header files
that include correct prototypes for all library functions. On such
hosts, PSIM can be built with many more than the standard C checks
enabled. The option --enable-sim-warnings controls this.
Ex: Default warnings
With just --enable-sim-warnings, the following -W options are enabled:
-Werror -Wall -Wpointer-arith -Wmissing-prototypes.
--enable-sim-opcode=which
Specify the file containing the rules for generating the instruction
decode and execute functions from the file ppc-instructions.
The form of the instruction decode and execute functions is controlled
by an opcode table. It specifies: the combination of switch
statements and jump tables to use when decoding an instruction and how
much of each instruction should be decoded before calling the
instruction execute function.
PSIM includes a number of opcode tables:
psim-opcode-simple
Generates a small compact two level switch statement
that will compile quickly and run reasonably fast.
This may be useful on a small machine.
psim-opcode-complex
(the default) A fairly aggressive instruction decode
table that includes the breaking out of a number
of special instruction cases (eg RA==0 vs RA!=0).
psim-opcode-flat
Identical to complex except a switch statement
is used. Ideal for when the icache is being
disabled.
psim-opcode-stupid
In addition to the instruction decodes performed
by psim-opcode-complex, this also full decodes mtspr,
mfspr, and branch instructions. The table generated
is very large and, as a consequence, only performs
well on machines with large caches.
ppc-opcode-test-1
ppc-opcode-test-2
Generate test (but workable) tables. These exercise
PSIM's ability to generate instruction decode functions
that are a combination of jump-tables and switch statements.
The program igen generates the instruction tables from the opcode
table and the ppc-instruction table.
--enable-sim-switch
Enable/disable the use of a switch statement when looking up the
attributes of a SPR register.
The PowerPC architecture defines a number of Special Purpose Registers
(SPR's). Associated with each of these registers are a number of
attributes (such as validity or size) which the instructions
mtspr/mfspr query as part of their execution.
For PSIM, this information is kept in a table (ppc-spr-table). The
program dgen converts this table into lookup routines (contained in
the generated files spreg.h spreg.c) that can be used to query an
SPR's attributes. Those lookup routines are either implemented as
a table or alternatively as a number of switch statements:
spr_table spr_info[] = { .... };
int spr_length(sprs spr) { return spr_info[spr].length; }
vs
int spr_length(sprs spr) { switch (spr) { case ..: return ..; } }
In general the first implementation (a table) is the most efficient.
It may, however, prove that when performing an aggressive optimization
where both the SPR is known and the above function is being inlined
(with the consequence that GCC can eliminate the switch statement)
that the second choice is improves performance.
In practice, only a marginal (if any benefit) has ever been seen.
--enable-sim-duplicate
Create a duplicate copy of each instruction function hardwiring
instruction fields that would have otherwise have been variable.
As discussed above, igen outputs a C function generated from the file
ppc-instructions (using the opcode rules) for each of the
instructions. Thus multiple entries in the instruction decode tables
may be pointing back at the same function. Enabling duplicate, will
result in psim creating a duplicate of the instruction's function for
each different entry in the instruction decode tables.
For instance, given the branch instruction:
0.19,6.BO,11.BI,16./,21.528,31.LK
...
if (LK) LR = (spreg)IEA(CIA + 4);
...
igen as part of its instruction lookup table may have generated two
different entries - one for LK=0 and one for LK=1. With duplicate
enabled, igen outputs (almost) duplicate copies of branch function,
one with LK hardwired to 0 and one with LK hardwired to 1.
By doing this the compiler is provided with additional information that
will allow it possibly eliminate dead code. (such as the assignment
to LK if LR==0).
Ex: default
Because this feature is such a big win, --enable-sim-duplicate is
turned on by default.
Ex: A small machine
Only rarely (eg on a very small host) would this feature need to be
disabled (using: --disable-sim-duplicate).
--enable-sim-filter=rule
Include/exclude PowerPC instructions that are specific to a particular
implementation.
Some of the PowerPC instructions included in the file ppc-instructions
are limited to certain specific PPC implementations. For instance,
the instruction:
0.58,6.RT,11.RA,16.DS,30.2:DS:64::Load Word Algebraic
Is only valid for the 64bit architecture. The enable-sim-filter flag
is passed to igen so that it can `filter out' any invalid
instructions. The filter rule has the form:
-f <name>
thus:
--enable-sim-filter='-f 64'
(the default) would filter out all 64bit instructions.
Ex: Remove floating point instructions
A given 32bit PowerPC implementation may not include floating point
hardware. Consequently there is little point in including floating
point instructions in the instruction table. The option:
--enable-sim-filter='-f 64 -f f'
will eliminate all floating point instructions from the instruction
table.
--enable-sim-icache=size
Set the size of the cache used to hold decoded instructions.
Psim executes instructions in two separate steps:
o instruction fetch/decode
o instruction execution
For a given instruction, the first stage need only be executed once
(the first time the instruction is encountered) while the second stage
must be executed every time the program `executes' that instruction.
Exploiting this, PSIM can maintain a cache of decoded instructions.
It will then use the decoded instruction from the cache in preference
to fetching/decoding the real instruction from memory.
Ex: default
Because this feature is normally such a big win, it is enabled by
default (with the cache size set to 1024 entries).
The 1024 entries equals 4096 bytes (or one page) of instructions.
Larger caches can be used but with caution - PSIM does not check for
address aliasing within its instruction cache.
Ex: disable the cache
There may be cases (for instance where the cache has a low hit rate)
where the psim performs better with no instruction cache. For such
situations, the cache can be disabled vis: --disable-sim-icache.
--enable-sim-inline[=module]
Specify the inlining of one or more modules.
Many architectures (in particular the x86) suffer from a large
function call overhead. By eliminating function calls (through
inlining of functions) a large performance gain can be achieved.
In PSIM, modules are inlined in one of two possible ways. Some
modules (such as the byte swapping code) can be inlined into any
module that calls them. Other modules, due to complex
interdependencies, are only inlined as a group when compiling the
external interface module psim.c.
Ex: default
By default the modules endian (handle be/le), bits (manipulate
bit-fields within words), cpu (the processor object) and events
(timers) are inlined in any module that calls them. This gives a
reasonable performance gain with little additional compilation
overhead.
Ex: recommended --enable-sim-inline
Assuming you machine is reasonably well configured, this option is
highly recommended. On the x86 several orders of magnitude
improvement in performance is possible.
Ex: fine tuning
The file std-config.h contains a detailed description of how the
inlining works. Individual modules can be inlined by specifying them.
For if you have a very large cache the model module could be inlined
with:
--enable-sim-inline=MODEL
--enable-sim-bswap
(x86 specific) Use the i486/P5/P6 byte swap instruction.
PSIM contains generic byte swapping code. For the x86 (P[4-6]) PSIM
can be built so that it uses the bswap instruction instead of relying
on the compiler to generate byte swap code.
Ex: default
By default, when compiling with GCC-2 on an i486/P5/P6 the bswap
instruction is used.
--enable-sim-endian=endian
Specify the byte order of the target.
By default, PSIM is able to execute both big and little endian
executables. As a consequence, every byte swap routine includes a
test to see if the byte swap is really needed. By specifying the byte
order of the target (and the host below) the need for this test can be
eliminated.
Clearly setting the byte order of the target is only useful when known
before hand.
--enable-sim-hostendain=end
As above but for the host.
Normally this option should not be needed. configure (autoconf) should
determine the byte order of the host automatically. However if for
some reason there is a problem, this option can be used to override
autoconf.
--enable-sim-smp=n
Set the maximum number of processors that PSIM can model.
Psim can model (with small limitation discussed else where) a
multi-processor PowerPC environment. While the overhead of
co-ordinating the execution of a number of processors is relatively
small it is still significant when compared to handling only one
processor.
This option only sets the maximum number of processors that can be
simulated. The number active during a given simulation run us
determined at run time.
Ex: default
By default 5 processors are configured but only one is enabled.
Additional processors can be enabled with the runtime option:
-o '/openprom/options/smp 5'
Ex: recommended
Unless you intend studying multi-processor systems there is little reason for having PSIM configured with SMP support. Specifying:
--disable-sim-smp
or --enable-sim-smp=0
will eliminate any SMP such as:
for (cpu = 0; cpu < nr_cpus; cpu++)
...
--enable-sim-xor-endian=n
Set the byte-size of the bus involved in the PowerPC's xor endian byte
swapping.
The PowerPC's implementation of BE/LE mode is different to what a
programmer may first expect. The details of this implementation are
discussed at length in PowerPC documentation.
Ex: default
By default this is configured with a value of 8 (the bus size of most
60x processors).
Ex: recommended
Unless you are expecting to test/debug PowerPC be/le switching code
this option is of little use and should be disabled:
--disable-sim-xor-endian
--enable-sim-bitsize=n
Specify the bit size (32/64) of the PowerPC to be modelled.
Note: By default 32 is specified. The implementation of the 64bit
architecture is still under development.
--enable-sim-hostbitsize=32|64
As above but for the host.
NOTE: Psim has yet to be built on a 64bit host.
--enable-sim-env=env
Hardwire the PowerPC environment being modelled (user, virtual or
operating).
The PowerPC architecture defines three different levels of compliance
to its architectural specification. These environments are discussed in detail in PowerPC publications.
user - normal user programs
virtual - an extension of the user environment (includes timers)
operating - kernel code
Ex: default
By default all three environments are supported.
Ex: recommended
If you only intend running psim with user (or operating) code then
PSIM should be configured accordingly. For user code, it eliminates:
support for timers and events and redundant VM calls.
--enable-sim-timebase
Enable/disable the time base register.
The PowerPC architecture (virtual environment) includes a time base
register. Maintaining that register incurs an overhead in
performance that can be eliminated by eliminating time-base register
support.
Ex: default
Normally this option is not used. Instead --enable-sim-env (above) us
used to disable/enable features such as the timebase register.
--enable-sim-alignment=align
Control the PowerPC's memory access alignment restrictions.
The PowerPC in LE mode only allows memory transfers of a correctly
aligned size/address. The above option controls how misaligned
accesses are handled.
strict All accesses must be correctly aligned
nonstrict Unaligned access allowed (the are split
into a number of aligned accesses).
Ex: default
Unless otherwise specified PSIM will auto configure a BE program to
allow miss-aligned accesses while a LE program will not.
Ex: 604e
The recently announced 604e processor allows miss-aligned accesses in both
BE and LE modes. If modeling the 604e then you should specify:
--enable-sim-alignment=nonstrict
--enable-sim-trace
Include code to trace PSIM's internal progress (also controlled by the
-t option).
Checking to see if a trace message should be output slows down a
simulation. Disabling this option (--disable-sim-trace) eliminates
completely that code.
--enable-sim-assert
Include the code that checks the correctness of parts of PSIM.
Eliminating such code (--disable-sim-assert) eliminates internal
consistency tests and their overhead.
--enable-sim-reserved-bits
Include code to check that the reserved fields of the instruction are
zero.
The PowerPC architecture defines certain fields of some instructions
as reserved (`/'). By default, for each instruction, PSIM will check
the reserved fields causing an invalid instruction exception if a
field is invalid. Disabling this option eliminates this test. This
is at the slight risk of PSIM treating an invalid instruction as
valid.
--enable-sim-float
Include support for hardware floating point.
--enable-sim-monitor=mon
Include support for basic instruction counting.
If you are not interested in the performance of either you program or
the simulator then you can disable this option.
--enable-sim-model=which
Hardwire the processor that will be used as a reference when modeling
execution units.
--enable-sim-default-model=which
Specify the processor of choice for the execution unit model.
--enable-sim-model-issue
Include support for the modeling of processor execution units.
----------------------------------------------------------------------
TYPICAL CONFIGURATION OPTIONS:
VEA CODE ONLY:
Here of note are:
o ramp up the compiler options (some
of the below are P5 specific).
o disable anything not used
CC=gcc ./configure \
--prefix=/applications/psim \
--target=powerpc-unknown-eabi \
--enable-sim-powerpc \
--enable-sim-warnings \
--enable-sim-inline \
--disable-sim-smp \
--enable-sim-bswap \
--enable-sim-duplicate \
--enable-sim-endian=big \
--disable-sim-xor-endian \
--enable-sim-env=user \
--disable-sim-reserved-bits \
--disable-sim-assert \
--disable-sim-trace \
--enable-sim-cflags='-g0 -O2 -fno-strength-reduce -fomit-frame-pointer -malign-loops=2 -malign-jumps=2 -malign-functions=2'
OEA CODE ONLY:
The key configuration changes are:
o turn off the instruction cache. The overhead
of flushing and reloading it is greater than
not having a cache.
o use a switch statement (ppc-opcode-flat) for
the instruction decode and then (-O3) fully
inline all functions.
o --enable-sim-warnings is not present. GCC (2.7.2)
gets confused by the instruction decode table
generated by igen (contains a perfect switch)
and, as a consequence, generates a bogus warning.
CC=gcc ./configure \
--prefix=/applications/psim \
--target=powerpc-unknown-eabi \
--enable-sim-powerpc \
--enable-sim-inline \
--disable-sim-smp \
--enable-sim-bswap \
--enable-sim-duplicate \
--enable-sim-endian=big \
--disable-sim-xor-endian \
--enable-sim-env=operating \
--disable-sim-reserved-bits \
--disable-sim-assert \
--disable-sim-trace \
--enable-sim-opcode=ppc-opcode-flat \
--disable-sim-icache \
--enable-sim-cflags='-g0 -O3 -fno-strength-reduce -fomit-frame-pointer -malign-loops=2 -malign-jumps=2 -malign-functions=2'
|