Page 1 of 1

64bit High Mem kernel

Posted: Sat Mar 01, 2008 6:24 pm
by untwisted
Hey all, been lurking waiting to see if there are any questions I could help with, but I think I'm still a bit too new at the 'game' to help much. In any case, if you would be so kind, I have another question on my hands.

I'm trying to move my kernel to high memory via ld script. I have checked out the wiki on how to do it with a 32 bit kernel, but to make the jump long mode we need paging enabled, which means (if I'm understanding it correctly) that the trick won't work for x86_64. I tried to fudge with some linker scripts to place part of our code in low mem, and the rest in high mem, but it doesn't seem to work. I created a new section right before the jump to 64 bit code in my boot.S and tried to load that and everything after it in to high mem, but am getting some relocation errors.

If anyone could point me in the right direction on how to move my kernel it'd be much appreciated :)

Thanks!

Posted: Sat Mar 01, 2008 8:02 pm
by SpooK
I think THIS THREAD may assist you.

Posted: Sat Mar 01, 2008 11:53 pm
by speal
I've set up an upper-memory kernel (long mode).

My linker script is here:
http://www.devlime.com/browser/trunk/ke ... /linker.ld

The executable is linked to a physical address of 0x1000000, but a virtual address 0xFFFFFFFF80000000

The booting process (using GRUB) is:

1. Start a 32 bit stub kernel with GRUB, and pass in the 64 bit kernel as as multiboot module
2. Set up a top level page directory (long mode paging) and GDT
3. The 32 bit loader reads modules, copies the kernel to its specified physical address and maps these pages to the specified virtual address range
4. Identity map physical memory up to the top of the stub kernel executable
5. Enable long mode, and then turn on paging to make the long mode switch
6. Do a long jump to another part of the loader, using the 64 bit code segment
7. Jump to the 64 bit kernel's entry address

Posted: Sun Mar 02, 2008 9:07 am
by untwisted
Thanks for the info! We weren't sure if we could just use the linker script and place our output in two different places or if we'd have to take the route that you went. With limited time we only had a chance to try one of them, and when that failed abysmally I figured I'd come ask before we sat around breaking things for too much longer.

You guys are great! <3