2014-02-07

Well, not quite. This is about as close as it comes though.

In the middle of last year, the Qemu Project finally gained a complete enough OpenBIOS implementation to boot Mac OS X in their PowerPC emulator. Considering PearPC hasn't been updated in quite some time and doesn't compile with JITC support under OS X, rendering it horribly slow, this improvement in Qemu is perhaps the first real attempt at making OS X run, well, on OS X.

But it has a couple of issues. For starters, the colours are horribly distorted. This appears to be an issue with the frame buffer and hopefully it will be fixed in a later version.



Secondly, Qemu's emulation of New World Macs isn't complete. When starting Qemu, you can choose to run it g3beige mode to emulate an Old World Mac based on the Gossamer architecture, or mac99 mode, which emulates a New World Mac. Emulating an Old World system will allow OS X Jaguar to boot, while the incomplete New World emulation can boot OS X Tiger.

What doesn't work is OS X Panther. Attempting to boot OS X Panther with Old World emulation results in the installer failing hardware checks, and attempting to boot it with New World emulation results in the system locking up during the boot process.

Other than the above, it works. Because I'm impatient and don't want to wait for these fixes, I decided to see if I could work around them.

Building Qemu PPC

First thing's first. You'll need Xcode installed from the Mac App Store. Once that's done, you'll want to install Homebrew unless you find sorting dependencies thrilling. Once Homebrew installs, it prompts you to run brew doctor from the command line to configure it.

You will then need to install two packages - pkg-config and glib. This is where Homebrew makes this so much easier. All you have to do is type one brew install command to install a package, then wait.

Install pkg-config

Code:

brew install pkg-config

Install glib

Code:

brew install glib

Now remember I said Qemu had a couple of issues before? This is where we work around one of them. Qemu uses GTK as its frame buffer, and this is where the inverted colours bug lies. So instead of attempting to fix it this time, I simply decided to disable GTK and use SDL instead. To do this, we'll need to install one more package:

Install SDL

Code:

brew install sdl

Now we start working on Qemu. Download the latest Qemu source tar.bz2 from Download - QEMU. I'm using v1.7.0 here, although v1.6.2 has a later release date. From what I gather, either is fine. I simply decompressed the archive to a folder on my desktop, nothing fancy here.

Once you have the source in a folder, it's time to make it do something. First, switch to the directory containing the source code.

Code:

cd /path/to/qemu/source/

Now we want to configure the source to build the PowerPC emulator. You first need to type ./configure followed by a few arguments. --target-list=ppc-softmmu tells the compiler to build the PowerPC emulator.

To work around the distorted colours issue, we're disabling GTK, so add --disable-gtk as well. Finally, because we're not using GTK, make Qemu use SDL instead with --enable-sdl. You should have the following:

Code:

./configure --target-list=ppc-softmmu --disable-gtk --enable-sdl

It can take a few moments for the Configure process to run. When it is done, we're ready to build the emulator. To do this, you can run make install to begin the process. However in order to keep the files that are built contained in a central location, I'm also using the DESTDIR argument to specify the output folder for the built files, like so:

Code:

make DESTDIR=$HOME/qemu install

The DESTDIR=$HOME/qemu argument forces the compiled files to be placed in a folder called qemu in the user's home folder.

Provided the build completed successfully, you should now have several files in that directory, like so:



Running Qemu

For now, we're focusing our attention to the bin folder. Change to this directory from the command line. If you used the same locations as me, it will be something like so:

Code:

cd ~/qemu/usr/local/bin/

Now, we should make a blank hard disk image to install OS X to. You can do this with the qemu-img utility that was compiled alongside the qemu-system-ppc application in the bin folder.

It's rather simple. You run qemu-img with the create flag, then -f qcow2 to set the image format to qcow2, then specify the location to create the disk image. I placed it alongside the app in the bin folder with ./machd.img. Finally, you specify the image size in GB. A 5GB image should be enough for a small install, so 5G will do. When you're done, it should look like so:

Code:

./qemu-img create -f qcow2 ./machd.img 5G

This is incredibly quick, almost instantaneous. That's normal. You should now have a machd.img folder in the location you specified.

Now it's time to start this machine up!

There are a number of variables to pass to the VM to make it behave in different ways. I'll do my best to explain these.

Quote:

./qemu-system-ppc

Starts the app.

-L pc-bios/

I haven't looked into this setting actually... but it works with it there.

-m 256

The amount of memory available to the VM in megabytes (MB). Note this is a lower case flag (-m).

-M g3beige or -M mac99

The type of machine to emulate. Use g3beige for Jaguar, or mac99 for Tiger. You can also use g3beige to run Panther - and i'll tell you how I fixed that soon.

-cpu G3 or -cpu G4 or -cpu 970fx

The type of processor to emulate. G3 and G4 both work with g3beige, however 970fx only works with mac99.

-hda /path/to/hard/disk/image.img

The path to the hard disk image you created earlier.

-cdrom /path/to/cd/image.iso

The path to the CD/DVD image you are using to install OS X.

-g 1024x768x32

The resolution and colour depth of the VM window. I can confirm 800x600 and 1024x768 work, but I'd imagine many more combinations do too. I'd recommend leaving the colour depth at 32 however. It may be possible to switch to lower colour depth to speed up the video, but I haven't had success doing so.

-boot c or -boot d

