Rebuilding Darwin from source: Part 2 Building the kernel

Re-creating the steps from 7 years ago the first phase was to build the Darwin kernel. Like everything else, once you know what is involved, it’s not all that difficult. But as always finding out the steps to get there is half the fun!

I’m going to assume if you want to follow along, that you’ve completed the first part of this exercise, and you have a Rhapsody DR 2 system up and running. Due to some issues I’ve had with creating a lot of files & filesystem corruption, we are going to create and add two more disks to the system. On Qemu we need to add them via the CLI:

qemu-img create -f vmdk source.vmdk 8G
qemu-img create -f vmdk scratch.vmdk 8G

Adding them to the command line gives us something like this:

qemu -L pc-bios -m 512 ^
-k en-us ^
-rhapsodymouse ^
-hda rhapsody.vmdk ^
-hdb source.vmdk ^
-hdd scratch.vmdk ^
-cdrom darwin-builder-04-23-2024.iso ^
-fda nic.flp ^
-net nic,model=ne2k_pci,vlan=1 ^
-net socket,udp=127.0.0.1:5001,remote=127.0.0.1:5000,vlan=1 ^
-boot c ^
%1 %2 %3 %4 %5 %6 %7

Additionally you’ll also need to download the current ‘darwin builder’ ISO that I’ve put up on sourceforge. As of today it is darwin-builder-04-23-2024.iso

Step one is to boot into single user mode. As we need to prep & format the disks under Darwin before the system starts up.

We need to check the hard disk, and then create the device names for the third hard disk.

fsck -y /dev/rhd0a
mount -w /
cd /dev
./MAKEDEV hd2

Now we need to run the ‘disk’ command which will abstract the whole volume creation. There are numerous flags, but we don’t need all that many.

disk -i -l 'src' /dev/rhd1a
disk -i -l 'scratch' /dev/rhd2a

The output scrolls off the screen, so I didn’t capture it, but you’ll see all the inodes being created, it’s a lot of output!

With the disks created, we can now shut down the VM

shutdown -h now

and then restart Qemu, and let it boot up normally. We’ll get to the login screen, login as the root user.

The first thing I’d recommend is to drag the Terminal.app from /System/Administration to the desktop to make it easier to get to. Rhapsody, unlike NeXTSTEP & OPENSTEP doesn’t have any dock, as the goal back then was to make Rhapsody look and feel more like Platinum MacOS.

The next thing to do is to make the system very insecure by allowing remote root logins. It’s just easier to deal with. You could use sed or just copy the one I provided from the CD-ROM.

cp /source/ttys /etc

And with that in place, its easy enough to telnet into the VM so you can copy/paste stuff in and out with ease!

You should now be able to verify that all 3 disks are mounted:

# mount | grep hd.a
/dev/hd0a on / (local)
/dev/hd1a on /src (local)
/dev/hd2a on /scratch (local)

From here it should be very simple to kick off the build process:

/source/phase1.sh

And this will kick off the build, recreating all the fun steps I’d gone through so many years ago. These projects now are building in the following order:

  • kernel-1
  • driverkit-139.1-1
  • cc-798
  • bootstrap_cmds-1
  • objc-1

The first phase of the script will unpack both the kernel & driverkit and install their respective header files into the OS. NeXT a bunch of symlinks are created to link the system to the driverkit. Next I decided to build the ObjectiveC compiler from 10.0, hoping it’s more bugfixed and slightly more optimized than what was available back in 1999. Building the compiler is a little involved, as a good GCC tradition is to be cross compiled first, then re-compile itself with itself, then do that again and verify that the 3rd recompile outputs the same as the second one. Yes it’s a thing. Yes it’s slow. Yes you are lucky to live in the future, this was really painful back in the day.

With the kernel compiled, we can then compile the bootstrap commands, and the objectiveC runtime that is used by the kernel. Nothing too exciting here.

DriverKit however….

The PCMCIA code was not included in any of the 0.x Darwins, so for laptop enthusiasts you are basically SOL. As a matter of fact, a lot of weird stuff was pruned out, that either could be ‘touched’ or borrowed from the PowerPC port and massaged into place. Luckily I had at least figured out a simple fix for PCIKernBus.h so at least PCI works.

