Part 2: Setting Up




Overview

Perform the necessary preparations so that your workstation can boot your own home-grown operating system(s).







Build a toolchain

This part may not be necessary depending on your environment. If you intend to develop on a different architecture machine, you will obviously need a different toolchain. My personal setup is a Pentium Pro as a workstation and a SS 1+ as a test bed. The machines are connected by Ethernet and I run minicom on the PPro to control the 1+ over the serial port.

First get the current binutils source from your favourite ftp mirror. Building binutils is rather straightforward and should offer no surprises. After unpacking the distribution, to build the cross-assembler, cross-linker, and friends, do a

$ ./configure --prefix=/usr/local/xdev-sun --target=sun4
$ make
$ su
# make install
Of course, you can change the prefix argument to whatever you want. You can even install them in the default /usr/local if you want since the configure script will detect that you are building a cross-toolchain and name the binaries sun4-gas, sun4-ld, and such.

Next is the cross-compiler. Unfortunately, this is not completely trivial. The problem is that GCC doesn't know how to open code certain basic functions for SPARC processors that reside in libgcc.a. Since libgcc.a needs to be library for a SPARC machine, you can't build it with your native compiler. You also can't build it with the cross-compiler since that would make those functions compile into infinite recursion. Basically, you have to build libgcc.a (actually, only libgcc2.a) on a SPARC machine. If you have an operating system on your SPARC computer or access to one that does, you can do the following to generate the library by building part of a native compiler on another system using its native compiler.

$ ./configure
$ make libgcc2.a
Then just transfer libgcc2.a to the machine building the cross-compiler and hack the Makefile to not build libgcc2.a. Beware and back up the compiled libgcc2.a first since you will not hack it right the first time and it will try to rebuild libgcc2.a and it will overwrite the copy you put there. Clear? To build the rest, do

$ ./configure --prefix=/usr/local/xdev-sun --target=sun4
$ make LANGUAGES=C
$ su
# make install
If you use C++, then change then add that to the languages variable. Note that unlike when building a native compiler, the cross-compiler does not get recompiled with itself.

Set up your computer

Your SPARC computer will need a bit of setup. Hopefully you have an operating system already installed on it. If not, you should consider doing so, even if it has to mount its root filesystem over NFS.

Unfortunately, the Solaris/NetBSD/OpenBSD bootloaders were designed to load a.out executables, not the SBBB boot images that we in SigOps use. For this reason, you will need to use my modified version of the OpenBSD second-stage bootstrap program. You have two options here:

  • boot from the network and send my second-stage as the initial boot program and have it load the SBBB boot image over NFS using RARP, bootparamd, and friends
  • dedicate a small partition to booting of your home-grown OS and install the normal OpenBSD boot block there with my modified second-stage
The first option is trivial; however, my 1+ seems to be very flaky about booting from the network, so I use the second option. You will probably want to have about two or three megabytes for this filesystem. Additionally, you will have to have another OS installed to copy the boot image into this filesystem before booting it. Edit your disklabel, create a filesystem on the new slice, and add it to your fstab. I assume it is sd0d and mounted under /xdev.

To build my second-stage bootstrap program, you will need the source. If you don't want to build it, you can get by with the binary and skip a few steps below. Do the following to build and install it into the new filesystem:

# cd /sys/arch/sparc/stand/boot
# mv boot.c boot.c.old
# cp ~/boot.c .
# make
# mv /usr/mdec/boot /usr/mdec/boot.old
# mv boot /usr/mdec
# halt
ok boot -s
...
# mount -a
# /usr/mdec/binstall ffs /xdev
# halt
ok boot
Note that you must reboot into single user mode to install the boot block and second-stage bootstrap program since the kernel will not let you do so while in secure mode.

Of course, if you get the old style `>' prompt from the monitor, you will need to do

>n
ok setenv sunmon-compat? false
ok setenv security-mode none
at your earliest convenience.


Writing an Operating System for SPARC-Based Computers is Copyright © 1998 by Sidney Cammeresi in its entirety. All rights reserved.

Permission is granted to make verbatim copies of this tutorial for non-commercial use provided this notice remains intact on all copies.