Page 1 of 1

In compatibility but not in 64-bit mode

Posted: Sat Jul 05, 2008 3:11 pm
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

Re: In compatibility but not in 64-bit mode

Posted: Sat Jul 05, 2008 11:27 pm
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.

Re: In compatibility but not in 64-bit mode

Posted: Sat Jul 05, 2008 11:41 pm
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)"

Re: In compatibility but not in 64-bit mode

Posted: Sat Jul 05, 2008 11:58 pm
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).

Re: In compatibility but not in 64-bit mode

Posted: Sun Jul 06, 2008 12:17 am
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

Re: In compatibility but not in 64-bit mode

Posted: Sun Jul 06, 2008 12:20 am
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.