Higher Half Tutorial - Loading Kernel as GRUB module
Posted: Fri May 02, 2014 9:47 am
Hey guys,
I've written a loader (that must be loaded by GRUB) to get my kernel to the higher memory. It basically does the following:
- sets up an initial GDT
- creates a bitmap of all free pages for a simple physical page allocator (which uses GRUBs memory map to check what is free)
- enables paging, recursively mapping the directory to itself in the last entry
- checks if there is a GRUB module with the path "/boot/kernel" ELF binary and creates the virtual image of that binary
- sets up and initial kernel stack and calls the entry method of the binary. the entry must then simply accept 1 parameter of the type "SetupInformation*", which points to a struct that contains all information the kernel later needs: its reserved area (for example 0xC0000000 - 0xC0030000), the location of the initial kernel stack (for example 0xC0031000), and the location of the bitmap (which is still in the lower half and must be copied) [and I will add the Multiboot data, too].
Then the only thing you must do to get a higher half kernel is compile your kernel as an ELF binary, which has a start address in the higher half, and add it with the loader binary into your image, and tell GRUB to boot the loader binary. Then use the setup information (copy needed multiboot data, copy the bitmap) and initialize like a bare bones kernel.
Now I have basically two questions:
1. Should I write a Wiki article (/edit the existing "Higher Half Kernel" article) about how to do this? Because I think that this is a little more advanced, I would not provide code examples, but only give instructions on what steps should (or at least could) be done to develop such a loader
2. Should I release the binary of the loader? This would allow anyone to create a higher half kernel by just compiling their kernel as an ELF binary, virtual linking to the higher half, with an entry point of the signature "void loadKernel(SetupInformation* info)" and voila, there is the higher half kernel, already with paging setup. From there on you can continue by loading a new GDT, setting up interrupts and so on. I don't think that releasing the source is a good idea, because if you know how stuff works, you can simply follow the tutorial (1.) and write your own loader.
What do you think?
Greets
I've written a loader (that must be loaded by GRUB) to get my kernel to the higher memory. It basically does the following:
- sets up an initial GDT
- creates a bitmap of all free pages for a simple physical page allocator (which uses GRUBs memory map to check what is free)
- enables paging, recursively mapping the directory to itself in the last entry
- checks if there is a GRUB module with the path "/boot/kernel" ELF binary and creates the virtual image of that binary
- sets up and initial kernel stack and calls the entry method of the binary. the entry must then simply accept 1 parameter of the type "SetupInformation*", which points to a struct that contains all information the kernel later needs: its reserved area (for example 0xC0000000 - 0xC0030000), the location of the initial kernel stack (for example 0xC0031000), and the location of the bitmap (which is still in the lower half and must be copied) [and I will add the Multiboot data, too].
Then the only thing you must do to get a higher half kernel is compile your kernel as an ELF binary, which has a start address in the higher half, and add it with the loader binary into your image, and tell GRUB to boot the loader binary. Then use the setup information (copy needed multiboot data, copy the bitmap) and initialize like a bare bones kernel.
Now I have basically two questions:
1. Should I write a Wiki article (/edit the existing "Higher Half Kernel" article) about how to do this? Because I think that this is a little more advanced, I would not provide code examples, but only give instructions on what steps should (or at least could) be done to develop such a loader
2. Should I release the binary of the loader? This would allow anyone to create a higher half kernel by just compiling their kernel as an ELF binary, virtual linking to the higher half, with an entry point of the signature "void loadKernel(SetupInformation* info)" and voila, there is the higher half kernel, already with paging setup. From there on you can continue by loading a new GDT, setting up interrupts and so on. I don't think that releasing the source is a good idea, because if you know how stuff works, you can simply follow the tutorial (1.) and write your own loader.
What do you think?
Greets