Migrating a kernel to another architecture?

I want to port the xnu core to the ARM architecture, with the ultimate goal of running the full core inside Qemu. Although I really understand that this is a very difficult task, I still want to go for it.

As far as I know, you should write an entry point for the kernel ( osfmk/arm/start.s ) where you perform general initialization (MMU and PlatformExpert), after which you can start the Kext / IOKit subsystems and load the processor-specific extensions (i.e. traps, GPIO, clocks), which are either pre-tied to a binary file or loaded by the bootloader (because the kernel cannot interact with the file system due to the inaccessibility of NAND extensions).

As long as I have a general idea of ​​how ARM processors work, I don’t even know where to start with xnu port, because I'm not quite sure how:

  • Low level debugging (since kernel debugging tools are not available at the start of the run).
  • Integrate the ARM branch with the rest of the kernel source tree (i.e. make sure the stuff in osfmk/kern works).
  • Create a normal environment to start an independent kernel ( machine_startup() );
  • Correct some platform specific code inside the core kernel code (most platform code is limited to osfmk/platform_name , but part of it must be integrated into osfmk/kern and others).

Are there any decent manuals for porting the XNU kernel (or at least Mach ) to different platforms, as well as Linux manuals?

+6
source share
2 answers

I can not give you an answer, but a few tips:

Big Guys do such work in a system with special hardware that allows the processor to be single-cycle, check registers, etc. And they can do most of the work on an emulator that has the same objects. Installing a hardware debugger is probably beyond your ability to create (and a little more expensive to buy), but the emulator is quite feasible (and how Gates and Allen started working on Altair BASIC - if Allen hadn't written the Gates emulator still play video games at Harvard) .

With the exception of the full debugger, if you have any type of character mapping, you can embed instructions in debugged code to write characters to the display as the code moves. Path A can write β€œA” in the next place (the index is stored somewhere in the reserved memory word), while path B will write β€œB”, etc. Very rude, but sometimes enough to make do for small projects.

So, I would prefer to write an emulator first. This is a good way to get to know the processor.

(Regarding the integration of things, I always just say "Hey Jeremy! Integrate this for me, right?")

+2
source

You will encounter some problem, because not all source codes are available. Part of the source code for the platform expert is available as part of the xnu sources, however com.apple.driver.AppleACPIPlatform.kext is not.

+1
source

Source: https://habr.com/ru/post/904380/


All Articles