Wack0 / maciNTosh

PowerPC Windows NT ported to Power Macintosh systems
GNU General Public License v2.0
522 stars 16 forks source link

Add Old World loading capabilities #31

Open MCJack123 opened 1 month ago

MCJack123 commented 1 month ago

This PR adds an extra build step to the arcloader/stage1 makefile which produces an XCOFF file that can be loaded from Old World Open Firmware versions. It uses a small program from the Linux sources to patch the XCOFF that GCC links, which makes the executable bootable.

This is mostly untested, as I don't have a G3 beige system (and DingusPPC is being weird), but the same process works on my OF 1.0.5 PM7600. I also don't know the blessing procedures quite yet, and if OF 1/2 is even able to detect alternate boot devices without changing boot-device in NVRAM.

Wack0 commented 1 month ago

About the blessing procedure, I believe from looking at OSX install images, it uses an APM partition with no data storing raw powerpc code, with base address + entrypoint in the partition table entry. OSX uses a mapped binary with mach-o headers present (IDA loads it fine as a mach-o even) but executable headers aren't required.

I was planning on modifying arcfw for clearing bss, and having a load image for oldworld that was basically loaded arcfw+custom loader in bss, placing it in the cd image then patching it after build (as far as I can tell no tool can set up such an APM partition in a hybrid ISO containing only code yet).

For dualboot, could probably add some boot menu in loader (and enable it only if mac partitions were created). Given the 16KB loader limit will be not present at all for oldworld...

MCJack123 commented 1 month ago

I just tried booting my 10.0 CD in my 7600 (holding C), and it appears that whatever it boots is a small script that sets the following NVRAM parameters:

and then resets the system, letting OF then hand it off to the OS X loader on the CD. System Disk appears to do the same thing when booting to an OS X CD. I also happen to have a Server 1.2 CD which is supported on the 7600, but it boots and installs from a Mac OS 8.5 System Folder instead - but the boot device setting from 10.0 still tries to boot Mac OS X Server from CD (which doesn't appear to work, it runs the loader but fails to find a kernel I think).

From a bit of digging, I believe the HFS Standard wrapper over the HFS+ partition holds the C-key boot data. There are three hidden files located on this hidden sub-partition:

Also possibly relevant is the HFS boot block, which I'm leaving a link to docs for in case it's necessary.

As for Open Firmware loading, you're correct about it loading from the APM - I'm not sure exactly where it comes from, but I'm guessing that /packages/mac-files looks for the first partition with boot code set up, and loads the entire image into memory. This could be used with either the existing ELF or this PR's XCOFF file, provided the start + base addresses are correct in APM.

So after a lot of investigation, I believe this is the way to make a "truly bootable" CD for an Open Firmware payload:

Alternatively, using an APM boot image:

Now, I don't really think I want to put in the effort to make this work without copying Apple's files - it's a lot of hacking to be able to hold "C" instead of typing a command once. But this is some food for thought, and I might play around with the Apple files a bit on my own to see what's possible.

Wack0 commented 1 month ago

"without copying Apple's files" - I already bundle the OS9 IDE drivers, the only way for installing them at all is reformat or having them present for OS9 drive setup to be able to update them... if I could have avoided bundling them (for dualboots) I would have...

Regarding the open firmware nvram changes, that would make sense given OSX BootX comes up in 1024x768 under dingusppc, the same as when dropping to OF prompt, yet OF boot switches back to 640x480.