Page 1 of 1

AMD64 Long Mode

Posted: Sat Sep 15, 2007 1:16 pm
by Fetrovsky
Howdy, I just registered as I plan on taking on my OS project seriously now... I'm starting with AMD64, and I printed the manuals from the site. However, I didn't find the sequence to start long mode... Can anybody point me to a tut or a man that says how?

Thanks a lot! and wish me luck :)

- Fetrovsky

im not sure if this is

Posted: Sat Sep 15, 2007 1:31 pm
by com1
im not sure if this is what your asking, but this is how you enable long mode:

disable paging

set the pae enable bit in CR4

load CR3 with physical address of PML4

set EFER.LME flag in msr 0xC00000080

enable paging

Posted: Sat Sep 15, 2007 3:05 pm
by speal
"Everything" you need is available in the AMD documentation on this page:
http://developer.amd.com/devguides.jsp

The long mode startup sequence is outlined in detail in the "AMD64 Architecture Programmer's Manual Volume 2: System Programming Rev 3.13" document, in chapter 14.

If you get totally stuck, you can contact me or take a look at my project here:
http://trac.devlime.com/neptune/browser ... unk/loader

The relevant code is in main.cpp, and loader.asm. You'll notice I've also got a workaround for GRUB's inability to read elf64 files. The 32 bit loader is loaded by grub, which then goes into long mode. It reads the elf64 kernel, passed as a GRUB module, and jumps to it once we're in long mode.

Hope that helps. Feel free to contact me if you're stumped.

Thanks

Posted: Sat Sep 15, 2007 9:40 pm
by Fetrovsky
Thanks a lot guys... I actually found right there in ch14 a piece of code that jumps into 32-bit PM and then 64-bit LM... I am having problems making _that_ code work... I don't know what's wrong....

Posted: Sat Sep 15, 2007 10:45 pm
by Dex
Here are some examples, of entering long mode with fasm:
http://board.flatassembler.net/topic.php?t=6206&start=0
They may help point you in the right direction

Note: to down load the zip file, you need to join.

Posted: Sat Sep 15, 2007 11:11 pm
by speal
Just noticed that the first post is quite old. That's okay, since this should be helpful to anyone looking to move to AMD64 now or in the long run.

Eventually this information should end up in the wiki though...