I want to port the xnu
kernel to the ARM architecture, with the ultimate goal of being able to run a full kernel inside Qemu. While I do realise that this is a very difficult task, I still want to have a go at it.
As far as I know, you're meant to write an entry point for the kernel (osfmk/arm/start.s
) where you do general initialisation (MMU and PlatformExpert) after which the Kext/IOKit subsystems can be started and load CPU specific extensions (ie. traps, GPIO, clock) which are either prelinked into the binary or loaded by the bootloader (because the kernel can't interact with the filesystem due to the NAND extensions not being available yet).
While I do have a general idea on how ARM CPUs work, I don't even know where to get started with the xnu
port, because I'm not entirely sure how to:
osfmk/kern
is working).machine_startup()
);osfmk/platform_name
but some of it has to be integrated into osfmk/kern
and others).Are there any decent guides on porting the XNU (or at least Mach) kernel to different platforms, just like there are Linux guides?
Can't give you an answer, but a few hints:
The "big guys" do this sort of work on a system with special hardware attached that allows the processor to be single-cycled, the registers examined, etc. And they may do much of the work on an emulator that has the same facilities. The hardware debugger setup is probably outside your capabilities to build (and a bit expensive to buy), but the emulator is entirely feasible (and is how Gates and Allen got started on Altair BASIC -- if Allen hadn't written the emulator Gates would still be playing video games at Harvard).
Short of a full debugger, if you have any sort of character display attached, you can embed instructions in the code being debugged to write characters to the display as the code progresses. Path A may write "A" in the next location (an index kept in a reserved memory word somewhere) while path B would write "B", etc. Very crude, but it's sometimes enough to get by for small projects.
So I guess I'd recommend writing the emulator first. It's a good way to become familiar with the processor anyway.
(As to integrating stuff, I always just say "Hey, Jeremy! Integrate this for me, will you?")
You will encounter a bit of a challenge as not all of the source code is available. Part of the source code of the Platform expert is available as part of the xnu sources, however the com.apple.driver.AppleACPIPlatform.kext is not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With