Jump to Long Mode Segment

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
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Jump to Long Mode Segment

Post by AJ »

Hi,

I am not there with the implementation yet, but am thinking about the design of the second-stage boot loader for my 64 bit OS. This is probably a simple yes/no answer, but can I do the following from 64-bit compatiblity mode:

Code: Select all

jmp [long mode segment]:[64 bit offset]
or will I have to initially jump to a 32 bit offset to enable long mode and do a second jump to a 64 bit offset once long mode is enabled?

Thanks for any help,
Adam
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Jump to Long Mode Segment

Post by Brendan »

Hi,
AJ wrote:I am not there with the implementation yet, but am thinking about the design of the second-stage boot loader for my 64 bit OS. This is probably a simple yes/no answer, but can I do the following from 64-bit compatiblity mode:

Code: Select all

jmp [long mode segment]:[64 bit offset]
Simple answer is "no" - a (32-bit or 16-bit) compatability code segment in long mode can't use REX prefixes, and therefore can't use 64-bit addressing.

The more complex answer would be that you might be able to fake it by doing a SYSCALL (without any SYSRET) or a software interrupt (without any IRET), where the target code removes anything the CPU pushed on the stack. This is probably more hassle than it's worth though...


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Hi,

As I hadn't used syscall/sysret before, I was a little unsure about what to do here. For anyone else trying the same thing, I have just implemented the syscall mechanism to call my kernel which is at 0xF000000000 from 32 bit code and it works very nicely.

Thanks Brendan,
Adam
Post Reply