Likewise for the kernel, there was some guessing on the EISA config, which also overlaps ISA, along with having to remove the PCMCIA cardbus .. bus.

APM crash

I had issues with the APM (Advanced Power Management), another laptopisim I suspect. I had to amputate that.

Naturally the cpuid code is broken much like early NT (I wonder if both were contributed by intel?), so it doesn’t detect any half way modern Pentium processors correctly which causes it to fall all the way back to the i386, which unfortunately, Rhapsody is compiled as 486 (remember NeXTSTEP had fat binaries allowing you to recompile for different processors and ship a single binary that can be ‘lipo’d into the appropriate one for the host). So being degraded to a 386 means nothing works.

bad CPU type in library!

yay.

Luckily patching the cpuid was pretty simple just force it always to be a Pentium. It is 1999 afterall.

I’ve done my best to make this a single script to run, and all being well you’ll get something that looks like errors, but it should be fine?!

System/Library/Frameworks/System.framework/Versions/B/Headers/bsd/i386/table.h
System/Library/Frameworks/System.framework/Versions/B/Headers/bsd/i386/types.h
System/Library/Frameworks/System.framework/Versions/B/Headers/bsd/i386/user.h
System/Library/Frameworks/System.framework/Versions/B/Headers/bsd/i386/vmparam.h
private/
private/dev/
private/dev/MAKEDEV
private/tftpboot/
private/tftpboot/mach_kernel
mach_kernel
tar: private/dev: Could not change access and modification times: Permission denied
tar: private/dev: Cannot change mode to 0755: Permission denied
tar: private/dev: Cannot chown to uid 0 gid 0: Permission denied
tar: Error exit delayed from previous errors

A quick look around shows that there is tgz files indicating that things have been compiled. I did backup the old original kernel as “rhapsody-gcc.tgz” in case you ever need it. Can’t imagine why but who knows?

qemu:13# ls -l /usr/src/*.tgz
-rw-r--r--  1 root  wheel   173706 Apr 23 15:25 /usr/src/bootstrap_cmds.bin.tgz
-rw-r--r--  1 root  wheel  2184460 Apr 23 15:33 /usr/src/cc-798-bin.tgz
-rw-r--r--  1 root  wheel  2747289 Apr 23 15:36 /usr/src/driverkit-kern-bin.tgz
-rw-r--r--  1 root  wheel  1264957 Apr 23 15:26 /usr/src/kernel-driverkit-hdrs.tgz
-rw-r--r--  1 root  wheel   116343 Apr 23 15:26 /usr/src/objc-bin.tgz
-rw-r--r--  1 root  wheel  2173005 Apr 23 15:26 /usr/src/rhapsody-gcc.tgz
qemu:14# ls -l /mach_kernel*
-r--r--r--  2 root  wheel  1459520 Apr 23 15:36 /mach_kernel
-r--r--r--  1 root  wheel  1404116 Apr 23 15:38 /mach_kernel-rhapsody

You should now be able to reboot into the kernel that you’d compiled!

Next up is Phase 2, where we compile the tools to enter the dark magic that is the Debian build system. Yes, you read that right, Apple/NeXT was all in on Debian.

Rebuilding Darwin from source: Part 1 Qemu

Back in the old old..

7 years ago!

It’s hard to believe it’s been 7 years ago since I reproduced Ncommander‘s adventure in building the Mach kernel from Darwin 0.1 sources that had been found years ago. At one point we’d managed to build enough of Darwin to do a dump/restore onto a new disk image, and have a mostly built Darwin system save for a hand full of files.

Time goes on by, and memories fade, and I thought it’d be worth going over the adventure, yet again. Just as it was true back then, I thought I’d reproduce the same setup that I’d been using back then. Qemu was a new and exciting thing back then, and

the Disk driver is VERY picky and honestly ancient Qemu is a pretty solid option to emulate NeXTSTEP/OPENSTEP/Rhapsody with some patches to both 0.8 & 0.9 by Michael Engel, which change a nested interrupt and add support for a busmouse, as the PS/2 mouse doesn’t work for some unknown reason. I know many are scared of old Qemu, but the disk support is pretty solid and the CPU recompilation is very fast, so having to rely on MinGW v3 isn’t so terrible.

