I’ve recently needed to do some porting work for a PPC32 CPU running Linux. At the time I didn’t have any PPC hardware (I’ve since acquired a PowerMac G5). Of course when we don’t have hardware, we can normally emulate it. Here is how I set up the emulation so I can remember for next time.

There are a couple of things we need to start with. First of all, QEMU, this is a multi platform emulator which can be found in most Linux distributions. On my machine I installed this with the required PPC32 parts by running:

sudo apt install qemu-system-ppc openbios-ppc

Next up we need an OS to install. I needed something a little older than normal, Debian 8.11 PowerPC edition. After this I created a blank 12GB hard disk image using:

qemu-img create -f qcow2 powerpc32.img 12G

Then install the OS using the following, these options are documented at https://wiki.qemu.org/Documentation/Platforms/PowerPC:

qemu-system-ppc -L pc-bios -boot d -M mac99,via=pmu -m 1024 -hda powerpc32.img -cdrom debian-8.11.0-powerpc-DVD-1.iso

The installer will be somewhat familiar if you have ever installed a Linux distro before. I recommend not installing the GUI for Debian 8.11, the emulated CPU is very slow and GNOME wouldn’t work.

After a long wait for the installer to finish I created a file called boot.sh with the following contents:

qemu-system-ppc -L pc-bios -boot c -prom-env "boot-device=hd:,\yaboot" -prom-env "boot-args=conf=hd:,\yaboot.conf" -M mac99,via=pmu -m 2048 -hda powerpc32.img

Now running boot.sh will boot the PowerPC 32bit Linux image and give it 2GB of RAM.

The final piece needed for Debian 8.11 is the APT repositories. The default ones do not work, so in the VM you need to edit /etc/apt/sources.list, remove the cdrom line and add the following:

deb http://archive.debian.org/debian jessie main contrib non-free
deb-src http://archive.debian.org/debian jessie main contrib non-free

We are now good to go! Compile away and find any big endian based bugs!

Featured image by Baz1521, used under CC-BY-SA 3.0 license.