Linking, loading, and the higher half kernel

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
duran
Posts: 22
Joined: Mon Jun 02, 2008 5:22 pm
Location: Sydney, Australia

Linking, loading, and the higher half kernel

Post by duran »

Afternoon osdevers,

A problem I've been having now that I've managed to get my head around interrupt servicing:

If I compile and link my kernel to be loaded to 1MiB, it is loaded at 1MiB in RAM. How then do I relocate it to the higher half of the virtual address space without having to recompute every symbol offset within? Even if I save myself some difficulty and build the image as an elf32 or similar, what is the proper method to do this? Do I need to write my own linker/loader routines already before I can move?

Or am I looking at this wrong, and all I need to do is memcpy the kernel image to the higher half and remap the page table to suit?
shikhin
Member
Member
Posts: 274
Joined: Sat Oct 09, 2010 3:35 am
Libera.chat IRC: shikhin
Contact:

Re: Linking, loading, and the higher half kernel

Post by shikhin »

Hi,
duran wrote:If I compile and link my kernel to be loaded to 1MiB, it is loaded at 1MiB in RAM. How then do I relocate it to the higher half of the virtual address space without having to recompute every symbol offset within? Even if I save myself some difficulty and build the image as an elf32 or similar, what is the proper method to do this?
The simplest option would be to compile and link the kernel to be loaded at whatever higher half address you chose (let's assume 0xC0000000). Then, ask GRUB (I assume you are using GRUB) to load your kernel at the 1MiB mark. There, a position independent assembly stub could enable paging to make 0xC0000000 point to the 1MiB mark, and jump to the real kernel.

Some people also use the GDT trick, which is explained at http://wiki.osdev.org/Higher_Half_With_GDT

Regards,
Shikhin
http://shikhin.in/

Current status: Gandr.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Linking, loading, and the higher half kernel

Post by gerryg400 »

Another way is to use a multistage loader. The loader is starts at 1MB and it loads the kernel at the correct higher half address.
If a trainstation is where trains stop, what is a workstation ?
Post Reply