While I had hid away a lot of these resources on archive.org, I thought it was best to just go back to the oldest post I had where I had painfully documented how to compile Qemu and get it working with NeXTSTEP, back on BSDnexus. I’m so glad I took the time so long ago to not only write it down, and add screenshots, but also tag the version numbers. Software drift, especially free software can be so difficult to pin down, and it’s nice to be able to return to a known good value. I went ahead and placed the recreated toolchain over on archive.org.

Rhapsody is a weird OS, in that NeXT had kind of given up on the OS market after their NeXT RISC Workstation had basically died with the 88k, and even their early abandoned PowerPC 601 aka MC98000/98601 port. Apple had left a few of the changelogs, in the source code. It’s very interesting stuff! I guess to go off on my own tangent NeXT was just too early, the cube with it’s Unix & magnetic optical media and great audio DSP capabilities was just too ahead of the curve. What the cube couldn’t pull off in 1988, the iMac and OS X sure did in 2001.

I also added UDP support to this Qemu so I could use the HecnetNT bridge trick giving me the ability to telnet/ftp into the VM greatly reducing my pain. Back in the day I had used NFS and the network slirp redirection. But I like having direct access so much more!

Rhapsody throws up yet another fun ‘road block’ in that the mouse buttons map backwards for some reason. It’s a trivial fix in the source code, but I made it a runtime option in case I needed or wanted to run NeXTSTEP. And it was a good thing, as I did need to find the NXLock.h file for building one part of Darwin.

When building Darwin, I started with the last x86 version of NeXTSTEP that was availble, and that was Apple ”Rhapsody” / Titan1U x86 Developer Release 2 from WinWorld. My thinking at the time and still is that the closer you can get your build to whatever they were using as ‘current’ the easier this will be.

Rhapsody can support an 8GB disk, so let’s go with that. This always has an issue with people that try much larger, and just fail, so for my sake and yours let’s just go with 8.

qemu-img.exe create -f vmdk rhapsody.vmdk 8G

And to simply start off the installer:

qemu -L pc-bios -m 128 ^
-k en-us ^
-rhapsodymouse ^
-hda rhapsody.vmdk ^
-cdrom rhapsody_dr2_x86.iso ^
-fda rhapsody_dr2_x86_InstallationFloppy.img ^
-boot a

You may be wondering, why only use 128MB of RAM? Well there is a bug in the shipping Rhapsody kernel that prevents booting on machines with more than 192? MB of RAM. Naturally, once we are to the point of building our own kernels this won’t be a problem but for now we are limited.

The bootloader will give us a few seconds to do anything fancy, I just hit -v so I always have the verbose boot.

From here it’s just a few options to go thru the installer

And a disk change is required

CONTROL+ALT+2 will bring up the monitor prompt, where we can change the disk

CONTROL+ALT+1 will return us to the console. Now we have to go through all the SCSI cards, and kind of compatible IDE cards

Further..

Further still…

And how select the Primary/Secondary(DUAL) EIDE/ATAPI Device Controller (v5.01)

We only need the one driver, so we’re good to go!

Continuing onwards will now start the kernel, along with a change to graphical mode. Just like a NeXT!

Now we can confirm again we want to install

As you can see there is our hard disk!

In the future we don’t need to dual boot so, just give it the entire disk.

A few more 1’s and we are finally installing!

Trust me it’s fast on Qemu!

And just like that, we’ve completed the first part of the install.

You can use CONTROL+ALT+2 to toggle back to the monitor and type in

eject fda

to eject the floppy, then it’s CONTROL+ALT+1 to return to the display and have it reboot. Qemu won’t try to boot to the hard disk, and with no disk in the drive, it’ll hang at the BIOS. Now is a good time to close Qemu and backup the hard disk. Mostly because I hate repeating this stuff.

To try to make this a bit easier, I’ve made a floppy disk with the NE2000 driver and updated kernel in one place where they can be injected via single user mode. A simple enough config file:

qemu -L pc-bios -m 128 ^
-k en-us ^
-rhapsodymouse ^
-hda rhapsody.vmdk ^
-cdrom rhapsody_dr2_x86.iso ^
-fda nic.flp ^
-boot c

