In compatibility but not in 64-bit 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
WindowsNT
Member
Member
Posts: 77
Joined: Thu Jun 26, 2008 12:55 pm

In compatibility but not in 64-bit mode

Post by WindowsNT »

Hello again.

After a lot of work I 've managed to enter long mode and I am now in compatibility code.
I think I 've defined an entry in the GDT for the 64-bit segment, but it seems that it is not interpreted as so.


1. Are there any differences between a 32-bit segment and a 64-bit segment in GDT apart from setting the D bit to 0?

2. Is the following code correct when jumping from compatibility mode (a 32-bit segment) do an 64-bit mode segment ?

db 0eah
dd LinearAddressOfStart64
dw code64_idx


3. When I want to go back to 32-bit compatibility segment, do I use:

db 0eah
dd AddressOfReturn32 (Not linear!)
dw code32_idx


4. Am I missing something ? It seems that my code64_idx is regarded as a simple 16-bit segment (D == 0) and therefore I cannot enter 64-bit mode, I am just moving around a 32-bit compatibility and a 16-bit compatibility segment.


Thanks a lot for any response.
Michael
thooot
Member
Member
Posts: 30
Joined: Sun Jun 01, 2008 11:20 am

Re: In compatibility but not in 64-bit mode

Post by thooot »

You also need to set the L bit (bit 21) to 1. With L=1, D=0 you will enter 64-bit long mode. I believe your jumps to & from long mode are correct.
WindowsNT
Member
Member
Posts: 77
Joined: Thu Jun 26, 2008 12:55 pm

Re: In compatibility but not in 64-bit mode

Post by WindowsNT »

You are right; that did the trick.

Is there any way to test if i am now in 64-bit mode? I am asking because, when I do something bad in it and an exception occurs, bochs still says "CPU is in compatibility mode (Active)"
WindowsNT
Member
Member
Posts: 77
Joined: Thu Jun 26, 2008 12:55 pm

Re: In compatibility but not in 64-bit mode

Post by WindowsNT »

For example, while in the 64-bit segment, i do this


xor rdx,rdx
mov rdx,0xeeeeeeee00000000
shr rdx,32
mov rax,rdx ; eax should now be 0xeeeeeeee

; Jump to compatibility segment
db 0eah
dd Back32
dw code32_idx

..

Back32:

cmp eax,0xeeeeeeee
jnz Err ; and this jump is executed


I am not sure if the RXX movs above actually are executing, or they are just movs with the REX prefix (that is valid in 16/32 bit segments).
WindowsNT
Member
Member
Posts: 77
Joined: Thu Jun 26, 2008 12:55 pm

Re: In compatibility but not in 64-bit mode

Post by WindowsNT »

OK it now works; I was able to see "Long mode (Active)" in Bochs.


My only last problem is how to return to compatibility

db 0eah -> This is not recognized and I get a crash
WindowsNT
Member
Member
Posts: 77
Joined: Thu Jun 26, 2008 12:55 pm

Re: In compatibility but not in 64-bit mode

Post by WindowsNT »

I believe I 've found it

push code32_idx
xor rcx,rcx
mov rcx,Back32
push rcx
retf


Correct me If I am wrong.
Post Reply