# Linux Kernel Module Cheat

## 20. Xen

https://en.wikipedia.org/wiki/Xen

TODO: get prototype working and then properly integrate:

    ./build-xen

Source: build-xen

This script attempts to build Xen for aarch64 and feed it into QEMU through submodules/boot-wrapper-aarch64

TODO: other archs not yet attempted.

The current bad behaviour is that it prints just:

    Boot-wrapper v0.2

and nothing else.

We will also need `CONFIG_XEN=y` on the Linux kernel, but first Xen should print some Xen messages before the kernel is ever reached.

If we pass to QEMU the xen image directly instead of the boot wrapper one:

    -kernel ../xen/xen/xen

then Xen messages do show up! So it seems that the configuration failure lies in the boot wrapper itself rather than Xen.

Maybe it is also possible to run Xen directly like this: QEMU can already load multiple images at different memory locations with the generic loader: https://github.com/qemu/qemu/blob/master/docs/generic-loader.txt which looks something along:

    -kernel file1.elf -device loader,file=file2.elf

so as long as we craft the correct DTB and feed it into Xen so that it can see the kernel, it should work. TODO does QEMU support patching the auto-generated DTB with pre-generated options? In the worst case we can just dump it hand hack it up though with `-machine dumpdtb`, see: Section 9.4, “Device tree emulator generation”.

Bibliography:

- this attempt was based on: https://wiki.xenproject.org/wiki/Xen_ARM_with_Virtualization_Extensions/FastModels which is the documentation for the ARM Fast Models closed source simulators.

- https://wiki.xenproject.org/wiki/Xen_ARM_with_Virtualization_Extensions/qemu-system-aarch64 this is the only QEMU aarch64 Xen page on the web. It uses the Ubuntu aarc64 image, which has EDK2.

  I however see no joy on blobs. Buildroot does not seem to support EDK 2.

Link on readme https://stackoverflow.com/questions/49348453/xen-on-qemu-with-arm64-architecture