Type in -s for SINGLE USER MODE. This is where a lot of Unix problems got solved in the old days

It’s a little tricky as this does involve typing. As instructed we need to check the hard disk prior to mounting it read/write

run the commands:

fsck -y /dev/rhd0a
mount -w /

Now we can mount the floppy disk

mkdir /mnt
mount /dev/fd0a /mnt
ls /mnt

I’ve included both the kernel & NE2000 driver in one file, and JUST the NE2000 driver in the other. For my sake I use the first one, update.tar.gz as I wanted to use the newer kernel ASAP. tar -zxvf didn’t want to run, so I did a rather awkward version to achieve the same thing.

cat /mnt/update.tar.gz | gzip -dc | tar -xvf -

With the files in place, you can now shut down the system with a simple

shutdown -h now

Once more again, I’d shut down the emulator, and backup the hard disk. If anything goes wrong you can restore your backups at any phase, at least saving some time!

Next is the graphical install. In this case I use the hecnet bridge to give full access, you can setup with the slirp driver with a simple “-net user” but it doesn’t matter at the moment Since I opted for the newer kernel, I can take advantage of the 512MB RAM.

qemu -L pc-bios -m 512 ^
-k en-us ^
-rhapsodymouse ^
-hda rhapsody.vmdk ^
-cdrom rhapsody_dr2_x86.iso ^
-fda rhapsody_dr2_x86_InstallationFloppy.img ^
-net nic,model=ne2k_pci,vlan=5 ^
-net socket,udp=0.0.0.0:5001,remote=127.0.0.1:5000 ^
-boot c ^

Booting Rhapsody

Now we have to setup the hardware. It should be somewhat straight forward, first we start with the monitor. The mouse should be working although I find that I have to move slowly. Sorry it tracks weird on real hardware too.

The Cirrus Logic GD5446 should be detected automatically, I just go with the default 1MB

Next under the mice, select the PS/2 mouse and remove it

This leaves us with the Bus Mouse driver.

Under the network tab, the NE2000 should be automatically detected.

On the last tab, I make a habit of removing the Parallel port freeing IRQ 7, in case I wanted it for something else.

Back to the summary, we now have Cirrus Logic video, NE2k networking, with no SCSI, no Audio.

With the config saved, now we can just install as is. I un-installed Japanese, but it doesn’t matter. You absolutely need the Development Tools, so may as well go with eveything.

The installation only takes a few minutes and we are ready to reboot

The kernel will now shut down.

Once more again this is a great time to make another backup of the hard disk. At this point this is a great backup to save, as we’ve installed the OS, and selected drivers, in the next reboot we’ll be personalizing the operating system.

We can re-run the last config once the disk has been saved. We’ll be greeted with a message that the Server isn’t responding. Answer YES to continue without networking.

From here we are in the Setup Assistant, taking a nod from MacOS 8

I use USA keyboards. The best keyboards! I touch type so I don’t have to deal with weird layouts.

Specify for a LAN connection

There is no DHCP support so specify a manual IP address.

The default stuff is just wrong.

On my LAN this is good enough. DONT add a router. It’ll just confuse it.

We don’t have or want NetInfo. This would be the server to give out IP addresses, and authentication. We don’t need it!

Leave the DNS servers blank

You can setup any location, it doesn’t matter.

Likewise, with NTP, turn it off.

We will then get the option to set the date/time manually. The default time is far too old and it’ll break stuff.

Next up is user accounts.

I always make local accounts.

Come up with some creative name

and a password

I don’t have it doing any automatic login. You can if you want, it’s all up to you, this one doesn’t matter.

Next is an Administrator password

And now we can apply our changes.

It takes seconds!

And now we’ere done. You may want yet another backup as this is tedious!

With the final configured backup in hand, now we can boot back one more time, and now we’re in SVGA mode!

Rhapsody DR2 Login Screen

Logging in as root will give me the desktop

Desktop

And there we are, all installed.

For anyone brave enough to have read all of this, but wants the quick and easy version, it’s up on archive.org!

In part two I’ll pick up with the source CD-ROM I’ve prepared, so we can start compiling Darwin!

