Copy Link
Add to Bookmark
Report
Bootstrap Idea for Linux - 2
written by Michael Steil, 2 June 2002
My proposal for booting Linux from within the Xbox kernel uses many ideas of anonymous' ideas, but might be simpler, because we do not have to defragment the Linux kernel and we can stay in Protected Mode.
Using MmMapIoSpace, we can get a window in virtual memory straight through to physical memory. The Linux kernel needs to be at 1 MB in physical memory in order to get started, so we use this call to be able to copy it there directly without having to defragment it. But there are some problems:
- we might overwrite parts of the NT kernel
- we might overwrite parts of our own code
- we might overwrite parts of the Linux kernel already in memory
- we might overwrite parts of the NT pagetables
That's why we do the following:
- Keep allocating 4 KB pages of memory between 1 MB and 2 MB in physical memory using MmAllocateContiguousEx until all memory there is allocated.
- Allocate 1 MB or virtual memory and put the Linux kernel there. Overwriting Linux will not be possible any more.
- Disable interrupts. Overwriting NT will not matter any more.
- Create a window through to physical memory between 1 MB - 2 MB using MmMapIoSpace. (We must ensure that our bootloader code does not reside between 1 MB and 2 MB in virtual address space, but this is easy: We can put our address in virtual memory into the XBE header.)
- Copy the rest of our code into the last page of 1 MB - 2 MB and jump there. (Hopefully we will not overwrite our current pagetables - but this is very unprobable.)
- Copy the Linux kernel image to 1 MB (again: pagetables?)
- Turn off paging
- Load the new GDT and IDT Linux expects
- Jump to 0x10:0x100000, i.e. run Linux
If we want to use an initial RAM disk, we need a larger window, but the reat basically stays the same.