I'm working on making my own boot loader and kernel in D, and I've come across a stumbling block.
Background:
- I'm writing everything from scratch. So the boot sector is in assembly. And I'm not using GRUB.
- I'm using Qemu for testing.
- The boot sector reads the kernel from the "disk" (which is currently just a flat binary file, whose first sector is the boot loader and the rest of which is the kernel code) into virtual address 0xC0000000, and calls
kmain(), the entrypoint of my kernel. - I'm using the PE file format for my kernel. (Please don't tell me to use Elf -- my choice is PE.)
The Problem
It's part of the kernel's job to be able to load PE files. So how do I load the kernel itself into memory in the first place, so that it can actually execute correctly?
I can't do this from the boot sector because (1) it doesn't fit in 512 bytes, and (2) it's painful to do in assembly. Obviously, I can't do it in the kernel itself either. So how should I do this?
ntoskrnl.exe) is a valid PE file... isn't it? - user541686