Darwin 0.3 & 1.0 on Qemu

Darwin 0.3 PowerPC

Interestingly enough a lot of the same weirdness of missing bits I saw on the x86, is also on the PowerPC.

There is no nice installer, the CD image actually boots MacOS 8.6 which currently won’t run on Qemu.  However Darwin 1.0 uses MacOS 9, which will.  There is not install program for Darwin, rather you need a secondary disk, that is partitioned so the volume manager will pick it up, and then you restore a backup onto the target disk.  Naturally the restore program from 0.3 won’t work, but the 1.0 will under the G4 Cube MacOS 9 CD-ROM install.

Also I couldn’t figure out the boot parameters so I used Steve Troughton Smith’s BootX loader https://github.com/steventroughtonsmith/BootX to get the OS booted.

qemu-system-ppc.exe -L pc-bios -drive file=..\darwin03.qcow2,index=0,format=qcow2,media=disk -drive file=BootX_custom.dmg,index=2,format=raw,media=disk -prom-env “boot-device=ide1:2,\BootX” -prom-env “boot-args=-v rd=hd0 debug=0xffe kdp=2” -prom-env “boot-file=ide0:8,\mach_kernel” -M g3beige

It’s a little convoluted but it does work.

I put together a binary package for Qemu on sourceforge here: Darwin03-PowerPC_qemu-2.11_04_22_2018.7z

Currently there is no networking, I’m guessing I need drivers from OS X 1.x but Ive had really bad luck with the mouse to try to open a terminal window to see if the new sungem NIC is functional at all.

Mac OS X Server 1.0 installs on Qemu

OS X Server 1.2 on qemu single user mode

That’s right, the ADB is usable enough now to type and move the mouse, meaning that OS X Server can now be installed within Qemu!

It’s incredibly slow, and the mouse is incredibly jumpy, but it’s actually running!

Basically, like A/UX, you boot up into MacOS to partition the drive.

qemu-system-ppc-screamer.exe -L pc-bios -m 256 -M mac99 -prom-env “boot-args=-v” -prom-env “auto-boot?=true” -prom-env “vga-ndrv?=true” -hda 2GB.vmdk -cdrom “Mac OS X Server 1.2, MOSX_Booter.iso” -sdl -device usb-mouse -device adb-keyboard -boot d

OS X Server 1.2 MacOS 9 Create OS X Server partition

And then kick off the installer:

OS X Server 1.2 MacOS 9 Start Install

Which really isn’t much to do, other than tagging the partition, and prepping the machine to reboot.

It’s OK

Qemu doesn’t emulate the NVRAM, so it’ll complete with this ‘non fatal’ ‘fatal error’

After that, boot into the OS X Server kernel, and continue the install:

qemu-system-ppc.exe -L pc-bios -prom-env “boot-args=-v rd=sd0″ -drive file=2GB.vmdk,index=1,format=vmdk,media=disk -M g3beige -cpu g3 -drive file=”Mac OS X Server 1.2, MOSX_Booter.iso”,index=0,format=raw,media=cdrom -prom-env “boot-device=cd:9,\\:tbxi” -m 256 -net none

OS X Server 1.2 installing text mode

It will then format the disk, and copy over the base operating system.  After that it’s time to shutdown, and reboot the VM.  I couldn’t figure out a pure hard disk boot, but again using the CD-ROM, you can just tell it to pull the root from the hard disk.

qemu-system-ppc.exe -L pc-bios -prom-env “boot-args=-v rd=hd0″ -drive file=2GB.vmdk,index=1,format=vmdk,media=disk -M g3beige -cpu g3 -drive file=”Mac OS X Server 1.2, MOSX_Booter.iso”,index=0,format=raw,media=cdrom -prom-env “boot-device=cd:9,\\:tbxi” -m 256 -net none

OS X Server 1.2 installing

And after this, it’ll want to reboot again.  Launch it up and now we get the initial setup

Setup Assistant

And with that out of the way, we can logon!

And after a while, it’ll load up the desktop

OS X Server 1.2 Desktop

As mentioned above, the mouse is incredibly jittery.  Doing anything graphical is very difficult. But here we are, running OS X/Rhapsody for the PowerPC!

