To make a simulator truely useful, the user needs to construct a development environment within which software development can occure.
Given the availability of the tools required to construct this environment: a compiler (GCC), an assembler (GAS), and a linker (GLD) along with several alternative C libraries one would hope that an environment could be quickly built.
Unfortunatly, while not difficult, constructing such environments can encounter problems. This document walks the user through the process of creating several alternatives:
Included in many PowerPC systems is Motorola's BUG monitor. This monitor includes, for client programs, a set of services that allow that program to interact with hardware devices such as the console using a simple system call interface.
PSIM is able to emulate a number of the services (including the console IO calls). If additional services are needed they can easily be added.
Cygnus support's newlib library includes includes an interface to the MOTO BUG services. The notes below discuss how I both built and run programs compiled using this library on PSIM.
The only confusing part about building a development environment based around newlib/binutils/gcc is a chicken/egg problem with include files: For GCC to build, a fairly complete set of include files must be installed but newlib won't install its include files until it has been built with gcc ...
I get around this by installing the problematic include files by hand.
The following files are needed:
From your favorite FTP site, the sources to gas/ld and gcc - mine happens to be archie.au :
ftp://archie.au/gnu/binutils-2.7.tar.gz ftp://archie.au/gnu/gcc-2.7.2.1.tar.gz
From ftp://ftp.cygnus.com/pub/newlib the source code to a library:
ftp://ftp.cygnus.com/pub/newlib/newlib-1.7.0.tar.gz
From ftp://ftp.ci.com.au/pub/psim some minor patches and updates to the above library:
ftp://ftp.ci.com.au/pub/psim/newlib-1.7.0+float+ppc-asm.tar.gz ftp://ftp.ci.com.au/pub/psim/newlib-1.7.0+ppc-fix.diff.gz
In addition you'll need to decide where you will be installing the development environment. You will notice that in the below I install things well away /usr/local instead installing everything under its own directory in /applications.
These notes are based on an installation performed on a Sun-OS-4/SPARC host. For other hosts and other configurations, the below should be considered as a guideline only.
$ cd /tmp/scratch # your scratch directory $ PSIM=/applications/psim $ ls -1 binutils-2.7.tar.gz gcc-2.7.2,tar.gz newlib-1.7.0+float+ppc-asm.tar.gz newlib-1.7.0+ppc-fix.diff.gz newlib-1.7.0.tar.gz
This is done first so that there is a gas/ld ready for the building of GCC and NEWLIB.
$ cd /tmp/scratch $ PSIM=/applications/psim $ gunzip < binutils-2.7.tar.gz | tar xf - $ cd binutils-2.7 $ ./configure --target=powerpc-unknown-eabi \ --prefix=$PSIM $ make $ make install $ cd .. $ rm -rf binutils-2.7
This also creates much of the installation directory tree.
$ cd /tmp/scratch $ PSIM=/applications/psim $ gunzip < newlib-1.7.0.tar.gz | tar xf -
New lib-1.7.0 had a few minor bugs (fixed in current): the header files float.h and ppc-asm.h were missing; the configure and Makefile's for the rs6000 (ppc) directory contained typos:
$ cd /tmp/scratch $ PSIM=/applications/psim $ cd newlib-1.7.0 $ gunzip < ../newlib-1.7.0+float+ppc-asm.tar.gz | tar xvf - $ gunzip < ../newlib-1.7.0+ppc-fix.diff.gz | patch -p1
Finally copy the include files to where GCC will see them:
$ cd /tmp/scratch $ PSIM=/applications/psim $ cd newlib-1.7.0/newlib/libc $ tar cf - include | \ ( cd $PSIM/powerpc-unknown-eabi && tar xf - )
$ cd /tmp/scratch $ PSIM=/applications/psim $ gunzip < gcc-2.7.2,tar.gz | tar xf - $ cd gcc-2.7.2 $ ./configure --target=powerpc-unknown-eabi \ --prefix=$PSIM $ make $ make install $ cd .. $ rm -rf gcc-2.7.2
Gcc likes to install its own dummy version of float that just returns an error.
$ cd /tmp/scratch $ PSIM=/applications/psim $ more $PSIM/lib/gcc-lib/powerpc-unknown-eabi/2.7.2/include/float.h $ rm $PSIM/lib/gcc-lib/powerpc-unknown-eabi/2.7.2/include/float.h
$ cd /tmp/scratch $ PSIM=/applications/psim $ cd newlib-1.7.0 $ ./configure --target=powerpc-unknown-eabi \ --prefix=$PSIM
Your path will need to include the recently installed gas/gcc when building. Either add it to your path or use:
$ cd /tmp/scratch $ PSIM=/applications/psim $ PATH=$PSIM/bin:$PATH make $ PATH=$PSIM/bin:$PATH make install
$ cat hello.c main() { printf("hello world\n"); }
The binary is linked with an entry point less than 0x100000 (1mb) so that psim will recognize the binary as needing the BUG/OEA instead of the BSD/UEA runtime environment.
$ PSIM=/applications/psim $ powerpc-unknown-eabi-gcc -v -o hello \ -Wl,-Ttext,0x4000,-Tdata,0x10000 \ $PSIM/powerpc-unknown-eabi/lib/mvme-crt0.o \ hello.c \ -lc -lmvme $ powerpc-unknown-eabi-objdump -h hello $ powerpc-unknown-eabi-run hello
It is also possible to force psim to use a specific run-time environment using the -e option vis:
$ powerpc-unknown-eabi-run -e bug hello
NetBSD, a UNIX like operating system has been ported to many many architectures and platforms. The portability of this operating system was exploited in creating a user mode UNIX development environment for PSIM.
The notes below were based on using a snapshot of NetBSD taken on the 7th of December 1996. Since NetBSD at the time of writing NetBSD was actively been ported to the PowerPC some or all of the patches below may no longer be required.
See the NetBSD Project web page for up-to-date information on the current status of the PowerPC port:
http://www.netbsd.org/
A copy of the NetBSD source code can be found in (the second URL is the one I use here in Australia):
ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-current/tar_files/src or ftp://netbsd.rmit.edu.au/pub/NetBSD/NetBSD-current/tar_files/src
While you are free to download all the tar files, only the below will be required:
include.tar.gz lib.tar.gz share.tar.gz sys.tar.gz usr.bin.tar.gz
Patches for NetBSD to add PowerPC support can be found in:
ftp://ftp.ci.com.au/pub/clayton
Fetch everything in that directory - diffs, tar archives and scripts.
while the compiler (gcc) and assember (binutils) can be found at your favorite gnu ftp site. I used versions:
gcc-2.7.2.1.tar.gz binutils-2.7.tar.gz
These notes are based on an installation performed on a Solaris2/x86 host. For other hosts and other configurations, the below should be considered as a guideline only.
The directory `/tmp/scratch' can be replaced by any local build directory of your choice.
The directory `/applications/psim' should be replaced by the destination directory for your particular site.
Just to make certain that everything is available:
$ cd /tmp/scratch $ PSIM=/applications/psim $ ls -1 binutils-2.7.tar.gz clayton-include-961205.diff clayton-lib-961205.diff clayton-lib-961219.tar.gz clayton-share-961205.diff clayton-sys-961205.diff clayton.chown.sh clayton.install.sh clayton.lorder.sh clayton.make.sh clayton.tsort.sh gcc-2.7.2.1.tar.gz gcc-2.7.2.1+sys-types.diff include.tar.gz lib.tar.gz share.tar.gz sys.tar.gz usr.bin.tar.gz
Firstly create many of the needed directories (some are created automatically later):
$ cd /tmp/scratch $ PSIM=/applications/psim $ for d in \ $PSIM \ $PSIM/bin \ $PSIM/bsd-root \ $PSIM/bsd-root/usr \ $PSIM/bsd-root/usr/share \ $PSIM/bsd-root/usr/share/doc \ $PSIM/bsd-root/usr/share/doc/psd \ $PSIM/bsd-root/usr/share/doc/psd/19.curses \ $PSIM/bsd-root/usr/include \ $PSIM/bsd-root/usr/lib \ $PSIM/powerpc-unknown-eabi \ $PSIM/powerpc-unknown-eabi/bin \ ; do \ test -d $d || mkdir $d \ ; done
Next, link the BSD and GNU include directories together. GCC expects include files to be in one location while the bsd install expects them in a second. The link is in the direction below because bsd's install also insists on a directory (not a link) for its install destination.
$ cd /tmp/scratch $ PSIM=/applications/psim $ rm -rf $PSIM/powerpc-unknown-eabi/include $ ln -s $PSIM/bsd-root/usr/include \ $PSIM/powerpc-unknown-eabi/include $ ls -l $PSIM/powerpc-unknown-eabi/include lrwxr-xr-x 1 cagney wheel 39 Mar 21 18:09 /applications/psim/powerpc-unknown-eabi/include -> /applications/psim/bsd-root/usr/include
I just unpack the components I know I'll be using later:
$ cd /tmp/scratch $ PSIM=/applications/psim $ for a in \ include.tar.gz \ lib.tar.gz \ sys.tar.gz \ share.tar.gz \ usr.bin.tar.gz \ ; do \ gunzip < $a | tar xvf - \ src/include \ src/lib \ src/sys \ src/share/mk \ src/usr.bin/lex \ src/usr.bin/make \ src/usr.bin/printenv \ src/usr.sbin/config \ ; done
Diffs are applied using something like:
$ cd /tmp/scratch $ PSIM=/applications/psim $ cd src $ patch -p1 < ../clayton-include-961205.diff $ patch -p1 < ../clayton-lib-961205.diff $ patch -p1 < ../clayton-share-961205.diff $ patch -p1 < ../clayton-sys-961205.diff $ cd ..
Then the tar archives, containing additional files, are unpacked:
$ cd /tmp/scratch $ PSIM=/applications/psim $ gunzip < clayton-lib-961219.tar.gz | tar xvf -
$ cd /tmp/scratch $ PSIM=/applications/psim $ cd src/usr.bin/make $ make -f Makefile.boot \ 'CC=cc -g -DPOSIX' \ MACHINE=powerpc \ MACHINE_ARCH=powerpc
You may encounter compiler warnings about the redefinition of the macros
MACHINE
and POSIX
. Don't be concerned by this, the exact
definition of these macro's is overridden later using a shell script.
If you encounter a linker problem (lst.lib/*.o not found) just perform
the link by hand.
$ cc -o bmake *.o
With bmake built, install it into the target specific bin directory:
$ cp bmake $PSIM/powerpc-unknown-eabi/bin/make $ cd ../../..
In addition to needing BSD make the build process assumes a number of BSD specific commands. To get around this several wrapper scripts are available.
powerpc-unknown-eabi-make
$ cd /tmp/scratch $ PSIM=/applications/psim $ sed -e 's,^root=.*,root='$PSIM',' \ < clayton.make.sh \ > $PSIM/bin/powerpc-unknown-eabi-make $ chmod a+x $PSIM/bin/powerpc-unknown-eabi-make
chown
$ cd /tmp/scratch $ PSIM=/applications/psim $ cp clayton.chown.sh $PSIM/powerpc-unknown-eabi/bin/chown $ chmod a+x $PSIM/powerpc-unknown-eabi/bin/chown
install
$ cd /tmp/scratch $ PSIM=/applications/psim $ cp clayton.install.sh $PSIM/powerpc-unknown-eabi/bin/install $ chmod a+x $PSIM/powerpc-unknown-eabi/bin/install
lorder
$ cd /tmp/scratch $ PSIM=/applications/psim $ cp clayton.lorder.sh $PSIM/powerpc-unknown-eabi/bin/lorder $ chmod a+x $PSIM/powerpc-unknown-eabi/bin/lorder
tsort
$ cd /tmp/scratch $ PSIM=/applications/psim $ cp clayton.tsort.sh $PSIM/powerpc-unknown-eabi/bin/tsort $ chmod a+x $PSIM/powerpc-unknown-eabi/bin/tsort
printf
$ cd /tmp/scratch $ PSIM=/applications/psim $ which printf ... unpack and build sh-utils $ cp printf $PSIM/powerpc-unknown-eabi/bin/printf
$ cd .../scrath $ PSIM=/applications/psim $ cd src/share $ tar cf - mk \ | ( cd $PSIM/bsd-root/usr/share \ && tar xvf - ) $ cd ../..
NetBSD avoids a potential chicken and egg problem with include files by
providing a separate install-includes target (called includes
).
This can be used to establish the include directory.
$ cd /tmp/scratch $ PSIM=/applications/psim $ for d in \ src/include \ src/sys \ src/lib \ ; do \ ( cd $d && powerpc-unknown-eabi-make includes ) \ ; done
$ cd /tmp/scratch $ PSIM=/applications/psim $ gunzip < binutils-2.7.tar.gz | tar xf - $ cd binutils-2.7 $ ./configure --target=powerpc-unknown-eabi \ --prefix=$PSIM $ make $ make install $ cd .. $ rm -rf binutils-2.7
This has the intended side effect of partially populating the psim directory tree which makes follow on steps easier.
$ cd /tmp/scratch $ PSIM=/applications/psim $ gunzip < gcc-2.7.2.1.tar.gz | tar xf -
If your version of GCC includes the file ginclude/ppc-asm.h then you should install that header file into the directory:
$PSIM/powerpc-unknown-eabi/include
More recent versions of GCC expect this file to be installed:
$ test -r gcc-2.7.2.1/ginclude/ppc-asm.h \ && cp gcc-2.7.2.1/ginclude/ppc-asm.h \ $PSIM/powerpc-unknown-eabi/include
Other than that, assuming the include files installed okay, the rest should be fine ....
$ cd /tmp/scratch $ PSIM=/applications/psim $ cd gcc-2.7.2.1 $ ./configure \ --target=powerpc-unknown-eabi \ --prefix=$PSIM $ make $ make install $ cd .. $ rm -rf gcc-2.7.2.1
$ cd /tmp/scratch $ PSIM=/applications/psim $ cd src/lib $ powerpc-unknown-eabi-make $ powerpc-unknown-eabi-make install $ cd ../..
If you encounter problems check the following (each discussed above):
$ cd /tmp/scratch $ PSIM=/applications/psim $ cd src/usr.bin/printenv $ powerpc-unknown-eabi-make $ powerpc-unknown-eabi-run -e netbsd printenv . . .
This environment is still under development.