Specifies what Qemu should automatically boot from. I still have to check, but I think -boot c forces a boot from the HDD image, while -boot d forces a boot from the CD/DVD image. You don't have to use this flag, but not specifying it will cause Qemu to boot to an Open Firmware prompt, and you will have to type boot hd:,\\:tbxi or boot cd:,\\:tbxi from there to choose the boot device - just like on a real Mac.

The command I use to start Qemu is:

Code:

./qemu-system-ppc -L pc-bios/ -m 256 -M g3beige -cpu G3 -cdrom /Users/me/Desktop/Panther1.iso -g 1024x768x32 -hda /Users/me/Desktop/machd.img

Keeping in mind that I chose to have my HD and CD images on the desktop, so my paths may look a little different. I also left off the -boot d argument since I'm comfortable with bashing commands into Open Firmware.

Having run that command and waited a surprisingly shot amount of time for it to boot considering it's an emulator, I finally see the product of my efforts.



If you're running OS X Jaguar or OS X Tiger, I'm told this is all you need to do. Go forth and install!

But wait, isn't that Panther I'm running? I promised I'd explain how to make Qemu accept OS X Panther, so if you feel adventurous, read on...

Patching OpenBIOS for Panther

When you enable -M g3beige while launching Qemu, it will happily boot from your Panther disc all the way into the installer. However the installer then chokes, telling you that OS X Panther can not be installed.

See, when Panther checks for incompatible machines, it looks for AAPL,PowerMac G3. This was a throwback to the Power Mac G3 Minitower and Desktop, which would run up to OS X Jaguar but were officially dropped with OS X Panther.

Of course, the OpenBIOS implementation used by Qemu for g3beige mode identifies as an AAPL,PowerMac G3. This is why the installer fails. So the trick is to modify OpenBIOS to make it identify as a Power Mac G3 Blue & White - the PowerMac1,1.

Fire up a Hex Editor. I recommend Hex Fiend.

Navigate to the folder where Qemu is stored, but this time go to share > qemu instead of bin and open openbios-ppc with your hex editor.

Now you want to select Edit > Find. In the Find field type:

Code:

41 41 50 4C 2C 50 6F 77 65 72 4D 61 63 20 47 33

And in Replace type:

Code:

50 6F 77 65 72 4D 61 63 31 2C 31 00 00 00 00 00

Then click Replace. The file should then look like this:

Once that is done, save the file. Boot up Qemu like you did before and start up from your OS X Panther disc. This time it should pass the machine identifier check and install OS X successfully.

All done!

Quote:

If you're curious as to what this hex edit does, read on. Otherwise you can skip this next part.

You want to search for the text string "AAPL,PowerMac G3" (without quotes) or hex 41 41 50 4C 2C 50 6F 77 65 72 4D 61 63 20 47 33. The hex may not have spaces, but in Hex Fiend it did. You should find it like so:

Now change it to text string "PowerMac1,1 " (without quotes) or hex 50 6F 77 65 72 4D 61 63 31 2C 31 00 00 00 00 00.

This is what it should then look like:

You may notice there's some extra spaces after "PowerMac1,1". This is intentional. Since "PowerMac1,1" is shorter than "AAPL,PowerMac G3" by 5 characters, we need to pad the missing characters with 5 spaces.

However, you can't simply hit the space bar a few times after typing "PowerMac1,1" since this will then include the spaces as characters in the machine identifier, and OS X won't be able to find the correct drivers for the platform. The reason is that a regular space in hex is 20, and we need the hex value of the spaces to be 00.

In other words, hitting space 5 times will be represented in hex like so:

Quote:

50 6F 77 65 72 4D 61 63 31 2C 31 20 20 20 20 20

And we need:

Quote:

50 6F 77 65 72 4D 61 63 31 2C 31 00 00 00 00 00

So while you can hit space 5 times after typing "PowerMac1,1", you'll need to change those "20"s in hex to "00"s.

Hopefully once the mac99 emulation is a little more complete, this modification will no longer be necessary and OS X Panther will boot up using the mac99 emulation as intended. Until then though, this is a suitable fix.

Conclusion

I worked on this late into the morning, and so hopefully I haven't missed anything important. Retracing my own steps while writing this allowed me to successfully compile Qemu again, so I think it's right.

Having installed OS X Panther under Qemu, I can safely say that performance wise, this blows PearPC out of the water. The OS is actually usable enough to play around with, although it still needs further improvements to actually be a practical use system. For example, sound and video acceleration don't work, and while networking does, it does so via a tap method. Some key mappings are also incomplete, so some keys like the Apple / Command key don't map to the guest.

However I was incredibly surprised to see that Qemu doesn't constantly hammer the host CPU, so while the emulation takes a decent amount of processing power to perform heavier tasks (such as installing the OS), its host CPU utilisation falls to as low at 12% on my 1.8GHz i5 MacBook Air when the PowerPC guest is idle. Needless to say, this emulation is very good.

All in all, it's a very promising start.

Most of all though, it's just a little fun. Anyone that loves to play around with older operating systems like I do will find this interesting.

Oh, and if anyone would like my pre-compiled version of Qemu with the OpenBIOS modification already applied, I'd be happy to send it over. From what I gather it should run on any x86_64 based Mac, but I don't have another machine to test on at the moment so I can't guarantee it. Still, if anyone would like to have a shot at it, I'll gladly send it over.

Cheers,

~ Michael.

Sources

OS X PowerPC on Qemu | Fun with virtualization

QEMU Mac OS X... Success! - Mike Levin

Installing Qemu for OSX and running PowerPC OSX 10.2, 10.3 or 10.4 [E-Maculation wiki]

Show more