That’s all!

Because the mouse is VERY jumpy at the moment, Im going to make some pre-configured disk images available because running the disk tool under OS 9 is a major pain.  The first image has only been partitioned, while the second has completed the ‘text mode setup’, aka a minimal install.

And that’s it for now!

One of those days.

/*
* Abosolutely brilliant. Assume that sizeof(long) == 4. The author of this
* code should give classes on how to write non-portable code. Other bitches:
*
* (1) assuming that all architectures are big endian
* (2) storing/accessing shorts on unaligned boundaries
* (3) assuming all machines align things to 4 byte boundaries
*
* Define a 2-byte word type and a 4-byte word type.
*/

source – internal.h

sigh.  Anyone have a PDO/Enterprise Objects disc? for some reason I think I need pdo.h

Darwin 0.3 booted multiuser!

Multiuser!

I know it doesn’t look exciting, but really it is!

Darwin03_qemu090_01_5_2017.7z

NetInfo is completely broken, but I just disabled it, I don’t think anyone cares.  It is missing some kernel system call, and copying the one from Rhapsody results in missing calls in the /System library.  So instead of spending more time on it, I just had the startup comment it out.

The headers and spiraling dependencies of things is out of control, so it really needs to be re-built.  But there is enough there for it to boot up, you can telnet into it, and compile simple programs.

As far as I’m aware none of the early Darwin’s ever were released as binary for x86, so I guess that is a nice thing.

The EIDE driver is still busted, I spent a day trying to debug it to come to the conclusion that, yes it does lose interrupts.  While stacking OO drivers to add features sure looks nice, it makes fundamental issues, either in the Driver itself, or the object framework (let’s face it, nothing is defect free) hard for an outsider to find.  From the outside I used to think it was either the DMA or the multisector transfers screwing it up, but with source in hand, disabling both did nothing.

4.4 BSD (darwin) (ttyp0)

login: root
[darwin:~] root# hostinfo
Mach kernel version:
Kernel Release 5.5:
Sun Apr 30 10:53:53 SGT 2017; root(rcbuilder):kernel-7/BUILD/RELEASE_I386
Copyright (c) 1988-1995,1997-1999 Apple Computer, Inc. All Rights Reserved.

Kernel configured for a single processor only.
1 processor is physically available.
Processor type: pentium (Intel Pentium)
Processor active: 0
Primary memory available: 64.00 megabytes.
Default processor set: 40 tasks, 71 threads, 1 processors
Load average: 0.99, Mach factor: 0.00
[darwin:~] root#

For people who like this kind of stuff.  In my limited testing, I found some configure scripts don’t like the idea of a Darwin with a major number of zero.  And seeing that this would fall into place during OS X Server 1.0.2, which makes it Rhapsody 5.5.  I don’t think either of the 1.2 or 1.2v3 Rhapsody 5.6 versions were ever released to the public in source, but maybe someone has a copy somewhere.

And, of course here is a gratuitous dmesg.

Kernel Release 5.5:
Sun Apr 30 10:53:53 SGT 2017; root(rcbuilder):kernel-7/BUILD/RELEASE_I386
Copyright (c) 1988-1995,1997-1999 Apple Computer, Inc. All Rights Reserved.

physical memory = 64.00 megabytes.
using 227 buffers containing 1.27 megabytes of memory
available memory = 59.19 megabytes. vm_page_free_count = 1d99
minimum quantum is 10 ms
Copyright (c) 1982, 1986, 1989, 1991, 1993
The Regents of the University of California. All rights reserved.

