# GXemul: SGI O2 emulation

Back to the index.

The SGI O2 emulation mode tries to emulate enough of the main MIPS processor and other peripherals of a real SGI O2 machine, to be able to boot guest OSes.

Emulated hardware:

- MIPS R10000 main CPU.
- RAM: Up to 256 MB works well, up to 1 GB (max of what a real O2 can handle) works with OpenBSD/sgi (and possibly the raw PROM)
- Interrupt controllers, etc.
- Serial port
- On-board O2 graphics; works well enough to run NetBSD/sgimips with X11.
- PS/2 Keyboard and mouse
- Ethernet, enough to (barely) run OpenBSD and NetBSD with root-on-nfs.

Things not yet emulated include: SCSI, audio.

This page contains instructions for how to install and run:

- NetBSD/sgimips
- OpenBSD/sgi
- Linux for O2 (not yet)
- IRIX (not yet)

and also some hints on how to make a backup copy of the PROM from your own O2 and run it in the emulator.

### NetBSD/sgimips:

NetBSD/sgimips can run in GXemul on an emulated SGI O2 (also known as IP32). The SCSI controller is not emulated yet, so NetBSD needs to boot with root-on-NFS:

1. First of all, an "`nfs server`" machine must be set up. This needs to have a 4000 MB `/tftpboot` partition. Install NetBSD/pmax 8.0 from CDROM. Do not configure the network and do not install any X11 packages on the nfs server, as they are not needed. Don't forget to add the extra partition!

2. Download the files corresponding to a NetBSD/sgimips CD-ROM iso image, and the GENERIC and INSTALL kernels:

       	ftp://ftp.NetBSD.org/pub/NetBSD/NetBSD-8.0/sgimips/binary/kernel/netbsd-GENERIC32_IP3x.gz
       	ftp://ftp.NetBSD.org/pub/NetBSD/NetBSD-8.0/sgimips/binary/kernel/netbsd-INSTALL32_IP3x.gz

       	wget -np -l 0 -r ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-8.0/sgimips/binary/sets/
       	mkisofs -U -o sgimips.iso ftp.netbsd.org/pub/NetBSD/NetBSD-8.0

