Jonathan Wilson wrote:
I think freeldr shoudl be modified to PE load the boot drivers and ntoskrnl, instead of just memory dumping. This should remove most of the bss hacks which use kernel_base, and the rest should use whatever freeldr pushes on the loader_block. For now, we were simply testing some things, and Royce's patch still helps a lot.
How does windows do this? I gather it does this through NTLDR but what does NTLDR do here?
While I haven't really verified this, so I can't be 100% sure, I strongly suspect it does the Right Thing(tm) - PE loads the modules.
This discussion has been going round and round since basically the time I got kernel+hal to compile with MSVC. I had to do some seriously cludgy hackery to
1) "inject" the multiboot header (which is basically just a few bytes telling multiboot "load this image at this hardware address, clean the memory between x and y for BSS use, and then jump to this absolute address afterwards - much like the C64 loaded and ran binary images), and
2) in-place relocate ntoskrnl.exe (this is before paging is turned on, why it was a little tricky to do from a combination of C and inline assembler :-) ). The MinGW build don't have this "problem", since it uses page-sized section alignment (meaning its layout is quite different from a kernel image from an NT system), and depended on GCC-internal stuff to get BSS segment and so on.
The solution is quite obvious: Create a small loader that is multiboot-able (and get loaded by the multiboot-loader loading boot program), that in turn loads the kernel(+hal IIRC) and relocates, makes sure BSS is zero, and jumps to the PE-designated entry-point.
/Mike