PCI Ver=2.10 BusCount=1 Features=[ BIOS16 CM1 ]
Found PCI 2.0 device: ID=0x12378086 at Dev=0 Func=0 Bus=0
Found PCI 2.0 device: ID=0x70008086 at Dev=1 Func=0 Bus=0
Found PCI 2.0 device: ID=0x70108086 at Dev=1 Func=1 Bus=0
Found PCI 2.0 device: ID=0x00a81013 at Dev=2 Func=0 Bus=0
Found PCI 2.0 device: ID=0x802910ec at Dev=3 Func=0 Bus=0
PCI bus support enabled
PnP: Plug and Play support enabled
ISA/EISA bus support enabled
ISA bus
DriverKit version 500
hc0: device detected at port 0x1f0 irq 14
hc0: Checking for ATA drive 0… Detected
hc0: Checking for ATA drive 1…
hc0: Checking for ATAPI drive 1…
hc0: Resetting drives…
Registering: hc0
hd0: QEMU HARDDISK 0.9.0
hd0: 4063 cylinders, 16 heads, 63 spt (disk geometry)
hd0: using multisector (16) transfers.
Registering: hd0
hd0: Device Block Size: 512 bytes
hd0: Device Capacity: 1999 MB
hd0: Disk Label: Disk
hc1: device detected at port 0x170 irq 15
hc1: Checking for ATA drive 0…
hc1: Checking for ATAPI drive 0… Detected
hc1: Checking for ATA drive 1…
hc1: Checking for ATAPI drive 1…
hc1: Resetting drives…
hc1: Drive 0: ATAPI CD-ROM (FAST DRQ, REMOVABLE, CMD PKT LEN=12)
hc1: LBA supported.
hc1: buffer type 3, 512 sectors.
Registering: hc1
IDEDisk: disk 0 is ATAPI
Registering: sc0
sd0: QEMU QEMU CD-ROM 0.9.
Registering: sd0 at Target 0 LUN 0 at sc0
sd0: Disk Not Ready
Registering: fc0
Registering: PS2Controller
Registering: PCKeyboard0
PCI bus support enabled
Registering: PCI0
Registering: EISA0
Registering: event0
Registering: kmDevice0
rootdev 300, howto 40000
BusMouse mouseInit: no resolution in config table. Default is 400
Bus mouse running
Registering: BusMouse
Display0: Cirrus Logic GD5434 detected (2097152 Bytes)
Display0: PCI Dev: 2 Func: 0 Bus: 0
Display: Mode selected: 800 x 600 @ 60 Hz (RGB:256/8)
Registering: Display0
NE2000 Generic Driver v0.9.1b
by Gabor Sebestyen

Vendor: RealTek RTL-8029
BASE: 0xc100; IRQ: 11
Registering: en0
en0: Ethernet address 52:54:00:12:34:56
Device inited…

Updated Darwin 0.3

Darwin03_29_4_2017.7z

It still boots single user mode, one of the source projects has a nice rm -rf $DSTROOT so it nuked what little progress I made during the week.

But I have the compiler running and lots more.  It has issues with netinfo which is really the only thing blocking it from multiuser boot.  Some syscall not found, and I need to dig into the kernel to see if it even exists…

I’ll re-build all the libs and headers.  Oddly enough the disk image I can build libraries and programs can’t build driverkit or the kernel…

Darwin 0.3 single user mode test drive

So I asked around for some old Darwin CD’s and I got lucky!

Darwin 0.3 Front

Volume 1, Summer of 1999!  Although the back doesn’t really give it justice:

Darwin 0.3 back

As you can guess, when they talk about binary and installers, it’s for the PowerMa computers of the era, and not x86.

So once more again, I was able to rebuild a kernel, and build some of the OS.  There isn’t really anything to see, it’s not even slightly usable.  However at the boot loader type in

-s

hit enter, and it’ll boot up in single user mode.

Darwin 0.3 single user mode

Darwin03_qemu090_24_4_2017.7z

There is no games, nothing fun to do, I didn’t even build a compiler.  It’s just enough to show that it’ll boot up.  If you manually conifgure the loop back you can ping yourself, launch inetd you can even try to telnet in, but control break is .. broken, and there is no NetInfo running so no passwords.

Of course for anyone finding this site today there are more newer, and capable images on my sourceforge page:

aapl-darwin/files/qemu-images/

Darwin 0.1 + Rhapsody DR 2 booted!


Following up from yesterday, here we go!

Rhapsody 1.0 booting

So I finally got it running, after some inspiration from NCommander over at nextcomputers.org forums, that the Darwin 0.1 kernel is in fact build-able, I went ahead and took a stab at it.  While he was trying to start from OPENSTEP, I tried it from something as close as I could to the target, which was Rhapsody DR2.

