AMD64 Long Mode

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
Fetrovsky
Posts: 3
Joined: Thu Oct 21, 2004 11:00 pm

AMD64 Long Mode

Post 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
com1
Member
Member
Posts: 105
Joined: Sat Apr 28, 2007 11:57 am
Location: TN

im not sure if this is

Post 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
oh microsoft, microsoft, what souls you have dismayed
speal
Member
Member
Posts: 43
Joined: Wed Mar 07, 2007 10:09 am
Location: Minneapolis, Minnesota
Contact:

Post 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.
Fetrovsky
Posts: 3
Joined: Thu Oct 21, 2004 11:00 pm

Thanks

Post 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....
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post 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.
speal
Member
Member
Posts: 43
Joined: Wed Mar 07, 2007 10:09 am
Location: Minneapolis, Minnesota
Contact:

Post 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...
Post Reply