3. Start the DECstation emulation:

       	gxemul -e 3max -d nbsd_pmax.img -d sgimips.iso

   Log in as root, configure the pmax machine as an NFS server, and extract the files from the sgimips CD-ROM image:

   `` |
       echo hostname=server >> /etc/rc.conf
       echo ifconfig_le0=\"inet 10.0.0.2\" >> /etc/rc.conf
       echo nameserver 10.0.0.254 >> /etc/resolv.conf
       echo 10.0.0.254 > /etc/mygate
       echo /tftpboot -maproot=root 10.0.0.1 > /etc/exports
       echo rpcbind=YES >> /etc/rc.conf
       echo nfs_server=YES >> /etc/rc.conf
       echo mountd=YES >> /etc/rc.conf
       echo bootparamd=YES >> /etc/rc.conf
       printf "client root=10.0.0.2:/tftpboot \\\n swap=10.0.0.2:/tftpboot/swap\n" > /etc/bootparams
       echo "bootps dgram udp wait root /usr/sbin/bootpd bootpd -d 4 -h 10.0.0.2" >> /etc/inetd.conf
       cat >> /etc/bootptab
       client:\
               :ht=ether:\
               :ha=082030000010:\
               :sm=255.0.0.0:\
               :lg=10.0.0.254:\
               :ip=10.0.0.1:\
               :rp=/tftpboot:
       (press CTRL-D)
       echo "08:20:30:00:00:10 client" > /etc/ethers
       echo 10.0.0.1 client > /etc/hosts

       cd /tftpboot; mount /dev/cd0a /mnt
       for a in /mnt/*/binary/sets/[bcegmtx]*.tgz; do echo $a; tar zxfp $a; done
       echo 10.0.0.2:/tftpboot / nfs rw 0 0 > /tftpboot/etc/fstab
       echo rc_configured=YES >> /tftpboot/etc/rc.conf
       echo 10.0.0.254 >> /tftpboot/etc/mygate
       echo nameserver 10.0.0.254 >> /tftpboot/etc/resolv.conf
       echo rc_configured=YES >> /tftpboot/etc/rc.conf
       dd if=/dev/zero of=swap bs=1024 count=262144
       cd /; umount /mnt; halt

4. Create a configuration file called `config_client`:

   `` |
       !  Configuration file for running NetBSD/sgimips diskless with
       !  a NetBSD/pmax machine as the nfs server.

       net(
       	add_remote("localhost:12444")   ! the server
       	local_port(12445)               ! the client
       )

       machine(
       	name("client machine")
       	serial_nr(1)

               type("sgi")
               subtype("o2")
       	use_x11(1)
       	memory(256)

               load("netbsd-INSTALL32_IP3x.gz")
               ! load("netbsd-GENERIC32_IP3x.gz")
       )

   ... and another configuration file for the server, `config_server`:

   `` |
       net(
       	local_port(12444)               ! the server
       	add_remote("localhost:12445")   ! the client
       )

       machine(
       	name("nfs server")
       	serial_nr(2)

               type("dec")
               subtype("5000/200")

               disk("nbsd_pmax.img")
       )

5. Boot the "`nfs server`" and the NetBSD/sgimips "`client machine`" as two separate emulator instances:

       	in one xterm:
       	gxemul @config_server

       	and then, in another xterm:
       	gxemul @config_client

6. In the NetBSD/sgimips window, choose "`x: Exit Install System`" in the installer's main menu, and then type:

       	ifconfig mec0 10.0.0.1; route add default 10.0.0.254
       	mount -v 10.0.0.2:/tftpboot /mnt
       	cd /mnt/dev; ./MAKEDEV all; cd /; umount /mnt
       	halt

   Then, once the client machine has halted, log in as `root` on the server machine and type `reboot`.

7. Once everything has been set up correctly, change `netbsd-INSTALL32_IP3x.gz` in `config_client` to `netbsd-GENERIC32_IP3x.gz` (the GENERIC kernel).

You might want to log in as `root` on the server machine, and run `tcpdump -lnvv` or similar, to see that what the client machine actually does on the network.

It should now be possible to boot NetBSD/sgimips using the NetBSD/pmax nfs server, using the following commands: (NOTE! Execute these two commands in separate xterms!)

    	gxemul @config_server
    	gxemul @config_client

If/when asked for "`root device:`" etc. on the client machine, enter the following values:

    	root device: mec0
    	dump device: 				(leave blank)
    	file system (default generic): 		(leave blank)
    	..
    	init path (default /sbin/init):		(leave blank)
    	Enter pathname of shell or RETURN for /bin/sh:	(leave blank)
    	Terminal type? [unknown] xterm
    	..
    	# exit			(to leave the single-user shell)

Note: Netbooting like this is very slow, so you need a lot of patience.

### OpenBSD/sgi:

OpenBSD/sgi can run in GXemul on an emulated O2 (SGI-IP32), with root on NFS.

GXemul does not yet emulate the AHC PCI SCSI controller in the O2, so it needs to boot via the emulated network. Another emulated machine must then be used as the nfs root server, and the emulated O2 machine must boot as a diskless client. Performing this setup is quite time consuming, but necessary:

1. First of all, the "`nfs server`" machine must be set up. Install NetBSD/pmax 8.0 from CDROM, perform a default install from CDROM without configuring the network, but add a 4000 MB `/tftpboot` partition when configuring the disk!

2. On the host, download the OpenBSD distribution, and do some fixup to make it possible to treat the tar files as SCSI disk images:

   `` |
       wget http://ftp.openbsd.org/pub/OpenBSD/6.4/sgi/base64.tgz
       wget http://ftp.openbsd.org/pub/OpenBSD/6.4/sgi/comp64.tgz
       wget http://ftp.openbsd.org/pub/OpenBSD/6.4/sgi/xbase64.tgz
       wget http://ftp.openbsd.org/pub/OpenBSD/6.4/sgi/xfont64.tgz
       wget http://ftp.openbsd.org/pub/OpenBSD/6.4/sgi/xserv64.tgz
       wget http://ftp.openbsd.org/pub/OpenBSD/6.4/sgi/xshare64.tgz
       gunzip base64.tgz
       gunzip comp64.tgz
       gunzip xbase64.tgz
       gunzip xfont64.tgz
       gunzip xserv64.tgz
       gunzip xshare64.tgz
       dd if=/dev/zero of=/dev/stdout bs=65536 count=1 >> base64.tar
       dd if=/dev/zero of=/dev/stdout bs=65536 count=1 >> comp64.tar
       dd if=/dev/zero of=/dev/stdout bs=65536 count=1 >> xbase64.tar
       dd if=/dev/zero of=/dev/stdout bs=65536 count=1 >> xfont64.tar
       dd if=/dev/zero of=/dev/stdout bs=65536 count=1 >> xserv64.tar
       dd if=/dev/zero of=/dev/stdout bs=65536 count=1 >> xshare64.tar

3. Start the emulation of the DECstation NFS server using this command line:

   `` |
       gxemul -xe 3max -d nbsd_pmax.img -d base64.tar -d comp64.tar -d xbase64.tar -d xfont64.tar -d xserv64.tar -d xshare64.tar

   and enter the following commands to configure the server for NFS serving and extract the OpenBSD distribution:

   `` |
       echo hostname=server >> /etc/rc.conf
       echo ifconfig_le0=\"inet 10.0.0.2\" >> /etc/rc.conf
       echo nameserver 10.0.0.254 >> /etc/resolv.conf
       echo 10.0.0.254 > /etc/mygate
       echo /tftpboot -maproot=root 10.0.0.1 > /etc/exports
       echo rpcbind=YES >> /etc/rc.conf
       echo nfs_server=YES >> /etc/rc.conf
       echo mountd=YES >> /etc/rc.conf
       echo bootparamd=YES >> /etc/rc.conf
       printf "client root=10.0.0.2:/tftpboot \\\n swap=10.0.0.2:/tftpboot/swap\n" > /etc/bootparams
       echo "08:20:30:00:00:10 client" > /etc/ethers
       echo 10.0.0.1 client > /etc/hosts

       cd /tftpboot
       tar xf /dev/sd1c
       tar xf /dev/sd2c
       tar xf /dev/sd3c
       tar xf /dev/sd4c
       tar xf /dev/sd5c
       tar xf /dev/sd6c

       tar zxfv var/sysmerge/etc.tgz
       tar zxfv var/sysmerge/xetc.tgz

       dd if=/dev/zero of=swap bs=1024 count=262144

       echo inet 10.0.0.1 > /tftpboot/etc/hostname.mec0
       echo nameserver 10.0.0.254 > /tftpboot/etc/resolv.conf
       echo 10.0.0.2:/tftpboot / nfs rw 0 0 > /tftpboot/etc/fstab
       echo 10.0.0.2:/tftpboot/swap none swap sw >> /tftpboot/etc/fstab

       halt

4. Download the OpenBSD/sgi GENERIC and RAMDISK kernels:

       	http://ftp.openbsd.org/pub/OpenBSD/6.4/sgi/bsd.IP32
       	http://ftp.openbsd.org/pub/OpenBSD/6.4/sgi/bsd.rd.IP32

5. Create a configuration file called `config_client`:

   `` |
       !  Configuration file for running OpenBSD/sgi diskless with
       !  a NetBSD/pmax machine as the nfs server.
       !
       !  This config file is for the client.

       net(
       	add_remote("localhost:12444")   ! the server
       	local_port(12445)               ! the client
       )

       machine(
       	name("client machine")
       	serial_nr(1)

               type("sgi")
               subtype("o2")
       	use_x11(1)
       	memory(1024)

               load("bsd.rd.IP32")
               ! load("bsd.IP32")
       )

   ... and another configuration file for the server, `config_server`:

   `` |
       net(
       	local_port(12444)               ! the server
       	add_remote("localhost:12445")   ! the client
       )

       machine(
       	name("nfs server")
       	serial_nr(2)

               type("dec")
               subtype("5000/200")

               disk("nbsd_pmax.img")
       )

6. Boot the "`nfs server`" and the OpenBSD/sgi "`client machine`" as two separate emulator instances:

       	in one xterm:
       	gxemul @config_server

       	and then, in another xterm:
       	gxemul @config_client

7. In the emulated OpenBSD/sgi client, type 's' for Shell and run these commands:

   `` |
       ifconfig mec0 10.0.0.1; route add default 10.0.0.254
       mount -v 10.0.0.2:/tftpboot /mnt
       cd /mnt/dev; ./MAKEDEV all; cd /; umount /mnt
       reboot

8. Change bsd.rd.IP32 to bsd.IP32 in the client configuration file.
9. Finally, run the client again:

       	gxemul @config_client

   If the root device is not auto-detected, enter `mec0`. Note that booting is very slow, so be patient.

Many things are not working yet, for example X11 does not start yet due to some bug in the keyboard emulation. It is also very slow, mostly due to having the file system on NFS. In order to self-compile GXemul under emulated OpenBSD/sgi, you need to run `swapctl -a /swap` as root.

### Linux for O2

NOTE: This does not work yet. The latest Linux r5k-ip32 kernels die with a NULL reference during bootup. Older versions may work better, but I have not had the time to set up NFS netbooting so I don't know whether that would really work, or trigger other bugs.

Linux for O2

### Experimenting with booting IRIX from a real SGI O2

NOTE: This does not work yet. These instructions are here mostly for me to know where to continue debugging, when there is time.

Preliminary instruction for how to boot the kernel from your real O2:

    $ gxemul -X -e o2 unix

where `unix` is the IP32 kernel. If you do not want to use the graphical framebuffer (`-X`), you can use lower-case `-x` to just use an xterm instead.

    IRIX Release 6.5 IP32 Version 10151453 System V
    Copyright 1987-2002 Silicon Graphics, Inc.
    All Rights Reserved.

    Total real memory  = 131072 kbytes
    CPU Frequency = 134Mhz
    1 CPU(s)

    Free small K0 = 0x411 pages (adding 0xa4 pages)

    QLFC: running as interrupt thread.
    QLFC: using spinlocks.

    PCI Configuration Report

    keyboard on port 0, mouse on port 1
    ec0: hardware ethernet address 08:20:30:00:00:10
    919 buffers
    PANIC: vfs_mountroot: no root found
    [Press reset to restart the machine.]

Right now, it does not work. There are several problems, most importantly there is no way to get IRIX to find the root file system from which to run; SCSI is not emulated, and the network emulation in GXemul is not good enough for IRIX to accept it for root-on-nfs. Also, attempting to use more than 256 MB of RAM fails.

### Experimenting with a PROM from a real SGI O2

Note: Normally, a dump of the PROM image from your real SGI O2 is not needed, if what you want to do is to run guest operating systems in the emulator.

Using a serial console hooked up to your O2, executing the PROM command

    >> dump -b 0xBFC00000:0xBFC80000

will dump 512 KB of the PROM range. Make sure you capture all the output into a file, and then convert the result into a raw binary. (If you don't have time to write a converter tool yourself, there is an example converter in the GXemul source code distribution: `experiments/sgiprom_to_bin`.)

Assuming you have extracted the PROM from your real machine into a file called `prom`, the following example shows how to start up the emulator with that image:

    $ gxemul -Q -X -e o2 0xbfc00000:prom

`-Q` turns off GXemul's built-in PROM emulation, allowing raw PROM images to be used. `-X` is used to display the graphical framebuffer. (`-X` can be omitted if only serial console is what you want.) And finally, `-e o2` selects the O2 emulation mode. 0xbfc00000 is the standard ROM address for MIPS-based systems.

The photo on the left is from the real machine. The screenshot to the right is from the emulator.

NOTE: The SGI O2 PROM does some hardware tests during startup that do not work in GXemul, in particular cache detection. So right now, there is a hack/workaround which skips cache detection in an ugly way. This has been verified to work with PROM versions 2.3, 4.13, and 4.18. For other versions, it may need to be manually skipped.

With a IP32 PROM version 4.13 for example, if the hack is commented out, the cache detection routine at 0xbfc05180 must be skipped:

    $ gxemul -p 0xffffffffbfc05180 -X -Q -e o2 0xbfc00000:prom-4.13

    ...
    when the breakpoint is hit, type:

    pc = ra
    continue

If the 'console' variable in the PROM's environment variable section was set to something starting with 'g', output will be graphical, otherwise it will be to serial console.

Note however that almost nothing works; most importantly, SCSI is not implemented for the SGI O2, so the emulated machine will not be able to boot from any kind of disk or CDROM. Audio or video hardware is not emulated at all yet either. Also, while the graphics emulation has been implemented well enough to run NetBSD, OpenBSD, and perhaps also Linux, other things may not work.