Back in the days of the NeXT / Apple merger, there was hope that OPENTSTEP could become the next great OS for the Apple Macintosh.  It had been a while since NeXT had the OS running so things had rotten somewhat, as time had passed on.  However, the first and most viable platform would of course be the x86.  Back in 1993 while feeling increased pressure in the hardware space, NeXT was forced to start porting away from their black m68k based hardware, and this was an opportunity to get their software running on different platforms.  And sadly in 1993, the NRW aka NeXT RISC Workstation that was in development with dual m88000 processors was killed along with all hardware projects. In the end it didn’t matter as much as the only processor from the early 90’s that has a vibrant future is the i386.

So back again to this transitional time before OS X 10, there were developer versions of this OS seeded out that required you to have an intel machine as OPENSTEP was being ported to the PowerPC machines that Apple was selling.

So, on May 14, 1998, the last public version for the Intel processor was released, DR2.

However, two interesting things happened along the way to what would become OS X Server 1.0 .  The first is that Apple gave up on the ‘yellow box‘ portable API, and to satisfy the GPL requirement to release changes to source code, Apple would go one further and release the source code to many of the internal system utilities, along with the kernel in what was known as Darwin.

This was a big deal for many of us, as the cost of getting the source code to any UNIX was incredibly prohibitive, and OS’s like Linux, NetBSD/OpenBSD/FreeBSD were picking up steam, OPENSTEP being awaken from it’s cryonic hibernation but with the promise of being free and open software was pretty great!  Back in the day it sure looked promising!

Obviously, things didn’t work out as everyone had hoped as Apple either straight up ignored anyone on the outside, or they hired people who showed promise, made them sign NDA’s and were basically never heard from again.

So the recently recovered source code to Darwin 0.1 corresponds with the release of the PowerPC only OS X Server 1.0.  However, as we all found out, Darwin will still built and maintained on Intel, as it was a very secretive plan B, in case something went wrong with the PowerPC platform.  Being portable had saved NeXT before, and now it would save Apple.

So with this little background, and a lot of stumbling around in the dark, I came up with some steps, that have permitted me to build the Darwin 0.1 kernel under DR2.

However, it was not perfect, and the biggest glaring issue was due to the software that was recovered, the layer known as driverkit, (driverkit-139.1-1.tar.gz) turns out to be from another, later release of Darwin, the 0.2 release, which the only thing surviving is the driver kit. Â It doesn’t build cleanly, and In order to get it to build I had to break the mach PCI bus. Â This means that yes, PCI devices will not load at runtime, only at boottime by sald.

After a lot of fighting, I was able to produce a system that could boot into both single user and multiuser mode, although it was unable to load drivers so there was no networking, and no UI.

In a fit of boredom, I built a bunch of the command line tools for Darwin, and a few libraries, and then went to see why the driverkit had a problem finding the reason why KernBus was undefined, or even with some attempts at helping all the methods were unknown, I stumbled onto the fact that during compilation it will generate new headers, and in those headers are the correct interface for driverkit to call into the KernBus.  So, I was able to quickly rebuild driverkit, then re-link into the kernel and now I could load drivers!  Thrilled with this much, I did something more aggressive, I made a dump of my install ‘target’ and then restored it onto an image of my dev VM.  And much to my amazement it booted up to the graphical login.  I now had PCI working correctly.

Darwin 0.1

This kind of thing is not for casual users, but if you install DR2 into a VM, you ought to be able to then use this ISO image, and follow these instructions, and you will then have a DR2 OS from 1998 with the OS X 1.0 kernel from 1999 running. The biggest difference I’ve noticed is that the newer kernel can use 512MB of RAM, a nice bump up from 192 which was the prior limit.

Obviously, there is a lot more work to be done, it’d be nice to find some source to an IDE or other block controller and modify it to work with the massive disks of today, along with the filesystem code to handle partitions larger than 2GB.

Maybe it will be possible to port in the driverkit to XNU, so we can get things like existing drivers, and SMP, massive filesystems etc.. It’s great to see we are going the right way.

For fans, here is a qemu 0.90 image+exe that can run Darwin 0.3 into single user mode.

EDIT and for people still hitting this, here is a multiuser bootable image.  I’ll keep updating on the source forge page.