1 |
330 |
jeremybenn |
|
2 |
|
|
PSIM - model the PowerPC environment
|
3 |
|
|
|
4 |
|
|
Copyright (C) 1994-1996, Andrew Cagney .
|
5 |
|
|
|
6 |
|
|
----------------------------------------------------------------------
|
7 |
|
|
|
8 |
|
|
Running PSIM
|
9 |
|
|
|
10 |
|
|
This file describes how to run the program PSIM.
|
11 |
|
|
|
12 |
|
|
o Walk through a number of examples from the
|
13 |
|
|
pre-built tar archive psim-test.
|
14 |
|
|
|
15 |
|
|
o Looks at the device tree used by PSIM.
|
16 |
|
|
|
17 |
|
|
o Notes on building a programmer environment to
|
18 |
|
|
use with PSIM (BSD/UEA and BUG/OEA)
|
19 |
|
|
|
20 |
|
|
|
21 |
|
|
----------------------------------------------------------------------
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
RUNNING PSIM:
|
25 |
|
|
|
26 |
|
|
|
27 |
|
|
The compressed tar archive psim-test available from:
|
28 |
|
|
|
29 |
|
|
ftp://ftp.ci.com.au/pub/psim/psim-test-1.0.1.tar.gz
|
30 |
|
|
or ftp://cambridge.cygnus.com/pub/psim/psim-test-1.0.1.tar.gz
|
31 |
|
|
|
32 |
|
|
contains a number of pre-built programs for running under PSIM. Each
|
33 |
|
|
pre-built binary is built both big and little endian. The suffixes
|
34 |
|
|
.be/.le (executables) .bo/.lo (object files) and .ba/.la (libraries)
|
35 |
|
|
are used.
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
To run one of these programs, use:
|
39 |
|
|
|
40 |
|
|
powerpc-unknown-eabi-run
|
41 |
|
|
|
42 |
|
|
for instance:
|
43 |
|
|
|
44 |
|
|
powerpc-unknown-eabi-run psim-test/uea/envp
|
45 |
|
|
|
46 |
|
|
The program envp prints out your shells environment - very useful!
|
47 |
|
|
More generally psim is run as (this is part of the output from the -h
|
48 |
|
|
option):
|
49 |
|
|
|
50 |
|
|
psim [ ... ] [ ... ]
|
51 |
|
|
|
52 |
|
|
Where
|
53 |
|
|
|
54 |
|
|
Name of the PowerPC program to run.
|
55 |
|
|
This can either be a PowerPC binary or
|
56 |
|
|
a text file containing a device tree
|
57 |
|
|
specification.
|
58 |
|
|
PSIM will attempt to determine from the
|
59 |
|
|
specified the intended emulation
|
60 |
|
|
environment.
|
61 |
|
|
If PSIM gets it wrong, the emulation
|
62 |
|
|
environment can be specified using the
|
63 |
|
|
`-e' option (described below).
|
64 |
|
|
|
65 |
|
|
Argument to be passed to
|
66 |
|
|
These arguments will be passed to
|
67 |
|
|
(as standard C argv, argc)
|
68 |
|
|
when is started.
|
69 |
|
|
|
70 |
|
|
See below
|
71 |
|
|
|
72 |
|
|
The following are valid s:
|
73 |
|
|
|
74 |
|
|
-m Specify the processor to model (604)
|
75 |
|
|
Selects the processor to use when
|
76 |
|
|
modeling execution units. Includes:
|
77 |
|
|
604, 603 and 603e
|
78 |
|
|
|
79 |
|
|
-e specify an OS or platform to model
|
80 |
|
|
Can be any of the following:
|
81 |
|
|
bug - OEA + MOTO BUG ROM calls
|
82 |
|
|
netbsd - UEA + NetBSD system calls
|
83 |
|
|
chirp - OEA + a few OpenBoot calls
|
84 |
|
|
|
85 |
|
|
-i Print instruction counting statistics
|
86 |
|
|
|
87 |
|
|
-I Print execution unit statistics
|
88 |
|
|
|
89 |
|
|
-r Set RAM size in bytes (OEA environments)
|
90 |
|
|
|
91 |
|
|
-t [!] Enable (disable) option
|
92 |
|
|
|
93 |
|
|
-o add device to the device tree
|
94 |
|
|
|
95 |
|
|
-h -? -H give more detailed usage
|
96 |
|
|
|
97 |
|
|
|
98 |
|
|
The `-H' option gives a long usage output. This includes a complete
|
99 |
|
|
list of all the pre-configured devices.
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
----------------------------------------------------------------------
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
RUNNING GDB:
|
106 |
|
|
|
107 |
|
|
|
108 |
|
|
If you built PSIM with gdb then the following is a quick start
|
109 |
|
|
tutorial.
|
110 |
|
|
|
111 |
|
|
At present GDB, if configured big-endian (say) unlike PSIM, does not
|
112 |
|
|
support the debugging of little endian binaries. If you find that
|
113 |
|
|
your program won't run at all, make certain that GDB and your
|
114 |
|
|
program's endianness match.
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
The most important thing is that before you can run the simulator you
|
118 |
|
|
must enable it. For the simulator, gdb is started like any program:
|
119 |
|
|
|
120 |
|
|
$ powerpc-unknown-eabi-gdb psim-test/uea/envp.be
|
121 |
|
|
|
122 |
|
|
Next the simulator is enabled. The command `target sim' accepts the
|
123 |
|
|
same options as can be specified on the PSIM command line.
|
124 |
|
|
|
125 |
|
|
(gdb) target sim
|
126 |
|
|
|
127 |
|
|
To trace the communication between psim and gdb specify `target sim -t
|
128 |
|
|
gdb'. Once enabled, the binary needs to be loaded, any breakpoints of
|
129 |
|
|
interest set, and the program run:
|
130 |
|
|
|
131 |
|
|
(gdb) load
|
132 |
|
|
(gdb) break main
|
133 |
|
|
(gdb) run
|
134 |
|
|
.
|
135 |
|
|
.
|
136 |
|
|
.
|
137 |
|
|
|
138 |
|
|
In addition, if you are wanting to run a program described by a device
|
139 |
|
|
tree you can `attach' to the simulation using (I assume that you have
|
140 |
|
|
applied the attach patch):
|
141 |
|
|
|
142 |
|
|
$ cd psim-test/tree
|
143 |
|
|
$ powerpc-unknown-eabi-gdb
|
144 |
|
|
(gdb) target sim
|
145 |
|
|
(gdb) attach device-tree
|
146 |
|
|
(gdb) run
|
147 |
|
|
|
148 |
|
|
Here GDB takes the programs initial state from the attached
|
149 |
|
|
device-tree instead of forcing initialisation.
|
150 |
|
|
|
151 |
|
|
|
152 |
|
|
----------------------------------------------------------------------
|
153 |
|
|
|
154 |
|
|
|
155 |
|
|
PROFILING:
|
156 |
|
|
|
157 |
|
|
|
158 |
|
|
PSIM includes a number of performance monitoring (profiling)
|
159 |
|
|
facilities:
|
160 |
|
|
|
161 |
|
|
o instruction frequency counting
|
162 |
|
|
|
163 |
|
|
o execution unit modeling (records
|
164 |
|
|
effective usage of units).
|
165 |
|
|
|
166 |
|
|
o instruction cache performance
|
167 |
|
|
|
168 |
|
|
As discussed in the file INSTALL, each can be configured to individual
|
169 |
|
|
requirements.
|
170 |
|
|
|
171 |
|
|
|
172 |
|
|
-i Enable instruction counting.
|
173 |
|
|
|
174 |
|
|
The frequency of all instructions is tabulated. In
|
175 |
|
|
addition (f configured) the hit/miss rate of the
|
176 |
|
|
instruction cache is output.
|
177 |
|
|
|
178 |
|
|
|
179 |
|
|
-I Enable execution unit analysis.
|
180 |
|
|
|
181 |
|
|
In addition to counting basic instructions also model
|
182 |
|
|
the performance of the processors execution units
|
183 |
|
|
|
184 |
|
|
|
185 |
|
|
-m
|
186 |
|
|
|
187 |
|
|
Select the processor to be modelled.
|
188 |
|
|
|
189 |
|
|
For execution unit analysis specify the processor that
|
190 |
|
|
is to be analysed. By default the 604 is modelled
|
191 |
|
|
however, support for other processors such as the
|
192 |
|
|
603 and 603e is included.
|
193 |
|
|
|
194 |
|
|
The output from a performance run (on a P90) for the program
|
195 |
|
|
psim-test/profile/bench is below. In this run psim was fairly
|
196 |
|
|
agressively configured (see the file INSTALL for compile time
|
197 |
|
|
configuration).
|
198 |
|
|
|
199 |
|
|
CPU #1 executed 41,994 AND instructions.
|
200 |
|
|
CPU #1 executed 519,785 AND Immediate instructions.
|
201 |
|
|
CPU #1 executed 680,058 Add instructions.
|
202 |
|
|
CPU #1 executed 41,994 Add Extended instructions.
|
203 |
|
|
CPU #1 executed 921,916 Add Immediate instructions.
|
204 |
|
|
CPU #1 executed 221,199 Add Immediate Carrying instructions.
|
205 |
|
|
CPU #1 executed 943,823 Add Immediate Shifted instructions.
|
206 |
|
|
CPU #1 executed 471,909 Add to Zero Extended instructions.
|
207 |
|
|
CPU #1 executed 571,915 Branch instructions.
|
208 |
|
|
CPU #1 executed 1,992,403 Branch Conditional instructions.
|
209 |
|
|
CPU #1 executed 571,910 Branch Conditional to Link Register instructions.
|
210 |
|
|
CPU #1 executed 320,431 Compare instructions.
|
211 |
|
|
CPU #1 executed 471,911 Compare Immediate instructions.
|
212 |
|
|
CPU #1 executed 145,867 Compare Logical instructions.
|
213 |
|
|
CPU #1 executed 442,414 Compare Logical Immediate instructions.
|
214 |
|
|
CPU #1 executed 1 Condition Register XOR instruction.
|
215 |
|
|
CPU #1 executed 103,873 Divide Word instructions.
|
216 |
|
|
CPU #1 executed 104,275 Divide Word Unsigned instructions.
|
217 |
|
|
CPU #1 executed 132,510 Extend Sign Byte instructions.
|
218 |
|
|
CPU #1 executed 178,895 Extend Sign Half Word instructions.
|
219 |
|
|
CPU #1 executed 871,920 Load Word and Zero instructions.
|
220 |
|
|
CPU #1 executed 41,994 Move From Condition Register instructions.
|
221 |
|
|
CPU #1 executed 100,005 Move from Special Purpose Register instructions.
|
222 |
|
|
CPU #1 executed 100,002 Move to Special Purpose Register instructions.
|
223 |
|
|
CPU #1 executed 804,619 Multiply Low Word instructions.
|
224 |
|
|
CPU #1 executed 421,201 OR instructions.
|
225 |
|
|
CPU #1 executed 471,910 OR Immediate instructions.
|
226 |
|
|
CPU #1 executed 1,292,020 Rotate Left Word Immediate then AND with Mask instructions.
|
227 |
|
|
CPU #1 executed 663,613 Shift Left Word instructions.
|
228 |
|
|
CPU #1 executed 1,151,564 Shift Right Algebraic Word Immediate instructions.
|
229 |
|
|
CPU #1 executed 871,922 Store Word instructions.
|
230 |
|
|
CPU #1 executed 100,004 Store Word with Update instructions.
|
231 |
|
|
CPU #1 executed 887,804 Subtract From instructions.
|
232 |
|
|
CPU #1 executed 83,988 Subtract From Immediate Carrying instructions.
|
233 |
|
|
CPU #1 executed 1 System Call instruction.
|
234 |
|
|
CPU #1 executed 207,746 XOR instructions.
|
235 |
|
|
|
236 |
|
|
CPU #1 executed 23,740,856 cycles.
|
237 |
|
|
CPU #1 executed 10,242,780 stalls waiting for data.
|
238 |
|
|
CPU #1 executed 1 stall waiting for a function unit.
|
239 |
|
|
CPU #1 executed 1 stall waiting for serialization.
|
240 |
|
|
CPU #1 executed 1,757,900 times a write-back slot was unavailable.
|
241 |
|
|
CPU #1 executed 1,088,135 branches.
|
242 |
|
|
CPU #1 executed 2,048,093 conditional branches fell through.
|
243 |
|
|
CPU #1 executed 1,088,135 successful branch predictions.
|
244 |
|
|
CPU #1 executed 904,268 unsuccessful branch predictions.
|
245 |
|
|
CPU #1 executed 742,557 branch if the condition is FALSE conditional branches.
|
246 |
|
|
CPU #1 executed 1,249,846 branch if the condition is TRUE conditional branches.
|
247 |
|
|
CPU #1 executed 571,910 branch always conditional branches.
|
248 |
|
|
CPU #1 executed 9,493,653 1st single cycle integer functional unit instructions.
|
249 |
|
|
CPU #1 executed 1,220,900 2nd single cycle integer functional unit instructions.
|
250 |
|
|
CPU #1 executed 1,254,768 multiple cycle integer functional unit instructions.
|
251 |
|
|
CPU #1 executed 1,843,846 load/store functional unit instructions.
|
252 |
|
|
CPU #1 executed 3,136,229 branch functional unit instructions.
|
253 |
|
|
CPU #1 executed 16,949,396 instructions that were accounted for in timing info.
|
254 |
|
|
CPU #1 executed 871,920 data reads.
|
255 |
|
|
CPU #1 executed 971,926 data writes.
|
256 |
|
|
CPU #1 executed 221 icache misses.
|
257 |
|
|
CPU #1 executed 16,949,396 instructions in total.
|
258 |
|
|
|
259 |
|
|
Simulator speed was 250,731 instructions/second
|
260 |
|
|
|
261 |
|
|
|
262 |
|
|
----------------------------------------------------------------------
|
263 |
|
|
|
264 |
|
|
|
265 |
|
|
PSIM CONFIGURATION - THE DEVICE TREE
|
266 |
|
|
|
267 |
|
|
|
268 |
|
|
Internally PSIM's configuration is controlled by a tree data
|
269 |
|
|
structure. This structure, created at run-time, intentionally
|
270 |
|
|
resembles the device tree used by OpenBoot firmware to describe a
|
271 |
|
|
machines hardware configuration.
|
272 |
|
|
|
273 |
|
|
PSIM can either create its device tree using a builtin emulation or
|
274 |
|
|
from one read in from a file.
|
275 |
|
|
|
276 |
|
|
During startup, the device tree is created using the following steps:
|
277 |
|
|
|
278 |
|
|
o Initial empty tree is created
|
279 |
|
|
|
280 |
|
|
o Any tree entry options specified on the
|
281 |
|
|
command line are merged in (the -o
|
282 |
|
|
option is used).
|
283 |
|
|
|
284 |
|
|
It should be pointed out that most of the
|
285 |
|
|
command line options (eg -r, -e, -m, -t
|
286 |
|
|
are all just short hand for corresponding
|
287 |
|
|
-o options).
|
288 |
|
|
|
289 |
|
|
o If the specified program is a device tree spec, that
|
290 |
|
|
is loaded.
|
291 |
|
|
|
292 |
|
|
If the specified program is a text file it is assumed
|
293 |
|
|
that that file contains a further specification of the
|
294 |
|
|
simulators device tree. That tree is loaded and
|
295 |
|
|
merged with the current tree options.
|
296 |
|
|
|
297 |
|
|
o The selected emulation fills out any remaining details.
|
298 |
|
|
|
299 |
|
|
By this stage the emulation environment that the program
|
300 |
|
|
needs will either be specified in the device tree
|
301 |
|
|
(through the -e option) or determined from the
|
302 |
|
|
characteristics of the binary.
|
303 |
|
|
|
304 |
|
|
The selected emulation will then fill out any missing
|
305 |
|
|
nodes in the device tree.
|
306 |
|
|
|
307 |
|
|
Most importantly earlier additions to the tree are not overridden by
|
308 |
|
|
later additions. Thus, command line options override information
|
309 |
|
|
found in the program file and both override any builtin emulation
|
310 |
|
|
entries.
|
311 |
|
|
|
312 |
|
|
The following is a summary of the most useful runtime configuration
|
313 |
|
|
options:
|
314 |
|
|
|
315 |
|
|
-e
|
316 |
|
|
-o '/openprom/options/os-emul '
|
317 |
|
|
|
318 |
|
|
Run program using the run-time
|
319 |
|
|
environment.
|
320 |
|
|
|
321 |
|
|
-r
|
322 |
|
|
-o '/openprom/options/oea-memory-size '
|
323 |
|
|
|
324 |
|
|
Set the size of the first bank of memory
|
325 |
|
|
(RAM from address 0 up).
|
326 |
|
|
|
327 |
|
|
-t print-device-tree
|
328 |
|
|
-o '/openprom/trace/print-device-tree 1'
|
329 |
|
|
|
330 |
|
|
-t dump-device-tree
|
331 |
|
|
-o '/openprom/trace/dump-device-tree 1'
|
332 |
|
|
|
333 |
|
|
Print out the device tree once it has been fully
|
334 |
|
|
populated. For dump-device-tree, exit simulator after
|
335 |
|
|
dumping the tree.
|
336 |
|
|
|
337 |
|
|
PSIM is able to reload the dumped device tree.
|
338 |
|
|
|
339 |
|
|
The format of the dumped tree is under development.
|
340 |
|
|
|
341 |
|
|
-o '/openprom/options/smp '
|
342 |
|
|
|
343 |
|
|
Enable processors for the simulation run.
|
344 |
|
|
See the directory psim-test/oea for an example.
|
345 |
|
|
|
346 |
|
|
-o '/openprom/options/alignment '
|
347 |
|
|
|
348 |
|
|
Where is 1 - nonstrict or 2 - strict.
|
349 |
|
|
Specify if the missaligned access are allowed
|
350 |
|
|
(non-strict) or result in an alignment exception
|
351 |
|
|
(strict).
|
352 |
|
|
|
353 |
|
|
Devices (if included in the file device_table.c) can also be specified
|
354 |
|
|
in a similar way. For instance, to add a second serial port, a
|
355 |
|
|
command like:
|
356 |
|
|
|
357 |
|
|
-o '/iobus@0x400000/console@0x000010'
|
358 |
|
|
|
359 |
|
|
would create a `console' device at offset 0x10 within the `iobus' at
|
360 |
|
|
memory address 0x400000.
|
361 |
|
|
|
362 |
|
|
For more detailed information on device specifiers see the notes on
|
363 |
|
|
the function dump_device_tree in the file device.c (found in the
|
364 |
|
|
source code).
|
365 |
|
|
|
366 |
|
|
|
367 |
|
|
----------------------------------------------------------------------
|
368 |
|
|
|
369 |
|
|
|
370 |
|
|
BUILDING A BUG/OEA DEVELOPMENT ENVIRONMENT
|
371 |
|
|
|
372 |
|
|
|
373 |
|
|
Background:
|
374 |
|
|
|
375 |
|
|
|
376 |
|
|
Included in many PowerPC systems is Motorola's BUG monitor. This
|
377 |
|
|
monitor includes, for client programs, a set of services that allow
|
378 |
|
|
that program to interact with hardware devices such as the console using
|
379 |
|
|
a simple system call interface.
|
380 |
|
|
|
381 |
|
|
PSIM is able to emulate a number of the services (including the
|
382 |
|
|
console IO calls). If additional services are needed they can easily
|
383 |
|
|
be added.
|
384 |
|
|
|
385 |
|
|
Cygnus support's newlib library includes includes an interface to the
|
386 |
|
|
MOTO BUG services. The notes below discuss how I both built and run
|
387 |
|
|
programs compiled using this library on PSIM.
|
388 |
|
|
|
389 |
|
|
The only confusing part about building a development environment based
|
390 |
|
|
around newlib/binutils/gcc is a chicken/egg problem with include
|
391 |
|
|
files:
|
392 |
|
|
|
393 |
|
|
For GCC to build, a fairly complete set of include
|
394 |
|
|
files must be installed but newlib won't install its
|
395 |
|
|
include files until it has been built with gcc ...
|
396 |
|
|
|
397 |
|
|
I get around this by installing the problematic include files by hand.
|
398 |
|
|
|
399 |
|
|
|
400 |
|
|
Preparation:
|
401 |
|
|
|
402 |
|
|
|
403 |
|
|
The following files are needed:
|
404 |
|
|
|
405 |
|
|
From your favorite FTP site, the sources to gas/ld and gcc - mine
|
406 |
|
|
happens to be archie.au :
|
407 |
|
|
|
408 |
|
|
ftp://archie.au/gnu/binutils-2.6.tar.gz
|
409 |
|
|
ftp://archie.au/gnu/gcc-2.7.2.tar.gz
|
410 |
|
|
|
411 |
|
|
From ftp://ftp.cygnus.com/pub/newlib the source code to a library:
|
412 |
|
|
|
413 |
|
|
ftp://ftp.cygnus.com/pub/newlib/newlib-1.7.0.tar.gz
|
414 |
|
|
|
415 |
|
|
From ftp://ftp.ci.com.au/pub/psim some minor patches and updates to
|
416 |
|
|
the above library:
|
417 |
|
|
|
418 |
|
|
ftp://ftp.ci.com.au/pub/psim/newlib-1.7.0+float+ppc-asm.tar.gz
|
419 |
|
|
ftp://ftp.ci.com.au/pub/psim/newlib-1.7.0+ppc-fix.diff.gz
|
420 |
|
|
ftp://ftp.ci.com.au/pub/psim/binutils-2.6+note.diff.gz
|
421 |
|
|
|
422 |
|
|
In addition you'll need to decide where you will be installing the
|
423 |
|
|
development environment. You will notice that in the below I install
|
424 |
|
|
things well away /usr/local instead installing everything under its
|
425 |
|
|
own directory in /applications.
|
426 |
|
|
|
427 |
|
|
|
428 |
|
|
Method:
|
429 |
|
|
|
430 |
|
|
|
431 |
|
|
These notes are based on an installation performed on a Sun-OS-4/SPARC
|
432 |
|
|
host. For other hosts and other configurations, the below should be
|
433 |
|
|
considered as a guideline only.
|
434 |
|
|
|
435 |
|
|
|
436 |
|
|
o Sanity check
|
437 |
|
|
|
438 |
|
|
$ cd .../scratch # your scratch directory
|
439 |
|
|
$ ls -1
|
440 |
|
|
binutils-2.6.tar.gz
|
441 |
|
|
binutils-2.6+note.diff.gz
|
442 |
|
|
gcc-2.7.2,tar.gz
|
443 |
|
|
newlib-1.7.0+float+ppc-asm.tar.gz
|
444 |
|
|
newlib-1.7.0+ppc-fix.diff.gz
|
445 |
|
|
newlib-1.7.0.tar.gz
|
446 |
|
|
|
447 |
|
|
|
448 |
|
|
o Unpack/build/install binutils
|
449 |
|
|
|
450 |
|
|
This is done first so that there is a gas/ld ready
|
451 |
|
|
for the building of GCC and NEWLIB.
|
452 |
|
|
|
453 |
|
|
$ cd .../scratch
|
454 |
|
|
$ gunzip < binutils-2.6.tar.gz | tar xf -
|
455 |
|
|
$ cd binutils-2.6
|
456 |
|
|
|
457 |
|
|
Optionally apply the note patch
|
458 |
|
|
|
459 |
|
|
$ gunzip ../binutils-2.6+note.diff.gz | patch
|
460 |
|
|
|
461 |
|
|
Then continue with the build
|
462 |
|
|
|
463 |
|
|
$ ./configure --target=powerpc-unknown-eabi \
|
464 |
|
|
--prefix=/applications/psim
|
465 |
|
|
$ make
|
466 |
|
|
$ make install
|
467 |
|
|
$ cd ..
|
468 |
|
|
$ rm -rf binutils-2.6
|
469 |
|
|
|
470 |
|
|
This also creates much of the installation directory
|
471 |
|
|
tree.
|
472 |
|
|
|
473 |
|
|
|
474 |
|
|
o Unpack newlib, install the include files so that they
|
475 |
|
|
are ready for GCC's build.
|
476 |
|
|
|
477 |
|
|
$ cd .../scratch
|
478 |
|
|
$ gunzip < newlib-1.7.0.tar.gz | tar xf -
|
479 |
|
|
|
480 |
|
|
New lib-1.7.0 had a few minor bugs (fixed in current):
|
481 |
|
|
the header files float.h and ppc-asm.h were missing;
|
482 |
|
|
the configure and Makefile's for the rs6000 (ppc) directory
|
483 |
|
|
contained typos:
|
484 |
|
|
|
485 |
|
|
$ cd .../scratch
|
486 |
|
|
$ cd newlib-1.7.0
|
487 |
|
|
$ gunzip < ../newlib-1.7.0+float+ppc-asm.tar.gz | tar xvf -
|
488 |
|
|
$ gunzip < ../newlib-1.7.0+ppc-fix.diff.gz | patch -p1
|
489 |
|
|
|
490 |
|
|
Finally copy the include files to where GCC will see them:
|
491 |
|
|
|
492 |
|
|
$ cd .../scratch
|
493 |
|
|
$ cd newlib-1.7.0/newlib/libc
|
494 |
|
|
$ tar cf - include | \
|
495 |
|
|
( cd /applications/psim/powerpc-unknown-eabi && tar xf - )
|
496 |
|
|
|
497 |
|
|
|
498 |
|
|
o Unpack/build gcc
|
499 |
|
|
|
500 |
|
|
$ cd .../scratch
|
501 |
|
|
$ gunzip < gcc-2.7.2,tar.gz | tar xf -
|
502 |
|
|
$ cd gcc-2.7.2
|
503 |
|
|
$ ./configure --target=powerpc-unknown-eabi \
|
504 |
|
|
--prefix=/applications/psim
|
505 |
|
|
$ make
|
506 |
|
|
$ make install
|
507 |
|
|
$ cd ..
|
508 |
|
|
$ rm -rf gcc-2.7.2
|
509 |
|
|
|
510 |
|
|
Gcc likes to install its own dummy version of float that
|
511 |
|
|
just returns an error.
|
512 |
|
|
|
513 |
|
|
$ more /applications/psim/lib/gcc-lib/powerpc-unknown-eabi/2.7.2/include/float.h
|
514 |
|
|
$ rm /applications/psim/lib/gcc-lib/powerpc-unknown-eabi/2.7.2/include/float.h
|
515 |
|
|
|
516 |
|
|
|
517 |
|
|
o Finish building/installing newlib
|
518 |
|
|
|
519 |
|
|
$ cd .../scratch
|
520 |
|
|
$ cd newlib-1.7.0
|
521 |
|
|
$ ./configure --target=powerpc-unknown-eabi \
|
522 |
|
|
--prefix=/applications/psim
|
523 |
|
|
|
524 |
|
|
Your path will need to include the recently installed
|
525 |
|
|
gas/gcc when building. Either add it to your path or
|
526 |
|
|
use:
|
527 |
|
|
|
528 |
|
|
$ PATH=/applications/psim/bin:$PATH make
|
529 |
|
|
$ PATH=/applications/psim/bin:$PATH make install
|
530 |
|
|
|
531 |
|
|
|
532 |
|
|
o Finally, test out the build
|
533 |
|
|
|
534 |
|
|
$ cat hello.c
|
535 |
|
|
main()
|
536 |
|
|
{
|
537 |
|
|
printf("hello world\n");
|
538 |
|
|
}
|
539 |
|
|
|
540 |
|
|
The binary is linked with an entry point less than 0x100000
|
541 |
|
|
(1mb) so that psim will recognize the binary as needing
|
542 |
|
|
the BUG/OEA instead of the BSD/UEA runtime environment.
|
543 |
|
|
|
544 |
|
|
$ powerpc-unknown-eabi-gcc -v -o hello \
|
545 |
|
|
-Wl,-Ttext,0x4000,-Tdata,0x10000 \
|
546 |
|
|
/applications/psim/powerpc-unknown-eabi/lib/mvme-crt0.o \
|
547 |
|
|
hello.c \
|
548 |
|
|
-lc -lmvme
|
549 |
|
|
$ powerpc-unknown-eabi-objdump -h hello
|
550 |
|
|
$ powerpc-unknown-eabi-run hello
|
551 |
|
|
|
552 |
|
|
It is also possible to force psim to use a specific
|
553 |
|
|
run-time environment using the -e option vis:
|
554 |
|
|
|
555 |
|
|
$ powerpc-unknown-eabi-run -e bug hello
|
556 |
|
|
|
557 |
|
|
|
558 |
|
|
|
559 |
|
|
|
560 |
|
|
----------------------------------------------------------------------
|
561 |
|
|
|
562 |
|
|
|
563 |
|
|
BUILDING A BSD/UEA DEVELOPMENT ENVIRONMENT
|
564 |
|
|
|
565 |
|
|
|
566 |
|
|
Background:
|
567 |
|
|
|
568 |
|
|
|
569 |
|
|
For a UEA to be useful it needs a supporting run-time environment.
|
570 |
|
|
PSIM implements a runtime environment based on the NetBSD system call
|
571 |
|
|
interface.
|
572 |
|
|
|
573 |
|
|
More than any thing, this user level emulation was the first
|
574 |
|
|
implemented because I happened to have the NetBSD source code lying
|
575 |
|
|
around.
|
576 |
|
|
|
577 |
|
|
|
578 |
|
|
Preparation:
|
579 |
|
|
|
580 |
|
|
|
581 |
|
|
This requires the NetBSD-1.1 source tree online. It can either be
|
582 |
|
|
obtained vi ftp:
|
583 |
|
|
|
584 |
|
|
try http://www.netbsd.org or ftp://ftp.netbsd.org
|
585 |
|
|
|
586 |
|
|
Alternatively obtain one of the NetBSD cdrom's. Patches to this source
|
587 |
|
|
tree that fill out much of the PowerPC code are available in:
|
588 |
|
|
|
589 |
|
|
ftp://ftp.ci.com.au/pub/clayton
|
590 |
|
|
|
591 |
|
|
Fetch everything in that directory - diffs, tar archives and scripts.
|
592 |
|
|
In addition patches to the bintuils and gcc are in:
|
593 |
|
|
|
594 |
|
|
ftp://ftp.ci.com.au/pub/psim/binutils-2.6+note.diff.gz
|
595 |
|
|
ftp://ftp.ci.com.au/pub/psim/gcc-2.7.2+sys-types.diff.gz
|
596 |
|
|
|
597 |
|
|
while the compiler (gcc) and assember (binutils) can be found at your
|
598 |
|
|
favorite gnu ftp site. I used versions:
|
599 |
|
|
|
600 |
|
|
gcc-2.7.2.tar.gz
|
601 |
|
|
binutils-2.6.tar.gz
|
602 |
|
|
|
603 |
|
|
|
604 |
|
|
|
605 |
|
|
|
606 |
|
|
Method:
|
607 |
|
|
|
608 |
|
|
|
609 |
|
|
These notes are based on an installation performed on a Solaris2/x86
|
610 |
|
|
host. For other hosts and other configurations, the below should be
|
611 |
|
|
considered as a guideline only.
|
612 |
|
|
|
613 |
|
|
|
614 |
|
|
o Sanity check
|
615 |
|
|
|
616 |
|
|
I assume that you have already obtained the NetBSD-1.1 source
|
617 |
|
|
code and unpacked it into the directory bsd-src. While the
|
618 |
|
|
full NetBSD source tree may not be needed, things are easier
|
619 |
|
|
if it is all online.
|
620 |
|
|
|
621 |
|
|
$ cd .../scratch
|
622 |
|
|
$ ls -1
|
623 |
|
|
binutils-2.6.tar.gz
|
624 |
|
|
binutils-2.6+note.diff.gz
|
625 |
|
|
clayton-include-960203.diff.gz
|
626 |
|
|
clayton-lib-960203.diff.gz
|
627 |
|
|
clayton-lib-960203.tar.gz
|
628 |
|
|
clayton-sys-960203.diff.gz
|
629 |
|
|
clayton-sys-960203.tar.gz
|
630 |
|
|
clayton.chown.sh
|
631 |
|
|
clayton.install.sh
|
632 |
|
|
clayton.lorder.sh
|
633 |
|
|
clayton.make.sh
|
634 |
|
|
gcc-2.7.2.tar.gz
|
635 |
|
|
gcc-2.7.2+sys-types.diff.gz
|
636 |
|
|
make.tar.gz
|
637 |
|
|
make.diff.gz
|
638 |
|
|
|
639 |
|
|
|
640 |
|
|
o Prepare the destination directory ready for installation.
|
641 |
|
|
|
642 |
|
|
Firstly create many of the needed directories (some are
|
643 |
|
|
created automatically later):
|
644 |
|
|
|
645 |
|
|
$ for d in \
|
646 |
|
|
/applications/psim \
|
647 |
|
|
/applications/psim/bsd-root \
|
648 |
|
|
/applications/psim/bsd-root/usr \
|
649 |
|
|
/applications/psim/bsd-root/usr/share \
|
650 |
|
|
/applications/psim/bsd-root/usr/share/doc \
|
651 |
|
|
/applications/psim/bsd-root/usr/share/doc/psd \
|
652 |
|
|
/applications/psim/bsd-root/usr/share/doc/psd/19.curses \
|
653 |
|
|
/applications/psim/bsd-root/usr/include \
|
654 |
|
|
/applications/psim/bsd-root/usr/lib \
|
655 |
|
|
/applications/psim/powerpc-unknown-eabi \
|
656 |
|
|
/applications/psim/powerpc-unknown-eabi/bin \
|
657 |
|
|
; \
|
658 |
|
|
do test -d $d || mkdir $d ; done
|
659 |
|
|
|
660 |
|
|
Next, link the BSD and GNU include directories together.
|
661 |
|
|
GCC expects include files to be in one location while the
|
662 |
|
|
bsd install expects them in a second. The link is in
|
663 |
|
|
the direction below because bsd's install also insists on
|
664 |
|
|
a directory (not a link) for its install destination.
|
665 |
|
|
|
666 |
|
|
$ rm -rf /applications/psim/powerpc-unknown-eabi/include
|
667 |
|
|
$ ln -s /applications/psim/bsd-root/usr/include \
|
668 |
|
|
/applications/psim/powerpc-unknown-eabi/include
|
669 |
|
|
|
670 |
|
|
$ ls -l /applications/psim/powerpc-unknown-eabi/include
|
671 |
|
|
lrwxr-xr-x 1 cagney wheel 39 Mar 21 18:09
|
672 |
|
|
/applications/psim/powerpc-unknown-eabi/include
|
673 |
|
|
-> /applications/psim/bsd-root/usr/include
|
674 |
|
|
|
675 |
|
|
|
676 |
|
|
o Build/install Berkeley make
|
677 |
|
|
|
678 |
|
|
The tar archive make.tar.gz contains a recent snapshot
|
679 |
|
|
of bmake from the NetBSD source tree. The notes below
|
680 |
|
|
describe how to build/install it. If you have access
|
681 |
|
|
to an even more recent version of bmake, use that.
|
682 |
|
|
|
683 |
|
|
Unpack the source code:
|
684 |
|
|
|
685 |
|
|
$ cd .../scratch
|
686 |
|
|
$ gunzip < make.tar.gz | tar xf -
|
687 |
|
|
$ cd make
|
688 |
|
|
|
689 |
|
|
Apply the patch in make.diff.gz that fixes a minor
|
690 |
|
|
problem with a build under Solaris (by now it should
|
691 |
|
|
be fixed in the NetBSD-current source tree).
|
692 |
|
|
|
693 |
|
|
$ gunzip < ../make.diff.gz | more
|
694 |
|
|
$ gunzip < ../make.diff.gz | patch
|
695 |
|
|
|
696 |
|
|
Build it
|
697 |
|
|
|
698 |
|
|
$ make -f Makefile.boot 'CC=gcc -g -DPOSIX'
|
699 |
|
|
|
700 |
|
|
With bmake built, install it into the target specific bin
|
701 |
|
|
directory:
|
702 |
|
|
|
703 |
|
|
$ cp bmake /applications/psim/powerpc-unknown-eabi/bin/make
|
704 |
|
|
$ cd ..
|
705 |
|
|
$ rm -rf make
|
706 |
|
|
|
707 |
|
|
|
708 |
|
|
o Set up a number of wrapper scripts for bmake so that it works.
|
709 |
|
|
|
710 |
|
|
In addition to needing BSD make the build process assumes
|
711 |
|
|
a number of BSD specific commands. To get around this
|
712 |
|
|
several wrapper scripts are available.
|
713 |
|
|
|
714 |
|
|
powerpc-unknown-eabi-make (clayton.make.sh)
|
715 |
|
|
|
716 |
|
|
Front end to Berkeley make setting it up for a
|
717 |
|
|
cross compilation
|
718 |
|
|
|
719 |
|
|
$ cp clayton.make.sh \
|
720 |
|
|
/applications/psim/bin/powerpc-unknown-eabi-make
|
721 |
|
|
$ chmod a+x \
|
722 |
|
|
/applications/psim/bin/powerpc-unknown-eabi-make
|
723 |
|
|
|
724 |
|
|
chown (clayton.chown.sh)
|
725 |
|
|
|
726 |
|
|
Wrapper that does not do any thing.
|
727 |
|
|
Avoids the need to be root when installing.
|
728 |
|
|
|
729 |
|
|
$ cp clayton.chown.sh \
|
730 |
|
|
/applications/psim/powerpc-unknown-eabi/bin/chown
|
731 |
|
|
$ chmod a+x \
|
732 |
|
|
/applications/psim/powerpc-unknown-eabi/bin/chown
|
733 |
|
|
|
734 |
|
|
install (clayton.install.sh)
|
735 |
|
|
|
736 |
|
|
Wrapper to strip away a number of bsd specific install
|
737 |
|
|
arguments.
|
738 |
|
|
|
739 |
|
|
$ cp clayton.install.sh \
|
740 |
|
|
/applications/psim/powerpc-unknown-eabi/bin/install
|
741 |
|
|
$ chmod a+x \
|
742 |
|
|
/applications/psim/powerpc-unknown-eabi/bin/install
|
743 |
|
|
|
744 |
|
|
lorder (clayton.lorder.sh)
|
745 |
|
|
|
746 |
|
|
Tweaked lorder script that will use nm etc from
|
747 |
|
|
binutils.
|
748 |
|
|
|
749 |
|
|
$ cp clayton.lorder.sh \
|
750 |
|
|
/applications/psim/powerpc-unknown-eabi/bin/lorder
|
751 |
|
|
$ chmod a+x \
|
752 |
|
|
/applications/psim/powerpc-unknown-eabi/bin/lorder
|
753 |
|
|
|
754 |
|
|
|
755 |
|
|
printf (?)
|
756 |
|
|
|
757 |
|
|
Some operating systems don't include the program
|
758 |
|
|
printf. If you host doesn't have one, then a
|
759 |
|
|
good source is the gnu sh-utils version.
|
760 |
|
|
|
761 |
|
|
Again, if that program is missing, then I suggest
|
762 |
|
|
installing it onto the powerpc specific program
|
763 |
|
|
directory:
|
764 |
|
|
|
765 |
|
|
/applications/psim/powerpc-unknown-eabi/bin
|
766 |
|
|
|
767 |
|
|
|
768 |
|
|
o Unpack the bsd source code (if you haven't already)
|
769 |
|
|
|
770 |
|
|
If you're short on disk space (like me) just unpack:
|
771 |
|
|
|
772 |
|
|
sys, lib, share/mk, include, usr.sbin/config,
|
773 |
|
|
usr.sbin/dbsym, gnu/lib/libg++/g++-include,
|
774 |
|
|
usr.bin/lex
|
775 |
|
|
|
776 |
|
|
Otherwize, assuming you have a CD-DRIVE:
|
777 |
|
|
|
778 |
|
|
$ cd .../scratch
|
779 |
|
|
$ mkdir bsd-src
|
780 |
|
|
$ cd bsd-src
|
781 |
|
|
$ for d in /cdrom/bsdisc_12_95_disc2/NetBSD-1.1/source/*11
|
782 |
|
|
do
|
783 |
|
|
echo $d
|
784 |
|
|
cat $d/*.?? | gunzip | tar xf -
|
785 |
|
|
done
|
786 |
|
|
|
787 |
|
|
Flatten the directory structure a little.
|
788 |
|
|
|
789 |
|
|
$ mv usr/src/* .
|
790 |
|
|
$ rmdir usr/src usr
|
791 |
|
|
$ cd ..
|
792 |
|
|
|
793 |
|
|
|
794 |
|
|
o Apply the clayton (PowerPC) patches to your constructed
|
795 |
|
|
tree.
|
796 |
|
|
|
797 |
|
|
$ cd .../scratch
|
798 |
|
|
$ cd bsd-src
|
799 |
|
|
|
800 |
|
|
Diffs are applied using something like:
|
801 |
|
|
|
802 |
|
|
$ gunzip < ../clayton-include-960312.diff.gz | patch -p1
|
803 |
|
|
$ gunzip < ../clayton-lib-960203.diff.gz | patch -p1
|
804 |
|
|
$ gunzip < ../clayton-sys-960203.diff.gz | patch -p1
|
805 |
|
|
|
806 |
|
|
The patch to sys/dev/pci/ncr.c.rej might fail.
|
807 |
|
|
|
808 |
|
|
The tar archives have a different problem, you need
|
809 |
|
|
to remove the `src' prefix. I used
|
810 |
|
|
|
811 |
|
|
$ ln -s . src
|
812 |
|
|
$ gunzip < ../clayton-lib-960203.tar.gz | tar xvf -
|
813 |
|
|
$ gunzip < ../clayton-sys-960203.tar.gz | tar xvf -
|
814 |
|
|
|
815 |
|
|
So that src/xxx unpacked into ./xxx
|
816 |
|
|
|
817 |
|
|
$ cd ..
|
818 |
|
|
|
819 |
|
|
|
820 |
|
|
o install Berkeley make's include (mk) files.
|
821 |
|
|
|
822 |
|
|
$ cd .../scrath
|
823 |
|
|
$ cd bsd-src/share
|
824 |
|
|
$ tar cf - mk | ( cd /applications/psim/bsd-root/usr/share \
|
825 |
|
|
&& tar xvf - )
|
826 |
|
|
$ cd ../..
|
827 |
|
|
|
828 |
|
|
|
829 |
|
|
o Install the include files
|
830 |
|
|
|
831 |
|
|
$ cd .../scratch
|
832 |
|
|
$ cd bsd-src/include
|
833 |
|
|
$ powerpc-unknown-eabi-make install
|
834 |
|
|
$ cd ../..
|
835 |
|
|
|
836 |
|
|
|
837 |
|
|
o Install a few other include files.
|
838 |
|
|
|
839 |
|
|
As discussed above in the section on building libnew,
|
840 |
|
|
the build process can have chicken/egg problems. In the
|
841 |
|
|
case of BSD's libc, it wants to use several include files
|
842 |
|
|
(from the installed include directory) before they are
|
843 |
|
|
installed. Just copy them in as seen below:
|
844 |
|
|
|
845 |
|
|
$ cd .../scratch
|
846 |
|
|
$ cd bsd-src
|
847 |
|
|
$ cp gnu/lib/libg++/g++-include/values.h \
|
848 |
|
|
/applications/psim/powerpc-unknown-eabi/include
|
849 |
|
|
$ cp lib/libcurses/curses.h \
|
850 |
|
|
/applications/psim/powerpc-unknown-eabi/include
|
851 |
|
|
$ cd ..
|
852 |
|
|
|
853 |
|
|
|
854 |
|
|
o Unpack/patch/build/install BINUTILS
|
855 |
|
|
|
856 |
|
|
$ cd .../scratch
|
857 |
|
|
$ gunzip < binutils-2.6.tar.gz | tar xf -
|
858 |
|
|
|
859 |
|
|
gas (bfd) 2.6 didn't support the reading and writing of
|
860 |
|
|
note sections. The patch binutils-2.6+note.diff.gz
|
861 |
|
|
adds support for this. PowerPC/ELF boot files being loaded
|
862 |
|
|
by OpenBoot ROM's should contain a PowerPC note section.
|
863 |
|
|
|
864 |
|
|
$ cd .../scratch
|
865 |
|
|
$ cd binutils-2.6/bfd
|
866 |
|
|
$ gunzip < ../../binutils-2.6+note.diff.gz | more
|
867 |
|
|
$ gunzip < ../../binutils-2.6+note.diff.gz | patch
|
868 |
|
|
$ cd ../..
|
869 |
|
|
|
870 |
|
|
Then continue with the build
|
871 |
|
|
|
872 |
|
|
$ cd .../scratch
|
873 |
|
|
$ cd binutils-2.6
|
874 |
|
|
$ ./configure --target=powerpc-unknown-eabi \
|
875 |
|
|
--prefix=/applications/psim
|
876 |
|
|
$ make
|
877 |
|
|
$ make install
|
878 |
|
|
$ cd ..
|
879 |
|
|
$ rm -rf binutils-2.6
|
880 |
|
|
|
881 |
|
|
This has the intended side effect of partially populating
|
882 |
|
|
the psim directory tree which makes follow on steps easier.
|
883 |
|
|
|
884 |
|
|
|
885 |
|
|
o Unpack/patch/build/install GCC
|
886 |
|
|
|
887 |
|
|
$ cd .../scratch
|
888 |
|
|
$ gunzip < gcc-2.7.2.tar.gz | tar xf -
|
889 |
|
|
$ cd gcc-2.7.2
|
890 |
|
|
|
891 |
|
|
GCC-2.7.2 and the BSD include files have a conflicting type
|
892 |
|
|
declaration. The patch below gets around this problem
|
893 |
|
|
(it may still be applicable to more recent versions of
|
894 |
|
|
GCC):
|
895 |
|
|
|
896 |
|
|
$ gunzip < ../gcc-2.7.2+sys-types.diff.gz | more
|
897 |
|
|
$ gunzip < ../gcc-2.7.2+sys-types.diff.gz | patch
|
898 |
|
|
|
899 |
|
|
If your version of GCC includes the file ginclude/ppc-asm.h
|
900 |
|
|
then you should install that header file into the directory:
|
901 |
|
|
/applications/psim/powerpc-unknown-eabi/include. More
|
902 |
|
|
recent versions of GCC expect this file to be installed:
|
903 |
|
|
|
904 |
|
|
$ test -r ginclude/ppc-asm.h \
|
905 |
|
|
&& cp ginclude/ppc-asm.h \
|
906 |
|
|
/applications/psim/powerpc-unknown-eabi/include
|
907 |
|
|
|
908 |
|
|
Other than that, assuming the include files installed
|
909 |
|
|
okay, the rest should be fine ....
|
910 |
|
|
|
911 |
|
|
$ ./configure --target=powerpc-unknown-eabi \
|
912 |
|
|
--prefix=/applications/psim
|
913 |
|
|
$ make CC=gcc
|
914 |
|
|
$ make CC=gcc install
|
915 |
|
|
$ cd ..
|
916 |
|
|
$ rm -rf gcc-2.7.2
|
917 |
|
|
|
918 |
|
|
|
919 |
|
|
o Build/install the Berkeley library:
|
920 |
|
|
|
921 |
|
|
$ cd .../scratch
|
922 |
|
|
$ cd bsd-src/lib
|
923 |
|
|
$ powerpc-unknown-eabi-make
|
924 |
|
|
$ powerpc-unknown-eabi-make install
|
925 |
|
|
$ cd ../..
|
926 |
|
|
|
927 |
|
|
If you encounter problems check the following (each
|
928 |
|
|
discussed above):
|
929 |
|
|
|
930 |
|
|
o GCC and BSD have a common include
|
931 |
|
|
directory
|
932 |
|
|
|
933 |
|
|
o all the missing include files installed
|
934 |
|
|
|
935 |
|
|
o all the wrapper programs installed
|
936 |
|
|
|
937 |
|
|
|
938 |
|
|
o Build/run a simple BSD program
|
939 |
|
|
|
940 |
|
|
$ cd .../scratch
|
941 |
|
|
$ cd bsd-src/usr.bin/printenv
|
942 |
|
|
$ powerpc-unknown-eabi-make
|
943 |
|
|
$ powerpc-unknown-eabi-run printenv
|
944 |
|
|
.
|
945 |
|
|
.
|
946 |
|
|
.
|
947 |
|
|
|
948 |
|
|
|
949 |
|
|
----------------------------------------------------------------------
|