I want to learn something about OS and networking with Xinu. I downloaded the source code from the xinu-os repo on github (up to 4d489eead3a49170f69041b959bd5a1bd8dff92d) and compiled xinu.boot and xinu.elf myself. To really get down to it, I wanted to do some modify-and-test. So my goal (and also the goal of this question) was to boot xinu in VBox.
To explain things a bit, I know that on the Xinu Page, there is a Versions of Xinu for a VM along with instructions item under the Code Available For Download section, which includes a VBox version (I will refer to it as the VBox version below). The reason I do not want to use that version is that it does not include as many features as in the code in github. I also know that there is a boot.xinu-os.org project in github, which advertises to be able to boot xinu in a javascript PC emulator. The reason I do not want to use that is because there seems to be some limitations, and I thought there could be more problems than the conventional way (maybe not). So I thought I could compile my own binaries with the code from the xinu-os repo, and easily ran them in a similar way as the VBox version in VBox, but I seemed to be wrong.
The VBox version from the Xinu page is using pxe and grub to boot. What I did was the following:
I followed the Multiboot Specification#OS-image-format, and added the required header to the end of _start, to make the binary multiboot-compliant:
/* /xinu/loader/platforms/x86/start.S
* ...
* #define MULTIBOOT_HEADER_MAGIC 0x1BADB002
* #define MULTIBOOT_HEADER_FLAGS 0x00000003
* _start:
* ...
*/
jmp startup
/* Enable multiboot support */
.align 4
.long MULTIBOOT_HEADER_MAGIC
.long MULTIBOOT_HEADER_FLAGS
.long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
I built my Xinu.boot
and Xinu.elf
out of the modified code.
Xinu.boot
used in the VBox version, and found that it was an 32bit elf for i386, but the Xinu.boot
I built with the Makefile was made from objcopy, while the Xinu.elf
was an elf. So I renamed Xinu.elf
I built to Xinu.boot
, and substituted it for that in the VBox version.Xinu.boot
, in the same environment.So my major question is what is the fundamental difference between my Xinu.boot
and that in the VBox version that prevents mine from pxe booting? Can anyone shed some light on it?
It took me a lot of readings and experiments to get there. My goal is still to run the Xinu I built myself, modify and test it. It does not need to be boot with pxe, but I hope I can run it in VBox rather than on some real hardware. My other questions are:
Xinu.boot
to boot? Because I tried to search for xinu in the files, but got nothing.kprintf
in the start.S, but got nowhere. I also tried to gdb Xinu.elf
, but it gave me a segmentation fault after running a few instructions. And why it cannot be debugged in gdb? (I am a newbie to assembly. So please explain.)I know my questions may be special and complex, and I am so awkward to express them in English. Any help will be greatly appreciated! Thanks in advance!
After quite a lot of reading, now I can successfully run the github version xinu in QEMU. This is how I did it:
After making, run with xinu with:
qemu-system-i386 -kernel xinu.elf
CTRL-ALT-3
, there will you find it!Booting with QEMU, you skip grub, together with any issues grub causes.
QEMU also makes it convenient for debugging. If you run xinu with:
qemu-system-i386 -s -S -kernel xinu.elf
QEMU will start and pause before any instruction is run (check the QEMU manual for more details about the parameters). Then, you can start gdb and attach to it by:
gdb xinu.elf
And after gdb starts, issue:
target remote localhost:1234
You will attach gdb onto the QEMU process running xinu. You can do whatever you normally do with gdb, such as setting breakpoints, displaying registers, or disassembling, etc. When all is done, issue c
(continue
) to kick off.
You may find that you cannot display the CRx
registers with gdb. You can do that with QEMU directly. Press CTRL-ALT-2
in the QEMU window, you will be put into a console, where you can issue:
info registers
And you will get all registers including the CRx
ones. There are more commands can be issued in that console. help
will give you more info about them.